From a7c13792e9e339480c763a42808baed77e13314b Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 4 Oct 2011 16:15:58 -0400 Subject: remove last ref from GtkMenuItems that we create --- libdbusmenu-gtk/client.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 1051f20..38b6a75 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -823,14 +823,22 @@ item_activate (DbusmenuClient * client, DbusmenuMenuitem * mi, guint timestamp, return; } -#ifdef MASSIVEDEBUGGING static void -destroy_gmi (GtkMenuItem * gmi, DbusmenuMenuitem * mi) +destroy_gmi (GtkMenuItem * gmi) { - g_debug("Destorying GTK Menuitem for %d", dbusmenu_menuitem_get_id(mi)); +#ifdef MASSIVEDEBUGGING + g_debug("Destroying GTK Menuitem %d", gmi); +#endif + + /* Call gtk_widget_destroy to remove from any containers and cleanup */ + gtk_widget_destroy(GTK_WIDGET(gmi)); + + /* Now remove last ref that we are holding (due to g_object_ref_sink in + dbusmenu_gtkclient_newitem_base). This should finalize the object */ + g_object_unref(G_OBJECT(gmi)); + return; } -#endif /** * dbusmenu_gtkclient_newitem_base: @@ -857,7 +865,7 @@ dbusmenu_gtkclient_newitem_base (DbusmenuGtkClient * client, DbusmenuMenuitem * /* Attach these two */ g_object_ref_sink(G_OBJECT(gmi)); - g_object_set_data_full(G_OBJECT(item), data_menuitem, gmi, (GDestroyNotify)gtk_widget_destroy); + g_object_set_data_full(G_OBJECT(item), data_menuitem, gmi, (GDestroyNotify)destroy_gmi); /* DbusmenuMenuitem signals */ g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), client); -- cgit v1.2.3 From fcd8e4126dea4e2fbde3a17fe842f2cd10750220 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Wed, 5 Oct 2011 14:59:21 -0400 Subject: when resetting an image widget and it's the only child of the menuitem, make sure we don't try to use free'd memory --- libdbusmenu-gtk/genericmenuitem.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/genericmenuitem.c b/libdbusmenu-gtk/genericmenuitem.c index 5488f93..ef77a2e 100644 --- a/libdbusmenu-gtk/genericmenuitem.c +++ b/libdbusmenu-gtk/genericmenuitem.c @@ -449,6 +449,7 @@ genericmenuitem_set_image (Genericmenuitem * menu_item, GtkWidget * image) if (GTK_IS_IMAGE(child)) { /* We've got a label, let's update it. */ imagew = GTK_IMAGE(child); + child = NULL; } else if (GTK_IS_BOX(child)) { /* Look for the label in the box */ gtk_container_foreach(GTK_CONTAINER(child), set_image_helper, &imagew); -- cgit v1.2.3 From c60ab35eae0b3a41f78f95da84e21c604bc98d57 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 13 Oct 2011 17:03:01 -0500 Subject: Don't try to get objects from boolean values. Handle the 'always show image' property by getting the image from the object and using that --- libdbusmenu-gtk/parser.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index e988c62..92932c5 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -1059,8 +1059,13 @@ widget_notify_cb (GtkWidget *widget, DBUSMENU_MENUITEM_PROP_VISIBLE, g_value_get_boolean (&prop_value)); } - else if (pspec->name == g_intern_static_string ("image") || - pspec->name == g_intern_static_string ("always-show-image")) + else if (pspec->name == g_intern_static_string ("always-show-image")) + { + GtkWidget *image = NULL; + g_object_get(widget, "image", &image, NULL); + update_icon (child, GTK_IMAGE(image)); + } + else if (pspec->name == g_intern_static_string ("image")) { GtkWidget *image; image = GTK_WIDGET (g_value_get_object (&prop_value)); -- cgit v1.2.3 From 1b83b3b0758d29d94a1e404f551939ea1885ad76 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 10 Nov 2011 17:49:27 -0500 Subject: make sure to cancel an idle callback when the object dies --- libdbusmenu-gtk/client.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'libdbusmenu-gtk') diff --git a/libdbusmenu-gtk/client.c b/libdbusmenu-gtk/client.c index 38b6a75..533764a 100644 --- a/libdbusmenu-gtk/client.c +++ b/libdbusmenu-gtk/client.c @@ -505,7 +505,6 @@ menu_item_stop_activating(DbusmenuMenuitem * mi) guint id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(parent), data_idle_close_id)); if (id > 0) { - g_source_remove(id); g_object_set_data(G_OBJECT(parent), data_idle_close_id, GINT_TO_POINTER(0)); should_close = TRUE; @@ -574,6 +573,14 @@ close_in_idle (DbusmenuMenuitem * mi) return FALSE; } +static void +cancel_idle_close_id (gpointer data) +{ + guint id = GPOINTER_TO_INT(data); + if (id > 0) + g_source_remove(id); +} + static void submenu_notify_visible_cb (GtkWidget * menu, GParamSpec * pspec, DbusmenuMenuitem * mi) { @@ -591,8 +598,8 @@ submenu_notify_visible_cb (GtkWidget * menu, GParamSpec * pspec, DbusmenuMenuite data_idle_close_id)); if (id == 0) { id = g_idle_add((GSourceFunc)close_in_idle, mi); - g_object_set_data(G_OBJECT(mi), data_idle_close_id, - GINT_TO_POINTER(id)); + g_object_set_data_full(G_OBJECT(mi), data_idle_close_id, + GINT_TO_POINTER(id), cancel_idle_close_id); } } } -- cgit v1.2.3