[gtk/theme-redux: 48/58] widget-factory: Stop dealing with prefer-dark



commit 040175cd92d5b7c7f728e66d363822d7f68d1f59
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Apr 11 15:50:44 2020 -0400

    widget-factory: Stop dealing with prefer-dark
    
    Instead, just toggle between known light/dark pairs
    for the builtin themes.

 demos/widget-factory/widget-factory.c | 45 +++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 15 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index 40ce3e286c..e04dd35d91 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -25,23 +25,46 @@
 #include <glib/gi18n.h>
 #include <gtk/gtk.h>
 
+static char *current_theme;
+
 static void
 change_dark_state (GSimpleAction *action,
                     GVariant      *state,
                     gpointer       user_data)
 {
   GtkSettings *settings = gtk_settings_get_default ();
+  gboolean prefer_dark = g_variant_get_boolean (state);
+  char *theme;
+  const char *new_theme = NULL;
 
-  g_object_set (G_OBJECT (settings),
-                "gtk-application-prefer-dark-theme",
-                g_variant_get_boolean (state),
+  g_object_get (G_OBJECT (settings),
+                "gtk-theme-name", &theme,
                 NULL);
 
+  if (prefer_dark)
+    {
+      if (strcmp (theme, "Adwaita") == 0)
+        new_theme = "Adwaita-dark";
+      else if (strcmp (theme, "HighContrastInverse") == 0)
+        new_theme = "HighContrast";
+    }
+  else
+    {
+      if (strcmp (theme, "Adwaita-dark") == 0)
+        new_theme = "Adwaita";
+      else if (strcmp (theme, "HighContrast") == 0)
+        new_theme = "HighContrastInverse";
+    }
+
+  if (new_theme)
+    g_object_set (G_OBJECT (settings),
+                  "gtk-theme-name", new_theme,
+                  NULL);
+
   g_simple_action_set_state (action, state);
-}
 
-static char *current_theme;
-static gboolean current_dark;
+  g_free (theme);
+}
 
 static void
 change_theme_state (GSimpleAction *action,
@@ -51,41 +74,34 @@ change_theme_state (GSimpleAction *action,
   GtkSettings *settings = gtk_settings_get_default ();
   const char *s;
   const char *theme;
-  gboolean prefer_dark = FALSE;
 
   s = g_variant_get_string (state, NULL);
 
   if (strcmp (s, "adwaita") == 0)
     {
       theme = "Adwaita";
-      prefer_dark = FALSE;
     }
   else if (strcmp (s, "adwaita-dark") == 0)
     {
-      theme = "Adwaita";
-      prefer_dark = TRUE;
+      theme = "Adwaita-dark";
     }
   else if (strcmp (s, "highcontrast") == 0)
     {
       theme = "HighContrast";
-      prefer_dark = FALSE;
     }
   else if (strcmp (s, "highcontrast-inverse") == 0)
     {
       theme = "HighContrastInverse";
-      prefer_dark = FALSE;
     }
   else if (strcmp (s, "current") == 0)
     {
       theme = current_theme;
-      prefer_dark = current_dark;
     }
   else
     return;
 
   g_object_set (G_OBJECT (settings),
                 "gtk-theme-name", theme,
-                "gtk-application-prefer-dark-theme", prefer_dark,
                 NULL);
 
   g_simple_action_set_state (action, state);
@@ -1739,7 +1755,6 @@ activate (GApplication *app)
 
   g_object_get (gtk_settings_get_default (),
                 "gtk-theme-name", &current_theme,
-                "gtk-application-prefer-dark-theme", &current_dark,
                 NULL);
 
   g_type_ensure (my_text_view_get_type ());


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