[Xfce4-commits] [panel-plugins/xfce4-statusnotifier-plugin] 01/02: Add option to load symbolic icons if available
noreply at xfce.org
noreply at xfce.org
Sat Jul 22 18:31:08 CEST 2017
This is an automated email from the git hooks/post-receive script.
n i n e t l s p u s h e d a c o m m i t t o b r a n c h m a s t e r
in repository panel-plugins/xfce4-statusnotifier-plugin.
commit 8abfbb20dd2ae38b52bc5bff0063c9feb3dfd1d4
Author: Viktor Odintsev <ninetls at xfce.org>
Date: Sat Jul 22 15:43:05 2017 +0300
Add option to load symbolic icons if available
---
panel-plugin/sn-config.c | 38 ++++++++++++++++++++++
panel-plugin/sn-config.h | 2 ++
panel-plugin/sn-dialog.c | 6 ++++
panel-plugin/sn-dialog.glade | 16 ++++++++++
panel-plugin/sn-icon-box.c | 75 ++++++++++++++++++++++++++++++++++++++------
5 files changed, 128 insertions(+), 9 deletions(-)
diff --git a/panel-plugin/sn-config.c b/panel-plugin/sn-config.c
index a5604b1..9a96682 100644
--- a/panel-plugin/sn-config.c
+++ b/panel-plugin/sn-config.c
@@ -42,6 +42,7 @@
#define DEFAULT_ICON_SIZE 22
#define DEFAULT_SINGLE_ROW FALSE
#define DEFAULT_SQUARE_ICONS FALSE
+#define DEFAULT_SYMBOLIC_ICONS FALSE
#define DEFAULT_MENU_IS_PRIMARY FALSE
#define DEFAULT_ORIENTATION GTK_ORIENTATION_HORIZONTAL
#define DEFAULT_PANEL_ORIENTATION GTK_ORIENTATION_HORIZONTAL
@@ -76,6 +77,7 @@ struct _SnConfig
gint icon_size;
gboolean single_row;
gboolean square_icons;
+ gboolean symbolic_icons;
gboolean menu_is_primary;
gboolean mode_whitelist;
GList *known_items;
@@ -98,6 +100,7 @@ enum
PROP_ICON_SIZE,
PROP_SINGLE_ROW,
PROP_SQUARE_ICONS,
+ PROP_SYMBOLIC_ICONS,
PROP_MENU_IS_PRIMARY,
PROP_MODE_WHITELIST,
PROP_KNOWN_ITEMS,
@@ -174,6 +177,13 @@ sn_config_class_init (SnConfigClass *klass)
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class,
+ PROP_SYMBOLIC_ICONS,
+ g_param_spec_boolean ("symbolic-icons", NULL, NULL,
+ DEFAULT_SYMBOLIC_ICONS,
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_property (object_class,
PROP_MENU_IS_PRIMARY,
g_param_spec_boolean ("menu-is-primary", NULL, NULL,
DEFAULT_MENU_IS_PRIMARY,
@@ -236,6 +246,7 @@ sn_config_init (SnConfig *config)
config->icon_size = DEFAULT_ICON_SIZE;
config->single_row = DEFAULT_SINGLE_ROW;
config->square_icons = DEFAULT_SQUARE_ICONS;
+ config->symbolic_icons = DEFAULT_SYMBOLIC_ICONS;
config->mode_whitelist = DEFAULT_MODE_WHITELIST;
config->known_items = NULL;
config->hidden_items = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
@@ -314,6 +325,10 @@ sn_config_get_property (GObject *object,
g_value_set_boolean (value, config->square_icons);
break;
+ case PROP_SYMBOLIC_ICONS:
+ g_value_set_boolean (value, config->symbolic_icons);
+ break;
+
case PROP_MENU_IS_PRIMARY:
g_value_set_boolean (value, config->menu_is_primary);
break;
@@ -392,6 +407,15 @@ sn_config_set_property (GObject *object,
}
break;
+ case PROP_SYMBOLIC_ICONS:
+ val = g_value_get_boolean (value);
+ if (config->symbolic_icons != val)
+ {
+ config->symbolic_icons = val;
+ g_signal_emit (G_OBJECT (config), sn_config_signals[CONFIGURATION_CHANGED], 0);
+ }
+ break;
+
case PROP_MENU_IS_PRIMARY:
val = g_value_get_boolean (value);
if (config->menu_is_primary != val)
@@ -482,6 +506,16 @@ sn_config_get_square_icons (SnConfig *config)
gboolean
+sn_config_get_symbolic_icons (SnConfig *config)
+{
+ g_return_val_if_fail (XFCE_IS_SN_CONFIG (config), DEFAULT_SYMBOLIC_ICONS);
+
+ return config->symbolic_icons;
+}
+
+
+
+gboolean
sn_config_get_menu_is_primary (SnConfig *config)
{
g_return_val_if_fail (XFCE_IS_SN_CONFIG (config), DEFAULT_MENU_IS_PRIMARY);
@@ -779,6 +813,10 @@ sn_config_new (const gchar *property_base)
xfconf_g_property_bind (channel, property, G_TYPE_BOOLEAN, config, "square-icons");
g_free (property);
+ property = g_strconcat (property_base, "/symbolic-icons", NULL);
+ xfconf_g_property_bind (channel, property, G_TYPE_BOOLEAN, config, "symbolic-icons");
+ g_free (property);
+
property = g_strconcat (property_base, "/menu-is-primary", NULL);
xfconf_g_property_bind (channel, property, G_TYPE_BOOLEAN, config, "menu-is-primary");
g_free (property);
diff --git a/panel-plugin/sn-config.h b/panel-plugin/sn-config.h
index 7506cc8..4ee8f03 100644
--- a/panel-plugin/sn-config.h
+++ b/panel-plugin/sn-config.h
@@ -58,6 +58,8 @@ gboolean sn_config_get_single_row (SnConfig
gboolean sn_config_get_square_icons (SnConfig *config);
+gboolean sn_config_get_symbolic_icons (SnConfig *config);
+
gboolean sn_config_get_menu_is_primary (SnConfig *config);
gint sn_config_get_icon_size (SnConfig *config);
diff --git a/panel-plugin/sn-dialog.c b/panel-plugin/sn-dialog.c
index 2c3ca7f..eec3bc0 100644
--- a/panel-plugin/sn-dialog.c
+++ b/panel-plugin/sn-dialog.c
@@ -433,6 +433,12 @@ sn_dialog_build (SnDialog *dialog)
G_OBJECT (object), "active",
G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+ object = gtk_builder_get_object (dialog->builder, "checkbutton-symbolic-icons");
+ g_return_val_if_fail (GTK_IS_WIDGET (object), FALSE);
+ g_object_bind_property (G_OBJECT (dialog->config), "symbolic-icons",
+ G_OBJECT (object), "active",
+ G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL);
+
object = gtk_builder_get_object (dialog->builder, "checkbutton-menu-is-primary");
g_return_val_if_fail (GTK_IS_WIDGET (object), FALSE);
g_object_bind_property (G_OBJECT (dialog->config), "menu-is-primary",
diff --git a/panel-plugin/sn-dialog.glade b/panel-plugin/sn-dialog.glade
index 7128341..693c72b 100644
--- a/panel-plugin/sn-dialog.glade
+++ b/panel-plugin/sn-dialog.glade
@@ -142,6 +142,22 @@
<property name="position">2</property>
</packing>
</child>
+ <child>
+ <object class="GtkCheckButton" id="checkbutton-symbolic-icons">
+ <property name="label" translatable="yes">Symbolic icons</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="tooltip_text" translatable="yes">Load symbolic icons if available</property>
+ <property name="use_action_appearance">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">3</property>
+ </packing>
+ </child>
</object>
</child>
</object>
diff --git a/panel-plugin/sn-icon-box.c b/panel-plugin/sn-icon-box.c
index 2ea64b1..f2a740f 100644
--- a/panel-plugin/sn-icon-box.c
+++ b/panel-plugin/sn-icon-box.c
@@ -74,6 +74,7 @@ struct _SnIconBox
guint item_icon_changed_handler;
guint config_notify_icon_size_handler;
+ guint config_notify_symbolic_icons_handler;
};
G_DEFINE_TYPE (SnIconBox, sn_icon_box, GTK_TYPE_CONTAINER)
@@ -120,6 +121,7 @@ sn_icon_box_init (SnIconBox *box)
box->item_icon_changed_handler = 0;
box->config_notify_icon_size_handler = 0;
+ box->config_notify_symbolic_icons_handler = 0;
}
@@ -199,6 +201,9 @@ sn_icon_box_new (SnItem *item,
box->config_notify_icon_size_handler =
g_signal_connect_swapped (config, "notify::icon-size",
G_CALLBACK (sn_icon_box_icon_changed), box);
+ box->config_notify_symbolic_icons_handler =
+ g_signal_connect_swapped (config, "notify::symbolic-icons",
+ G_CALLBACK (sn_icon_box_icon_changed), box);
box->item_icon_changed_handler =
g_signal_connect_swapped (item, "icon-changed",
G_CALLBACK (sn_icon_box_icon_changed), box);
@@ -218,6 +223,8 @@ sn_icon_box_finalize (GObject *object)
g_signal_handler_disconnect (box->item, box->item_icon_changed_handler);
if (box->config_notify_icon_size_handler != 0)
g_signal_handler_disconnect (box->config, box->config_notify_icon_size_handler);
+ if (box->config_notify_symbolic_icons_handler != 0)
+ g_signal_handler_disconnect (box->config, box->config_notify_symbolic_icons_handler);
G_OBJECT_CLASS (sn_icon_box_parent_class)->finalize (object);
}
@@ -230,12 +237,16 @@ sn_icon_box_apply_icon (GtkWidget *image,
GtkIconTheme *icon_theme_from_path,
const gchar *icon_name,
GdkPixbuf *icon_pixbuf,
- gint icon_size)
+ gint icon_size,
+ gboolean prefer_symbolic)
{
- GtkIconInfo *icon_info;
+ GtkIconInfo *icon_info = NULL;
GdkPixbuf *work_pixbuf = NULL;
- gchar *work_icon_name = FALSE;
+ gchar *work_icon_name = NULL;
+ gchar *symbolic_icon_name = NULL;
+ gint symbolic_icon_size;
gboolean use_pixbuf = TRUE;
+ gboolean use_symbolic = FALSE;
gint width, height;
gchar *s1, *s2;
gint max_size = icon_size;
@@ -275,13 +286,54 @@ sn_icon_box_apply_icon (GtkWidget *image,
if (work_pixbuf == NULL)
{
- icon_info = gtk_icon_theme_lookup_icon (icon_theme,
- sn_preferred_name (),
- icon_size, 0);
+ if (prefer_symbolic && strstr (sn_preferred_name (), "-symbolic") == NULL)
+ {
+ symbolic_icon_name = g_strdup_printf ("%s-symbolic", sn_preferred_name ());
+
+ symbolic_icon_size = icon_size;
+ if (symbolic_icon_size <= 48)
+ {
+ /* calculate highest bit (e.g. 22 -> 16, 63 -> 32) */
+ symbolic_icon_size |= symbolic_icon_size >> 1;
+ symbolic_icon_size |= symbolic_icon_size >> 2;
+ symbolic_icon_size |= symbolic_icon_size >> 4;
+ symbolic_icon_size |= symbolic_icon_size >> 8;
+ symbolic_icon_size |= symbolic_icon_size >> 16;
+ symbolic_icon_size = symbolic_icon_size - (symbolic_icon_size >> 1);
+ }
+
+ icon_info = gtk_icon_theme_lookup_icon (icon_theme,
+ symbolic_icon_name,
+ symbolic_icon_size,
+ 0);
+ if (icon_info != NULL)
+ {
+ if (gtk_icon_info_is_symbolic (icon_info))
+ {
+ use_symbolic = TRUE;
+ max_size = symbolic_icon_size;
+ }
+ else
+ {
+ g_object_unref (icon_info);
+ icon_info = NULL;
+ }
+ }
+ }
+
+ if (icon_info == NULL)
+ {
+ icon_info = gtk_icon_theme_lookup_icon (icon_theme,
+ sn_preferred_name (),
+ icon_size, 0);
+ }
+
if (icon_info != NULL)
{
gtk_image_set_from_icon_name (GTK_IMAGE (image),
- sn_preferred_name (),
+ use_symbolic
+ ? symbolic_icon_name
+ : sn_preferred_name (),
GTK_ICON_SIZE_BUTTON);
g_object_unref (icon_info);
use_pixbuf = FALSE;
@@ -328,6 +380,9 @@ sn_icon_box_apply_icon (GtkWidget *image,
if (work_icon_name != NULL)
g_free (work_icon_name);
+ if (symbolic_icon_name != NULL)
+ g_free (symbolic_icon_name);
+
gtk_image_set_pixel_size (GTK_IMAGE (image), max_size);
}
@@ -345,10 +400,12 @@ sn_icon_box_icon_changed (GtkWidget *widget)
GtkIconTheme *icon_theme;
GtkIconTheme *icon_theme_from_path = NULL;
gint icon_size;
+ gboolean symbolic_icons;
box = XFCE_SN_ICON_BOX (widget);
icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (widget)));
icon_size = sn_config_get_icon_size (box->config);
+ symbolic_icons = sn_config_get_symbolic_icons (box->config);
sn_item_get_icon (box->item, &theme_path,
&icon_name, &icon_pixbuf,
@@ -361,9 +418,9 @@ sn_icon_box_icon_changed (GtkWidget *widget)
}
sn_icon_box_apply_icon (box->icon, icon_theme, icon_theme_from_path,
- icon_name, icon_pixbuf, icon_size);
+ icon_name, icon_pixbuf, icon_size, symbolic_icons);
sn_icon_box_apply_icon (box->overlay, icon_theme, icon_theme_from_path,
- overlay_icon_name, overlay_icon_pixbuf, icon_size);
+ overlay_icon_name, overlay_icon_pixbuf, icon_size, symbolic_icons);
if (icon_theme_from_path != NULL)
g_object_unref (icon_theme_from_path);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list