From 1edc78050399e0e88f4ef8b59f66c649e4862b89 Mon Sep 17 00:00:00 2001 From: Luke Yelavich Date: Tue, 31 Jan 2012 18:32:11 +1100 Subject: When parsing an existing GTK menu hierarchy, we should also set the DBUSMENU_MENU_ITEM_ACCESSIBLE_DESC property, if the accessible name for the menu differs from the text of the menu item label. --- libdbusmenu-gtk/parser.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'libdbusmenu-gtk/parser.c') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 0ecfa1e..65a6b57 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -41,6 +41,7 @@ typedef struct _ParserData GtkWidget *widget; GtkWidget *shell; GtkWidget *image; + AtkObject *accessible; } ParserData; typedef struct _RecurseContext @@ -67,6 +68,9 @@ static void image_notify_cb (GtkWidget * widget, static void action_notify_cb (GtkAction * action, GParamSpec * pspec, gpointer data); +static void a11y_name_notify_cb (AtkObject * accessible, + GParamSpec * pspec, + gpointer data); static void item_inserted_cb (GtkContainer * menu, GtkWidget * widget, #ifdef HAVE_GTK3 @@ -200,6 +204,12 @@ parse_data_free (gpointer data) g_object_remove_weak_pointer(G_OBJECT(pdata->image), (gpointer*)&pdata->image); } + if (pdata != NULL && pdata->accessible != NULL) { + g_signal_handlers_disconnect_matched(pdata->accessible, (GSignalMatchType)G_SIGNAL_MATCH_FUNC, + 0, 0, NULL, G_CALLBACK(a11y_name_notify_cb), NULL); + g_object_remove_weak_pointer(G_OBJECT(pdata->accessible), (gpointer*)&pdata->accessible); + } + g_free(pdata); return; @@ -582,6 +592,27 @@ construct_dbusmenu_for_widget (GtkWidget * widget) mi); g_object_add_weak_pointer(G_OBJECT (label), (gpointer*)&pdata->label); + AtkObject *accessible = gtk_widget_get_accessible (widget); + if (accessible) + { + // Getting the accessible name of the Atk object retrieves the text + // of the menu item label, unless the application has set an alternate + // accessible name. + const gchar * label_text = gtk_label_get_text (GTK_LABEL (label)); + const gchar * a11y_name = atk_object_get_name (accessible); + if (g_strcmp0 (a11y_name, label_text)) + dbusmenu_menuitem_property_set (mi, "accessible-desc", a11y_name); + + // An application may set an alternate accessible name in the future, + // so we had better watch out for it. + pdata->accessible = accessible; + g_signal_connect (G_OBJECT (accessible), + "accessible-name", + G_CALLBACK (a11y_name_notify_cb), + mi); + g_object_add_weak_pointer(G_OBJECT (accessible), (gpointer*)&pdata->accessible); + } + if (GTK_IS_ACTIVATABLE (widget)) { GtkActivatable *activatable = GTK_ACTIVATABLE (widget); @@ -947,6 +978,28 @@ action_notify_cb (GtkAction *action, } } +static void +a11y_name_notify_cb (AtkObject *accessible, + GParamSpec *pspec, + gpointer data) +{ + DbusmenuMenuitem *item = (DbusmenuMenuitem *)data; + GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible)); + GtkWidget *label = find_menu_label (widget); + const gchar *label_text = gtk_label_get_text (GTK_LABEL (label)); + const gchar *name = atk_object_get_name (accessible); + + /* If an application sets the accessible name to NULL, then a subsequent + * call to get the accessible name from the Atk object should return the same + * string as the text of the menu item label, in which case, we want to clear + * the accessible description property of the dbusmenu item. + */ + if (!g_strcmp0 (name, label_text)) + dbusmenu_menuitem_property_set (item, "accessible-desc", NULL); + else + dbusmenu_menuitem_property_set (item, "accessible-desc", name); +} + static void item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data) { -- cgit v1.2.3 From 03819d755f5c8380b48bca51599981e205c066f4 Mon Sep 17 00:00:00 2001 From: Luke Yelavich Date: Wed, 1 Feb 2012 09:51:00 +1100 Subject: Fix up monitoring of the atk object, didn't understand that notification was the same as the GTK widgets as well. --- libdbusmenu-gtk/parser.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk/parser.c') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 65a6b57..06eabba 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -607,7 +607,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) // so we had better watch out for it. pdata->accessible = accessible; g_signal_connect (G_OBJECT (accessible), - "accessible-name", + "notify", G_CALLBACK (a11y_name_notify_cb), mi); g_object_add_weak_pointer(G_OBJECT (accessible), (gpointer*)&pdata->accessible); @@ -994,10 +994,13 @@ a11y_name_notify_cb (AtkObject *accessible, * string as the text of the menu item label, in which case, we want to clear * the accessible description property of the dbusmenu item. */ - if (!g_strcmp0 (name, label_text)) - dbusmenu_menuitem_property_set (item, "accessible-desc", NULL); - else - dbusmenu_menuitem_property_set (item, "accessible-desc", name); + if (pspec->name == g_intern_static_string ("accessible-name")) + { + if (!g_strcmp0 (name, label_text)) + dbusmenu_menuitem_property_set (item, "accessible-desc", NULL); + else + dbusmenu_menuitem_property_set (item, "accessible-desc", name); + } } static void -- cgit v1.2.3 From 4b30d2a7628d7e9b117da392a8f93325e4aa2e38 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 10 Feb 2012 10:16:45 -0600 Subject: Adding a detail hint on the notify signal --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk/parser.c') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 06eabba..4fb366a 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -607,7 +607,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) // so we had better watch out for it. pdata->accessible = accessible; g_signal_connect (G_OBJECT (accessible), - "notify", + "notify::accessible-name", G_CALLBACK (a11y_name_notify_cb), mi); g_object_add_weak_pointer(G_OBJECT (accessible), (gpointer*)&pdata->accessible); -- cgit v1.2.3 From 7174e85c2dd89f6b3ae2fa5a3ba5a70d06b3ca1a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 10 Feb 2012 10:19:20 -0600 Subject: Use the #define property name instead of a string --- libdbusmenu-gtk/parser.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk/parser.c') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 4fb366a..3cf09b2 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -601,7 +601,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) const gchar * label_text = gtk_label_get_text (GTK_LABEL (label)); const gchar * a11y_name = atk_object_get_name (accessible); if (g_strcmp0 (a11y_name, label_text)) - dbusmenu_menuitem_property_set (mi, "accessible-desc", a11y_name); + dbusmenu_menuitem_property_set (mi, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC, a11y_name); // An application may set an alternate accessible name in the future, // so we had better watch out for it. @@ -997,9 +997,9 @@ a11y_name_notify_cb (AtkObject *accessible, if (pspec->name == g_intern_static_string ("accessible-name")) { if (!g_strcmp0 (name, label_text)) - dbusmenu_menuitem_property_set (item, "accessible-desc", NULL); + dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC, NULL); else - dbusmenu_menuitem_property_set (item, "accessible-desc", name); + dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC, name); } } -- cgit v1.2.3