Commit b98caf93 authored by Bastien Nocera's avatar Bastien Nocera Committed by Matthias Clasen
Browse files

GtkCssProvider: Take into account variant

When loading a theme, make sure we take into account the variant
so we don't use the plain version when the theme changes.

Also make sure to fallback to the plain theme when loading a variant
parent 7f3aa920
......@@ -4003,24 +4003,31 @@ _gtk_css_provider_get_theme_dir (void)
* gtk_css_provider_get_named:
* @name: A theme name
* @variant: variant to load, for example, "dark", or %NULL for the default
* @variant: (allow-none): variant to load, for example, "dark", or
* %NULL for the default
* Loads a theme from the usual theme paths
* Returns: (transfer none): a #GtkCssProvider with the theme loaded.
* This memory is owned by GTK+, and you must not free it.
* This memory is owned by GTK+, and you must not free it.
GtkCssProvider *
gtk_css_provider_get_named (const gchar *name,
const gchar *variant)
static GHashTable *themes = NULL;
GtkCssProvider *provider;
gchar *key;
if (G_UNLIKELY (!themes))
themes = g_hash_table_new (g_str_hash, g_str_equal);
provider = g_hash_table_lookup (themes, name);
if (variant == NULL)
key = (gchar *)name;
key = g_strconcat (name, "-", variant, NULL);
provider = g_hash_table_lookup (themes, key);
if (!provider)
......@@ -4048,7 +4055,9 @@ gtk_css_provider_get_named (const gchar *name,
if (!path)
gchar *theme_dir = _gtk_css_provider_get_theme_dir ();
gchar *theme_dir;
theme_dir = _gtk_css_provider_get_theme_dir ();
path = g_build_filename (theme_dir, name, subpath, NULL);
g_free (theme_dir);
......@@ -4063,12 +4072,11 @@ gtk_css_provider_get_named (const gchar *name,
if (path)
GError *error = NULL;
GError *error;
provider = gtk_css_provider_new ();
gtk_css_provider_load_from_path (provider, path, &error);
if (error)
error = NULL;
if (!gtk_css_provider_load_from_path (provider, path, &error))
g_warning ("Could not load named theme \"%s\": %s", name, error->message);
g_error_free (error);
......@@ -4077,9 +4085,12 @@ gtk_css_provider_get_named (const gchar *name,
provider = NULL;
g_hash_table_insert (themes, g_strdup (name), provider);
g_hash_table_insert (themes, g_strdup (key), provider);
if (key != name)
g_free (key);
return provider;
......@@ -2672,7 +2672,8 @@ settings_update_theme (GtkSettings *settings)
static GQuark quark_theme_name = 0;
GtkSettingsPrivate *priv = settings->priv;
GtkCssProvider *provider, *new_provider = NULL;
GtkCssProvider *provider;
GtkCssProvider *new_provider;
gboolean prefer_dark_theme;
gchar *theme_name;
......@@ -2686,14 +2687,15 @@ settings_update_theme (GtkSettings *settings)
"gtk-application-prefer-dark-theme", &prefer_dark_theme,
new_provider = NULL;
if (theme_name && *theme_name)
gchar *variant = NULL;
if (prefer_dark_theme)
variant = "dark";
new_provider = gtk_css_provider_get_named (theme_name, "dark");
new_provider = gtk_css_provider_get_named (theme_name, variant);
if (!new_provider)
new_provider = gtk_css_provider_get_named (theme_name, NULL);
if (new_provider != provider)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment