Merge lp:~dcbw/libdbusmenu/libdbusmenu into lp:libdbusmenu/15.10

Proposed by Dan Williams
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: 479
Merged at revision: 479
Proposed branch: lp:~dcbw/libdbusmenu/libdbusmenu
Merge into: lp:libdbusmenu/15.10
Diff against target: 276 lines (+59/-33)
4 files modified
configure.ac (+0/-1)
libdbusmenu-gtk/client.c (+6/-1)
libdbusmenu-gtk/genericmenuitem.c (+15/-10)
libdbusmenu-gtk/parser.c (+38/-21)
To merge this branch: bzr merge lp:~dcbw/libdbusmenu/libdbusmenu
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
Dan Williams (community) Needs Resubmitting
Review via email: mp+286843@code.launchpad.net

Commit message

gtk: look for GtkImages on regular GtkMenuItems too

GtkImageMenuItem is deprecated, and the recommended replacement
is a normal GtkMenuItem packed manually with a label and an image.
To ensure applications that use recommended GTK practices can still
show menu item images, check the children of a normal GtkMenuItem
for a GtkImage too, just like is done for the label child.

Description of the change

GtkImageMenuItem has been deprecated for a long time in upstream GTK; projects that use dbusmenu but do not want to depend on deprecated GTK functionality cannot use images in menu items because dbusmenu only looks for images on GtkImageMenuItems.

Upstream recommended replacement for GtkImageMenuItem is to simply pack your own label + image into a normal GtkMenuItem. Thus, make dbusmenu look for images in normal GtkMenuItems to.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Looks good, thanks for your contribution and the nice cleanup.

There's just one small fix to do: http://paste.ubuntu.com/15180692/ otherwise libappindicator based menus will be misaligned (http://i.imgur.com/DXqeWwy.png)

review: Needs Fixing
lp:~dcbw/libdbusmenu/libdbusmenu updated
478. By Dan Williams <email address hidden>

gtk: fix some GTKv3 deprecations and get rid of HAVE_GTK3

479. By Dan Williams <email address hidden>

gtk: look for GtkImages on regular GtkMenuItems too

GtkImageMenuItem is deprecated, and the recommended replacement
is a normal GtkMenuItem packed manually with a label and an image.
To ensure applications that use recommended GTK practices can still
show menu item images, check the children of a normal GtkMenuItem
for a GtkImage too, just like is done for the label child.

Revision history for this message
Dan Williams (dcbw) wrote :

> Looks good, thanks for your contribution and the nice cleanup.
>
> There's just one small fix to do: http://paste.ubuntu.com/15180692/ otherwise
> libappindicator based menus will be misaligned
> (http://i.imgur.com/DXqeWwy.png)

I was testing nm-applet (which does use libappindicator) using https://extensions.gnome.org/extension/615/appindicator-support/, obligatory screenshot without the halign here:

http://people.redhat.com/dcbw/nm-applet-indicator.png

but the changes don't seem to hurt anything and are likely correct. Repushed.

Revision history for this message
Dan Williams (dcbw) :
review: Needs Resubmitting
Revision history for this message
Dan Williams (dcbw) wrote :

No idea how to move the review back to 'pending' or whatever it is, so I tried 'resubmit'. If that's not correct, sorry!

Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

> No idea how to move the review back to 'pending' or whatever it is, so I tried
> 'resubmit'. If that's not correct, sorry!

It was already in "pending mode" (until the top value is under "Needs review"), no worries.

Anyway, thanks for the update!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2013-07-22 05:15:14 +0000
3+++ configure.ac 2016-02-23 20:10:45 +0000
4@@ -67,7 +67,6 @@
5 glib-2.0 >= $GLIB_REQUIRED_VERSION,
6 [have_gtk=yes]
7 )
8- AC_DEFINE(HAVE_GTK3, 1, [whether gtk3 is available])
9 ],
10 [test "x$with_gtk" = x2],
11 [PKG_CHECK_MODULES(DBUSMENUGTK, gtk+-2.0 >= $GTK_REQUIRED_VERSION
12
13=== modified file 'libdbusmenu-gtk/client.c'
14--- libdbusmenu-gtk/client.c 2013-05-15 11:44:38 +0000
15+++ libdbusmenu-gtk/client.c 2016-02-23 20:10:45 +0000
16@@ -842,7 +842,7 @@
17 doesn't expose the right variables. We need to figure
18 this out as menus won't get grabs properly.
19 TODO FIXME HELP ARGHHHHHHHH */
20-#if (HAVE_GTK3 == 0)
21+#if !GTK_CHECK_VERSION(3,0,0)
22 if (!GTK_MENU_SHELL (parent)->active) {
23 gtk_grab_add (parent);
24 GTK_MENU_SHELL (parent)->have_grab = TRUE;
25@@ -1278,7 +1278,12 @@
26 gtk_icon_size_lookup(GTK_ICON_SIZE_MENU, &width, &height);
27
28 gtk_widget_set_size_request(GTK_WIDGET(gtkimage), width, height);
29+#if GTK_CHECK_VERSION(3,0,0)
30+ gtk_widget_set_halign(GTK_WIDGET(gtkimage), GTK_ALIGN_START);
31+ gtk_widget_set_valign(GTK_WIDGET(gtkimage), GTK_ALIGN_CENTER);
32+#else
33 gtk_misc_set_alignment(GTK_MISC(gtkimage), 0.0, 0.5);
34+#endif
35 }
36
37 genericmenuitem_set_image(GENERICMENUITEM(gimi), gtkimage);
38
39=== modified file 'libdbusmenu-gtk/genericmenuitem.c'
40--- libdbusmenu-gtk/genericmenuitem.c 2012-11-21 18:13:53 +0000
41+++ libdbusmenu-gtk/genericmenuitem.c 2016-02-23 20:10:45 +0000
42@@ -62,7 +62,7 @@
43 /* GObject stuff */
44 G_DEFINE_TYPE (Genericmenuitem, genericmenuitem, GTK_TYPE_CHECK_MENU_ITEM);
45
46-#if HAVE_GTK3
47+#if GTK_CHECK_VERSION(3,0,0)
48 static void draw_indicator (GtkCheckMenuItem *check_menu_item, cairo_t *cr);
49 static void (*parent_draw_indicator) (GtkCheckMenuItem *check_menu_item, cairo_t *cr) = NULL;
50 #else
51@@ -83,7 +83,7 @@
52 object_class->dispose = genericmenuitem_dispose;
53 object_class->finalize = genericmenuitem_finalize;
54
55-#ifdef HAVE_GTK3
56+#if GTK_CHECK_VERSION(3,2,0)
57 GtkWidgetClass * widget_class = GTK_WIDGET_CLASS(klass);
58
59 gtk_widget_class_set_accessible_role(widget_class, ATK_ROLE_MENU_ITEM);
60@@ -115,7 +115,7 @@
61 self->priv->disposition = GENERICMENUITEM_DISPOSITION_NORMAL;
62 self->priv->label_text = NULL;
63
64-#ifndef HAVE_GTK3
65+#if !GTK_CHECK_VERSION(3,0,0)
66 AtkObject * aobj = gtk_widget_get_accessible(GTK_WIDGET(self));
67 if (aobj != NULL) {
68 atk_object_set_role(aobj, ATK_ROLE_MENU_ITEM);
69@@ -148,7 +148,7 @@
70 /* Checks to see if we should be drawing a little box at
71 all. If we should be, let's do that, otherwise we're
72 going suppress the box drawing. */
73-#if HAVE_GTK3
74+#if GTK_CHECK_VERSION(3,0,0)
75 static void
76 draw_indicator (GtkCheckMenuItem *check_menu_item, cairo_t *cr)
77 {
78@@ -310,12 +310,12 @@
79 /* We need to put the child into a new box and
80 make the box the child of the menu item. Basically
81 we're inserting a box in the middle. */
82- #ifdef HAVE_GTK3
83+#if GTK_CHECK_VERSION(3,0,0)
84 GtkWidget * hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,
85 get_toggle_space(GTK_WIDGET(menu_item)));
86- #else
87+#else
88 GtkWidget * hbox = gtk_hbox_new(FALSE, get_toggle_space(GTK_WIDGET(menu_item)));
89- #endif
90+#endif
91 g_object_ref(child);
92 gtk_container_remove(GTK_CONTAINER(menu_item), child);
93 gtk_box_pack_start(GTK_BOX(hbox), child, FALSE, FALSE, 0);
94@@ -334,7 +334,12 @@
95 /* Build it */
96 labelw = GTK_LABEL(gtk_accel_label_new(local_label));
97 gtk_label_set_use_markup(GTK_LABEL(labelw), TRUE);
98+#if GTK_CHECK_VERSION(3,0,0)
99+ gtk_widget_set_halign(GTK_WIDGET(labelw), GTK_ALIGN_START);
100+ gtk_widget_set_valign(GTK_WIDGET(labelw), GTK_ALIGN_CENTER);
101+#else
102 gtk_misc_set_alignment(GTK_MISC(labelw), 0.0, 0.5);
103+#endif
104 gtk_accel_label_set_accel_widget(GTK_ACCEL_LABEL(labelw), GTK_WIDGET(menu_item));
105
106 if (has_mnemonic(in_label, FALSE)) {
107@@ -541,12 +546,12 @@
108 /* We need to put the child into a new box and
109 make the box the child of the menu item. Basically
110 we're inserting a box in the middle. */
111- #ifdef HAVE_GTK3
112+#if GTK_CHECK_VERSION(3,0,0)
113 GtkWidget * hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,
114 get_toggle_space(GTK_WIDGET(menu_item)));
115- #else
116+#else
117 GtkWidget * hbox = gtk_hbox_new(FALSE, get_toggle_space(GTK_WIDGET(menu_item)));
118- #endif
119+#endif
120 g_object_ref(child);
121 gtk_container_remove(GTK_CONTAINER(menu_item), child);
122 gtk_box_pack_end(GTK_BOX(hbox), child, TRUE, TRUE, 0);
123
124=== modified file 'libdbusmenu-gtk/parser.c'
125--- libdbusmenu-gtk/parser.c 2015-03-04 22:18:54 +0000
126+++ libdbusmenu-gtk/parser.c 2016-02-23 20:10:45 +0000
127@@ -82,7 +82,8 @@
128 static void update_icon (DbusmenuMenuitem * menuitem,
129 ParserData * pdata,
130 GtkImage * image);
131-static GtkWidget * find_menu_label (GtkWidget * widget);
132+static GtkWidget * find_menu_child (GtkWidget * widget,
133+ GType child_type);
134 static void label_notify_cb (GtkWidget * widget,
135 GParamSpec * pspec,
136 gpointer data);
137@@ -648,7 +649,7 @@
138
139 gboolean visible = FALSE;
140 gboolean sensitive = FALSE;
141- if (GTK_IS_SEPARATOR_MENU_ITEM (widget) || !find_menu_label (widget))
142+ if (GTK_IS_SEPARATOR_MENU_ITEM (widget) || !find_menu_child (widget, GTK_TYPE_LABEL))
143 {
144 dbusmenu_menuitem_property_set (mi,
145 DBUSMENU_MENUITEM_PROP_TYPE,
146@@ -659,6 +660,8 @@
147 }
148 else
149 {
150+ GtkWidget *image = NULL;
151+
152 pdata->widget_accel_handler_id = g_signal_connect (widget, "accel-closures-changed",
153 G_CALLBACK (accel_changed), mi);
154
155@@ -674,20 +677,26 @@
156
157 pdata->widget_toggle_handler_id = g_signal_connect (widget, "activate", G_CALLBACK (checkbox_toggled), mi);
158 }
159-
160- if (GTK_IS_IMAGE_MENU_ITEM (widget))
161+ else if (GTK_IS_IMAGE_MENU_ITEM (widget))
162 {
163- GtkWidget *image;
164
165 image = gtk_image_menu_item_get_image (GTK_IMAGE_MENU_ITEM (widget));
166
167- if (GTK_IS_IMAGE (image))
168- {
169- update_icon (mi, pdata, GTK_IMAGE (image));
170- }
171- }
172-
173- GtkWidget *label = find_menu_label (widget);
174+ }
175+ else
176+ {
177+ // GtkImageMenuItem is deprecated, so check regular GtkMenuItems
178+ // for an image child too
179+ image = find_menu_child (widget, GTK_TYPE_IMAGE);
180+ }
181+
182+ if (GTK_IS_IMAGE (image))
183+ {
184+ update_icon (mi, pdata, GTK_IMAGE (image));
185+ }
186+
187+
188+ GtkWidget *label = find_menu_child (widget, GTK_TYPE_LABEL);
189
190 // Sometimes, an app will directly find and modify the label
191 // (like empathy), so watch the label especially for that.
192@@ -907,7 +916,11 @@
193 GTK_ICON_LOOKUP_FORCE_SIZE);
194 if (info != NULL) {
195 pixbuf = gtk_icon_info_load_icon (info, NULL);
196+#if GTK_CHECK_VERSION(3,8,0)
197+ g_object_unref (info);
198+#else
199 gtk_icon_info_free (info);
200+#endif
201 }
202 break;
203
204@@ -944,11 +957,11 @@
205 }
206
207 static GtkWidget *
208-find_menu_label (GtkWidget *widget)
209+find_menu_child (GtkWidget *widget, GType child_type)
210 {
211- GtkWidget *label = NULL;
212+ GtkWidget *child = NULL;
213
214- if (GTK_IS_LABEL (widget))
215+ if (G_TYPE_CHECK_INSTANCE_TYPE (widget, child_type))
216 return widget;
217
218 if (GTK_IS_CONTAINER (widget))
219@@ -960,16 +973,16 @@
220
221 for (l = children; l; l = l->next)
222 {
223- label = find_menu_label (l->data);
224+ child = find_menu_child (l->data, child_type);
225
226- if (label)
227+ if (child)
228 break;
229 }
230
231 g_list_free (children);
232 }
233
234- return label;
235+ return child;
236 }
237
238 static void
239@@ -1121,7 +1134,7 @@
240 {
241 DbusmenuMenuitem * item = DBUSMENU_MENUITEM(data);
242 GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
243- GtkWidget *label = find_menu_label (widget);
244+ GtkWidget *label = find_menu_child (widget, GTK_TYPE_LABEL);
245 const gchar *label_text = gtk_label_get_text (GTK_LABEL (label));
246 const gchar *name = atk_object_get_name (accessible);
247
248@@ -1335,7 +1348,7 @@
249 GtkWidget *child,
250 gpointer data)
251 {
252- if (find_menu_label (child) != NULL)
253+ if (find_menu_child (widget, GTK_TYPE_LABEL) != NULL)
254 handle_first_label (data);
255 }
256
257@@ -1433,6 +1446,9 @@
258
259 item = gtk_widget_get_ancestor (GTK_WIDGET (image),
260 GTK_TYPE_IMAGE_MENU_ITEM);
261+ if (!item)
262+ item = gtk_widget_get_ancestor (GTK_WIDGET (image),
263+ GTK_TYPE_MENU_ITEM);
264
265 if (item)
266 {
267@@ -1446,7 +1462,8 @@
268 if (gtk_menu_images)
269 return TRUE;
270
271- return gtk_image_menu_item_get_always_show_image (GTK_IMAGE_MENU_ITEM (item));
272+ if (GTK_IS_IMAGE_MENU_ITEM (item))
273+ return gtk_image_menu_item_get_always_show_image (GTK_IMAGE_MENU_ITEM (item));
274 }
275
276 return FALSE;

Subscribers

People subscribed via source and target branches

to all changes: