[gtk+] Load theme settings from the right location
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Load theme settings from the right location
- Date: Tue, 22 Mar 2016 02:40:53 +0000 (UTC)
commit 7cb36aba404c699f83579e039d6e97525b261231
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Mar 17 00:57:45 2016 -0400
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
gtk/gtkcssprovider.c | 42 +++++++++++++++++++++++++++---------------
gtk/gtkcssproviderprivate.h | 4 +++-
gtk/gtksettings.c | 17 +++++++++--------
gtk/inspector/visual.c | 2 +-
4 files changed, 40 insertions(+), 25 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 0057ad2..2c72034 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -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
{
diff --git a/gtk/gtkcssproviderprivate.h b/gtk/gtkcssproviderprivate.h
index 7a3777f..bca8e79 100644
--- a/gtk/gtkcssproviderprivate.h
+++ b/gtk/gtkcssproviderprivate.h
@@ -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,
diff --git a/gtk/gtksettings.c b/gtk/gtksettings.c
index 6275167..e91a734 100644
--- a/gtk/gtksettings.c
+++ b/gtk/gtksettings.c
@@ -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
diff --git a/gtk/inspector/visual.c b/gtk/inspector/visual.c
index 2f6a64f..cd4efb9 100644
--- a/gtk/inspector/visual.c
+++ b/gtk/inspector/visual.c
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]