[gtksourceview] map: mix foreground with background for general text



commit e6433e2eb0fa02193e8d78af6920760659cd12f2
Author: Christian Hergert <chergert redhat com>
Date:   Mon Jun 21 20:57:10 2021 -0700

    map: mix foreground with background for general text
    
    We don't want the map to detract from the document at hand, so it should
    be a bit less vibrant for general purpose text. The specific tags we can't
    do much about, and that seems to be fine for most code.
    
    Instead of using alpha, we mix here so that we have faster rendering paths.

 gtksourceview/gtksourcemap.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)
---
diff --git a/gtksourceview/gtksourcemap.c b/gtksourceview/gtksourcemap.c
index 2561a563..3350a0c3 100644
--- a/gtksourceview/gtksourcemap.c
+++ b/gtksourceview/gtksourcemap.c
@@ -320,7 +320,8 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
        GtkSourceStyle *style = NULL;
        GtkTextBuffer *buffer;
        GString *gstr;
-       gchar *background = NULL;
+       char *background = NULL;
+       char *foreground = NULL;
 
        priv = gtk_source_map_get_instance_private (map);
 
@@ -382,16 +383,45 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
 
        if (style != NULL)
        {
+               gboolean foreground_set;
+               gboolean background_set;
+
                g_object_get (style,
+                             "foreground", &foreground,
+                             "foreground-set", &foreground_set,
                              "background", &background,
+                             "background-set", &background_set,
                              NULL);
+
+               if (!foreground_set)
+               {
+                       g_clear_pointer (&foreground, g_free);
+               }
+
+               if (!background_set)
+               {
+                       g_clear_pointer (&background, g_free);
+               }
        }
 
        priv->had_color = background != NULL;
 
        if (background != NULL)
        {
+               if (foreground == NULL)
+               {
+                       GtkStyleContext *style_context;
+                       GdkRGBA color;
+
+                       style_context = gtk_widget_get_style_context (GTK_WIDGET (map));
+                       gtk_style_context_get_color (style_context, &color);
+                       foreground = gdk_rgba_to_string (&color);
+               }
+
                g_string_append_printf (gstr,
+                                       "textview.source-map {"
+                                       " color: mix(%s,%s,.25);"
+                                       "}\n"
                                        "slider {"
                                        " background-color: alpha(%s,.25);"
                                        " transition-duration: 300ms;"
@@ -399,10 +429,12 @@ gtk_source_map_rebuild_css (GtkSourceMap *map)
                                        "slider:hover {"
                                        " background-color: alpha(%s,.35);"
                                        "}\n",
+                                       foreground, background,
                                        background, background);
        }
 
        g_free (background);
+       g_free (foreground);
 
        if (gstr->len > 0)
        {


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