aboutsummaryrefslogtreecommitdiff
path: root/libdbusmenu-gtk
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2012-04-09 09:15:17 -0500
committerTed Gould <ted@gould.cx>2012-04-09 09:15:17 -0500
commit475110aa2fe3a47cf6331fbd5941f34a9461fd81 (patch)
treebf2318e8b94cf0b74ea17b496e9d5331a3c065ec /libdbusmenu-gtk
parente0eb750e8c36a4116247ea80b4d055a9f821459a (diff)
parent2d60549a2394ce7d73907abcaca22b48553d6c5b (diff)
downloadlibdbusmenu-475110aa2fe3a47cf6331fbd5941f34a9461fd81.tar.gz
libdbusmenu-475110aa2fe3a47cf6331fbd5941f34a9461fd81.tar.bz2
libdbusmenu-475110aa2fe3a47cf6331fbd5941f34a9461fd81.zip
Catching up to trunk
Diffstat (limited to 'libdbusmenu-gtk')
-rw-r--r--libdbusmenu-gtk/Makefile.am10
-rw-r--r--libdbusmenu-gtk/client.c41
-rw-r--r--libdbusmenu-gtk/genericmenuitem.c24
-rw-r--r--libdbusmenu-gtk/parser.c81
4 files changed, 90 insertions, 66 deletions
diff --git a/libdbusmenu-gtk/Makefile.am b/libdbusmenu-gtk/Makefile.am
index fcebd04..b52098f 100644
--- a/libdbusmenu-gtk/Makefile.am
+++ b/libdbusmenu-gtk/Makefile.am
@@ -57,12 +57,14 @@ libdbusmenu_gtk_la_SOURCES = \
parser.c
libdbusmenu_gtk_la_LDFLAGS = \
+ $(COVERAGE_LDFLAGS) \
-version-info $(LIBDBUSMENU_CURRENT):$(LIBDBUSMENU_REVISION):$(LIBDBUSMENU_AGE) \
-no-undefined \
-export-symbols-regex "^[^_].*"
libdbusmenu_gtk_la_CFLAGS = \
$(DBUSMENUGTK_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
-I$(top_srcdir) \
-Wall -Werror -Wno-error=deprecated-declarations \
-DG_LOG_DOMAIN="\"LIBDBUSMENU-GTK\""
@@ -117,7 +119,12 @@ DbusmenuGtk_0_4_gir_INCLUDES = \
GObject-2.0 \
$(GTKGIR) \
Dbusmenu-0.4
-DbusmenuGtk_0_4_gir_CFLAGS = $(DBUSMENUGTK_CFLAGS) -I$(top_srcdir)
+DbusmenuGtk_0_4_gir_CFLAGS = \
+ $(DBUSMENUGTK_CFLAGS) \
+ $(COVERAGE_CFLAGS) \
+ -I$(top_srcdir)
+DbusmenuGtk_0_4_gir_LDFLAGS = \
+ $(COVERAGE_LDFLAGS)
DbusmenuGtk_0_4_gir_LIBS = libdbusmenu-gtk$(VER).la \
$(top_builddir)/libdbusmenu-glib/libdbusmenu-glib.la
DbusmenuGtk_0_4_gir_FILES = $(addprefix $(srcdir)/, $(introspection_sources))
@@ -127,6 +134,7 @@ DbusmenuGtk_0_4_gir_EXPORT_PACKAGES = dbusmenu-gtk$(VER)-0.4
# We duplicate these for the same reason as libdbusmenu_gtk3includedir above
DbusmenuGtk3_0_4_gir_INCLUDES = $(DbusmenuGtk_0_4_gir_INCLUDES)
DbusmenuGtk3_0_4_gir_CFLAGS = $(DbusmenuGtk_0_4_gir_CFLAGS)
+DbusmenuGtk3_0_4_gir_LDFLAGS = $(DbusmenuGtk_0_4_gir_LDFLAGS)
DbusmenuGtk3_0_4_gir_LIBS = $(DbusmenuGtk_0_4_gir_LIBS)
DbusmenuGtk3_0_4_gir_FILES = $(DbusmenuGtk_0_4_gir_FILES)
DbusmenuGtk3_0_4_gir_NAMESPACE = $(DbusmenuGtk_0_4_gir_NAMESPACE)
diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c
index 830356a..60af93f 100644
--- a/libdbusmenu-gtk/client.c
+++ b/libdbusmenu-gtk/client.c
@@ -735,17 +735,32 @@ process_a11y_desc (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * variant,
return;
}
- const gchar * setname = NULL;
if (variant != NULL) {
+ const gchar * setname = NULL;
setname = g_variant_get_string(variant, NULL);
+ atk_object_set_name(aobj, setname);
+ } else {
+ /* The atk docs advise to set the name of the atk object to an empty
+ * string, but GTK doesn't yet do the same, and setting the name to NULL
+ * causes tests to fail.
+ */
+ const gchar * label = NULL;
+ label = dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_LABEL);
+
+ if (label != NULL) {
+ gchar * setname = NULL;
+
+ /* We don't want the underscore for mnewmonics */
+ GRegex * regex = g_regex_new ("_", 0, 0, NULL);
+ setname = g_regex_replace_literal (regex, label, -1, 0, "", 0, NULL);
+ g_regex_unref(regex);
+
+ atk_object_set_name(aobj, setname);
+ g_free(setname);
+ }
}
- if (setname == NULL) {
- setname = "";
- }
-
- atk_object_set_name(aobj, setname);
return;
}
@@ -772,22 +787,13 @@ menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * variant, Db
process_disposition(mi, gmi, variant, gtkclient);
} else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_ACCESSIBLE_DESC)) {
process_a11y_desc(mi, gmi, variant, gtkclient);
+ } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_SHORTCUT)) {
+ refresh_shortcut(gtkclient, mi);
}
return;
}
-/* Special handler for the shortcut changing as we need to have the
- client for that one to get the accel group. */
-static void
-menu_shortcut_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * value, DbusmenuGtkClient * client)
-{
- if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_SHORTCUT)) {
- refresh_shortcut(client, mi);
- }
- return;
-}
-
/* The new menuitem signal only happens if we don't have a type handler
for the type of the item. This should be an error condition and we're
printing out a message. */
@@ -903,7 +909,6 @@ dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem *
/* DbusmenuMenuitem signals */
g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), client);
- g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_shortcut_change_cb), client);
g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(delete_child), client);
g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(move_child), client);
diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c
index 435c808..e9c8367 100644
--- a/libdbusmenu-gtk/genericmenuitem.c
+++ b/libdbusmenu-gtk/genericmenuitem.c
@@ -83,6 +83,12 @@ genericmenuitem_class_init (GenericmenuitemClass *klass)
object_class->dispose = genericmenuitem_dispose;
object_class->finalize = genericmenuitem_finalize;
+#ifdef HAVE_GTK3
+ GtkWidgetClass * widget_class = GTK_WIDGET_CLASS(klass);
+
+ gtk_widget_class_set_accessible_role(widget_class, ATK_ROLE_MENU_ITEM);
+#endif
+
GtkCheckMenuItemClass * check_class = GTK_CHECK_MENU_ITEM_CLASS (klass);
parent_draw_indicator = check_class->draw_indicator;
@@ -109,6 +115,13 @@ genericmenuitem_init (Genericmenuitem *self)
self->priv->disposition = GENERICMENUITEM_DISPOSITION_NORMAL;
self->priv->label_text = NULL;
+#ifndef HAVE_GTK3
+ AtkObject * aobj = gtk_widget_get_accessible(GTK_WIDGET(self));
+ if (aobj != NULL) {
+ atk_object_set_role(aobj, ATK_ROLE_MENU_ITEM);
+ }
+#endif
+
return;
}
@@ -347,18 +360,29 @@ genericmenuitem_set_check_type (Genericmenuitem * item, GenericmenuitemCheckType
}
item->priv->check_type = check_type;
+ AtkObject * aobj = gtk_widget_get_accessible(GTK_WIDGET(item));
switch (item->priv->check_type) {
case GENERICMENUITEM_CHECK_TYPE_NONE:
/* We don't need to do anything here as we're queuing the
draw and then when it draws it'll avoid drawing the
check on the item. */
+
+ if (aobj != NULL) {
+ atk_object_set_role(aobj, ATK_ROLE_MENU_ITEM);
+ }
break;
case GENERICMENUITEM_CHECK_TYPE_CHECKBOX:
gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(item), FALSE);
+ if (aobj != NULL) {
+ atk_object_set_role(aobj, ATK_ROLE_CHECK_MENU_ITEM);
+ }
break;
case GENERICMENUITEM_CHECK_TYPE_RADIO:
gtk_check_menu_item_set_draw_as_radio(GTK_CHECK_MENU_ITEM(item), TRUE);
+ if (aobj != NULL) {
+ atk_object_set_role(aobj, ATK_ROLE_RADIO_MENU_ITEM);
+ }
break;
default:
g_warning("Generic Menuitem invalid check type: %d", check_type);
diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c
index 019a304..b98f34b 100644
--- a/libdbusmenu-gtk/parser.c
+++ b/libdbusmenu-gtk/parser.c
@@ -44,6 +44,7 @@ typedef struct _ParserData
GtkWidget *shell;
GtkWidget *image;
AtkObject *accessible;
+
} ParserData;
typedef struct _RecurseContext
@@ -59,6 +60,8 @@ static void accel_changed (GtkWidget * widget,
static void checkbox_toggled (GtkWidget * widget,
DbusmenuMenuitem * mi);
static void update_icon (DbusmenuMenuitem * menuitem,
+ ParserData * pdata,
+ GtkImageMenuItem * gmenuitem,
GtkImage * image);
static GtkWidget * find_menu_label (GtkWidget * widget);
static void label_notify_cb (GtkWidget * widget,
@@ -82,8 +85,6 @@ static void item_inserted_cb (GtkContainer * menu,
static void item_removed_cb (GtkContainer * menu,
GtkWidget * widget,
gpointer data);
-static void theme_changed_cb (GtkIconTheme * theme,
- gpointer data);
static void item_activated (DbusmenuMenuitem * item,
guint timestamp,
gpointer user_data);
@@ -217,14 +218,6 @@ parse_data_free (gpointer data)
return;
}
-static void
-widget_freed (gpointer data, GObject * obj)
-{
- g_signal_handlers_disconnect_by_func(gtk_icon_theme_get_default(), G_CALLBACK(theme_changed_cb), obj);
-
- return;
-}
-
/* Called when the dbusmenu item that we're keeping around
is finalized */
static void
@@ -233,9 +226,7 @@ dbusmenu_item_freed (gpointer data, GObject * obj)
ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(obj), PARSER_DATA);
if (pdata != NULL && pdata->widget != NULL) {
- g_signal_handlers_disconnect_by_func(gtk_icon_theme_get_default(), G_CALLBACK(theme_changed_cb), pdata->widget);
g_object_steal_data(G_OBJECT(pdata->widget), CACHED_MENUITEM);
- g_object_weak_unref(G_OBJECT(pdata->widget), widget_freed, NULL);
}
}
@@ -277,7 +268,6 @@ new_menuitem (GtkWidget * widget)
g_object_set_data_full(G_OBJECT(item), PARSER_DATA, pdata, parse_data_free);
g_object_weak_ref(G_OBJECT(item), dbusmenu_item_freed, NULL);
- g_object_weak_ref(G_OBJECT(widget), widget_freed, NULL);
pdata->widget = widget;
g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->widget);
@@ -568,19 +558,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget)
if (GTK_IS_IMAGE (image))
{
- update_icon (mi, GTK_IMAGE (image));
-
- /* Watch for theme changes because if gicon changes, we want to send a
- different pixbuf. */
- g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()),
- "changed", G_CALLBACK(theme_changed_cb), widget);
-
- pdata->image = image;
- g_signal_connect (G_OBJECT (image),
- "notify",
- G_CALLBACK (image_notify_cb),
- mi);
- g_object_add_weak_pointer(G_OBJECT (image), (gpointer*)&pdata->image);
+ update_icon (mi, pdata, GTK_IMAGE_MENU_ITEM(widget), GTK_IMAGE (image));
}
}
@@ -737,7 +715,7 @@ checkbox_toggled (GtkWidget *widget, DbusmenuMenuitem *mi)
}
static void
-update_icon (DbusmenuMenuitem *menuitem, GtkImage *image)
+update_icon (DbusmenuMenuitem *menuitem, ParserData * pdata, GtkImageMenuItem * gmenuitem, GtkImage *image)
{
GdkPixbuf * pixbuf = NULL;
const gchar * icon_name = NULL;
@@ -746,6 +724,29 @@ update_icon (DbusmenuMenuitem *menuitem, GtkImage *image)
GtkIconInfo * info;
gint width;
+ /* Check to see if we're changing the image. If so, we need to track
+ that little bugger */
+ /* Why check for gmenuitem being NULL? Because there are some cases where
+ we can't get it easily, and those mean it's not changed just the icon
+ underneith, so we can ignore these larger impacts */
+ if (image != GTK_IMAGE(pdata->image) && gmenuitem != NULL) {
+
+ if (pdata->image != NULL) {
+ g_signal_handlers_disconnect_by_func(pdata->image, G_CALLBACK(image_notify_cb), menuitem);
+ g_object_remove_weak_pointer(G_OBJECT(pdata->image), (gpointer*)&pdata->image);
+ }
+
+ pdata->image = GTK_WIDGET(image);
+
+ if (pdata->image != NULL) {
+ g_signal_connect (G_OBJECT (pdata->image),
+ "notify",
+ G_CALLBACK (image_notify_cb),
+ menuitem);
+ g_object_add_weak_pointer(G_OBJECT (pdata->image), (gpointer*)&pdata->image);
+ }
+ }
+
if (image != NULL && should_show_image (image)) {
switch (gtk_image_get_storage_type (image)) {
case GTK_IMAGE_EMPTY:
@@ -946,7 +947,8 @@ image_notify_cb (GtkWidget *widget,
pspec->name == g_intern_static_string ("stock") ||
pspec->name == g_intern_static_string ("storage-type"))
{
- update_icon (mi, GTK_IMAGE (widget));
+ ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(mi), PARSER_DATA);
+ update_icon (mi, pdata, NULL, GTK_IMAGE (widget));
}
}
@@ -1134,13 +1136,15 @@ widget_notify_cb (GtkWidget *widget,
{
GtkWidget *image = NULL;
g_object_get(widget, "image", &image, NULL);
- update_icon (child, GTK_IMAGE(image));
+ ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(child), PARSER_DATA);
+ update_icon (child, pdata, GTK_IMAGE_MENU_ITEM(widget), GTK_IMAGE(image));
}
else if (pspec->name == g_intern_static_string ("image"))
{
GtkWidget *image;
image = GTK_WIDGET (g_value_get_object (&prop_value));
- update_icon (child, GTK_IMAGE (image));
+ ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(child), PARSER_DATA);
+ update_icon (child, pdata, GTK_IMAGE_MENU_ITEM(widget), GTK_IMAGE (image));
}
else if (pspec->name == g_intern_static_string ("parent"))
{
@@ -1250,23 +1254,6 @@ item_removed_cb (GtkContainer *menu, GtkWidget *widget, gpointer data)
return;
}
-static void
-theme_changed_cb (GtkIconTheme *theme, gpointer data)
-{
- GtkWidget *image;
-
- image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (data));
-
- gpointer pmi = g_object_get_data(G_OBJECT(data), CACHED_MENUITEM);
- if (pmi != NULL) {
- update_icon(DBUSMENU_MENUITEM(pmi), GTK_IMAGE(image));
- }
-
- /* Switch signal to new theme */
- g_signal_handlers_disconnect_by_func(theme, G_CALLBACK(theme_changed_cb), data);
- g_signal_connect(gtk_icon_theme_get_default(), "changed", G_CALLBACK(theme_changed_cb), data);
-}
-
static gboolean
should_show_image (GtkImage *image)
{