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 ++++++++++++++++++++++++++++++++++++++++++++++++ libdbusmenu-gtk/parser.h | 1 + 2 files changed, 54 insertions(+) (limited to 'libdbusmenu-gtk') 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) { diff --git a/libdbusmenu-gtk/parser.h b/libdbusmenu-gtk/parser.h index 97fa9c6..191a8ac 100644 --- a/libdbusmenu-gtk/parser.h +++ b/libdbusmenu-gtk/parser.h @@ -31,6 +31,7 @@ License version 3 and version 2.1 along with this program. If not, see #include #include +#include G_BEGIN_DECLS -- 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') 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') 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') 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 From c0f0a8f2cc4adf48ea56ea0296037c00fe6c2c5c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 10 Feb 2012 10:22:34 -0600 Subject: Don't pass a NULL name to set_name --- libdbusmenu-gtk/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 14c71ab..71b2456 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -747,7 +747,7 @@ menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * variant, Db } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_DISPOSITION)) { process_disposition(mi, gmi, variant, gtkclient); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC)) { - atk_object_set_name(gtk_widget_get_accessible(GTK_WIDGET(gmi)), variant == NULL ? NULL : + atk_object_set_name(gtk_widget_get_accessible(GTK_WIDGET(gmi)), variant == NULL ? "" : g_variant_get_string(variant, NULL)); } -- cgit v1.2.3 From 74aa7ec5b2b0854fd053f627fed224c6035147d5 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 10 Feb 2012 10:27:31 -0600 Subject: Refactor setting the ATK Object name into a function that can do all the error handling needed. --- libdbusmenu-gtk/client.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 71b2456..927f0ae 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -725,6 +725,26 @@ process_disposition (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * varian return; } +/* Process the accessible description */ +static void +process_a11y_desc (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * variant, DbusmenuGtkClient * gtkclient) +{ + AtkObject * aobj = gtk_widget_get_accessible(GTK_WIDGET(gmi)); + + if (aobj == NULL) { + return; + } + + const gchar * setname = NULL; + + if (variant != NULL) { + setname = g_variant_get_string(variant, NULL); + } + + atk_object_set_name(aobj, setname); + return; +} + /* Whenever we have a property change on a DbusmenuMenuitem we need to be responsive to that. */ static void @@ -747,8 +767,7 @@ menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * variant, Db } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_DISPOSITION)) { process_disposition(mi, gmi, variant, gtkclient); } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC)) { - atk_object_set_name(gtk_widget_get_accessible(GTK_WIDGET(gmi)), variant == NULL ? "" : - g_variant_get_string(variant, NULL)); + process_a11y_desc(mi, gmi, variant, gtkclient); } return; @@ -894,8 +913,7 @@ dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * process_toggle_state(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE)); process_submenu(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY), client); process_disposition(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_DISPOSITION), client); - atk_object_set_name(gtk_widget_get_accessible(GTK_WIDGET(gmi)), - g_variant_get_string(dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC), NULL)); + process_a11y_desc(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC), client); refresh_shortcut(client, item); /* Oh, we're a child, let's deal with that */ -- cgit v1.2.3 From 344a334ed85f1c820f641374f8d41422da74c973 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 10 Feb 2012 10:30:17 -0600 Subject: Heh, wrote the code but forgot to handle the error --- libdbusmenu-gtk/client.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 927f0ae..5bf7469 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -741,6 +741,10 @@ process_a11y_desc (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * variant, setname = g_variant_get_string(variant, NULL); } + if (setname == NULL) { + setname = ""; + } + atk_object_set_name(aobj, setname); return; } -- cgit v1.2.3