From dc103227e86bf67c8c9118010887f8ba7c924e35 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 16 Aug 2010 10:58:16 -0500 Subject: Handling comment nodes better. --- libdbusmenu-glib/client.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 7c73b7b..98049d5 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -1126,6 +1126,9 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it /* g_debug("Looking at child: %d", position); */ gint childid = parse_node_get_id(children); if (childid < 0) { + /* Don't increment the position when there isn't a valid + node in the XML tree. It's probably a comment. */ + position--; continue; } DbusmenuMenuitem * childmi = NULL; @@ -1143,11 +1146,13 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it } if (childmi == NULL) { + g_debug("Building new menu item %d at position %d", childid, position); /* If we can't recycle, then we build a new one */ childmi = parse_layout_new_child(childid, client, item); dbusmenu_menuitem_child_add_position(item, childmi, position); g_object_unref(childmi); } else { + g_debug("Recycling menu item %d at position %d", childid, position); /* If we can recycle, make sure it's in the right place */ dbusmenu_menuitem_child_reorder(item, childmi, position); parse_layout_update(childmi, client); @@ -1175,6 +1180,19 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it children = node->children; GList * childmis = dbusmenu_menuitem_get_children(item); while (children != NULL && childmis != NULL) { + gint xmlid = parse_node_get_id(children); + /* If this isn't a valid menu item we need to move on + until we have one. This avoids things like comments. */ + if (xmlid < 0) { + children = children->next; + continue; + } + + #if 1 + gint miid = dbusmenu_menuitem_get_id(DBUSMENU_MENUITEM(childmis->data)); + g_debug("Recursing parse_layout_xml. XML ID: %d MI ID: %d", xmlid, miid); + #endif + parse_layout_xml(client, children, DBUSMENU_MENUITEM(childmis->data), item, proxy); children = children->next; -- cgit v1.2.3 From d2bd004b2cbb7a383d1b75200fe857091f6fe89c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 16 Aug 2010 10:59:53 -0500 Subject: Putting the debugging messages under MASSIVEDEBUGGING --- libdbusmenu-glib/client.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 98049d5..73a7aac 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -1146,13 +1146,17 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it } if (childmi == NULL) { + #ifdef MASSIVEDEBUGGING g_debug("Building new menu item %d at position %d", childid, position); + #endif /* If we can't recycle, then we build a new one */ childmi = parse_layout_new_child(childid, client, item); dbusmenu_menuitem_child_add_position(item, childmi, position); g_object_unref(childmi); } else { + #ifdef MASSIVEDEBUGGING g_debug("Recycling menu item %d at position %d", childid, position); + #endif /* If we can recycle, make sure it's in the right place */ dbusmenu_menuitem_child_reorder(item, childmi, position); parse_layout_update(childmi, client); @@ -1188,7 +1192,7 @@ parse_layout_xml(DbusmenuClient * client, xmlNodePtr node, DbusmenuMenuitem * it continue; } - #if 1 + #ifdef MASSIVEDEBUGGING gint miid = dbusmenu_menuitem_get_id(DBUSMENU_MENUITEM(childmis->data)); g_debug("Recursing parse_layout_xml. XML ID: %d MI ID: %d", xmlid, miid); #endif -- cgit v1.2.3 From 98b759aaa21779694f5708a93d900c3204742133 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 17 Aug 2010 16:12:48 -0500 Subject: Getting the signal for the request to activate the item --- libdbusmenu-glib/client.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 73a7aac..d127b21 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -123,6 +123,7 @@ static void update_layout (DbusmenuClient * client); static void menuitem_get_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * error, gpointer data); static void get_properties_globber (DbusmenuClient * client, gint id, const gchar ** properties, org_ayatana_dbusmenu_get_properties_reply callback, gpointer user_data); static GQuark error_domain (void); +static void item_activated (DBusGProxy * proxy, gint id, gint timestamp, DbusmenuClient * client); /* Build a type */ G_DEFINE_TYPE (DbusmenuClient, dbusmenu_client, G_TYPE_OBJECT); @@ -582,6 +583,14 @@ get_properties_globber (DbusmenuClient * client, gint id, const gchar ** propert return; } +/* Called when a server item wants to activate the menu */ +static void +item_activated (DBusGProxy * proxy, gint id, gint timestamp, DbusmenuClient * client) +{ + + return; +} + /* Annoying little wrapper to make the right function update */ static void layout_update (DBusGProxy * proxy, guint revision, gint parent, DbusmenuClient * client) @@ -821,6 +830,10 @@ build_proxies (DbusmenuClient * client) dbus_g_proxy_add_signal(priv->menuproxy, "ItemUpdated", G_TYPE_INT, G_TYPE_INVALID); dbus_g_proxy_connect_signal(priv->menuproxy, "ItemUpdated", G_CALLBACK(id_update), client, NULL); + dbus_g_object_register_marshaller(_dbusmenu_server_marshal_VOID__INT_UINT, G_TYPE_NONE, G_TYPE_INT, G_TYPE_UINT, G_TYPE_INVALID); + dbus_g_proxy_add_signal(priv->menuproxy, "ItemActivationRequested", G_TYPE_INT, G_TYPE_UINT, G_TYPE_INVALID); + dbus_g_proxy_connect_signal(priv->menuproxy, "ItemActivationRequested", G_CALLBACK(item_activated), client, NULL); + update_layout(client); return; -- cgit v1.2.3 From 65d0fad51540858ca7a8cf850f6d0c3e0feaf949 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 17 Aug 2010 16:45:09 -0500 Subject: Getting to the menu item. --- libdbusmenu-glib/client.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index d127b21..25d64b6 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -123,7 +123,7 @@ static void update_layout (DbusmenuClient * client); static void menuitem_get_properties_cb (DBusGProxy * proxy, GHashTable * properties, GError * error, gpointer data); static void get_properties_globber (DbusmenuClient * client, gint id, const gchar ** properties, org_ayatana_dbusmenu_get_properties_reply callback, gpointer user_data); static GQuark error_domain (void); -static void item_activated (DBusGProxy * proxy, gint id, gint timestamp, DbusmenuClient * client); +static void item_activated (DBusGProxy * proxy, gint id, guint timestamp, DbusmenuClient * client); /* Build a type */ G_DEFINE_TYPE (DbusmenuClient, dbusmenu_client, G_TYPE_OBJECT); @@ -585,8 +585,21 @@ get_properties_globber (DbusmenuClient * client, gint id, const gchar ** propert /* Called when a server item wants to activate the menu */ static void -item_activated (DBusGProxy * proxy, gint id, gint timestamp, DbusmenuClient * client) +item_activated (DBusGProxy * proxy, gint id, guint timestamp, DbusmenuClient * client) { + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); + + if (priv->root == NULL) { + g_warning("Asked to activate item %d when we don't have a menu structure.", id); + return; + } + + DbusmenuMenuitem * menuitem = dbusmenu_menuitem_find_id(priv->root, id); + if (menuitem == NULL) { + g_warning("Unable to find menu item %d to activate.", id); + return; + } + return; } -- cgit v1.2.3 From 6566022e1f2afc97d6ffafbec3ca54bf63fd19f9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 17 Aug 2010 20:42:22 -0500 Subject: Adding a new signal for when items activate. --- libdbusmenu-glib/client.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 25d64b6..7b1a762 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -41,6 +41,7 @@ License version 3 and version 2.1 along with this program. If not, see #include "client-menuitem.h" #include "dbusmenu-client.h" #include "server-marshal.h" +#include "client-marshal.h" /* Properties */ enum { @@ -54,6 +55,7 @@ enum { LAYOUT_UPDATED, ROOT_CHANGED, NEW_MENUITEM, + ITEM_ACTIVATE, LAST_SIGNAL }; @@ -188,6 +190,22 @@ dbusmenu_client_class_init (DbusmenuClientClass *klass) NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1, G_TYPE_OBJECT); + /** + DbusmenuClient::item-activate: + @arg0: The #DbusmenuClient object + @arg1: The #DbusmenuMenuitem activated + @arg2: A timestamp that the event happened at + + Signaled when the server wants to activate an item in + order to display the menu. + */ + signals[ITEM_ACTIVATE] = g_signal_new(DBUSMENU_CLIENT_SIGNAL_ITEM_ACTIVATE, + G_TYPE_FROM_CLASS (klass), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (DbusmenuClientClass, item_activate), + NULL, NULL, + _dbusmenu_client_marshal_VOID__OBJECT_UINT, + G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_UINT); g_object_class_install_property (object_class, PROP_DBUSOBJECT, g_param_spec_string(DBUSMENU_CLIENT_PROP_DBUS_OBJECT, "DBus Object we represent", -- cgit v1.2.3 From 8fd2e5cea3d717c2332aeefe9c74f6ac9bebe4af Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 17 Aug 2010 20:45:19 -0500 Subject: Passing the signal up the pipe --- libdbusmenu-glib/client.c | 1 + 1 file changed, 1 insertion(+) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 7b1a762..cc91b32 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -618,6 +618,7 @@ item_activated (DBusGProxy * proxy, gint id, guint timestamp, DbusmenuClient * c return; } + g_signal_emit(G_OBJECT(client), signals[ITEM_ACTIVATE], 0, menuitem, timestamp, TRUE); return; } -- cgit v1.2.3