[meld] misc: Guess whether we're running under a dark theme (bgo#788455)



commit c8909e38f1b9b84a355baf130d244e394d47621a
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Mon Oct 23 07:05:21 2017 +1000

    misc: Guess whether we're running under a dark theme (bgo#788455)
    
    The always-use-dark-theme toggle is going away, or being unsupported, or
    something... so now we're left guessing whether the user is running a
    dark theme. Obviously this is just excellent and not at all dodgy.

 meld/misc.py |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)
---
diff --git a/meld/misc.py b/meld/misc.py
index a26d10a..26b275f 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -161,6 +161,19 @@ def get_base_style_scheme():
     else:
         gtk_settings = Gtk.Settings.get_default()
         use_dark = gtk_settings.props.gtk_application_prefer_dark_theme
+
+    # As of 3.28, the global dark theme switch is going away.
+    if not use_dark:
+        from meld.sourceview import MeldSourceView
+        stylecontext = MeldSourceView().get_style_context()
+        background_set, rgba = (
+            stylecontext.lookup_color('theme_bg_color'))
+
+        # 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
+
     base_scheme_name = (
         MELD_STYLE_SCHEME_DARK if use_dark else MELD_STYLE_SCHEME)
 


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