From 10a0d01be7c04b0538fa183451d18950d613b563 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Mar 2012 08:31:59 -0500 Subject: Bumping the version of the wire protocol --- libdbusmenu-glib/server.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index a8e9214..d85c5fa 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -42,7 +42,7 @@ License version 3 and version 2.1 along with this program. If not, see static void layout_update_signal (DbusmenuServer * server); -#define DBUSMENU_VERSION_NUMBER 2 +#define DBUSMENU_VERSION_NUMBER 3 #define DBUSMENU_INTERFACE "com.canonical.dbusmenu" /* Privates, I'll show you mine... */ -- cgit v1.2.3 From 52617668cec85a2864819b3f86073096a7543363 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Mar 2012 09:27:35 -0500 Subject: Put in functions to handle the new group functions --- libdbusmenu-glib/server.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index d85c5fa..0eff073 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -116,7 +116,9 @@ enum { METHOD_GET_PROPERTY, METHOD_GET_PROPERTIES, METHOD_EVENT, + METHOD_EVENT_GROUP, METHOD_ABOUT_TO_SHOW, + METHOD_ABOUT_TO_SHOW_GROUP, /* Counter, do not remove! */ METHOD_COUNT }; @@ -189,9 +191,15 @@ static void bus_get_properties (DbusmenuServer * server, static void bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation); +static void bus_event_group (DbusmenuServer * server, + GVariant * params, + GDBusMethodInvocation * invocation); static void bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation); +static void bus_about_to_show_group (DbusmenuServer * server, + GVariant * params, + GDBusMethodInvocation * invocation); static void find_servers_cb (GDBusConnection * connection, const gchar * sender, const gchar * path, @@ -356,9 +364,15 @@ dbusmenu_server_class_init (DbusmenuServerClass *class) dbusmenu_method_table[METHOD_EVENT].interned_name = g_intern_static_string("Event"); dbusmenu_method_table[METHOD_EVENT].func = bus_event; + dbusmenu_method_table[METHOD_EVENT_GROUP].interned_name = g_intern_static_string("EventGroup"); + dbusmenu_method_table[METHOD_EVENT_GROUP].func = bus_event_group; + dbusmenu_method_table[METHOD_ABOUT_TO_SHOW].interned_name = g_intern_static_string("AboutToShow"); dbusmenu_method_table[METHOD_ABOUT_TO_SHOW].func = bus_about_to_show; + dbusmenu_method_table[METHOD_ABOUT_TO_SHOW_GROUP].interned_name = g_intern_static_string("AboutToShowGroup"); + dbusmenu_method_table[METHOD_ABOUT_TO_SHOW_GROUP].func = bus_about_to_show_group; + return; } @@ -1634,6 +1648,15 @@ bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * i return; } +/* Respond to the event group method that will send events to a + variety of menuitems */ +static void +bus_event_group (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) +{ + /* TODO: DO THIS */ + return; +} + /* Recieve the About To Show function. Pass it to our menu item. */ static void bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) @@ -1669,6 +1692,15 @@ bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvoca return; } +/* Handle the about to show on a set of menus and tell all of them that + we love them */ +static void +bus_about_to_show_group (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) +{ + /* TODO: DO THIS */ + return; +} + /* Public Interface */ /** dbusmenu_server_new: -- cgit v1.2.3 From bc358d3583dc68af36648d09f74d39fa1665c647 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Mar 2012 09:38:16 -0500 Subject: Pulling the core event handling into its own function --- libdbusmenu-glib/server.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index e67ec58..04b9b68 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -1647,6 +1647,28 @@ event_local_handler (gpointer user_data) return FALSE; } +/* The core menu finding and doing the work part of the two + event functions */ +static gboolean +bus_event_core (DbusmenuServer * server, gint32 id, gchar * event_type, GVariant * data, guint32 timestamp) +{ + DbusmenuMenuitem * mi = lookup_menuitem_by_id(server, id); + + if (mi == NULL) { + return FALSE; + } + + idle_event_t * event_data = g_new0(idle_event_t, 1); + event_data->mi = g_object_ref(mi); + event_data->eventid = event_type; /* give away our allocation */ + event_data->timestamp = timestamp; + event_data->variant = data; /* give away our reference */ + + g_timeout_add(0, event_local_handler, event_data); + + return TRUE; +} + /* Handles the events coming off of DBus */ static void bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) @@ -1668,9 +1690,7 @@ bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * i g_variant_get(params, "(isvu)", &id, &etype, &data, &ts); - DbusmenuMenuitem * mi = lookup_menuitem_by_id(server, id); - - if (mi == NULL) { + if (!bus_event_core(server, id, etype, data, ts)) { g_dbus_method_invocation_return_error(invocation, error_quark(), INVALID_MENUITEM_ID, @@ -1678,16 +1698,7 @@ bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * i id); g_free(etype); g_variant_unref(data); - } else { - idle_event_t * event_data = g_new0(idle_event_t, 1); - event_data->mi = g_object_ref(mi); - event_data->eventid = etype; /* give away our allocation */ - event_data->timestamp = ts; - event_data->variant = data; /* give away our reference */ - - g_timeout_add(0, event_local_handler, event_data); - if (~g_dbus_message_get_flags (g_dbus_method_invocation_get_message (invocation)) & G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED) { g_dbus_method_invocation_return_value(invocation, NULL); } -- cgit v1.2.3 From 37c153112c49f04f44cf1781ee49d369ac3ea84c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Mar 2012 10:32:36 -0500 Subject: Fleshing out the event group function --- libdbusmenu-glib/server.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 04b9b68..ab1e0bc 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -1712,7 +1712,54 @@ bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * i static void bus_event_group (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { - /* TODO: DO THIS */ + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + + if (priv->root == NULL) { + g_dbus_method_invocation_return_error(invocation, + error_quark(), + NO_VALID_LAYOUT, + "There currently isn't a layout in this server"); + return; + } + + gint32 id; + gchar *etype; + GVariant *data; + guint32 ts; + GVariantIter iter; + GVariantBuilder builder; + + g_variant_iter_init(&iter, params); + g_variant_builder_init(&builder, G_VARIANT_TYPE("ai")); + gboolean gotone = FALSE; + + while (g_variant_iter_loop(&iter, "(isvu)", &id, &etype, &data, &ts)) { + if (bus_event_core(server, id, etype, data, ts)) { + gotone = TRUE; + } else { + g_variant_builder_add_value(&builder, g_variant_new_int32(id)); + } + } + + GVariant * errors = g_variant_builder_end(&builder); + g_variant_ref_sink(errors); + + if (gotone) { + if (~g_dbus_message_get_flags (g_dbus_method_invocation_get_message (invocation)) & G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED) { + g_dbus_method_invocation_return_value(invocation, g_variant_new_tuple(&errors, 1)); + } + } else { + gchar * ids = g_variant_print(errors, FALSE); + g_dbus_method_invocation_return_error(invocation, + error_quark(), + INVALID_MENUITEM_ID, + "The IDs supplied '%s' do not refer to any menu items we have", + ids); + g_free(ids); + } + + g_variant_unref(errors); + return; } -- cgit v1.2.3 From 2d42ea2907a69630d5d7d6af242914a595727b86 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Mar 2012 10:34:16 -0500 Subject: Make it so the memory handling of the event_core function is more predictable and correct. --- libdbusmenu-glib/server.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index ab1e0bc..39641a5 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -1660,9 +1660,9 @@ bus_event_core (DbusmenuServer * server, gint32 id, gchar * event_type, GVariant idle_event_t * event_data = g_new0(idle_event_t, 1); event_data->mi = g_object_ref(mi); - event_data->eventid = event_type; /* give away our allocation */ + event_data->eventid = g_strdup(event_type); event_data->timestamp = timestamp; - event_data->variant = data; /* give away our reference */ + event_data->variant = g_variant_ref(data); g_timeout_add(0, event_local_handler, event_data); @@ -1696,14 +1696,15 @@ bus_event (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * i INVALID_MENUITEM_ID, "The ID supplied %d does not refer to a menu item we have", id); - g_free(etype); - g_variant_unref(data); } else { if (~g_dbus_message_get_flags (g_dbus_method_invocation_get_message (invocation)) & G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED) { g_dbus_method_invocation_return_value(invocation, NULL); } } + g_free(etype); + g_variant_unref(data); + return; } -- cgit v1.2.3 From 89c84d51382ed5ea769d9ff40eed7062c06214fc Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Mar 2012 11:12:21 -0500 Subject: Fleshing out the about-to-show group handler --- libdbusmenu-glib/server.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 39641a5..289a332 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -1804,7 +1804,61 @@ bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvoca static void bus_about_to_show_group (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) { - /* TODO: DO THIS */ + DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server); + + if (priv->root == NULL) { + g_dbus_method_invocation_return_error(invocation, + error_quark(), + NO_VALID_LAYOUT, + "There currently isn't a layout in this server"); + return; + } + + gint32 id; + GVariantIter iter; + GVariantBuilder builder; + + g_variant_iter_init(&iter, params); + g_variant_builder_init(&builder, G_VARIANT_TYPE("ai")); + gboolean gotone = FALSE; + + while (g_variant_iter_loop(&iter, "(i)", &id)) { + DbusmenuMenuitem * mi = lookup_menuitem_by_id(server, id); + if (mi != NULL) { + dbusmenu_menuitem_send_about_to_show(mi, NULL, NULL); + gotone = TRUE; + } else { + g_variant_builder_add_value(&builder, g_variant_new_int32(id)); + } + } + + GVariant * errors = g_variant_builder_end(&builder); + g_variant_ref_sink(errors); + + if (gotone) { + if (~g_dbus_message_get_flags (g_dbus_method_invocation_get_message (invocation)) & G_DBUS_MESSAGE_FLAGS_NO_REPLY_EXPECTED) { + GVariantBuilder tuple; + g_variant_builder_init(&tuple, G_VARIANT_TYPE_TUPLE); + + /* Updates needed */ + g_variant_builder_add_value(&tuple, g_variant_new_array(G_VARIANT_TYPE_INT32, NULL, 0)); + /* Errors */ + g_variant_builder_add_value(&tuple, errors); + + g_dbus_method_invocation_return_value(invocation, g_variant_builder_end(&tuple)); + } + } else { + gchar * ids = g_variant_print(errors, FALSE); + g_dbus_method_invocation_return_error(invocation, + error_quark(), + INVALID_MENUITEM_ID, + "The IDs supplied '%s' do not refer to any menu items we have", + ids); + g_free(ids); + } + + g_variant_unref(errors); + return; } -- cgit v1.2.3 From c780e1632e57e24233ee374d96b74375c881696b Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Mar 2012 11:16:56 -0500 Subject: Move the actual about-to-show call into the idle incase we get a ton of them (I'm looking at you HUD) --- libdbusmenu-glib/server.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 289a332..2ba45d9 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -1764,6 +1764,18 @@ bus_event_group (DbusmenuServer * server, GVariant * params, GDBusMethodInvocati return; } +/* Does the about-to-show in an idle loop so we don't block things */ +/* NOTE: this only works so easily as we don't return the value, if we + were to do that it would get more complex. */ +static gboolean +bus_about_to_show_idle (gpointer user_data) +{ + DbusmenuMenuitem * mi = DBUSMENU_MENUITEM(user_data); + dbusmenu_menuitem_send_about_to_show(mi, NULL, NULL); + g_object_unref(mi); + return FALSE; +} + /* Recieve the About To Show function. Pass it to our menu item. */ static void bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvocation * invocation) @@ -1791,7 +1803,7 @@ bus_about_to_show (DbusmenuServer * server, GVariant * params, GDBusMethodInvoca return; } - dbusmenu_menuitem_send_about_to_show(mi, NULL, NULL); + g_timeout_add(0, bus_about_to_show_idle, g_object_ref(mi)); /* GTK+ does not support about-to-show concept for now */ g_dbus_method_invocation_return_value(invocation, @@ -1825,7 +1837,7 @@ bus_about_to_show_group (DbusmenuServer * server, GVariant * params, GDBusMethod while (g_variant_iter_loop(&iter, "(i)", &id)) { DbusmenuMenuitem * mi = lookup_menuitem_by_id(server, id); if (mi != NULL) { - dbusmenu_menuitem_send_about_to_show(mi, NULL, NULL); + g_timeout_add(0, bus_about_to_show_idle, g_object_ref(mi)); gotone = TRUE; } else { g_variant_builder_add_value(&builder, g_variant_new_int32(id)); -- cgit v1.2.3 From 37eaae37fb9dc7163e3e91bc81debcca22ae46ff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Mar 2012 16:23:39 -0500 Subject: Unpacking the tuple --- libdbusmenu-glib/server.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/server.c') diff --git a/libdbusmenu-glib/server.c b/libdbusmenu-glib/server.c index 2ba45d9..091b243 100644 --- a/libdbusmenu-glib/server.c +++ b/libdbusmenu-glib/server.c @@ -1723,6 +1723,7 @@ bus_event_group (DbusmenuServer * server, GVariant * params, GDBusMethodInvocati return; } + GVariant * events = g_variant_get_child_value(params, 0); gint32 id; gchar *etype; GVariant *data; @@ -1730,7 +1731,7 @@ bus_event_group (DbusmenuServer * server, GVariant * params, GDBusMethodInvocati GVariantIter iter; GVariantBuilder builder; - g_variant_iter_init(&iter, params); + g_variant_iter_init(&iter, events); g_variant_builder_init(&builder, G_VARIANT_TYPE("ai")); gboolean gotone = FALSE; @@ -1760,6 +1761,7 @@ bus_event_group (DbusmenuServer * server, GVariant * params, GDBusMethodInvocati } g_variant_unref(errors); + g_variant_unref(events); return; } -- cgit v1.2.3