From 8f3d928d573ea2dc9a8f3aae42935befd1d09196 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist <cazfi74@gmail.com> Date: Sat, 23 Sep 2023 12:07:00 +0300 Subject: [PATCH 32/32] gtk4: Use single theme provider There really isn't "default provider" concept, but we just drop the provider completely when we want no theming. See osdn #48679 Signed-off-by: Marko Lindqvist <cazfi74@gmail.com> --- client/gui-gtk-4.0/themes.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/client/gui-gtk-4.0/themes.c b/client/gui-gtk-4.0/themes.c index 3b0b3c98e0..e63cf8d740 100644 --- a/client/gui-gtk-4.0/themes.c +++ b/client/gui-gtk-4.0/themes.c @@ -37,19 +37,20 @@ #include "themes_g.h" +static GtkCssProvider *theme_provider = NULL; + /*************************************************************************//** Loads a gtk theme directory/theme_name *****************************************************************************/ void gui_load_theme(const char *directory, const char *theme_name) { - static GtkCssProvider *fc_css_provider = NULL; char buf[strlen(directory) + strlen(theme_name) + 32]; - if (fc_css_provider == NULL) { - fc_css_provider = gtk_css_provider_new(); + if (theme_provider == NULL) { + theme_provider = gtk_css_provider_new(); gtk_style_context_add_provider_for_display( gtk_widget_get_display(toplevel), - GTK_STYLE_PROVIDER(fc_css_provider), + GTK_STYLE_PROVIDER(theme_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } @@ -57,7 +58,7 @@ void gui_load_theme(const char *directory, const char *theme_name) fc_snprintf(buf, sizeof(buf), "%s/%s/gtk-4.0/gtk.css", directory, theme_name); - gtk_css_provider_load_from_file(fc_css_provider, g_file_new_for_path(buf)); + gtk_css_provider_load_from_file(theme_provider, g_file_new_for_path(buf)); } /*************************************************************************//** @@ -78,17 +79,12 @@ void gui_clear_theme(void) } } - /* Still no theme loaded -> load system default theme */ - if (!theme_loaded) { - static GtkCssProvider *default_provider = NULL; - - if (default_provider == NULL) { - default_provider = gtk_css_provider_new(); - } - gtk_style_context_add_provider_for_display( + /* Still no theme loaded -> drop theme provider */ + if (!theme_loaded && theme_provider != NULL) { + gtk_style_context_remove_provider_for_display( gtk_widget_get_display(toplevel), - GTK_STYLE_PROVIDER(default_provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + GTK_STYLE_PROVIDER(theme_provider)); + theme_provider = NULL; } } -- 2.40.1