[gnome-text-editor] recoloring: allow looking up overrides from metadata



commit 28ed9632a94fc8799af212e80d616747589ae955
Author: Christian Hergert <christian hergert me>
Date:   Mon Dec 27 10:20:32 2021 -0800

    recoloring: allow looking up overrides from metadata
    
    This will allow loading accent colors from the <metadata> block
    of the style-scheme for cases where auto-generating colors is
    not creating the level of contrast or hue we want.
    
    Related #274

 src/editor-recoloring.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/src/editor-recoloring.c b/src/editor-recoloring.c
index 792b070..b5c75b6 100644
--- a/src/editor-recoloring.c
+++ b/src/editor-recoloring.c
@@ -96,6 +96,19 @@ get_background (GtkSourceStyleScheme *scheme,
   return get_color (scheme, style_name, bg, BACKGROUND);
 }
 
+static gboolean
+get_metadata_color (GtkSourceStyleScheme *scheme,
+                    const char           *key,
+                    GdkRGBA              *color)
+{
+  const char *str;
+
+  if ((str = gtk_source_style_scheme_get_metadata (scheme, key)))
+    return gdk_rgba_parse (color, str);
+
+  return FALSE;
+}
+
 static void
 define_color (GString       *str,
               const char    *name,
@@ -251,10 +264,12 @@ _editor_recoloring_generate_css (GtkSourceStyleScheme *style_scheme)
   define_color_mixed (str, "view_bg_color", &text_bg, &white, is_dark ? .1 : .3);
   define_color (str, "view_fg_color", &text_fg);
 
-  if (get_background (style_scheme, "selection", &color))
+  if (get_metadata_color (style_scheme, "accent_bg_color", &color) ||
+      get_background (style_scheme, "selection", &color))
     define_color (str, "accent_bg_color", &color);
 
-  if (get_foreground (style_scheme, "selection", &color))
+  if (get_metadata_color (style_scheme, "accent_fg_color", &color) ||
+      get_foreground (style_scheme, "selection", &color))
     define_color (str, "accent_fg_color", &color);
 
   if (get_background (style_scheme, "selection", &color))


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