diff options
Diffstat (limited to 'libdbusmenu-gtk')
-rw-r--r-- | libdbusmenu-gtk/parser.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index b0a5cfd..8954d64 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -345,6 +345,23 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) return; } +static gchar * +sanitize_label_text (const gchar * label) +{ + /* Label contains underscores, which we like, and pango markup, + which we don't. */ + gchar * sanitized = NULL; + GError * error = NULL; + if (pango_parse_markup (label, -1, 0, NULL, &sanitized, NULL, &error)) { + return sanitized; + } + else { + g_warning ("Could not parse '%s': %s", label, error->message); + g_error_free (error); + return g_strdup (label); + } +} + /* Turn a widget into a dbusmenu item depending on the type of GTK object that it is. */ static DbusmenuMenuitem * @@ -428,9 +445,9 @@ construct_dbusmenu_for_widget (GtkWidget * widget) { // Sometimes, an app will directly find and modify the label // (like empathy), so watch the label especially for that. - dbusmenu_menuitem_property_set (mi, - "label", - gtk_label_get_text (GTK_LABEL (label))); + gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (label))); + dbusmenu_menuitem_property_set (mi, "label", text); + g_free (text); pdata->label = label; g_signal_connect (G_OBJECT (label), @@ -673,9 +690,11 @@ label_notify_cb (GtkWidget *widget, if (pspec->name == g_intern_static_string ("label")) { + gchar * text = sanitize_label_text (gtk_label_get_label (GTK_LABEL (widget))); dbusmenu_menuitem_property_set (child, DBUSMENU_MENUITEM_PROP_LABEL, - gtk_label_get_text (GTK_LABEL (widget))); + text); + g_free (text); } } @@ -729,9 +748,11 @@ action_notify_cb (GtkAction *action, } else if (pspec->name == g_intern_static_string ("label")) { + gchar * text = sanitize_label_text (gtk_action_get_label (action)); dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_LABEL, - gtk_action_get_label (action)); + text); + g_free (text); } } |