[libadwaita/wip/exalm/inspector: 1/4] demo: Handle system-supports-color-schemes changes in runtime




commit 2bf941011dc43a1eaa53ce722205abfe17bd201f
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Mon Sep 27 03:21:22 2021 +0500

    demo: Handle system-supports-color-schemes changes in runtime
    
    Show/hide the button dynamically and not only on startup. Reset color
    scheme to default upon hiding the button too.

 examples/adw-demo-window.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/examples/adw-demo-window.c b/examples/adw-demo-window.c
index 05e9a3d5..a8aa1110 100644
--- a/examples/adw-demo-window.c
+++ b/examples/adw-demo-window.c
@@ -49,6 +49,18 @@ color_scheme_button_clicked_cb (AdwDemoWindow *self)
     adw_style_manager_set_color_scheme (manager, ADW_COLOR_SCHEME_FORCE_DARK);
 }
 
+static void
+notify_system_supports_color_schemes_cb (AdwDemoWindow *self)
+{
+  AdwStyleManager *manager = adw_style_manager_get_default ();
+  gboolean supports = adw_style_manager_get_system_supports_color_schemes (manager);
+
+  gtk_widget_set_visible (self->color_scheme_button, !supports);
+
+  if (supports)
+    adw_style_manager_set_color_scheme (manager, ADW_COLOR_SCHEME_DEFAULT);
+}
+
 static void
 notify_visible_child_cb (GObject       *sender,
                          GParamSpec    *pspec,
@@ -456,8 +468,13 @@ adw_demo_window_init (AdwDemoWindow *self)
 
   gtk_widget_init_template (GTK_WIDGET (self));
 
-  gtk_widget_set_visible (self->color_scheme_button,
-                          !adw_style_manager_get_system_supports_color_schemes (manager));
+  g_signal_connect_object (manager,
+                           "notify::system-supports-color-schemes",
+                           G_CALLBACK (notify_system_supports_color_schemes_cb),
+                           self,
+                           G_CONNECT_SWAPPED);
+
+  notify_system_supports_color_schemes_cb (self);
 
   avatar_page_init (self);
 


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