[gnome-shell/wip/sass] st-theme-node: Add support for -st-icon-style property



commit 7b96a0f14f89ef1d054beadf995254f48de4083f
Author: Florian Müllner <fmuellner gnome org>
Date:   Sat Nov 29 14:53:36 2014 +0000

    st-theme-node: Add support for -st-icon-style property
    
    GTK+ added support for a -gtk-icon-style property in themes to
    enforce a particular icon style. Do the same for shell themes
    with an -st-icon-style property, with the same set of possible
    values as the GTK+ variant:
      'requested' - use symbolic or fullcolor icon depending on the
                    icon name (default)
      'regular'   - enforce fullcolor icons
      'symbolic'  - enforce symbolic icons
    
    https://bugzilla.gnome.org/show_bug.cgi?id=740447

 src/st/st-texture-cache.c |   19 ++++++++++++++-----
 src/st/st-theme-node.c    |   42 ++++++++++++++++++++++++++++++++++++++++++
 src/st/st-theme-node.h    |    8 ++++++++
 3 files changed, 64 insertions(+), 5 deletions(-)
---
diff --git a/src/st/st-texture-cache.c b/src/st/st-texture-cache.c
index 09addbe..ccee96c 100644
--- a/src/st/st-texture-cache.c
+++ b/src/st/st-texture-cache.c
@@ -842,16 +842,25 @@ st_texture_cache_load_gicon (StTextureCache    *cache,
   GtkIconInfo *info;
   StTextureCachePolicy policy;
   StIconColors *colors = NULL;
+  StIconStyle icon_style = ST_ICON_STYLE_REQUESTED;
   GtkIconLookupFlags lookup_flags;
 
   if (theme_node)
-    colors = st_theme_node_get_icon_colors (theme_node);
+    {
+      colors = st_theme_node_get_icon_colors (theme_node);
+      icon_style = st_theme_node_get_icon_style (theme_node);
+    }
 
   /* Do theme lookups in the main thread to avoid thread-unsafety */
   theme = cache->priv->icon_theme;
 
   lookup_flags = GTK_ICON_LOOKUP_USE_BUILTIN;
 
+  if (icon_style == ST_ICON_STYLE_REGULAR)
+    lookup_flags |= GTK_ICON_LOOKUP_FORCE_REGULAR;
+  else if (icon_style == ST_ICON_STYLE_SYMBOLIC)
+    lookup_flags |= GTK_ICON_LOOKUP_FORCE_SYMBOLIC;
+
   if (clutter_get_default_text_direction () == CLUTTER_TEXT_DIRECTION_RTL)
     lookup_flags |= GTK_ICON_LOOKUP_DIR_RTL;
   else
@@ -871,8 +880,8 @@ st_texture_cache_load_gicon (StTextureCache    *cache,
   if (colors)
     {
       /* This raises some doubts about the practice of using string keys */
-      key = g_strdup_printf (CACHE_PREFIX_ICON 
"%s,size=%d,scale=%d,colors=%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x",
-                             gicon_string, size, scale,
+      key = g_strdup_printf (CACHE_PREFIX_ICON 
"%s,size=%d,scale=%d,style=%d,colors=%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x,%2x%2x%2x%2x",
+                             gicon_string, size, scale, icon_style,
                              colors->foreground.red, colors->foreground.blue, colors->foreground.green, 
colors->foreground.alpha,
                              colors->warning.red, colors->warning.blue, colors->warning.green, 
colors->warning.alpha,
                              colors->error.red, colors->error.blue, colors->error.green, colors->error.alpha,
@@ -880,8 +889,8 @@ st_texture_cache_load_gicon (StTextureCache    *cache,
     }
   else
     {
-      key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d,scale=%d",
-                             gicon_string, size, scale);
+      key = g_strdup_printf (CACHE_PREFIX_ICON "%s,size=%d,scale=%d,style=%d",
+                             gicon_string, size, scale, icon_style);
     }
   g_free (gicon_string);
 
diff --git a/src/st/st-theme-node.c b/src/st/st-theme-node.c
index c6c6e89..9aedc3b 100644
--- a/src/st/st-theme-node.c
+++ b/src/st/st-theme-node.c
@@ -2392,6 +2392,48 @@ st_theme_node_get_transition_duration (StThemeNode *node)
   return st_slow_down_factor * node->transition_duration;
 }
 
+StIconStyle
+st_theme_node_get_icon_style (StThemeNode *node)
+{
+  int i;
+
+  ensure_properties (node);
+
+  for (i = node->n_properties - 1; i >= 0; i--)
+    {
+      CRDeclaration *decl = node->properties[i];
+
+      if (strcmp (decl->property->stryng->str, "-st-icon-style") == 0)
+        {
+          CRTerm *term;
+
+          for (term = decl->value; term; term = term->next)
+            {
+              if (term->type != TERM_IDENT)
+                goto next_decl;
+
+              if (strcmp (term->content.str->stryng->str, "requested") == 0)
+                return ST_ICON_STYLE_REQUESTED;
+              else if (strcmp (term->content.str->stryng->str, "regular") == 0)
+                return ST_ICON_STYLE_REGULAR;
+              else if (strcmp (term->content.str->stryng->str, "symbolic") == 0)
+                return ST_ICON_STYLE_SYMBOLIC;
+              else
+                g_warning ("Unknown -st-icon-style \"%s\"",
+                           term->content.str->stryng->str);
+            }
+        }
+
+    next_decl:
+      ;
+    }
+
+  if (node->parent_node)
+    return st_theme_node_get_icon_style (node->parent_node);
+
+  return ST_ICON_STYLE_REQUESTED;
+}
+
 StTextDecoration
 st_theme_node_get_text_decoration (StThemeNode *node)
 {
diff --git a/src/st/st-theme-node.h b/src/st/st-theme-node.h
index a193f5a..0a5edf9 100644
--- a/src/st/st-theme-node.h
+++ b/src/st/st-theme-node.h
@@ -94,6 +94,12 @@ typedef enum {
   ST_GRADIENT_RADIAL
 } StGradientType;
 
+typedef enum {
+  ST_ICON_STYLE_REQUESTED,
+  ST_ICON_STYLE_REGULAR,
+  ST_ICON_STYLE_SYMBOLIC
+} StIconStyle;
+
 typedef struct _StThemeNodePaintState StThemeNodePaintState;
 
 struct _StThemeNodePaintState {
@@ -220,6 +226,8 @@ int    st_theme_node_get_max_height    (StThemeNode  *node);
 
 int    st_theme_node_get_transition_duration (StThemeNode *node);
 
+StIconStyle st_theme_node_get_icon_style (StThemeNode *node);
+
 StTextDecoration st_theme_node_get_text_decoration (StThemeNode *node);
 
 StTextAlign st_theme_node_get_text_align (StThemeNode *node);


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