[gnome-klotski/gnome-3-36] Adapt to new HC theme.



commit 52aaf33b99f292915609fd9c769aea5c536bcfce
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Apr 24 23:21:26 2020 +0200

    Adapt to new HC theme.

 data/klotski.css        | 21 ++++++++-------------
 src/klotski-window.vala | 40 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 13 deletions(-)
---
diff --git a/data/klotski.css b/data/klotski.css
index 7c21881..8bc08f4 100644
--- a/data/klotski.css
+++ b/data/klotski.css
@@ -27,25 +27,25 @@ stack#stack-packs > label {
   font-weight: bold;
 }
 
-.treeview-container treeview {
+window:not(.hc-theme) .treeview-container treeview {
   background-color: transparent;
 }
-.treeview-container treeview:backdrop {
+window:not(.hc-theme) .treeview-container treeview:backdrop {
   color: @theme_unfocused_fg_color;
 }
-.treeview-container treeview:hover {
+window:not(.hc-theme) .treeview-container treeview:hover {
   background-color: @theme_bg_color;
 }
-.treeview-container treeview:hover:backdrop {
+window:not(.hc-theme) .treeview-container treeview:hover:backdrop {
   background-color: @theme_unfocused_bg_color;
 }
-.treeview-container treeview:selected,
-.treeview-container treeview:selected:hover {
+window:not(.hc-theme) .treeview-container treeview:selected,
+window:not(.hc-theme) .treeview-container treeview:selected:hover {
   background-color: @theme_selected_bg_color;
   color: @theme_selected_fg_color;
 }
-.treeview-container treeview:selected:backdrop,
-.treeview-container treeview:selected:backdrop:hover {
+window:not(.hc-theme) .treeview-container treeview:selected:backdrop,
+window:not(.hc-theme) .treeview-container treeview:selected:backdrop:hover {
   background-color: @theme_unfocused_selected_bg_color;
   color: @theme_unfocused_selected_fg_color;
 }
@@ -63,11 +63,6 @@ treeview.toggle-like-pixbuf check:checked {
   -gtk-icon-source: -gtk-icontheme("gtk-yes"); /* TODO maybe deprecated; replace with CSS? */
 }
 
-/* https://bugzilla.gnome.org/show_bug.cgi?id=744531 */
-button.flat:disabled {
-  color: @theme_unfocused_bg_color;
-}
-
 /*\
 * * the end
 \*/
diff --git a/src/klotski-window.vala b/src/klotski-window.vala
index a3ffdfd..b89762e 100644
--- a/src/klotski-window.vala
+++ b/src/klotski-window.vala
@@ -533,6 +533,8 @@ private class KlotskiWindow : ApplicationWindow
         if (settings.get_boolean ("window-is-maximized"))
             maximize ();
 
+        manage_high_contrast ();
+
         add_action_entries (win_actions, this);
         lookup_non_nullable_action ("prev-pack",    out prev_pack);
         lookup_non_nullable_action ("next-pack",    out next_pack);
@@ -976,4 +978,42 @@ private class KlotskiWindow : ApplicationWindow
         else
             liststore_skill.set (iter, 1, solved);
     }
+
+    /*\
+    * * manage high-constrast
+    \*/
+
+    private StyleContext window_style_context;
+
+    private inline void manage_high_contrast ()
+    {
+        Gtk.Settings? nullable_gtk_settings = Gtk.Settings.get_default ();
+        if (nullable_gtk_settings == null)
+            return;
+
+        window_style_context = get_style_context ();
+
+        Gtk.Settings gtk_settings = (!) nullable_gtk_settings;
+        gtk_settings.notify ["gtk-theme-name"].connect (update_highcontrast_state);
+        _update_highcontrast_state (gtk_settings.gtk_theme_name);
+    }
+
+    private void update_highcontrast_state (Object gtk_settings, ParamSpec unused)
+    {
+        _update_highcontrast_state (((Gtk.Settings) gtk_settings).gtk_theme_name);
+    }
+
+    private bool highcontrast_state = false;
+    private void _update_highcontrast_state (string theme_name)
+    {
+        bool highcontrast_new_state = "HighContrast" in theme_name;
+        if (highcontrast_new_state == highcontrast_state)
+            return;
+        highcontrast_state = highcontrast_new_state;
+
+        if (highcontrast_new_state)
+            window_style_context.add_class ("hc-theme");
+        else
+            window_style_context.remove_class ("hc-theme");
+    }
 }


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