From 761cd05f56dd236e787ce7da56740b7e0c6ae399 Mon Sep 17 00:00:00 2001 From: Aurelien Gateau Date: Wed, 3 Mar 2010 12:29:28 +0100 Subject: Started to implement about-to-show support --- libdbusmenu-glib/client.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 309a11c..7cf5a14 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -668,6 +668,36 @@ dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name return; } +static void +about_to_show_cb (DBusGProxy * proxy, gboolean need_update, GError * error, gpointer userdata) +{ + DbusmenuClient * client = DBUSMENU_CLIENT(userdata); + if (error != NULL) { + g_warning("Unable to send about_to_show: %s", error->message); + return; + } + + if (need_update) { + update_layout(client); + } + return; +} + +void +dbusmenu_client_send_about_to_show(DbusmenuClient * client, gint id) +{ + DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); + org_ayatana_dbusmenu_about_to_show_async (priv->menuproxy, id, about_to_show_cb, client); + /* + FIXME: We should wait until either + - about_to_show_cb has been called and need_update was false + - about_to_show_cb has been called, need_update was true and menu has been + updated + - about_to_show_cb has not been called and we already waited for 10msecs + */ + return; +} + /* Parse recursively through the XML and make it into objects as need be */ static DbusmenuMenuitem * -- cgit v1.2.3 From 75b0bba462e192a32e4484e52d0751852d03df12 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 31 Mar 2010 12:29:20 -0500 Subject: Adding a bunch of comments --- libdbusmenu-glib/client.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 7cf5a14..940adad 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -660,6 +660,8 @@ menuitem_call_cb (DBusGProxy * proxy, GError * error, gpointer userdata) return; } +/* Sends the event over DBus to the server on the other side + of the bus. */ void dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name, const GValue * value, guint timestamp) { @@ -668,6 +670,8 @@ dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name return; } +/* Reports errors and responds to update request that were a result + of sending the about to show signal. */ static void about_to_show_cb (DBusGProxy * proxy, gboolean need_update, GError * error, gpointer userdata) { @@ -683,17 +687,22 @@ about_to_show_cb (DBusGProxy * proxy, gboolean need_update, GError * error, gpoi return; } +/* Sends the about to show signal for a given id to the + server on the other side of DBus */ void dbusmenu_client_send_about_to_show(DbusmenuClient * client, gint id) { DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); org_ayatana_dbusmenu_about_to_show_async (priv->menuproxy, id, about_to_show_cb, client); /* - FIXME: We should wait until either + TODO: We should ideally restrict the displaying of the menu until: + - about_to_show_cb has been called and need_update was false - about_to_show_cb has been called, need_update was true and menu has been updated - about_to_show_cb has not been called and we already waited for 10msecs + + There's not really support in GTK for doing this easily. */ return; } -- cgit v1.2.3 From cae176681adb2e32464ec690b319008ae04a4a09 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 31 Mar 2010 13:47:27 -0500 Subject: Adding a set of callbacks so that we can respond to the about to show request. --- libdbusmenu-glib/client.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'libdbusmenu-glib/client.c') diff --git a/libdbusmenu-glib/client.c b/libdbusmenu-glib/client.c index 940adad..ef0205f 100644 --- a/libdbusmenu-glib/client.c +++ b/libdbusmenu-glib/client.c @@ -670,40 +670,55 @@ dbusmenu_client_send_event (DbusmenuClient * client, gint id, const gchar * name return; } +typedef struct _about_to_show_t about_to_show_t; +struct _about_to_show_t { + DbusmenuClient * client; + void (*cb) (gpointer data); + gpointer cb_data; +}; + /* Reports errors and responds to update request that were a result of sending the about to show signal. */ static void about_to_show_cb (DBusGProxy * proxy, gboolean need_update, GError * error, gpointer userdata) { - DbusmenuClient * client = DBUSMENU_CLIENT(userdata); + about_to_show_t * data = (about_to_show_t *)userdata; + if (error != NULL) { g_warning("Unable to send about_to_show: %s", error->message); - return; + /* Note: we're just ensuring only the callback gets called */ + need_update = FALSE; } + /* If we need to update, do that first. */ if (need_update) { - update_layout(client); + update_layout(data->client); } + + if (data->cb != NULL) { + data->cb(data->cb_data); + } + + g_object_unref(data->client); + g_free(data); + return; } /* Sends the about to show signal for a given id to the server on the other side of DBus */ void -dbusmenu_client_send_about_to_show(DbusmenuClient * client, gint id) +dbusmenu_client_send_about_to_show(DbusmenuClient * client, gint id, void (*cb)(gpointer data), gpointer cb_data) { DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client); - org_ayatana_dbusmenu_about_to_show_async (priv->menuproxy, id, about_to_show_cb, client); - /* - TODO: We should ideally restrict the displaying of the menu until: - - about_to_show_cb has been called and need_update was false - - about_to_show_cb has been called, need_update was true and menu has been - updated - - about_to_show_cb has not been called and we already waited for 10msecs + about_to_show_t * data = g_new0(about_to_show_t, 1); + data->client = client; + data->cb = cb; + data->cb_data = cb_data; + g_object_ref(client); - There's not really support in GTK for doing this easily. - */ + org_ayatana_dbusmenu_about_to_show_async (priv->menuproxy, id, about_to_show_cb, data); return; } -- cgit v1.2.3