Merge lp:~ted/libdbusmenu/submenu-woes into lp:libdbusmenu/0.5

Proposed by Ted Gould
Status: Merged
Merged at revision: 291
Proposed branch: lp:~ted/libdbusmenu/submenu-woes
Merge into: lp:libdbusmenu/0.5
Diff against target: 141 lines (+49/-16)
3 files modified
libdbusmenu-glib/client.c (+6/-3)
libdbusmenu-glib/menuitem.c (+1/-1)
libdbusmenu-gtk/client.c (+42/-12)
To merge this branch: bzr merge lp:~ted/libdbusmenu/submenu-woes
Reviewer Review Type Date Requested Status
Jay Taoko (community) Approve
Review via email: mp+56434@code.launchpad.net

Description of the change

Make it so that we follow the child-display property more than the existance of children for building the GTK menu.

To post a comment you must log in.
Revision history for this message
Jay Taoko (jaytaoko) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'libdbusmenu-glib/client.c'
2--- libdbusmenu-glib/client.c 2011-03-29 02:24:01 +0000
3+++ libdbusmenu-glib/client.c 2011-04-05 19:03:00 +0000
4@@ -331,6 +331,8 @@
5 return;
6 }
7
8+#define LAYOUT_PROPS_COUNT 5
9+
10 static void
11 dbusmenu_client_init (DbusmenuClient *self)
12 {
13@@ -351,13 +353,14 @@
14
15 priv->layoutcall = NULL;
16
17- gchar * layout_props[5];
18+ gchar * layout_props[LAYOUT_PROPS_COUNT + 1];
19 layout_props[0] = DBUSMENU_MENUITEM_PROP_TYPE;
20 layout_props[1] = DBUSMENU_MENUITEM_PROP_LABEL;
21 layout_props[2] = DBUSMENU_MENUITEM_PROP_VISIBLE;
22 layout_props[3] = DBUSMENU_MENUITEM_PROP_ENABLED;
23- layout_props[4] = NULL;
24- priv->layout_props = g_variant_new_strv((const gchar * const *)layout_props, 4);
25+ layout_props[4] = DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY;
26+ layout_props[LAYOUT_PROPS_COUNT] = NULL;
27+ priv->layout_props = g_variant_new_strv((const gchar * const *)layout_props, LAYOUT_PROPS_COUNT);
28 g_variant_ref_sink(priv->layout_props);
29
30 priv->current_revision = 0;
31
32=== modified file 'libdbusmenu-glib/menuitem.c'
33--- libdbusmenu-glib/menuitem.c 2011-03-16 15:27:00 +0000
34+++ libdbusmenu-glib/menuitem.c 2011-04-05 19:03:00 +0000
35@@ -446,7 +446,7 @@
36 {
37 g_return_if_fail(DBUSMENU_IS_MENUITEM(mi));
38
39- if (dbusmenu_menuitem_get_children(mi) == NULL) {
40+ if (dbusmenu_menuitem_get_children(mi) == NULL && g_strcmp0(DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU, dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY)) != 0) {
41 g_warning("About to Show called on an item wihtout submenus. We're ignoring it.");
42 } else {
43 gboolean dummy;
44
45=== modified file 'libdbusmenu-gtk/client.c'
46--- libdbusmenu-gtk/client.c 2011-03-16 15:27:00 +0000
47+++ libdbusmenu-gtk/client.c 2011-04-05 19:03:00 +0000
48@@ -551,11 +551,43 @@
49 return;
50 }
51
52+/* Submenu processing */
53+static void
54+process_submenu (DbusmenuMenuitem * mi, GtkMenuItem * gmi, GVariant * variant, DbusmenuGtkClient * gtkclient)
55+{
56+ const gchar * submenu = NULL;
57+ if (variant != NULL) {
58+ submenu = g_variant_get_string(variant, NULL);
59+ }
60+
61+ if (g_strcmp0(submenu, DBUSMENU_MENUITEM_CHILD_DISPLAY_SUBMENU) != 0) {
62+ /* This is the only case we're really supporting right now,
63+ so if it's not this, we want to clean up. */
64+ /* We're just going to warn for now. */
65+ gpointer pmenu = g_object_get_data(G_OBJECT(mi), data_menu);
66+ if (pmenu != NULL) {
67+ g_warning("The child-display variable is set to '%s' but there's a menu, odd?", submenu);
68+ }
69+ } else {
70+ /* We need to build a menu for these guys to live in. */
71+ GtkMenu * menu = GTK_MENU(gtk_menu_new());
72+ g_object_set_data(G_OBJECT(mi), data_menu, menu);
73+
74+ gtk_menu_item_set_submenu(gmi, GTK_WIDGET(menu));
75+
76+ g_signal_connect(menu, "notify::visible", G_CALLBACK(submenu_notify_visible_cb), mi);
77+ }
78+
79+ return;
80+}
81+
82 /* Whenever we have a property change on a DbusmenuMenuitem
83 we need to be responsive to that. */
84 static void
85-menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * variant, GtkMenuItem * gmi)
86+menu_prop_change_cb (DbusmenuMenuitem * mi, gchar * prop, GVariant * variant, DbusmenuGtkClient * gtkclient)
87 {
88+ GtkMenuItem * gmi = dbusmenu_gtkclient_menuitem_get(gtkclient, mi);
89+
90 if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_LABEL)) {
91 gtk_menu_item_set_label(gmi, variant == NULL ? NULL : g_variant_get_string(variant, NULL));
92 } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_VISIBLE)) {
93@@ -566,6 +598,8 @@
94 process_toggle_type(mi, gmi, variant);
95 } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE)) {
96 process_toggle_state(mi, gmi, variant);
97+ } else if (!g_strcmp0(prop, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY)) {
98+ process_submenu(mi, gmi, variant, gtkclient);
99 }
100
101 return;
102@@ -704,7 +738,7 @@
103 #endif
104
105 /* DbusmenuMenuitem signals */
106- g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), gmi);
107+ g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_prop_change_cb), client);
108 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_PROPERTY_CHANGED, G_CALLBACK(menu_shortcut_change_cb), client);
109 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_REMOVED, G_CALLBACK(delete_child), client);
110 g_signal_connect(G_OBJECT(item), DBUSMENU_MENUITEM_SIGNAL_CHILD_MOVED, G_CALLBACK(move_child), client);
111@@ -720,6 +754,7 @@
112 process_sensitive(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_ENABLED));
113 process_toggle_type(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE));
114 process_toggle_state(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE));
115+ process_submenu(item, gmi, dbusmenu_menuitem_property_get_variant(item, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY), client);
116 refresh_shortcut(client, item);
117
118 /* Oh, we're a child, let's deal with that */
119@@ -741,17 +776,12 @@
120 if (g_strcmp0(dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_TYPE), DBUSMENU_CLIENT_TYPES_SEPARATOR) == 0) { return; }
121
122 gpointer ann_menu = g_object_get_data(G_OBJECT(mi), data_menu);
123+ if (ann_menu == NULL) {
124+ g_warning("Children but no menu, someone's been naughty with their '" DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY "' property: '%s'", dbusmenu_menuitem_property_get(mi, DBUSMENU_MENUITEM_PROP_CHILD_DISPLAY));
125+ return;
126+ }
127+
128 GtkMenu * menu = GTK_MENU(ann_menu);
129- if (menu == NULL) {
130- /* Oh, we don't have a submenu, build one! */
131- menu = GTK_MENU(gtk_menu_new());
132- g_object_set_data(G_OBJECT(mi), data_menu, menu);
133-
134- GtkMenuItem * parent = dbusmenu_gtkclient_menuitem_get(gtkclient, mi);
135- gtk_menu_item_set_submenu(parent, GTK_WIDGET(menu));
136-
137- g_signal_connect(menu, "notify::visible", G_CALLBACK(submenu_notify_visible_cb), mi);
138- }
139
140 GtkMenuItem * childmi = dbusmenu_gtkclient_menuitem_get(gtkclient, child);
141 gtk_menu_shell_insert(GTK_MENU_SHELL(menu), GTK_WIDGET(childmi), position);

Subscribers

People subscribed via source and target branches