Load theme settings from the right location

When loading a per-theme settings.ini file, look for it in
the same directory where we found the gtk.css file for the
theme. Previously, we were always looking in
$prefix/share/themes/THEME/gtk-3.0/, even if the css was
loaded from somewhere else.

https://bugzilla.gnome.org/show_bug.cgi?id=641354
This commit is contained in:
Matthias Clasen 2016-03-17 00:57:45 -04:00
parent 475d916eb9
commit 7cb36aba40
4 changed files with 40 additions and 25 deletions

View File

@ -130,6 +130,7 @@ struct _GtkCssProviderPrivate
GArray *rulesets;
GtkCssSelectorTree *tree;
GResource *resource;
gchar *path;
};
enum {
@ -827,6 +828,8 @@ gtk_css_provider_finalize (GObject *object)
priv->resource = NULL;
}
g_free (priv->path);
G_OBJECT_CLASS (gtk_css_provider_parent_class)->finalize (object);
}
@ -904,7 +907,7 @@ gtk_css_provider_invalid_token (GtkCssProvider *provider,
"expected %s", expected);
}
static void
static void
css_provider_commit (GtkCssProvider *css_provider,
GSList *selectors,
GtkCssRuleset *ruleset)
@ -947,6 +950,12 @@ gtk_css_provider_reset (GtkCssProvider *css_provider)
priv->resource = NULL;
}
if (priv->path)
{
g_free (priv->path);
priv->path = NULL;
}
g_hash_table_remove_all (priv->symbolic_colors);
g_hash_table_remove_all (priv->keyframes);
@ -1976,18 +1985,23 @@ gtk_css_provider_get_default (void)
}
gchar *
_gtk_css_provider_get_theme_dir (void)
_gtk_get_theme_dir (void)
{
const gchar *var;
gchar *path;
var = g_getenv ("GTK_DATA_PREFIX");
if (var)
path = g_build_filename (var, "share", "themes", NULL);
else
path = g_build_filename (_gtk_get_data_prefix (), "share", "themes", NULL);
if (var == NULL)
var = _gtk_get_data_prefix ();
return g_build_filename (var, "share", "themes", NULL);
}
return path;
/* Return the path that this providers gtk.css was loaded from,
* if it is part of a theme, otherwise NULL.
*/
const gchar *
_gtk_css_provider_get_theme_dir (GtkCssProvider *provider)
{
return provider->priv->path;
}
#if (GTK_MINOR_VERSION % 2)
@ -2058,9 +2072,9 @@ _gtk_css_find_theme (const gchar *name,
const gchar *variant)
{
gchar *path;
const gchar *var;
const char *const *dirs;
int i;
char *dir;
/* First look in the user's data directory */
path = _gtk_css_find_theme_dir (g_get_user_data_dir (), "themes", name, variant);
@ -2082,11 +2096,9 @@ _gtk_css_find_theme (const gchar *name,
}
/* Finally, try in the default theme directory */
var = g_getenv ("GTK_DATA_PREFIX");
if (!var)
var = _gtk_get_data_prefix ();
path = _gtk_css_find_theme_dir (var, "share" G_DIR_SEPARATOR_S "themes", name, variant);
dir = _gtk_get_theme_dir ();
path = _gtk_css_find_theme_dir (dir, NULL, name, variant);
g_free (dir);
return path;
}
@ -2151,9 +2163,9 @@ _gtk_css_provider_load_named (GtkCssProvider *provider,
/* Only set this after load, as load_from_path will clear it */
provider->priv->resource = resource;
provider->priv->path = dir;
g_free (path);
g_free (dir);
}
else
{

View File

@ -22,7 +22,9 @@
G_BEGIN_DECLS
gchar *_gtk_css_provider_get_theme_dir (void);
gchar *_gtk_get_theme_dir (void);
const gchar *_gtk_css_provider_get_theme_dir (GtkCssProvider *provider);
void _gtk_css_provider_load_named (GtkCssProvider *provider,
const gchar *name,

View File

@ -3219,7 +3219,7 @@ settings_update_theme (GtkSettings *settings)
GtkSettingsPrivate *priv = settings->priv;
gchar *theme_name;
gchar *theme_variant;
gchar *theme_dir;
const gchar *theme_dir;
gchar *path;
get_theme_name (settings, &theme_name, &theme_variant);
@ -3228,16 +3228,17 @@ settings_update_theme (GtkSettings *settings)
theme_name, theme_variant);
/* reload per-theme settings */
theme_dir = _gtk_css_provider_get_theme_dir ();
path = g_build_filename (theme_dir, theme_name, "gtk-3.0", "settings.ini", NULL);
if (g_file_test (path, G_FILE_TEST_EXISTS))
gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
theme_dir = _gtk_css_provider_get_theme_dir (priv->theme_provider);
if (theme_dir)
{
path = g_build_filename (theme_dir, "settings.ini", NULL);
if (g_file_test (path, G_FILE_TEST_EXISTS))
gtk_settings_load_from_key_file (settings, path, GTK_SETTINGS_SOURCE_THEME);
g_free (path);
}
g_free (theme_name);
g_free (theme_variant);
g_free (theme_dir);
g_free (path);
}
static void

View File

@ -273,7 +273,7 @@ init_theme (GtkInspectorVisual *vis)
}
g_strfreev (builtin_themes);
path = _gtk_css_provider_get_theme_dir ();
path = _gtk_get_theme_dir ();
fill_gtk (path, t);
g_free (path);