cssprovider: Export correct API

gtk_css_provider_get_named() is the old GTK3 style API to load themes.

Instead, export the function we currently use,
gtk_css_provider_load_named().

As a side effect we allow people to load a theme as often as they want
without conflicting with GTK's theme.
This commit is contained in:
Benjamin Otte 2019-04-18 02:05:58 +02:00
parent 0c87b62251
commit 1aa1610611
5 changed files with 14 additions and 56 deletions

View File

@ -5076,7 +5076,7 @@ gtk_border_get_type
<FILE>gtkcssprovider</FILE>
<TITLE>GtkCssProvider</TITLE>
GtkCssProvider
gtk_css_provider_get_named
gtk_css_provider_load_named
gtk_css_provider_load_from_data
gtk_css_provider_load_from_file
gtk_css_provider_load_from_path

View File

@ -1342,7 +1342,7 @@ _gtk_css_find_theme (const gchar *name,
}
/**
* _gtk_css_provider_load_named:
* gtk_css_provider_load_named:
* @provider: a #GtkCssProvider
* @name: A theme name
* @variant: (allow-none): variant to load, for example, "dark", or
@ -1351,12 +1351,12 @@ _gtk_css_find_theme (const gchar *name,
* 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 than GTK uses for loading its own theme.
* theme that GTK uses for loading its own theme.
**/
void
_gtk_css_provider_load_named (GtkCssProvider *provider,
const gchar *name,
const gchar *variant)
gtk_css_provider_load_named (GtkCssProvider *provider,
const gchar *name,
const gchar *variant)
{
gchar *path;
gchar *resource_path;
@ -1413,57 +1413,17 @@ _gtk_css_provider_load_named (GtkCssProvider *provider,
if (variant)
{
/* If there was a variant, try without */
_gtk_css_provider_load_named (provider, name, NULL);
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);
gtk_css_provider_load_named (provider, DEFAULT_THEME_NAME, NULL);
}
}
}
/**
* gtk_css_provider_get_named:
* @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
*
* Returns: (transfer none): a #GtkCssProvider with the theme loaded.
* This memory is owned by GTK+, and you must not free it.
*/
GtkCssProvider *
gtk_css_provider_get_named (const gchar *name,
const gchar *variant)
{
static GHashTable *themes = NULL;
GtkCssProvider *provider;
gchar *key;
if (variant == NULL)
key = g_strdup (name);
else
key = g_strconcat (name, "-", variant, NULL);
if (G_UNLIKELY (!themes))
themes = g_hash_table_new (g_str_hash, g_str_equal);
provider = g_hash_table_lookup (themes, key);
if (!provider)
{
provider = gtk_css_provider_new ();
_gtk_css_provider_load_named (provider, name, variant);
g_hash_table_insert (themes, g_strdup (key), provider);
}
g_free (key);
return provider;
}
static int
compare_properties (gconstpointer a, gconstpointer b, gpointer style)
{

View File

@ -78,8 +78,9 @@ void gtk_css_provider_load_from_resource (GtkCssProvider *css_provid
const gchar *resource_path);
GDK_AVAILABLE_IN_ALL
GtkCssProvider * gtk_css_provider_get_named (const gchar *name,
const gchar *variant);
void gtk_css_provider_load_named (GtkCssProvider *self,
const char *name,
const char *variant);
G_END_DECLS

View File

@ -26,10 +26,6 @@ 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,
const gchar *variant);
void gtk_css_provider_set_keep_css_sections (void);
G_END_DECLS

View File

@ -2215,8 +2215,9 @@ settings_update_theme (GtkSettings *settings)
get_theme_name (settings, &theme_name, &theme_variant);
_gtk_css_provider_load_named (priv->theme_provider,
theme_name, theme_variant);
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);