From 5ca1fb1a1b34bdbaf0c966d9cc786ecf71d0df21 Mon Sep 17 00:00:00 2001 From: lukefromdc Date: Thu, 21 Jun 2018 18:35:13 -0400 Subject: 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 --- mate-panel/libpanel-util/panel-gtk.c | 43 ++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) (limited to 'mate-panel/libpanel-util') 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 #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 */ +/*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; } -- cgit v1.2.1