Skip to content

Commit

Permalink
Panel-gtk.c: Show menu icons only when "menus-have-icons" is set
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lukefromdc committed Jun 25, 2018
1 parent 2d3406f commit 5ca1fb1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
3 changes: 3 additions & 0 deletions data/theme/mate-panel.css
Expand Up @@ -8,3 +8,6 @@ MatePanelAppletFrameDBus > MatePanelAppletFrameDBus {
background-size: 12px 22px;
}

.mate-panel-menu-icon-box{
min-width: 16px;
}
43 changes: 41 additions & 2 deletions mate-panel/libpanel-util/panel-gtk.c
Expand Up @@ -26,13 +26,19 @@
#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
* code was:
* Copyright (C) 2005 Vincent Untz <vuntz@gnome.org>
*/

/*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)
Expand Down Expand Up @@ -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);
Expand All @@ -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;
}

Expand All @@ -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);
Expand All @@ -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;
}

Expand Down

0 comments on commit 5ca1fb1

Please sign in to comment.