Skip to content

Commit 5ca1fb1

Browse files
committed
Panel-gtk.c: Show menu icons only when "menus-have-icons" is set
Most panel menus excluding main menus. Bind gsettings preference "menus have icons" to visibility of icon. Pack the icon into a box with a 16px min-width set in panel.css to hold the space when the icons are not shown Duplicate as much as possible behavior of now-deprecated GtkImageMenuItem replaced by github.com/mate-desktop/mate-panel/commit/86701517e7d7cb3d2c08a40d76af97308f18902c Use only one icon-settings gsettings object to control this in all menuitems controlled by panel-gtk.c The use of a single gsettings object is based on code by Albert Muktupavels https://github.com/muktupavels
1 parent 2d3406f commit 5ca1fb1

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

data/theme/mate-panel.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,6 @@ MatePanelAppletFrameDBus > MatePanelAppletFrameDBus {
88
background-size: 12px 22px;
99
}
1010

11+
.mate-panel-menu-icon-box{
12+
min-width: 16px;
13+
}

mate-panel/libpanel-util/panel-gtk.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,19 @@
2626
#include <glib/gi18n.h>
2727

2828
#include "panel-gtk.h"
29+
#include "panel-cleanup.h"
2930

3031
/*
3132
* Originally based on code from panel-properties-dialog.c. This part of the
3233
* code was:
3334
* Copyright (C) 2005 Vincent Untz <vuntz@gnome.org>
3435
*/
3536

37+
/*There should be only one icon_settings object for the whole panel
38+
*So we need a global variable here
39+
*/
40+
static GSettings *icon_settings = NULL;
41+
3642
static void
3743
panel_gtk_file_chooser_preview_update (GtkFileChooser *chooser,
3844
gpointer data)
@@ -160,12 +166,27 @@ panel_file_chooser_dialog_new (const gchar *title,
160166
return result;
161167
}
162168

169+
170+
static void
171+
ensure_icon_settings (void)
172+
{
173+
if (icon_settings != NULL)
174+
return;
175+
176+
icon_settings = g_settings_new ("org.mate.interface");
177+
178+
panel_cleanup_register (panel_cleanup_unref_and_nullify,
179+
&icon_settings);
180+
}
181+
163182
GtkWidget *
164183
panel_image_menu_item_new_from_icon (const gchar *icon_name,
165184
const gchar *label_name)
166185
{
167186
GtkWidget *icon;
187+
GtkStyleContext *context;
168188
GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
189+
GtkWidget *icon_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
169190

170191
if (icon_name)
171192
icon = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
@@ -175,12 +196,20 @@ panel_image_menu_item_new_from_icon (const gchar *icon_name,
175196
GtkWidget *label_menu = gtk_label_new_with_mnemonic (g_strconcat (label_name, " ", NULL));
176197
GtkWidget *menuitem = gtk_menu_item_new ();
177198

178-
gtk_container_add (GTK_CONTAINER (box), icon);
199+
context = gtk_widget_get_style_context (GTK_WIDGET(icon_box));
200+
gtk_style_context_add_class(context,"mate-panel-menu-icon-box");
201+
202+
gtk_container_add (GTK_CONTAINER (icon_box), icon);
203+
gtk_container_add (GTK_CONTAINER (box), icon_box);
179204
gtk_container_add (GTK_CONTAINER (box), label_menu);
180205

181206
gtk_container_add (GTK_CONTAINER (menuitem), box);
182207
gtk_widget_show_all (menuitem);
183208

209+
ensure_icon_settings();
210+
g_settings_bind (icon_settings, "menus-have-icons", icon, "visible",
211+
G_SETTINGS_BIND_GET);
212+
184213
return menuitem;
185214
}
186215

@@ -189,7 +218,9 @@ panel_image_menu_item_new_from_gicon (GIcon *gicon,
189218
const gchar *label_name)
190219
{
191220
GtkWidget *icon;
221+
GtkStyleContext *context;
192222
GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
223+
GtkWidget *icon_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
193224

194225
if (gicon)
195226
icon = gtk_image_new_from_gicon (gicon, GTK_ICON_SIZE_MENU);
@@ -198,13 +229,21 @@ panel_image_menu_item_new_from_gicon (GIcon *gicon,
198229

199230
GtkWidget *label_menu = gtk_label_new_with_mnemonic (g_strconcat (label_name, " ", NULL));
200231
GtkWidget *menuitem = gtk_menu_item_new ();
232+
233+
context = gtk_widget_get_style_context (GTK_WIDGET(icon_box));
234+
gtk_style_context_add_class(context,"mate-panel-menu-icon-box");
201235

202-
gtk_container_add (GTK_CONTAINER (box), icon);
236+
gtk_container_add (GTK_CONTAINER (icon_box), icon);
237+
gtk_container_add (GTK_CONTAINER (box), icon_box);
203238
gtk_container_add (GTK_CONTAINER (box), label_menu);
204239

205240
gtk_container_add (GTK_CONTAINER (menuitem), box);
206241
gtk_widget_show_all (menuitem);
207242

243+
ensure_icon_settings();
244+
g_settings_bind (icon_settings, "menus-have-icons", icon, "visible",
245+
G_SETTINGS_BIND_GET);
246+
208247
return menuitem;
209248
}
210249

0 commit comments

Comments
 (0)