[meld] style: Rework dark scheme detection based on GtkSourceView style scheme



commit a8815c53b32555f47c6a50c47993e51fe0c90734
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Fri Jul 5 10:12:35 2019 +1000

    style: Rework dark scheme detection based on GtkSourceView style scheme
    
    This makes more sense and works in more scenarios. If a user selects a
    dark sourceview syntax highlighting scheme, then that's the background
    that's going to get used, regardless of what the GTK+ theme says. The
    only scenario in which the GTK+ theme background matters is when the
    sourceview scheme doesn't have a background set.

 meld/style.py | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)
---
diff --git a/meld/style.py b/meld/style.py
index 18e53320..c05d9efc 100644
--- a/meld/style.py
+++ b/meld/style.py
@@ -43,19 +43,30 @@ def get_base_style_scheme() -> GtkSource.StyleScheme:
     if base_style_scheme:
         return base_style_scheme
 
-    use_dark = False
-
-    # As of 3.28, the global dark theme switch is going away.
-    if not use_dark:
+    from meld.settings import meldsettings
+    style_scheme = meldsettings.style_scheme
+
+    # Get our text background colour by checking the 'text' style of
+    # the user's selected style scheme, falling back to the GTK+ theme
+    # background if there is no style scheme background set.
+    style = style_scheme.get_style('text') if style_scheme else None
+    if style:
+        background = style.props.background
+        rgba = Gdk.RGBA()
+        rgba.parse(background)
+    else:
+        # This case will only be hit for GtkSourceView style schemes
+        # that don't set a text background, like the "Classic" scheme.
         from meld.sourceview import MeldSourceView
         stylecontext = MeldSourceView().get_style_context()
         background_set, rgba = (
             stylecontext.lookup_color('theme_bg_color'))
+        if not background_set:
+            rgba = Gdk.RGBA(1, 1, 1, 1)
 
-        # This heuristic is absolutely dire. I made it up. There's
-        # literally no basis to this.
-        if background_set and rgba.red + rgba.green + rgba.blue < 1.0:
-            use_dark = True
+    # This heuristic is absolutely dire. I made it up. There's
+    # literally no basis to this.
+    use_dark = (rgba.red + rgba.green + rgba.blue) < 1.0
 
     base_scheme_name = (
         MeldStyleScheme.dark if use_dark else MeldStyleScheme.base)


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