Compare commits
6 Commits
async-dial
...
theme-load
Author | SHA1 | Date | |
---|---|---|---|
|
979e3cd685 | ||
|
4cfde0bdc8 | ||
|
872dd9856b | ||
|
df0648bd74 | ||
|
dbd20a6ba6 | ||
|
bc64f7d815 |
@@ -18,7 +18,7 @@ def get_files(subdir,extension):
|
|||||||
|
|
||||||
xml += '''
|
xml += '''
|
||||||
<file>theme/Adwaita/gtk.css</file>
|
<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.css</file>
|
||||||
<file>theme/Adwaita/gtk-contained-dark.css</file>
|
<file>theme/Adwaita/gtk-contained-dark.css</file>
|
||||||
'''
|
'''
|
||||||
|
@@ -117,7 +117,6 @@ struct _GtkCssProviderPrivate
|
|||||||
GArray *rulesets;
|
GArray *rulesets;
|
||||||
GtkCssSelectorTree *tree;
|
GtkCssSelectorTree *tree;
|
||||||
GResource *resource;
|
GResource *resource;
|
||||||
gchar *path;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
@@ -602,8 +601,6 @@ gtk_css_provider_finalize (GObject *object)
|
|||||||
priv->resource = NULL;
|
priv->resource = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (priv->path);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (gtk_css_provider_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gtk_css_provider_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -653,12 +650,6 @@ gtk_css_provider_reset (GtkCssProvider *css_provider)
|
|||||||
priv->resource = NULL;
|
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->symbolic_colors);
|
||||||
g_hash_table_remove_all (priv->keyframes);
|
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 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)
|
#if (GTK_MINOR_VERSION % 2)
|
||||||
#define MINOR (GTK_MINOR_VERSION + 1)
|
#define MINOR (GTK_MINOR_VERSION + 1)
|
||||||
#else
|
#else
|
||||||
@@ -1254,17 +1234,16 @@ _gtk_css_provider_get_theme_dir (GtkCssProvider *provider)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Look for
|
* Look for
|
||||||
* $dir/$subdir/gtk-4.16/gtk-$variant.css
|
* $dir/$subdir/gtk-4.16/gtk.css
|
||||||
* $dir/$subdir/gtk-4.14/gtk-$variant.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.
|
* and return the first found file.
|
||||||
*/
|
*/
|
||||||
static gchar *
|
static gchar *
|
||||||
_gtk_css_find_theme_dir (const gchar *dir,
|
_gtk_css_find_theme_dir (const gchar *dir,
|
||||||
const gchar *subdir,
|
const gchar *subdir,
|
||||||
const gchar *name,
|
const gchar *name)
|
||||||
const gchar *variant)
|
|
||||||
{
|
{
|
||||||
gchar *file;
|
gchar *file;
|
||||||
gchar *base;
|
gchar *base;
|
||||||
@@ -1272,10 +1251,7 @@ _gtk_css_find_theme_dir (const gchar *dir,
|
|||||||
gint i;
|
gint i;
|
||||||
gchar *path;
|
gchar *path;
|
||||||
|
|
||||||
if (variant)
|
file = g_strdup ("gtk.css");
|
||||||
file = g_strconcat ("gtk-", variant, ".css", NULL);
|
|
||||||
else
|
|
||||||
file = g_strdup ("gtk.css");
|
|
||||||
|
|
||||||
if (subdir)
|
if (subdir)
|
||||||
base = g_build_filename (dir, subdir, name, NULL);
|
base = g_build_filename (dir, subdir, name, NULL);
|
||||||
@@ -1304,8 +1280,7 @@ _gtk_css_find_theme_dir (const gchar *dir,
|
|||||||
#undef MINOR
|
#undef MINOR
|
||||||
|
|
||||||
static gchar *
|
static gchar *
|
||||||
_gtk_css_find_theme (const gchar *name,
|
_gtk_css_find_theme (const gchar *name)
|
||||||
const gchar *variant)
|
|
||||||
{
|
{
|
||||||
gchar *path;
|
gchar *path;
|
||||||
const char *const *dirs;
|
const char *const *dirs;
|
||||||
@@ -1313,12 +1288,12 @@ _gtk_css_find_theme (const gchar *name,
|
|||||||
char *dir;
|
char *dir;
|
||||||
|
|
||||||
/* First look in the user's data directory */
|
/* 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)
|
if (path)
|
||||||
return path;
|
return path;
|
||||||
|
|
||||||
/* Next look in the user's home directory */
|
/* 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)
|
if (path)
|
||||||
return path;
|
return path;
|
||||||
|
|
||||||
@@ -1326,62 +1301,42 @@ _gtk_css_find_theme (const gchar *name,
|
|||||||
dirs = g_get_system_data_dirs ();
|
dirs = g_get_system_data_dirs ();
|
||||||
for (i = 0; dirs[i]; i++)
|
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)
|
if (path)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finally, try in the default theme directory */
|
/* Finally, try in the default theme directory */
|
||||||
dir = _gtk_get_theme_dir ();
|
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);
|
g_free (dir);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
static gboolean
|
||||||
* gtk_css_provider_load_named:
|
gtk_css_provider_load_theme (GtkCssProvider *provider,
|
||||||
* @provider: a #GtkCssProvider
|
const gchar *name)
|
||||||
* @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)
|
|
||||||
{
|
{
|
||||||
gchar *path;
|
gchar *path;
|
||||||
gchar *resource_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
|
/* try loading the resource for the theme. This is mostly meant for built-in
|
||||||
* themes.
|
* themes.
|
||||||
*/
|
*/
|
||||||
if (variant)
|
resource_path = g_strconcat ("/org/gtk/libgtk/theme/", name, "/gtk.css", NULL);
|
||||||
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);
|
|
||||||
|
|
||||||
if (g_resources_get_info (resource_path, 0, NULL, NULL, NULL))
|
if (g_resources_get_info (resource_path, 0, NULL, NULL, NULL))
|
||||||
{
|
{
|
||||||
gtk_css_provider_load_from_resource (provider, resource_path);
|
gtk_css_provider_load_from_resource (provider, resource_path);
|
||||||
g_free (resource_path);
|
g_free (resource_path);
|
||||||
return;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (resource_path);
|
g_free (resource_path);
|
||||||
|
|
||||||
/* Next try looking for files in the various theme directories. */
|
/* 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)
|
if (path)
|
||||||
{
|
{
|
||||||
GtkCssProviderPrivate *priv = gtk_css_provider_get_instance_private (provider);
|
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 */
|
/* Only set this after load, as load_from_path will clear it */
|
||||||
priv->resource = resource;
|
priv->resource = resource;
|
||||||
priv->path = dir;
|
|
||||||
|
|
||||||
|
g_free (dir);
|
||||||
g_free (path);
|
g_free (path);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Things failed! Fall back! Fall back! */
|
|
||||||
|
|
||||||
if (variant)
|
return TRUE;
|
||||||
{
|
|
||||||
/* 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 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
|
static int
|
||||||
|
@@ -80,7 +80,7 @@ void gtk_css_provider_load_from_resource (GtkCssProvider *css_provid
|
|||||||
GDK_AVAILABLE_IN_ALL
|
GDK_AVAILABLE_IN_ALL
|
||||||
void gtk_css_provider_load_named (GtkCssProvider *provider,
|
void gtk_css_provider_load_named (GtkCssProvider *provider,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *variant);
|
const char *fallback);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
@@ -24,8 +24,6 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
gchar *_gtk_get_theme_dir (void);
|
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);
|
void gtk_css_provider_set_keep_css_sections (void);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
@@ -2208,29 +2208,27 @@ static void
|
|||||||
settings_update_theme (GtkSettings *settings)
|
settings_update_theme (GtkSettings *settings)
|
||||||
{
|
{
|
||||||
GtkSettingsPrivate *priv = settings->priv;
|
GtkSettingsPrivate *priv = settings->priv;
|
||||||
gchar *theme_name;
|
char *theme_name;
|
||||||
gchar *theme_variant;
|
char *theme_variant;
|
||||||
const gchar *theme_dir;
|
char *theme_fallback;
|
||||||
gchar *path;
|
|
||||||
|
|
||||||
get_theme_name (settings, &theme_name, &theme_variant);
|
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,
|
gtk_css_provider_load_named (priv->theme_provider,
|
||||||
theme_name,
|
theme_name,
|
||||||
theme_variant);
|
theme_fallback);
|
||||||
|
|
||||||
/* 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_free (theme_name);
|
g_free (theme_name);
|
||||||
g_free (theme_variant);
|
g_free (theme_variant);
|
||||||
|
g_free (theme_fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
const cairo_font_options_t *
|
const cairo_font_options_t *
|
||||||
|
Reference in New Issue
Block a user