Also look in system data dirs for themes
authorMatthias Clasen <mclasen@redhat.com>
Thu, 17 Mar 2016 04:32:53 +0000 (00:32 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Tue, 22 Mar 2016 02:19:19 +0000 (22:19 -0400)
With this change, we now look in
$XDG_DATA_HOME/themes/THEME/gtk-3.x
$HOME/.themes/THEME/gtk-3.x
$XDG_DATA_DIRS/themes/THEME/gtk-3.x
GTK_DATA_PREFIX/themes/THEME/gtk-3.x

https://bugzilla.gnome.org/show_bug.cgi?id=641354

gtk/gtkcssprovider.c

index ec2982bdbb3f5881d6bec35b4813790324c9fcf3..0057ad28ed1b21f4e681daabacf91c7a1476f897 100644 (file)
  * gtk_style_context_add_provider_for_screen().
 
  * In addition, certain files will be read when GTK+ is initialized. First, the
- * file $XDG_CONFIG_HOME/gtk-3.0/gtk.css` is loaded if it exists. Then, GTK+ tries
- * to load `$HOME/.themes/theme-name/gtk-3.0/gtk.css`, falling back to
+ * file $XDG_CONFIG_HOME/gtk-3.0/gtk.css` is loaded if it exists. Then, GTK+
+ * loads the first existing file among
+ * `XDG_DATA_HOME/themes/theme-name/gtk-VERSION/gtk.css`,
+ * `$HOME/.themes/theme-name/gtk-VERSION/gtk.css`,
+ * `$XDG_DATA_DIRS/themes/theme-name/gtk-VERSION/gtk.css` and
  * `DATADIR/share/themes/THEME/gtk-VERSION/gtk.css`, where THEME is the name of
  * the current theme (see the #GtkSettings:gtk-theme-name setting), DATADIR
- * is the prefix configured when GTK+ was compiledunless overridden by the
- * `GTK_DATA_PREFIX` environment variable, and VERSION is the GTK+ version number.
+ * is the prefix configured when GTK+ was compiled (unless overridden by the
+ * `GTK_DATA_PREFIX` environment variable), and VERSION is the GTK+ version number.
  * If no file is found for the current version, GTK+ tries older versions all the
  * way back to 3.0.
  *
@@ -2056,8 +2059,10 @@ _gtk_css_find_theme (const gchar *name,
 {
   gchar *path;
   const gchar *var;
+  const char *const *dirs;
+  int i;
 
-  /* First look in the user's config directory */
+  /* First look in the user's data directory */
   path = _gtk_css_find_theme_dir (g_get_user_data_dir (), "themes", name, variant);
   if (path)
     return path;
@@ -2067,6 +2072,15 @@ _gtk_css_find_theme (const gchar *name,
   if (path)
     return path;
 
+  /* Look in system data directories */
+  dirs = g_get_system_data_dirs ();
+  for (i = 0; dirs[i]; i++)
+    {
+      path = _gtk_css_find_theme_dir (dirs[i], "themes", name, variant);
+      if (path)
+        return path;
+    }
+
   /* Finally, try in the default theme directory */
   var = g_getenv ("GTK_DATA_PREFIX");
   if (!var)