[gtk+] Allow selecting a dark variant with GTK_THEME
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Allow selecting a dark variant with GTK_THEME
- Date: Fri, 7 Mar 2014 00:30:42 +0000 (UTC)
commit 15004e59306de29b5a0cf3195ccf266100a423b2
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Mar 6 19:27:37 2014 -0500
Allow selecting a dark variant with GTK_THEME
Dark themes need to be debugged, too.
Author: Matthias Clasen <mclasen redhat com>
docs/reference/gtk/running.sgml | 4 +++
gtk/gtksettings.c | 57 +++++++++++++++++++++++++-------------
2 files changed, 41 insertions(+), 20 deletions(-)
---
diff --git a/docs/reference/gtk/running.sgml b/docs/reference/gtk/running.sgml
index 8065e19..05f0510 100644
--- a/docs/reference/gtk/running.sgml
+++ b/docs/reference/gtk/running.sgml
@@ -322,6 +322,10 @@ additional environment variables.
that is specified by the gtk-theme-name setting. This is intended
mainly for easy debugging of theme issues.
</para>
+ <para>
+ It is also possible to specify a theme variant to load, by appending
+ the variant name with a colon, like this: `GTK_THEME=Adwaita:dark`.
+ </para>
</formalpara>
<para>
diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c
index ea043e3..5c834ef 100644
--- a/gtk/gtksettings.c
+++ b/gtk/gtksettings.c
@@ -2976,47 +2976,63 @@ settings_update_provider (GdkScreen *screen,
}
}
-static char *
-get_theme_name (GtkSettings *settings)
+static void
+get_theme_name (GtkSettings *settings,
+ gchar **theme_name,
+ gchar **theme_variant)
{
- char *theme_name = NULL;
+ gboolean prefer_dark;
+
+ *theme_name = NULL;
+ *theme_variant = NULL;
if (g_getenv ("GTK_THEME"))
- theme_name = g_strdup (g_getenv ("GTK_THEME"));
+ *theme_name = g_strdup (g_getenv ("GTK_THEME"));
- if (theme_name && *theme_name)
- return theme_name;
+ if (*theme_name && **theme_name)
+ {
+ char *p;
+ p = strrchr (*theme_name, ':');
+ if (p) {
+ *p = '\0';
+ p++;
+ *theme_variant = g_strdup (p);
+ }
+
+g_print ("theme: %s variant: %s\n", *theme_name, *theme_variant);
+ return;
+ }
+
+ g_free (*theme_name);
- g_free (theme_name);
g_object_get (settings,
- "gtk-theme-name", &theme_name,
+ "gtk-theme-name", theme_name,
+ "gtk-application-prefer-dark-theme", &prefer_dark,
NULL);
- if (theme_name && *theme_name)
- return theme_name;
+ if (prefer_dark)
+ *theme_variant = g_strdup ("dark");
- g_free (theme_name);
- return g_strdup (DEFAULT_THEME_NAME);
+ if (*theme_name && **theme_name)
+ return;
+
+ g_free (*theme_name);
+ *theme_name = g_strdup (DEFAULT_THEME_NAME);
}
static void
settings_update_theme (GtkSettings *settings)
{
GtkSettingsPrivate *priv = settings->priv;
- gboolean prefer_dark_theme;
gchar *theme_name;
+ gchar *theme_variant;
gchar *theme_dir;
gchar *path;
- g_object_get (settings,
- "gtk-application-prefer-dark-theme", &prefer_dark_theme,
- NULL);
-
- theme_name = get_theme_name (settings);
+ get_theme_name (settings, &theme_name, &theme_variant);
_gtk_css_provider_load_named (priv->theme_provider,
- theme_name,
- prefer_dark_theme ? "dark" : NULL);
+ theme_name, theme_variant);
/* reload per-theme settings */
theme_dir = _gtk_css_provider_get_theme_dir ();
@@ -3026,6 +3042,7 @@ settings_update_theme (GtkSettings *settings)
gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
g_free (theme_name);
+ g_free (theme_variant);
g_free (theme_dir);
g_free (path);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]