Merge lp:~mterry/libdbusmenu/proxy-gtk-menu-images into lp:libdbusmenu/12.10

Proposed by Michael Terry
Status: Merged
Approved by: Charles Kerr
Approved revision: 422
Merged at revision: 422
Proposed branch: lp:~mterry/libdbusmenu/proxy-gtk-menu-images
Merge into: lp:libdbusmenu/12.10
Diff against target: 115 lines (+63/-0)
1 file modified
libdbusmenu-gtk/parser.c (+63/-0)
To merge this branch: bzr merge lp:~mterry/libdbusmenu/proxy-gtk-menu-images
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Review via email: mp+123576@code.launchpad.net

Description of the change

There is a gsettings key org.gnome.desktop.interface.menus-have-icons which, when changed, gets translated into an XSettings value by gnome-settings-daemon. When that happens, all GTK+ apps notice and their GtkSettings objects emit property changes.

However, libdbusmenu does not notice. You can watch this happen by opening dconf-editor, toggling that key, and watching the behavior of the Power menu (which is native to the top bar) and the Network menu (which is proxied over dbusmenu by nm-applet). The Power menu changes appropriately. The Network menu does not.

This branch fixes that by updating parser.c to first, pay attention to which screen a widget is on. When that changes (or on init), we then watch that screen's GtkSettings object. And when it tells us the menu-icon value is different, we see if we need to change the icon we send over the wire.

Works for me in testing.

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :

Looks good. Thanks for this!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'libdbusmenu-gtk/parser.c'
--- libdbusmenu-gtk/parser.c 2012-04-10 16:05:52 +0000
+++ libdbusmenu-gtk/parser.c 2012-09-10 15:36:24 +0000
@@ -60,6 +60,9 @@
60 gulong widget_accel_handler_id;60 gulong widget_accel_handler_id;
61 gulong widget_toggle_handler_id;61 gulong widget_toggle_handler_id;
62 gulong widget_visible_handler_id;62 gulong widget_visible_handler_id;
63 gulong widget_screen_changed_handler_id;
64
65 gulong settings_notify_handler_id;
6366
64} ParserData;67} ParserData;
6568
@@ -116,6 +119,12 @@
116static void widget_add_cb (GtkWidget * widget,119static void widget_add_cb (GtkWidget * widget,
117 GtkWidget * child,120 GtkWidget * child,
118 gpointer data);121 gpointer data);
122static void widget_screen_changed_cb (GtkWidget * widget,
123 GdkScreen * old_screen,
124 gpointer data);
125static void settings_notify_cb (GtkSettings * settings,
126 GParamSpec * pspec,
127 gpointer data);
119static gboolean should_show_image (GtkImage * image);128static gboolean should_show_image (GtkImage * image);
120static void menuitem_notify_cb (GtkWidget * widget,129static void menuitem_notify_cb (GtkWidget * widget,
121 GParamSpec * pspec,130 GParamSpec * pspec,
@@ -130,6 +139,7 @@
130static const char * interned_str_always_show_image = NULL;139static const char * interned_str_always_show_image = NULL;
131static const char * interned_str_file = NULL;140static const char * interned_str_file = NULL;
132static const char * interned_str_gicon = NULL;141static const char * interned_str_gicon = NULL;
142static const char * interned_str_gtk_menu_images = NULL;
133static const char * interned_str_icon_name = NULL; 143static const char * interned_str_icon_name = NULL;
134static const char * interned_str_icon_set = NULL; 144static const char * interned_str_icon_set = NULL;
135static const char * interned_str_image = NULL; 145static const char * interned_str_image = NULL;
@@ -155,6 +165,7 @@
155 interned_str_always_show_image = g_intern_static_string ("always-show-image");165 interned_str_always_show_image = g_intern_static_string ("always-show-image");
156 interned_str_file = g_intern_static_string ("file");166 interned_str_file = g_intern_static_string ("file");
157 interned_str_gicon = g_intern_static_string ("gicon");167 interned_str_gicon = g_intern_static_string ("gicon");
168 interned_str_gtk_menu_images = g_intern_static_string ("gtk-menu-images");
158 interned_str_icon_name = g_intern_static_string ("icon-name");169 interned_str_icon_name = g_intern_static_string ("icon-name");
159 interned_str_icon_set = g_intern_static_string ("icon-set");170 interned_str_icon_set = g_intern_static_string ("icon-set");
160 interned_str_image = g_intern_static_string ("image");171 interned_str_image = g_intern_static_string ("image");
@@ -291,6 +302,9 @@
291 dbusmenu_gtk_clear_signal_handler (o, &pdata->widget_accel_handler_id);302 dbusmenu_gtk_clear_signal_handler (o, &pdata->widget_accel_handler_id);
292 dbusmenu_gtk_clear_signal_handler (o, &pdata->widget_toggle_handler_id);303 dbusmenu_gtk_clear_signal_handler (o, &pdata->widget_toggle_handler_id);
293 dbusmenu_gtk_clear_signal_handler (o, &pdata->widget_visible_handler_id);304 dbusmenu_gtk_clear_signal_handler (o, &pdata->widget_visible_handler_id);
305 dbusmenu_gtk_clear_signal_handler (o, &pdata->widget_screen_changed_handler_id);
306 dbusmenu_gtk_clear_signal_handler (gtk_widget_get_settings (GTK_WIDGET (o)),
307 &pdata->settings_notify_handler_id);
294 g_object_remove_weak_pointer(o, (gpointer*)&pdata->widget);308 g_object_remove_weak_pointer(o, (gpointer*)&pdata->widget);
295309
296 /* since the DbusmenuMenuitem is being destroyed, uncache it from the GtkWidget */310 /* since the DbusmenuMenuitem is being destroyed, uncache it from the GtkWidget */
@@ -746,6 +760,10 @@
746 pdata->widget_add_handler_id = g_signal_connect (widget, "add",760 pdata->widget_add_handler_id = g_signal_connect (widget, "add",
747 G_CALLBACK (widget_add_cb), mi);761 G_CALLBACK (widget_add_cb), mi);
748762
763 pdata->widget_screen_changed_handler_id = g_signal_connect (widget, "screen-changed",
764 G_CALLBACK (widget_screen_changed_cb), mi);
765 widget_screen_changed_cb (widget, NULL, mi);
766
749 return mi;767 return mi;
750 }768 }
751769
@@ -1282,6 +1300,51 @@
1282 handle_first_label (data);1300 handle_first_label (data);
1283}1301}
12841302
1303/* Pass NULL for pspec to update all settings at once */
1304static void
1305widget_screen_changed_cb (GtkWidget * widget, GdkScreen * old_screen, gpointer data)
1306{
1307 DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(data);
1308 g_return_if_fail (mi != NULL);
1309
1310 ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(mi), PARSER_DATA);
1311
1312 if (old_screen != NULL)
1313 dbusmenu_gtk_clear_signal_handler (gtk_settings_get_for_screen (old_screen),
1314 &pdata->settings_notify_handler_id);
1315 pdata->settings_notify_handler_id = g_signal_connect (gtk_widget_get_settings (widget), "notify",
1316 G_CALLBACK (settings_notify_cb), mi);
1317
1318 /* And update widget now that we have a new GtkSettings */
1319 settings_notify_cb (gtk_widget_get_settings (widget), NULL, mi);
1320}
1321
1322/* Pass NULL for pspec to update all settings at once */
1323static void
1324settings_notify_cb (GtkSettings * settings, GParamSpec * pspec, gpointer data)
1325{
1326 GValue prop_value = {0};
1327 DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(data);
1328 g_return_if_fail (mi != NULL);
1329
1330 ensure_interned_strings_loaded ();
1331
1332 if (pspec != NULL)
1333 {
1334 g_value_init (&prop_value, pspec->value_type);
1335 g_object_get_property (G_OBJECT (settings), pspec->name, &prop_value);
1336 }
1337
1338 if (pspec == NULL || pspec->name == interned_str_gtk_menu_images)
1339 {
1340 ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(mi), PARSER_DATA);
1341 update_icon (mi, pdata, GTK_IMAGE(pdata->image));
1342 }
1343
1344 if (pspec != NULL)
1345 g_value_unset (&prop_value);
1346}
1347
1285/* A child item was added to a menu we're watching. Let's try to integrate it. */1348/* A child item was added to a menu we're watching. Let's try to integrate it. */
1286static void1349static void
1287item_inserted_cb (GtkContainer *menu,1350item_inserted_cb (GtkContainer *menu,

Subscribers

People subscribed via source and target branches

to all changes: