[gtk/widget-factory-theme] widget-factory: Add theme switch
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/widget-factory-theme] widget-factory: Add theme switch
- Date: Thu, 26 Mar 2020 17:54:15 +0000 (UTC)
commit 8ab2e31b5807696e2e8385980ed29dd7cc93f514
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Mar 26 13:51:59 2020 -0400
widget-factory: Add theme switch
Add a submenu to test the builtin themes. This is mainly
for the benefit of the artists working on those themes.
demos/widget-factory/widget-factory.c | 61 ++++++++++++++++++++++++++++++++--
demos/widget-factory/widget-factory.ui | 34 ++++++++++++++++---
2 files changed, 89 insertions(+), 6 deletions(-)
---
diff --git a/demos/widget-factory/widget-factory.c b/demos/widget-factory/widget-factory.c
index 2445af7c27..9dd12e62c9 100644
--- a/demos/widget-factory/widget-factory.c
+++ b/demos/widget-factory/widget-factory.c
@@ -26,7 +26,7 @@
#include <gtk/gtk.h>
static void
-change_theme_state (GSimpleAction *action,
+change_dark_state (GSimpleAction *action,
GVariant *state,
gpointer user_data)
{
@@ -40,6 +40,57 @@ change_theme_state (GSimpleAction *action,
g_simple_action_set_state (action, state);
}
+static char *current_theme;
+static gboolean current_dark;
+
+static void
+change_theme_state (GSimpleAction *action,
+ GVariant *state,
+ gpointer user_data)
+{
+ 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;
+ }
+ 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);
+}
+
static GtkWidget *page_stack;
static void
@@ -1671,7 +1722,8 @@ activate (GApplication *app)
GtkCssProvider *provider;
GMenuModel *model;
static GActionEntry win_entries[] = {
- { "dark", NULL, NULL, "false", change_theme_state },
+ { "dark", NULL, NULL, "false", change_dark_state },
+ { "theme", NULL, "s", "'current'", change_theme_state },
{ "transition", NULL, NULL, "false", change_transition_state },
{ "search", activate_search, NULL, NULL, NULL },
{ "delete", activate_delete, NULL, NULL, NULL },
@@ -1703,6 +1755,11 @@ activate (GApplication *app)
GPermission *permission;
GAction *action;
+ g_object_get (gtk_settings_get_default (),
+ "gtk-theme-name", ¤t_theme,
+ "gtk-application-prefer-dark-theme", ¤t_dark,
+ NULL);
+
g_type_ensure (my_text_view_get_type ());
provider = gtk_css_provider_new ();
diff --git a/demos/widget-factory/widget-factory.ui b/demos/widget-factory/widget-factory.ui
index fd6be0c188..ecca3b4ff1 100644
--- a/demos/widget-factory/widget-factory.ui
+++ b/demos/widget-factory/widget-factory.ui
@@ -6,10 +6,36 @@
<attribute name="label" translatable="yes">Get Busy</attribute>
<attribute name="action">win.busy</attribute>
</item>
- <item>
- <attribute name="label" translatable="yes">Dark Theme</attribute>
- <attribute name="action">win.dark</attribute>
- </item>
+ <submenu>
+ <attribute name="label" translatable="yes">Theme</attribute>
+ <section>
+ <item>
+ <attribute name="label" translatable="yes">Current theme</attribute>
+ <attribute name="action">win.theme</attribute>
+ <attribute name="target">current</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Adwaita</attribute>
+ <attribute name="action">win.theme</attribute>
+ <attribute name="target">adwaita</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">Adwaita dark</attribute>
+ <attribute name="action">win.theme</attribute>
+ <attribute name="target">adwaita-dark</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">High contrast</attribute>
+ <attribute name="action">win.theme</attribute>
+ <attribute name="target">highcontrast</attribute>
+ </item>
+ <item>
+ <attribute name="label" translatable="yes">High contrast inverse</attribute>
+ <attribute name="action">win.theme</attribute>
+ <attribute name="target">highcontrast-inverse</attribute>
+ </item>
+ </section>
+ </submenu>
<item>
<attribute name="label" translatable="yes">Slide Pages</attribute>
<attribute name="action">win.transition</attribute>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]