[libhandy/wip/exalm/dark: 5/6] demo: Rework the dark mode button
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libhandy/wip/exalm/dark: 5/6] demo: Rework the dark mode button
- Date: Mon, 20 Sep 2021 10:32:33 +0000 (UTC)
commit bf638021efd614bac96cdd7d20cec984866e4538
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sun Aug 29 21:09:03 2021 +0500
demo: Rework the dark mode button
Only show it if the system doesn't support color schemes.
examples/hdy-demo-window.c | 38 ++++++++++++++++++++++----------------
examples/hdy-demo-window.ui | 7 +++----
2 files changed, 25 insertions(+), 20 deletions(-)
---
diff --git a/examples/hdy-demo-window.c b/examples/hdy-demo-window.c
index 7fe9424c..08e562aa 100644
--- a/examples/hdy-demo-window.c
+++ b/examples/hdy-demo-window.c
@@ -12,7 +12,8 @@ struct _HdyDemoWindow
HdyLeaflet *content_box;
GtkStack *header_revealer;
GtkStack *header_stack;
- GtkImage *theme_variant_image;
+ GtkWidget *color_scheme_button;
+ GtkImage *color_scheme_image;
GtkStackSidebar *sidebar;
GtkStack *stack;
HdyComboRow *leaflet_transition_row;
@@ -42,20 +43,21 @@ struct _HdyDemoWindow
G_DEFINE_TYPE (HdyDemoWindow, hdy_demo_window, HDY_TYPE_APPLICATION_WINDOW)
static void
-theme_variant_button_clicked_cb (HdyDemoWindow *self)
+color_scheme_button_clicked_cb (HdyDemoWindow *self)
{
- GtkSettings *settings = gtk_settings_get_default ();
- gboolean prefer_dark_theme;
+ HdyStyleManager *manager = hdy_style_manager_get_default ();
- g_object_get (settings, "gtk-application-prefer-dark-theme", &prefer_dark_theme, NULL);
- g_object_set (settings, "gtk-application-prefer-dark-theme", !prefer_dark_theme, NULL);
+ if (hdy_style_manager_get_dark (manager))
+ hdy_style_manager_set_color_scheme (manager, HDY_COLOR_SCHEME_LIGHT);
+ else
+ hdy_style_manager_set_color_scheme (manager, HDY_COLOR_SCHEME_DARK);
}
static gboolean
-prefer_dark_theme_to_icon_name_cb (GBinding *binding,
- const GValue *from_value,
- GValue *to_value,
- gpointer user_data)
+dark_to_icon_name_cb (GBinding *binding,
+ const GValue *from_value,
+ GValue *to_value,
+ gpointer user_data)
{
g_value_set_string (to_value,
g_value_get_boolean (from_value) ? "light-mode-symbolic" :
@@ -479,7 +481,8 @@ hdy_demo_window_class_init (HdyDemoWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, content_box);
gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, header_revealer);
gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, header_stack);
- gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, theme_variant_image);
+ gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, color_scheme_button);
+ gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, color_scheme_image);
gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, sidebar);
gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, stack);
gtk_widget_class_bind_template_child (widget_class, HdyDemoWindow, leaflet_transition_row);
@@ -510,7 +513,7 @@ hdy_demo_window_class_init (HdyDemoWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, notify_leaflet_transition_cb);
gtk_widget_class_bind_template_callback (widget_class, notify_deck_transition_cb);
gtk_widget_class_bind_template_callback (widget_class, deck_go_next_row_activated_cb);
- gtk_widget_class_bind_template_callback (widget_class, theme_variant_button_clicked_cb);
+ gtk_widget_class_bind_template_callback (widget_class, color_scheme_button_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, view_switcher_demo_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, notify_carousel_orientation_cb);
gtk_widget_class_bind_template_callback (widget_class, notify_carousel_indicators_cb);
@@ -589,18 +592,21 @@ avatar_page_init (HdyDemoWindow *self)
static void
hdy_demo_window_init (HdyDemoWindow *self)
{
- GtkSettings *settings = gtk_settings_get_default ();
+ HdyStyleManager *manager = hdy_style_manager_get_default ();
gtk_widget_init_template (GTK_WIDGET (self));
- g_object_bind_property_full (settings, "gtk-application-prefer-dark-theme",
- self->theme_variant_image, "icon-name",
+ g_object_bind_property_full (manager, "dark",
+ self->color_scheme_image, "icon-name",
G_BINDING_SYNC_CREATE,
- prefer_dark_theme_to_icon_name_cb,
+ dark_to_icon_name_cb,
NULL,
NULL,
NULL);
+ gtk_widget_set_visible (self->color_scheme_button,
+ !hdy_style_manager_get_system_supports_color_scheme (manager));
+
hdy_combo_row_set_for_enum (self->leaflet_transition_row, HDY_TYPE_LEAFLET_TRANSITION_TYPE,
leaflet_transition_name, NULL, NULL);
hdy_combo_row_set_selected_index (self->leaflet_transition_row, HDY_LEAFLET_TRANSITION_TYPE_OVER);
diff --git a/examples/hdy-demo-window.ui b/examples/hdy-demo-window.ui
index 20dc6fff..d0be5b5d 100644
--- a/examples/hdy-demo-window.ui
+++ b/examples/hdy-demo-window.ui
@@ -46,12 +46,11 @@
<property name="title" translatable="yes">Handy Demo</property>
<property name="show_close_button">True</property>
<child>
- <object class="GtkButton">
- <property name="visible">True</property>
+ <object class="GtkButton" id="color_scheme_button">
<property name="can_focus">True</property>
- <signal name="clicked" handler="theme_variant_button_clicked_cb" swapped="yes"/>
+ <signal name="clicked" handler="color_scheme_button_clicked_cb" swapped="yes"/>
<child>
- <object class="GtkImage" id="theme_variant_image">
+ <object class="GtkImage" id="color_scheme_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]