[gimp/wip/jehan/icons: 1/3] app: toolbox can load symbolic icon variants with automatic dark...



commit e83d346f4c4d7641cbf4454b34fe1784d4833773
Author: Jehan <jehan girinstud io>
Date:   Sun May 20 21:27:07 2018 +0200

    app: toolbox can load symbolic icon variants with automatic dark...
    
    ... or light versions.
    Current source was just proposing 2 symbolic icon themes, a dark and a
    light. After some research, I can see that some GTK+ functions have
    support for searching variants of icons, and in particular, it will mean
    that they will properly color the icons depending on whether we are
    using a dark or light theme.
    
    - gtk_icon_theme_lookup_icon() function does such a search of the
      symbolic variant (fallbacking to the non-symbolic one with
      GTK_ICON_LOOKUP_GENERIC_FALLBACK).
    - Then gtk_icon_info_load_symbolic*() functions render the icons,
      matching to the theme background.
    This is the first step toward better icon support. Note that right now
    it breaks a few things, like icon resizing and direct icon theme update.
    But this is just an intermediary commit.

 app/widgets/gimptoolpalette.c |   42 +++++++++++++++++++++++++++++++++++++---
 1 files changed, 38 insertions(+), 4 deletions(-)
---
diff --git a/app/widgets/gimptoolpalette.c b/app/widgets/gimptoolpalette.c
index 76f0178..508a7ef 100644
--- a/app/widgets/gimptoolpalette.c
+++ b/app/widgets/gimptoolpalette.c
@@ -379,12 +379,46 @@ gimp_tool_palette_set_toolbox (GimpToolPalette *palette,
     {
       GimpToolInfo  *tool_info = list->data;
       GtkToolItem   *item;
-      const gchar   *icon_name;
-
-      icon_name = gimp_viewable_get_icon_name (GIMP_VIEWABLE (tool_info));
+      GtkIconTheme  *icon_theme;
+      gchar         *icon_name;
+      GtkIconInfo   *icon_info;
+      GtkIconSize    icon_size;
+      gint           icon_width;
+      gint           icon_height;
+
+      icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (group));
+      icon_name  = g_strdup_printf ("%s-symbolic",
+                                    gimp_viewable_get_icon_name (GIMP_VIEWABLE (tool_info)));
+      icon_size = gtk_tool_palette_get_icon_size (GTK_TOOL_PALETTE (palette));
+      gtk_icon_size_lookup (icon_size, &icon_width, &icon_height);
+
+      icon_info = gtk_icon_theme_lookup_icon (icon_theme, icon_name,
+                                              MAX (icon_width, icon_height),
+                                              GTK_ICON_LOOKUP_GENERIC_FALLBACK);
+      g_free (icon_name);
 
       item = gtk_radio_tool_button_new (item_group);
-      gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), icon_name);
+      if (icon_info)
+        {
+          GdkPixbuf *pixbuf;
+          GtkWidget *image;
+
+          pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info,
+                                                            gtk_widget_get_style_context (group),
+                                                            NULL, NULL);
+          image = gtk_image_new_from_pixbuf (pixbuf);
+          gtk_widget_show (image);
+
+          gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (item), image);
+
+          g_object_unref (icon_info);
+          g_object_unref (pixbuf);
+        }
+      else
+        {
+          gtk_tool_button_set_icon_name (GTK_TOOL_BUTTON (item), icon_name);
+        }
+
       item_group = gtk_radio_tool_button_get_group (GTK_RADIO_TOOL_BUTTON (item));
       gtk_tool_item_group_insert (GTK_TOOL_ITEM_GROUP (group), item, -1);
       gtk_widget_show (GTK_WIDGET (item));


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]