Merge lp:~agateau/libdbusmenu/about-to-show into lp:libdbusmenu/0.5

Proposed by Aurélien Gâteau
Status: Merged
Merged at revision: not available
Proposed branch: lp:~agateau/libdbusmenu/about-to-show
Merge into: lp:libdbusmenu/0.5
Diff against target: 250 lines (+110/-5)
9 files modified
libdbusmenu-glib/client-menuitem.c (+10/-0)
libdbusmenu-glib/client.c (+30/-0)
libdbusmenu-glib/client.h (+2/-0)
libdbusmenu-glib/dbus-menu.xml (+5/-0)
libdbusmenu-glib/menuitem.c (+14/-0)
libdbusmenu-glib/menuitem.h (+5/-1)
libdbusmenu-glib/server.c (+23/-0)
libdbusmenu-gtk/client.c (+8/-4)
libdbusmenu-gtk/menu.c (+13/-0)
To merge this branch: bzr merge lp:~agateau/libdbusmenu/about-to-show
Reviewer Review Type Date Requested Status
David Barth (community) Needs Information
Review via email: mp+20570@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Aurélien Gâteau (agateau) wrote :

This changeset adds the "bool AboutToShow(int)" method and ensures this method is called when menus are about to show.

Current code does not exploit the returned value, which should be set to true by the server if the menu has been updated. It should nevertheless ensure KDE application menus will continue to show up correctly in the GNOME desktop when the hack I introduced in dbusmenu-qt for Lucid a3 is removed.

Revision history for this message
David Barth (dbarth) wrote :

What's the FIXME about in dbusmenu_client_send_about_to_show ?

review: Needs Information
Revision history for this message
Aurélien Gâteau (agateau) wrote :

Right now the code does not wait for aboutToShow() to answer before showing the menu. This means it may show an empty menu before receiving the updated menu. Still it's better than always showing an empty menu (as is the case with Kopete without the patch).

Actually the code Ted merged is a bit different, so this FIXME no longer apply I think.

Revision history for this message
Ted Gould (ted) wrote :

On Thu, 2010-04-01 at 08:57 +0000, Aurélien Gâteau wrote:
> Actually the code Ted merged is a bit different, so this
> FIXME no longer apply I think.

Well, kinda. It just pushes the FIXME into the GTK lib instead of being
in the Glib one. But I think it can be fixed without changing GLib now
which was my goal. I think Cody will have to fix the actual pausing for
L+1 as I'm not sure how to do that.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libdbusmenu-glib/client-menuitem.c'
2--- libdbusmenu-glib/client-menuitem.c 2010-02-04 02:45:12 +0000
3+++ libdbusmenu-glib/client-menuitem.c 2010-03-03 16:52:15 +0000
4@@ -46,6 +46,7 @@
5 static void dbusmenu_client_menuitem_dispose (GObject *object);
6 static void dbusmenu_client_menuitem_finalize (GObject *object);
7 static void handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp);
8+static void send_about_to_show (DbusmenuMenuitem * mi);
9
10 G_DEFINE_TYPE (DbusmenuClientMenuitem, dbusmenu_client_menuitem, DBUSMENU_TYPE_MENUITEM);
11
12@@ -61,6 +62,7 @@
13
14 DbusmenuMenuitemClass * mclass = DBUSMENU_MENUITEM_CLASS(klass);
15 mclass->handle_event = handle_event;
16+ mclass->send_about_to_show = send_about_to_show;
17
18 return;
19 }
20@@ -104,3 +106,11 @@
21 dbusmenu_client_send_event(priv->client, dbusmenu_menuitem_get_id(mi), name, value, timestamp);
22 return;
23 }
24+
25+static void
26+send_about_to_show (DbusmenuMenuitem * mi)
27+{
28+ DbusmenuClientMenuitemPrivate * priv = DBUSMENU_CLIENT_MENUITEM_GET_PRIVATE(mi);
29+ dbusmenu_client_send_about_to_show(priv->client, dbusmenu_menuitem_get_id(mi));
30+ return;
31+}
32
33=== modified file 'libdbusmenu-glib/client.c'
34--- libdbusmenu-glib/client.c 2010-02-24 19:17:38 +0000
35+++ libdbusmenu-glib/client.c 2010-03-03 16:52:15 +0000
36@@ -668,6 +668,36 @@
37 return;
38 }
39
40+static void
41+about_to_show_cb (DBusGProxy * proxy, gboolean need_update, GError * error, gpointer userdata)
42+{
43+ DbusmenuClient * client = DBUSMENU_CLIENT(userdata);
44+ if (error != NULL) {
45+ g_warning("Unable to send about_to_show: %s", error->message);
46+ return;
47+ }
48+
49+ if (need_update) {
50+ update_layout(client);
51+ }
52+ return;
53+}
54+
55+void
56+dbusmenu_client_send_about_to_show(DbusmenuClient * client, gint id)
57+{
58+ DbusmenuClientPrivate * priv = DBUSMENU_CLIENT_GET_PRIVATE(client);
59+ org_ayatana_dbusmenu_about_to_show_async (priv->menuproxy, id, about_to_show_cb, client);
60+ /*
61+ FIXME: We should wait until either
62+ - about_to_show_cb has been called and need_update was false
63+ - about_to_show_cb has been called, need_update was true and menu has been
64+ updated
65+ - about_to_show_cb has not been called and we already waited for 10msecs
66+ */
67+ return;
68+}
69+
70 /* Parse recursively through the XML and make it into
71 objects as need be */
72 static DbusmenuMenuitem *
73
74=== modified file 'libdbusmenu-glib/client.h'
75--- libdbusmenu-glib/client.h 2010-02-04 17:59:00 +0000
76+++ libdbusmenu-glib/client.h 2010-03-03 16:52:15 +0000
77@@ -109,6 +109,8 @@
78 const gchar * name,
79 const GValue * value,
80 guint timestamp);
81+void dbusmenu_client_send_about_to_show(DbusmenuClient * client,
82+ gint id);
83
84 /**
85 SECTION:client
86
87=== modified file 'libdbusmenu-glib/dbus-menu.xml'
88--- libdbusmenu-glib/dbus-menu.xml 2010-02-04 23:56:30 +0000
89+++ libdbusmenu-glib/dbus-menu.xml 2010-03-03 16:52:15 +0000
90@@ -265,6 +265,11 @@
91 </arg>
92 </method>
93
94+ <method name="AboutToShow">
95+ <arg type="i" name="id" direction="in"></arg>
96+ <arg type="b" name="needUpdate" direction="out"></arg>
97+ </method>
98+
99 <!-- Signals -->
100 <signal name="ItemPropertyUpdated">
101 <dox:d>
102
103=== modified file 'libdbusmenu-glib/menuitem.c'
104--- libdbusmenu-glib/menuitem.c 2010-02-08 22:02:12 +0000
105+++ libdbusmenu-glib/menuitem.c 2010-03-03 16:52:15 +0000
106@@ -1203,3 +1203,17 @@
107 }
108 return;
109 }
110+void
111+dbusmenu_menuitem_send_about_to_show (DbusmenuMenuitem * mi)
112+{
113+ g_return_if_fail(DBUSMENU_IS_MENUITEM(mi));
114+ #ifdef MASSIVEDEBUGGING
115+ g_debug("Submenu for menuitem %d (%s) is about to be shown", ID(mi), LABEL(mi));
116+ #endif
117+ DbusmenuMenuitemClass * class = DBUSMENU_MENUITEM_GET_CLASS(mi);
118+
119+ if (class->send_about_to_show != NULL) {
120+ return class->send_about_to_show(mi);
121+ }
122+ return;
123+}
124
125=== modified file 'libdbusmenu-glib/menuitem.h'
126--- libdbusmenu-glib/menuitem.h 2010-02-05 18:48:48 +0000
127+++ libdbusmenu-glib/menuitem.h 2010-03-03 16:52:15 +0000
128@@ -95,6 +95,8 @@
129 @handle_event: This function is to override how events are handled
130 by subclasses. Look at #dbusmenu_menuitem_handle_event for
131 lots of good information.
132+ @send_about_to_show: Virtual function that notifies server that the
133+ client is about to show a menu.
134 @reserved1: Reserved for future use.
135 @reserved2: Reserved for future use.
136 @reserved3: Reserved for future use.
137@@ -116,9 +118,10 @@
138 /* Virtual functions */
139 void (*buildxml) (GPtrArray * stringarray);
140 void (*handle_event) (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp);
141+ void (*send_about_to_show) (DbusmenuMenuitem * mi);
142
143 void (*reserved1) (void);
144- void (*reserved2) (void);
145+ /* void (*reserved2) (void); */
146 /* void (*reserved3) (void); */
147 /* void (*reserved4) (void); -- realized, realloc when bumping lib version */
148 };
149@@ -159,6 +162,7 @@
150
151 void dbusmenu_menuitem_foreach (DbusmenuMenuitem * mi, void (*func) (DbusmenuMenuitem * mi, gpointer data), gpointer data);
152 void dbusmenu_menuitem_handle_event (DbusmenuMenuitem * mi, const gchar * name, const GValue * value, guint timestamp);
153+void dbusmenu_menuitem_send_about_to_show (DbusmenuMenuitem * mi);
154
155 /**
156 SECTION:menuitem
157
158=== modified file 'libdbusmenu-glib/server.c'
159--- libdbusmenu-glib/server.c 2010-02-18 16:27:53 +0000
160+++ libdbusmenu-glib/server.c 2010-03-03 16:52:16 +0000
161@@ -41,6 +41,7 @@
162 static gboolean _dbusmenu_server_get_group_properties (DbusmenuServer * server, GArray * ids, GArray * properties, GHashTable ** values, GError ** error);
163 static gboolean _dbusmenu_server_event (DbusmenuServer * server, gint id, gchar * eventid, GValue * data, guint timestamp, GError ** error);
164 static gboolean _dbusmenu_server_get_children (DbusmenuServer * server, gint id, GPtrArray * properties, GPtrArray ** output, GError ** error);
165+static gboolean _dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error);
166
167 #include "dbusmenu-server.h"
168
169@@ -578,6 +579,28 @@
170 return TRUE;
171 }
172
173+static gboolean
174+_dbusmenu_server_about_to_show (DbusmenuServer * server, gint id, gboolean * need_update, GError ** error)
175+{
176+ DbusmenuServerPrivate * priv = DBUSMENU_SERVER_GET_PRIVATE(server);
177+ DbusmenuMenuitem * mi = dbusmenu_menuitem_find_id(priv->root, id);
178+
179+ if (mi == NULL) {
180+ if (error != NULL) {
181+ g_set_error(error,
182+ error_quark(),
183+ INVALID_MENUITEM_ID,
184+ "The ID supplied %d does not refer to a menu item we have",
185+ id);
186+ }
187+ return FALSE;
188+ }
189+
190+ /* GTK+ does not support about-to-show concept for now */
191+ *need_update = FALSE;
192+ return TRUE;
193+}
194+
195 /* Public Interface */
196 /**
197 dbusmenu_server_new:
198
199=== modified file 'libdbusmenu-gtk/client.c'
200--- libdbusmenu-gtk/client.c 2010-02-04 18:56:49 +0000
201+++ libdbusmenu-gtk/client.c 2010-03-03 16:52:16 +0000
202@@ -109,10 +109,14 @@
203 static gboolean
204 menu_pressed_cb (GtkMenuItem * gmi, DbusmenuMenuitem * mi)
205 {
206- GValue value = {0};
207- g_value_init(&value, G_TYPE_INT);
208- g_value_set_int(&value, 0);
209- dbusmenu_menuitem_handle_event(mi, "clicked", &value, gtk_get_current_event_time());
210+ if (gtk_menu_item_get_submenu(gmi) == NULL) {
211+ GValue value = {0};
212+ g_value_init(&value, G_TYPE_INT);
213+ g_value_set_int(&value, 0);
214+ dbusmenu_menuitem_handle_event(mi, "clicked", &value, gtk_get_current_event_time());
215+ } else {
216+ dbusmenu_menuitem_send_about_to_show(mi);
217+ }
218 return TRUE;
219 }
220
221
222=== modified file 'libdbusmenu-gtk/menu.c'
223--- libdbusmenu-gtk/menu.c 2009-10-05 14:00:34 +0000
224+++ libdbusmenu-gtk/menu.c 2010-03-03 16:52:16 +0000
225@@ -96,6 +96,17 @@
226 }
227
228 static void
229+menu_focus_cb(DbusmenuGtkMenu * menu, gpointer userdata)
230+{
231+ g_debug(__FUNCTION__);
232+ DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(menu);
233+ if (priv->client != NULL) {
234+ dbusmenu_client_send_about_to_show(DBUSMENU_CLIENT(priv->client), 0);
235+ }
236+ return;
237+}
238+
239+static void
240 dbusmenu_gtkmenu_init (DbusmenuGtkMenu *self)
241 {
242 DbusmenuGtkMenuPrivate * priv = DBUSMENU_GTKMENU_GET_PRIVATE(self);
243@@ -105,6 +116,8 @@
244 priv->dbus_object = NULL;
245 priv->dbus_name = NULL;
246
247+ g_signal_connect(G_OBJECT(self), "focus", G_CALLBACK(menu_focus_cb), self);
248+
249 return;
250 }
251

Subscribers

People subscribed via source and target branches