From fd68aaf57b7b616434d6593f4b0627ec00fb7d97 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 2 Mar 2012 14:01:34 -0600 Subject: Track the theme changed signal so we ensure that we can drop it eventually --- libdbusmenu-gtk/parser.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 019a304..bdfc3e2 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -44,6 +44,8 @@ typedef struct _ParserData GtkWidget *shell; GtkWidget *image; AtkObject *accessible; + + guint theme_changed_sig; } ParserData; typedef struct _RecurseContext @@ -212,6 +214,11 @@ parse_data_free (gpointer data) g_object_remove_weak_pointer(G_OBJECT(pdata->accessible), (gpointer*)&pdata->accessible); } + if (pdata != NULL && pdata->theme_changed_sig != 0) { + g_signal_handler_disconnect(gtk_icon_theme_get_default(), pdata->theme_changed_sig); + pdata->theme_changed_sig = 0; + } + g_free(pdata); return; @@ -572,7 +579,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) /* 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()), + pdata->theme_changed_sig = g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), "changed", G_CALLBACK(theme_changed_cb), widget); pdata->image = image; -- cgit v1.2.3 From 16848ad3b788226b2f247dea73895580eb5b2d71 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 2 Mar 2012 14:20:49 -0600 Subject: Changing 'update_icon' to take more variables so we can do more fun stuff with it soon! --- libdbusmenu-gtk/parser.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index bdfc3e2..b6595f5 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -61,6 +61,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, @@ -575,7 +577,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) if (GTK_IS_IMAGE (image)) { - update_icon (mi, GTK_IMAGE (image)); + update_icon (mi, pdata, GTK_IMAGE_MENU_ITEM(widget), GTK_IMAGE (image)); /* Watch for theme changes because if gicon changes, we want to send a different pixbuf. */ @@ -744,7 +746,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; @@ -953,7 +955,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)); } } @@ -1141,13 +1144,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")) { @@ -1266,7 +1271,8 @@ theme_changed_cb (GtkIconTheme *theme, gpointer data) gpointer pmi = g_object_get_data(G_OBJECT(data), CACHED_MENUITEM); if (pmi != NULL) { - update_icon(DBUSMENU_MENUITEM(pmi), GTK_IMAGE(image)); + ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(pmi), PARSER_DATA); + update_icon(DBUSMENU_MENUITEM(pmi), pdata, NULL, GTK_IMAGE(image)); } /* Switch signal to new theme */ -- cgit v1.2.3 From 6f5a36c2abdad2fccc9848f34b3572c425abd39e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 2 Mar 2012 14:40:37 -0600 Subject: Moving the adding of signals to the update_icon function so that everyone gets them --- libdbusmenu-gtk/parser.c | 44 ++++++++++++++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index b6595f5..1092485 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -578,18 +578,6 @@ construct_dbusmenu_for_widget (GtkWidget * widget) if (GTK_IS_IMAGE (image)) { update_icon (mi, pdata, GTK_IMAGE_MENU_ITEM(widget), GTK_IMAGE (image)); - - /* Watch for theme changes because if gicon changes, we want to send a - different pixbuf. */ - pdata->theme_changed_sig = 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); } } @@ -755,6 +743,38 @@ update_icon (DbusmenuMenuitem *menuitem, ParserData * pdata, GtkImageMenuItem * 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->theme_changed_sig != 0) { + g_signal_handler_disconnect(gtk_icon_theme_get_default(), pdata->theme_changed_sig); + pdata->theme_changed_sig = 0; + } + + pdata->theme_changed_sig = g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), + "changed", G_CALLBACK(theme_changed_cb), gmenuitem); + + 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) { + pdata->theme_changed_sig = g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), + "changed", G_CALLBACK(theme_changed_cb), gmenuitem); + 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: -- cgit v1.2.3 From e11292ff7e55e6eeeef7ebb9260b238601db49c7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 2 Mar 2012 15:19:45 -0600 Subject: Not sending the update signal if the value is being cleared and it was already cleared --- libdbusmenu-glib/menuitem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 18db4ef..46546d6 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1253,7 +1253,8 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro becuse it has been unref'd when replaced in the hash table. But the fact that there was a value is the imporant part. */ - if (!inhash || replaced) { + if ((!inhash || replaced) && + !(!inhash && value == NULL)) { GVariant * signalval = value; if (signalval == NULL) { -- cgit v1.2.3 From e9c3459c80d3db095712b93992548ee03ae80b90 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 2 Mar 2012 15:26:08 -0600 Subject: Don't need to setup this signal twice --- libdbusmenu-gtk/parser.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 1092485..70ffcea 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -754,9 +754,6 @@ update_icon (DbusmenuMenuitem *menuitem, ParserData * pdata, GtkImageMenuItem * pdata->theme_changed_sig = 0; } - pdata->theme_changed_sig = g_signal_connect(G_OBJECT(gtk_icon_theme_get_default()), - "changed", G_CALLBACK(theme_changed_cb), gmenuitem); - 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); -- cgit v1.2.3 -- cgit v1.2.3 From a19fad6da18d3aec7aed4a4cddf3aeeb87249319 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 8 Mar 2012 08:51:49 -0600 Subject: Switching out logic, we're using replaced now because it gets set everytime that the hashtable is modified, and if we weren't modifying the hash table in some way, we don't want to signal. And, conversely, no one cares if we didn't modify the hash table. --- libdbusmenu-glib/menuitem.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libdbusmenu-glib/menuitem.c b/libdbusmenu-glib/menuitem.c index 46546d6..253fe6e 100644 --- a/libdbusmenu-glib/menuitem.c +++ b/libdbusmenu-glib/menuitem.c @@ -1253,8 +1253,7 @@ dbusmenu_menuitem_property_set_variant (DbusmenuMenuitem * mi, const gchar * pro becuse it has been unref'd when replaced in the hash table. But the fact that there was a value is the imporant part. */ - if ((!inhash || replaced) && - !(!inhash && value == NULL)) { + if (replaced) { GVariant * signalval = value; if (signalval == NULL) { -- cgit v1.2.3