Compare commits

...

6 Commits

Author SHA1 Message Date
Matthias Clasen
979e3cd685 Change the setup of theme resources
Make Adwaita-dark a standalone separate
theme with the expected directory layout.
2019-05-08 19:00:00 +00:00
Matthias Clasen
4cfde0bdc8 settings: Adapt to css provider api change
Pass a fallback theme name instead of a variant.
2019-05-08 18:59:30 +00:00
Matthias Clasen
872dd9856b css provider: Change gtk_css_provider_load_named
Instead of taking an optional variant, take
an optional fallback theme name. So, instead
of load_named (p, "Adwaita", "dark"), you now
call load_named (p, "Adwaita-dark", "Adwaita").
2019-05-08 18:57:43 +00:00
Matthias Clasen
df0648bd74 css provider: Drop an unused field 2019-05-08 18:23:04 +00:00
Matthias Clasen
dbd20a6ba6 css provider: Drop an unused private api
This was only used for settings, and we are
not loading theme settings anymore.
2019-05-08 18:01:54 +00:00
Matthias Clasen
bc64f7d815 settings: Stop loading theme settings
This was invented for Windows themes, back in
the day, and we don't ship a Windows theme
anymore. We want to get to a place where
settings are always in GSettings.
2019-05-08 17:59:09 +00:00
5 changed files with 71 additions and 97 deletions

View File

@@ -18,7 +18,7 @@ def get_files(subdir,extension):
xml += '''
<file>theme/Adwaita/gtk.css</file>
<file>theme/Adwaita/gtk-dark.css</file>
<file alias='theme/Adwaita-dark/gtk.css'>theme/Adwaita/gtk-dark.css</file>
<file>theme/Adwaita/gtk-contained.css</file>
<file>theme/Adwaita/gtk-contained-dark.css</file>
'''

View File

@@ -117,7 +117,6 @@ struct _GtkCssProviderPrivate
GArray *rulesets;
GtkCssSelectorTree *tree;
GResource *resource;
gchar *path;
};
enum {
@@ -602,8 +601,6 @@ gtk_css_provider_finalize (GObject *object)
priv->resource = NULL;
}
g_free (priv->path);
G_OBJECT_CLASS (gtk_css_provider_parent_class)->finalize (object);
}
@@ -653,12 +650,6 @@ 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);
@@ -1235,17 +1226,6 @@ _gtk_get_theme_dir (void)
return g_build_filename (var, "share", "themes", NULL);
}
/* 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)
{
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (provider);
return priv->path;
}
#if (GTK_MINOR_VERSION % 2)
#define MINOR (GTK_MINOR_VERSION + 1)
#else
@@ -1254,17 +1234,16 @@ _gtk_css_provider_get_theme_dir (GtkCssProvider *provider)
/*
* Look for
* $dir/$subdir/gtk-4.16/gtk-$variant.css
* $dir/$subdir/gtk-4.14/gtk-$variant.css
* $dir/$subdir/gtk-4.16/gtk.css
* $dir/$subdir/gtk-4.14/gtk.css
* ...
* $dir/$subdir/gtk-4.0/gtk-$variant.css
* $dir/$subdir/gtk-4.0/gtk.css
* and return the first found file.
*/
static gchar *
_gtk_css_find_theme_dir (const gchar *dir,
const gchar *subdir,
const gchar *name,
const gchar *variant)
const gchar *name)
{
gchar *file;
gchar *base;
@@ -1272,10 +1251,7 @@ _gtk_css_find_theme_dir (const gchar *dir,
gint i;
gchar *path;
if (variant)
file = g_strconcat ("gtk-", variant, ".css", NULL);
else
file = g_strdup ("gtk.css");
file = g_strdup ("gtk.css");
if (subdir)
base = g_build_filename (dir, subdir, name, NULL);
@@ -1304,8 +1280,7 @@ _gtk_css_find_theme_dir (const gchar *dir,
#undef MINOR
static gchar *
_gtk_css_find_theme (const gchar *name,
const gchar *variant)
_gtk_css_find_theme (const gchar *name)
{
gchar *path;
const char *const *dirs;
@@ -1313,12 +1288,12 @@ _gtk_css_find_theme (const gchar *name,
char *dir;
/* First look in the user's data directory */
path = _gtk_css_find_theme_dir (g_get_user_data_dir (), "themes", name, variant);
path = _gtk_css_find_theme_dir (g_get_user_data_dir (), "themes", name);
if (path)
return path;
/* Next look in the user's home directory */
path = _gtk_css_find_theme_dir (g_get_home_dir (), ".themes", name, variant);
path = _gtk_css_find_theme_dir (g_get_home_dir (), ".themes", name);
if (path)
return path;
@@ -1326,62 +1301,42 @@ _gtk_css_find_theme (const gchar *name,
dirs = g_get_system_data_dirs ();
for (i = 0; dirs[i]; i++)
{
path = _gtk_css_find_theme_dir (dirs[i], "themes", name, variant);
path = _gtk_css_find_theme_dir (dirs[i], "themes", name);
if (path)
return path;
}
/* Finally, try in the default theme directory */
dir = _gtk_get_theme_dir ();
path = _gtk_css_find_theme_dir (dir, NULL, name, variant);
path = _gtk_css_find_theme_dir (dir, NULL, name);
g_free (dir);
return path;
}
/**
* gtk_css_provider_load_named:
* @provider: a #GtkCssProvider
* @name: A theme name
* @variant: (allow-none): variant to load, for example, "dark", or
* %NULL for the default
*
* Loads a theme from the usual theme paths. The actual process of
* finding the theme might change between releases, but it is
* guaranteed that this function uses the same mechanism to load the
* theme that GTK uses for loading its own theme.
**/
void
gtk_css_provider_load_named (GtkCssProvider *provider,
const gchar *name,
const gchar *variant)
static gboolean
gtk_css_provider_load_theme (GtkCssProvider *provider,
const gchar *name)
{
gchar *path;
gchar *resource_path;
g_return_if_fail (GTK_IS_CSS_PROVIDER (provider));
g_return_if_fail (name != NULL);
gtk_css_provider_reset (provider);
/* try loading the resource for the theme. This is mostly meant for built-in
* themes.
*/
if (variant)
resource_path = g_strdup_printf ("/org/gtk/libgtk/theme/%s/gtk-%s.css", name, variant);
else
resource_path = g_strdup_printf ("/org/gtk/libgtk/theme/%s/gtk.css", name);
resource_path = g_strconcat ("/org/gtk/libgtk/theme/", name, "/gtk.css", NULL);
if (g_resources_get_info (resource_path, 0, NULL, NULL, NULL))
{
gtk_css_provider_load_from_resource (provider, resource_path);
g_free (resource_path);
return;
return TRUE;
}
g_free (resource_path);
/* Next try looking for files in the various theme directories. */
path = _gtk_css_find_theme (name, variant);
path = _gtk_css_find_theme (name);
if (path)
{
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (provider);
@@ -1400,26 +1355,49 @@ gtk_css_provider_load_named (GtkCssProvider *provider,
/* Only set this after load, as load_from_path will clear it */
priv->resource = resource;
priv->path = dir;
g_free (dir);
g_free (path);
}
else
{
/* Things failed! Fall back! Fall back! */
if (variant)
{
/* If there was a variant, try without */
gtk_css_provider_load_named (provider, name, NULL);
}
else
{
/* Worst case, fall back to the default */
g_return_if_fail (!g_str_equal (name, DEFAULT_THEME_NAME)); /* infloop protection */
gtk_css_provider_load_named (provider, DEFAULT_THEME_NAME, NULL);
}
return TRUE;
}
return FALSE;
}
/**
* gtk_css_provider_load_named:
* @provider: a #GtkCssProvider
* @name: A theme name
* @fallback: (allow-none): Fallback theme to load if @name is
* not available, or %NULL for the default
*
* Loads a theme from the usual theme paths. The actual process of
* finding the theme might change between releases, but it is
* guaranteed that this function uses the same mechanism to load the
* theme that GTK uses for loading its own theme.
*
* The @fallback can be used to try loading THEME-dark,
* falling back to THEME.
**/
void
gtk_css_provider_load_named (GtkCssProvider *provider,
const gchar *name,
const gchar *fallback)
{
g_return_if_fail (GTK_IS_CSS_PROVIDER (provider));
g_return_if_fail (name != NULL);
gtk_css_provider_reset (provider);
if (gtk_css_provider_load_theme (provider, name))
return;
if (fallback &&
gtk_css_provider_load_theme (provider, fallback))
return;
gtk_css_provider_load_theme (provider, DEFAULT_THEME_NAME);
}
static int

View File

@@ -80,7 +80,7 @@ void gtk_css_provider_load_from_resource (GtkCssProvider *css_provid
GDK_AVAILABLE_IN_ALL
void gtk_css_provider_load_named (GtkCssProvider *provider,
const char *name,
const char *variant);
const char *fallback);
G_END_DECLS

View File

@@ -24,8 +24,6 @@ G_BEGIN_DECLS
gchar *_gtk_get_theme_dir (void);
const gchar *_gtk_css_provider_get_theme_dir (GtkCssProvider *provider);
void gtk_css_provider_set_keep_css_sections (void);
G_END_DECLS

View File

@@ -2208,29 +2208,27 @@ static void
settings_update_theme (GtkSettings *settings)
{
GtkSettingsPrivate *priv = settings->priv;
gchar *theme_name;
gchar *theme_variant;
const gchar *theme_dir;
gchar *path;
char *theme_name;
char *theme_variant;
char *theme_fallback;
get_theme_name (settings, &theme_name, &theme_variant);
if (theme_variant)
{
theme_fallback = theme_name;
theme_name = g_strconcat (theme_fallback, "-", theme_variant, NULL);
}
else
theme_fallback = NULL;
gtk_css_provider_load_named (priv->theme_provider,
theme_name,
theme_variant);
/* reload per-theme settings */
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);
}
theme_fallback);
g_free (theme_name);
g_free (theme_variant);
g_free (theme_fallback);
}
const cairo_font_options_t *