From f89f8476599522aa7fbb61e4c0605d639a1be45e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 Apr 2011 10:57:39 -0500 Subject: Only activate items that have submenus --- libdbusmenu-gtk/parser.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 4972856..f21e548 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -290,6 +290,20 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) GList *iter; for (iter = children; iter != NULL; iter = iter->next) { + /* Make sure that we have a menu item before we start calling + functions that depend on it. This should almost always be + the case. */ + if (!GTK_IS_MENU_ITEM(iter->data)) { + continue; + } + + /* If the item is not opening a submenu we don't want to activate + it as that'd cause an action. Like opening a preferences dialog + to the user. That's not a good idea. */ + if (gtk_menu_item_get_submenu(GTK_WIDGET(iter->data)) == NULL) { + continue; + } + gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), iter->data, TRUE); -- cgit v1.2.3 From 3121fee23fd19cd773fe40f3e3f6dfd53581e3b7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 15 Apr 2011 10:59:07 -0500 Subject: Oops, wrong object type --- libdbusmenu-gtk/parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index f21e548..d2cb287 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -300,7 +300,7 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) /* If the item is not opening a submenu we don't want to activate it as that'd cause an action. Like opening a preferences dialog to the user. That's not a good idea. */ - if (gtk_menu_item_get_submenu(GTK_WIDGET(iter->data)) == NULL) { + if (gtk_menu_item_get_submenu(GTK_MENU_ITEM(iter->data)) == NULL) { continue; } -- cgit v1.2.3 From 7c726c9b99b9e02965b63a19e14920a7f6bb78c2 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Fri, 15 Apr 2011 14:53:28 -0400 Subject: watch new submenus for additions and removals --- libdbusmenu-gtk/parser.c | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 4972856..71474ae 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -270,6 +270,23 @@ new_menuitem (GtkWidget * widget) return item; } +static void +watch_submenu(DbusmenuMenuitem * mi, GtkWidget * menu) +{ + ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(mi), PARSER_DATA); + + pdata->shell = menu; + g_signal_connect (G_OBJECT (menu), + "child-added", + G_CALLBACK (child_added_cb), + mi); + g_signal_connect (G_OBJECT (menu), + "child-removed", + G_CALLBACK (child_removed_cb), + mi); + g_object_add_weak_pointer(G_OBJECT (menu), (gpointer*)&pdata->shell); +} + static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { @@ -300,19 +317,7 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) if (recurse->parent == NULL) { recurse->parent = new_menuitem(widget); - - ParserData *pdata = (ParserData *)g_object_get_data(G_OBJECT(recurse->parent), PARSER_DATA); - - pdata->shell = widget; - g_signal_connect (G_OBJECT (widget), - "child-added", - G_CALLBACK (child_added_cb), - recurse->parent); - g_signal_connect (G_OBJECT (widget), - "child-removed", - G_CALLBACK (child_removed_cb), - recurse->parent); - g_object_add_weak_pointer(G_OBJECT (widget), (gpointer*)&pdata->shell); + watch_submenu(recurse->parent, widget); } gtk_container_foreach (GTK_CONTAINER (widget), @@ -561,16 +566,7 @@ construct_dbusmenu_for_widget (GtkWidget * widget) GtkWidget *submenu = gtk_menu_item_get_submenu(GTK_MENU_ITEM(widget)); if (submenu) { - pdata->shell = submenu; - g_signal_connect (G_OBJECT (submenu), - "child-added", - G_CALLBACK (child_added_cb), - mi); - g_signal_connect (G_OBJECT (submenu), - "child-removed", - G_CALLBACK (child_removed_cb), - mi); - g_object_add_weak_pointer(G_OBJECT(submenu), (gpointer*)&pdata->shell); + watch_submenu(mi, submenu); } if (!g_object_get_data (G_OBJECT (widget), "gtk-empty-menu-item") && !GTK_IS_TEAROFF_MENU_ITEM (widget)) @@ -1077,6 +1073,7 @@ widget_notify_cb (GtkWidget *widget, if (item != NULL) { GtkWidget * menu = GTK_WIDGET (g_value_get_object (&prop_value)); parse_menu_structure_helper(menu, &recurse); + watch_submenu(item, menu); } else { /* Note: it would be really odd that we wouldn't have a cached item, but we should handle that appropriately. */ -- cgit v1.2.3 From 199c68f1e85dec4fefb56c6e64fc93ac2616f334 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Fri, 15 Apr 2011 14:59:54 -0400 Subject: activate new toplevel menu items --- libdbusmenu-gtk/parser.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 4972856..79153d5 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -1106,6 +1106,14 @@ child_added_cb (GtkContainer *menu, GtkWidget *widget, gpointer data) recurse.toplevel = gtk_widget_get_toplevel(GTK_WIDGET(menu)); recurse.parent = menuitem; + if (GTK_IS_MENU_BAR(menu)) { + /* We should fake-activate this menuitem just like we do other + toplevel entries. */ + gtk_menu_shell_activate_item (GTK_MENU_SHELL (menu), + widget, + TRUE); + } + parse_menu_structure_helper(widget, &recurse); } -- cgit v1.2.3 From c6f266a166a1ab7bf312ccfd9aa56d23fe85ae76 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Fri, 15 Apr 2011 15:32:48 -0400 Subject: refactor this branch a bit to rebase on trunk --- libdbusmenu-gtk/parser.c | 60 +++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/libdbusmenu-gtk/parser.c b/libdbusmenu-gtk/parser.c index 4bc7f69..4708a64 100644 --- a/libdbusmenu-gtk/parser.c +++ b/libdbusmenu-gtk/parser.c @@ -287,6 +287,33 @@ watch_submenu(DbusmenuMenuitem * mi, GtkWidget * menu) g_object_add_weak_pointer(G_OBJECT (menu), (gpointer*)&pdata->shell); } +static void +activate_toplevel_item (GtkWidget * item) +{ + /* Make sure that we have a menu item before we start calling + functions that depend on it. This should almost always be + the case. */ + if (!GTK_IS_MENU_ITEM(item)) { + return; + } + + /* If the item is not opening a submenu we don't want to activate + it as that'd cause an action. Like opening a preferences dialog + to the user. That's not a good idea. */ + if (gtk_menu_item_get_submenu(GTK_MENU_ITEM(item)) == NULL) { + return; + } + + GtkWidget * shell = gtk_widget_get_parent (item); + if (!GTK_IS_MENU_BAR (shell)) { + return; + } + + gtk_menu_shell_activate_item (GTK_MENU_SHELL (shell), + item, + TRUE); +} + static void parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) { @@ -303,30 +330,9 @@ parse_menu_structure_helper (GtkWidget * widget, RecurseContext * recurse) * Note that this will not force menuitems in submenus to be updated as well. */ if (recurse->parent == NULL && GTK_IS_MENU_BAR(widget)) { - GList *children = gtk_container_get_children (GTK_CONTAINER (widget)); - GList *iter; - - for (iter = children; iter != NULL; iter = iter->next) { - /* Make sure that we have a menu item before we start calling - functions that depend on it. This should almost always be - the case. */ - if (!GTK_IS_MENU_ITEM(iter->data)) { - continue; - } - - /* If the item is not opening a submenu we don't want to activate - it as that'd cause an action. Like opening a preferences dialog - to the user. That's not a good idea. */ - if (gtk_menu_item_get_submenu(GTK_MENU_ITEM(iter->data)) == NULL) { - continue; - } - - gtk_menu_shell_activate_item (GTK_MENU_SHELL (widget), - iter->data, - TRUE); - } - - g_list_free (children); + gtk_container_foreach (GTK_CONTAINER (widget), + (GtkCallback)activate_toplevel_item, + NULL); } if (recurse->parent == NULL) { @@ -1118,11 +1124,7 @@ child_added_cb (GtkContainer *menu, GtkWidget *widget, gpointer data) recurse.parent = menuitem; if (GTK_IS_MENU_BAR(menu)) { - /* We should fake-activate this menuitem just like we do other - toplevel entries. */ - gtk_menu_shell_activate_item (GTK_MENU_SHELL (menu), - widget, - TRUE); + activate_toplevel_item (widget); } parse_menu_structure_helper(widget, &recurse); -- cgit v1.2.3 From 74d51c3bd4e3f86939c37e4f5b1ca0835f4c868b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 18 Apr 2011 16:28:01 -0500 Subject: Referencing the server for as long as we're looking up the bus. --- libdbusmenu-glib/server.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index a41e6ce..4c3732f 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -455,6 +455,7 @@ set_property (GObject * obj, guint id, const GValue * value, GParamSpec * pspec) g_return_if_fail(priv->bus_lookup != NULL); } + g_object_ref(obj); g_bus_get(G_BUS_TYPE_SESSION, priv->bus_lookup, bus_got_cb, obj); } else { register_object(DBUSMENU_SERVER(obj)); @@ -694,6 +695,7 @@ bus_got_cb (GObject * obj, GAsyncResult * result, gpointer user_data) if (error != NULL) { g_warning("Unable to get session bus: %s", error->message); g_error_free(error); + g_object_unref(G_OBJECT(user_data)); return; } @@ -706,6 +708,7 @@ bus_got_cb (GObject * obj, GAsyncResult * result, gpointer user_data) register_object(DBUSMENU_SERVER(user_data)); + g_object_unref(G_OBJECT(user_data)); return; } -- cgit v1.2.3 From c76c9af81ecf4f8f9073f1440ed129f02d71b188 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Tue, 19 Apr 2011 13:54:37 -0400 Subject: fix typo that prevented Qt apps from sending some property updates --- libdbusmenu-glib/client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 2e6b09a..588c940 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -1239,7 +1239,7 @@ menuproxy_signal_cb (GDBusProxy * proxy, gchar * sender, gchar * signal, GVarian } else if (priv->root == NULL) { /* Drop out here, all the rest of these really need to have a root node so we can just ignore them if there isn't one. */ - } else if (g_strcmp0(signal, "ItemPropertiesUpdated") == 0) { + } else if (g_strcmp0(signal, "ItemsPropertiesUpdated") == 0) { /* Remove before adding just incase there is a duplicate, against the rules, but we can handle it so let's do it. */ GVariantIter ritems; -- cgit v1.2.3