aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-gtk
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2012-02-10 10:35:39 -0600
committerTed Gould <ted@gould.cx>2012-02-10 10:35:39 -0600
commite5354a3ceb63f6bbe0097807122260c82e9836d4 (patch)
tree653bc7c7b92ba1e085ce3830f453da9fcbcd3b03 /libdbusmenu-gtk
parent85e15ef6892cb1946ef6cc04dab5fc26f0f08f83 (diff)
parent344a334ed85f1c820f641374f8d41422da74c973 (diff)
downloadlibdbusmenu-e5354a3ceb63f6bbe0097807122260c82e9836d4.tar.gz
libdbusmenu-e5354a3ceb63f6bbe0097807122260c82e9836d4.tar.bz2
libdbusmenu-e5354a3ceb63f6bbe0097807122260c82e9836d4.zip
Parse and handle a11y descriptions
Diffstat (limited to 'libdbusmenu-gtk')
-rw-r--r--libdbusmenu-gtk/client.c28
-rw-r--r--libdbusmenu-gtk/parser.c58
2 files changed, 84 insertions, 2 deletions
diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c
index 884c11e..30ded29 100644
--- a/libdbusmenu-gtk/client.c
+++ b/libdbusmenu-gtk/client.c
@@ -725,6 +725,30 @@ 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);
+ }
+
+ if (setname == NULL) {
+ setname = "";
+ }
+
+ 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 +771,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,6 +917,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);
+ process_a11y_desc(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC), client);
refresh_shortcut(client, item);
const gchar * a11y_desc = dbusmenu_menuitem_property_get(item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC);
diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c
index 0ecfa1e..aefbd05 100644
--- a/libdbusmenu-gtk/parser.c
+++ b/libdbusmenu-gtk/parser.c
@@ -26,6 +26,8 @@ License version 3 and version 2.1 along with this program. If not, see
<http://www.gnu.org/licenses/>
*/
+#include <atk/atk.h>
+
#include "parser.h"
#include "menuitem.h"
#include "client.h"
@@ -41,6 +43,7 @@ typedef struct _ParserData
GtkWidget *widget;
GtkWidget *shell;
GtkWidget *image;
+ AtkObject *accessible;
} ParserData;
typedef struct _RecurseContext
@@ -67,6 +70,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 +206,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 +594,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, 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.
+ pdata->accessible = accessible;
+ g_signal_connect (G_OBJECT (accessible),
+ "notify::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);
@@ -948,6 +981,31 @@ 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 (pspec->name == g_intern_static_string ("accessible-name"))
+ {
+ if (!g_strcmp0 (name, label_text))
+ dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC, NULL);
+ else
+ dbusmenu_menuitem_property_set (item, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC, name);
+ }
+}
+
+static void
item_activated (DbusmenuMenuitem *item, guint timestamp, gpointer user_data)
{
GtkWidget *child;