[gnome-builder/wip/gtk4-port] plugins/omni-gutter: add fallback style lookups



commit 7a4fb184c3495f98ab8c37c74f4dc8e3ea0b1973
Author: Christian Hergert <chergert redhat com>
Date:   Mon May 2 13:54:51 2022 -0700

    plugins/omni-gutter: add fallback style lookups
    
    That way if we have a mapping to another style, we can try to find that
    instead of just bailing to the internal fallback color.

 src/plugins/omni-gutter/gbp-omni-gutter-renderer.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/plugins/omni-gutter/gbp-omni-gutter-renderer.c 
b/src/plugins/omni-gutter/gbp-omni-gutter-renderer.c
index ed944e66c..e0ddb8919 100644
--- a/src/plugins/omni-gutter/gbp-omni-gutter-renderer.c
+++ b/src/plugins/omni-gutter/gbp-omni-gutter-renderer.c
@@ -410,7 +410,10 @@ get_style_rgba (GtkSourceStyleScheme *scheme,
                 int                   type,
                 GdkRGBA              *rgba)
 {
-  GtkSourceStyle *style;
+  GtkSourceLanguageManager *langs;
+  GtkSourceLanguage *def;
+  GtkSourceStyle *style = NULL;
+  const char *fallback = style_name;
 
   g_assert (!scheme || GTK_SOURCE_IS_STYLE_SCHEME (scheme));
   g_assert (style_name != NULL);
@@ -422,7 +425,18 @@ get_style_rgba (GtkSourceStyleScheme *scheme,
   if (scheme == NULL)
     return FALSE;
 
-  if (NULL != (style = gtk_source_style_scheme_get_style (scheme, style_name)))
+  langs = gtk_source_language_manager_get_default ();
+  def = gtk_source_language_manager_get_language (langs, "def");
+
+  g_assert (def != NULL);
+
+  while (style == NULL && fallback != NULL)
+    {
+      if (!(style = gtk_source_style_scheme_get_style (scheme, fallback)))
+        fallback = gtk_source_language_get_style_fallback (def, fallback);
+    }
+
+  if (style != NULL)
     {
       g_autofree gchar *str = NULL;
       gboolean set = FALSE;


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