summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlukefromdc <[email protected]>2018-06-21 18:35:13 -0400
committerlukefromdc <[email protected]>2018-06-25 18:47:53 -0400
commit5ca1fb1a1b34bdbaf0c966d9cc786ecf71d0df21 (patch)
tree34b3c2b7ba72f3f6cb414aea2d8532265f891727
parent2d3406f482a341805f9827b95e4b588feb0218ce (diff)
downloadmate-panel-5ca1fb1a1b34bdbaf0c966d9cc786ecf71d0df21.tar.bz2
mate-panel-5ca1fb1a1b34bdbaf0c966d9cc786ecf71d0df21.tar.xz
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
-rw-r--r--data/theme/mate-panel.css3
-rw-r--r--mate-panel/libpanel-util/panel-gtk.c43
2 files changed, 44 insertions, 2 deletions
diff --git a/data/theme/mate-panel.css b/data/theme/mate-panel.css
index bfa890d1..e53950d2 100644
--- a/data/theme/mate-panel.css
+++ b/data/theme/mate-panel.css
@@ -8,3 +8,6 @@ MatePanelAppletFrameDBus > MatePanelAppletFrameDBus {
background-size: 12px 22px;
}
+.mate-panel-menu-icon-box{
+ min-width: 16px;
+}
diff --git a/mate-panel/libpanel-util/panel-gtk.c b/mate-panel/libpanel-util/panel-gtk.c
index 4ac3e9bc..47cf17db 100644
--- a/mate-panel/libpanel-util/panel-gtk.c
+++ b/mate-panel/libpanel-util/panel-gtk.c
@@ -26,6 +26,7 @@
#include <glib/gi18n.h>
#include "panel-gtk.h"
+#include "panel-cleanup.h"
/*
* Originally based on code from panel-properties-dialog.c. This part of the
@@ -33,6 +34,11 @@
* Copyright (C) 2005 Vincent Untz <[email protected]>
*/
+/*There should be only one icon_settings object for the whole panel
+ *So we need a global variable here
+ */
+static GSettings *icon_settings = NULL;
+
static void
panel_gtk_file_chooser_preview_update (GtkFileChooser *chooser,
gpointer data)
@@ -160,12 +166,27 @@ panel_file_chooser_dialog_new (const gchar *title,
return result;
}
+
+static void
+ensure_icon_settings (void)
+{
+ if (icon_settings != NULL)
+ return;
+
+ icon_settings = g_settings_new ("org.mate.interface");
+
+ panel_cleanup_register (panel_cleanup_unref_and_nullify,
+ &icon_settings);
+}
+
GtkWidget *
panel_image_menu_item_new_from_icon (const gchar *icon_name,
const gchar *label_name)
{
GtkWidget *icon;
+ GtkStyleContext *context;
GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ GtkWidget *icon_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
if (icon_name)
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,
GtkWidget *label_menu = gtk_label_new_with_mnemonic (g_strconcat (label_name, " ", NULL));
GtkWidget *menuitem = gtk_menu_item_new ();
- gtk_container_add (GTK_CONTAINER (box), icon);
+ context = gtk_widget_get_style_context (GTK_WIDGET(icon_box));
+ gtk_style_context_add_class(context,"mate-panel-menu-icon-box");
+
+ gtk_container_add (GTK_CONTAINER (icon_box), icon);
+ gtk_container_add (GTK_CONTAINER (box), icon_box);
gtk_container_add (GTK_CONTAINER (box), label_menu);
gtk_container_add (GTK_CONTAINER (menuitem), box);
gtk_widget_show_all (menuitem);
+ ensure_icon_settings();
+ g_settings_bind (icon_settings, "menus-have-icons", icon, "visible",
+ G_SETTINGS_BIND_GET);
+
return menuitem;
}
@@ -189,7 +218,9 @@ panel_image_menu_item_new_from_gicon (GIcon *gicon,
const gchar *label_name)
{
GtkWidget *icon;
+ GtkStyleContext *context;
GtkWidget *box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
+ GtkWidget *icon_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
if (gicon)
icon = gtk_image_new_from_gicon (gicon, GTK_ICON_SIZE_MENU);
@@ -198,13 +229,21 @@ panel_image_menu_item_new_from_gicon (GIcon *gicon,
GtkWidget *label_menu = gtk_label_new_with_mnemonic (g_strconcat (label_name, " ", NULL));
GtkWidget *menuitem = gtk_menu_item_new ();
+
+ context = gtk_widget_get_style_context (GTK_WIDGET(icon_box));
+ gtk_style_context_add_class(context,"mate-panel-menu-icon-box");
- gtk_container_add (GTK_CONTAINER (box), icon);
+ gtk_container_add (GTK_CONTAINER (icon_box), icon);
+ gtk_container_add (GTK_CONTAINER (box), icon_box);
gtk_container_add (GTK_CONTAINER (box), label_menu);
gtk_container_add (GTK_CONTAINER (menuitem), box);
gtk_widget_show_all (menuitem);
+ ensure_icon_settings();
+ g_settings_bind (icon_settings, "menus-have-icons", icon, "visible",
+ G_SETTINGS_BIND_GET);
+
return menuitem;
}