[gtk/wip/otte/symbolic-paintable] icontheme: Refactor gtk_icon_theme_lookup_symbolic_colors()



commit 9237c8be670ae78e60e87b45a234403c8209075a
Author: Benjamin Otte <otte redhat com>
Date:   Mon Aug 30 04:52:47 2021 +0200

    icontheme: Refactor gtk_icon_theme_lookup_symbolic_colors()
    
    With the new enum, the code looks much cleaner.

 gtk/gtkcssimageicontheme.c |  2 +-
 gtk/gtkicontheme.c         | 38 ++++++++++++++++----------------------
 gtk/gtkiconthemeprivate.h  |  5 +----
 gtk/gtkrendericon.c        |  2 +-
 4 files changed, 19 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkcssimageicontheme.c b/gtk/gtkcssimageicontheme.c
index b9096b1006..02e0c8a346 100644
--- a/gtk/gtkcssimageicontheme.c
+++ b/gtk/gtkcssimageicontheme.c
@@ -156,7 +156,7 @@ gtk_css_image_icon_theme_compute (GtkCssImage      *image,
   copy->icon_theme = gtk_icon_theme_get_for_display (display);
   copy->serial = gtk_icon_theme_get_serial (copy->icon_theme);
   copy->scale = gtk_style_provider_get_scale (provider);
-  gtk_icon_theme_lookup_symbolic_colors (style, &copy->colors[0], &copy->colors[3], &copy->colors[2], 
&copy->colors[1]);
+  gtk_icon_theme_lookup_symbolic_colors (style, copy->colors);
 
   return GTK_CSS_IMAGE (copy);
 }
diff --git a/gtk/gtkicontheme.c b/gtk/gtkicontheme.c
index eb6b7285d3..91ea519a26 100644
--- a/gtk/gtkicontheme.c
+++ b/gtk/gtkicontheme.c
@@ -2543,35 +2543,29 @@ gtk_icon_theme_error_quark (void)
 
 void
 gtk_icon_theme_lookup_symbolic_colors (GtkCssStyle *style,
-                                       GdkRGBA     *color_out,
-                                       GdkRGBA     *success_out,
-                                       GdkRGBA     *warning_out,
-                                       GdkRGBA     *error_out)
+                                       GdkRGBA      color_out[4])
 {
   GtkCssValue *palette, *color;
+  const char *names[4] = {
+    [GTK_SYMBOLIC_COLOR_ERROR] = "error",
+    [GTK_SYMBOLIC_COLOR_WARNING] = "warning",
+    [GTK_SYMBOLIC_COLOR_SUCCESS] = "success"
+  };
   const GdkRGBA *lookup;
+  gsize i;
 
   color = style->core->color;
   palette = style->core->icon_palette;
-  *color_out = *gtk_css_color_value_get_rgba (color);
-
-  lookup = gtk_css_palette_value_get_color (palette, "success");
-  if (lookup)
-    *success_out = *lookup;
-  else
-    *success_out = *color_out;
-
-  lookup = gtk_css_palette_value_get_color (palette, "warning");
-  if (lookup)
-    *warning_out = *lookup;
-  else
-    *warning_out = *color_out;
+  color_out[GTK_SYMBOLIC_COLOR_FOREGROUND] = *gtk_css_color_value_get_rgba (color);
 
-  lookup = gtk_css_palette_value_get_color (palette, "error");
-  if (lookup)
-    *error_out = *lookup;
-  else
-    *error_out = *color_out;
+  for (i = 1; i < 4; i++)
+    {
+      lookup = gtk_css_palette_value_get_color (palette, names[i]);
+      if (lookup)
+        color_out[i] = *lookup;
+      else
+        color_out[i] = color_out[GTK_SYMBOLIC_COLOR_FOREGROUND];
+    }
 }
 
 
diff --git a/gtk/gtkiconthemeprivate.h b/gtk/gtkiconthemeprivate.h
index bab1011d69..0d877332a3 100644
--- a/gtk/gtkiconthemeprivate.h
+++ b/gtk/gtkiconthemeprivate.h
@@ -28,10 +28,7 @@ const char *gtk_string_set_add (GtkStringSet *set,
 #define IMAGE_MISSING_RESOURCE_PATH "/org/gtk/libgtk/icons/16x16/status/image-missing.png"
 
 void gtk_icon_theme_lookup_symbolic_colors   (GtkCssStyle      *style,
-                                              GdkRGBA          *color_out,
-                                              GdkRGBA          *success_out,
-                                              GdkRGBA          *warning_out,
-                                              GdkRGBA          *error_out);
+                                              GdkRGBA           color_out[4]);
 
 int gtk_icon_theme_get_serial (GtkIconTheme *self);
 
diff --git a/gtk/gtkrendericon.c b/gtk/gtkrendericon.c
index 2cd601aa34..a6c878491c 100644
--- a/gtk/gtkrendericon.c
+++ b/gtk/gtkrendericon.c
@@ -116,7 +116,7 @@ gtk_css_style_snapshot_icon_paintable (GtkCssStyle  *style,
   is_symbolic_paintable = GTK_IS_SYMBOLIC_PAINTABLE (paintable);
   if (is_symbolic_paintable)
     {
-      gtk_icon_theme_lookup_symbolic_colors (style, &colors[0], &colors[3], &colors[2], &colors[1]);
+      gtk_icon_theme_lookup_symbolic_colors (style, colors);
 
       if (gdk_rgba_is_clear (&colors[0]))
         goto transparent;


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