From 83043e9a33e07c35ed3beb04bfaf1a0173355925 Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Tue, 26 Sep 2023 19:25:39 +0300 Subject: [PATCH 32/32] gtk3(.22): Use single theme provider There really isn't "default provider" concept, but we just drop the provider completely when we want no theming. Reported by l29ah See osdn #45601 Signed-off-by: Marko Lindqvist --- client/gui-gtk-3.0/themes.c | 26 +++++++++++--------------- client/gui-gtk-3.22/themes.c | 26 +++++++++++--------------- 2 files changed, 22 insertions(+), 30 deletions(-) diff --git a/client/gui-gtk-3.0/themes.c b/client/gui-gtk-3.0/themes.c index 0c2516a1cd..e89c06b55c 100644 --- a/client/gui-gtk-3.0/themes.c +++ b/client/gui-gtk-3.0/themes.c @@ -37,20 +37,21 @@ #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; GError *error = 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_screen( gtk_widget_get_screen(toplevel), - GTK_STYLE_PROVIDER(fc_css_provider), + GTK_STYLE_PROVIDER(theme_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } @@ -58,9 +59,9 @@ void gui_load_theme(const char *directory, const char *theme_name) fc_snprintf(buf, sizeof(buf), "%s/%s/gtk-3.0/gtk.css", directory, theme_name); - gtk_css_provider_load_from_file(fc_css_provider, g_file_new_for_path(buf), &error); + gtk_css_provider_load_from_file(theme_provider, g_file_new_for_path(buf), &error); - if (error) { + if (error != NULL) { g_warning("%s\n", error->message); } @@ -86,16 +87,11 @@ 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_screen( + if (!theme_loaded && theme_provider != NULL) { + gtk_style_context_remove_provider_for_screen( gtk_widget_get_screen(toplevel), - GTK_STYLE_PROVIDER(default_provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + GTK_STYLE_PROVIDER(theme_provider)); + theme_provider = NULL; } } diff --git a/client/gui-gtk-3.22/themes.c b/client/gui-gtk-3.22/themes.c index 98b673637c..3b79fde9ea 100644 --- a/client/gui-gtk-3.22/themes.c +++ b/client/gui-gtk-3.22/themes.c @@ -37,20 +37,21 @@ #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; GError *error = 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_screen( gtk_widget_get_screen(toplevel), - GTK_STYLE_PROVIDER(fc_css_provider), + GTK_STYLE_PROVIDER(theme_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } @@ -58,9 +59,9 @@ void gui_load_theme(const char *directory, const char *theme_name) fc_snprintf(buf, sizeof(buf), "%s/%s/gtk-3.0/gtk.css", directory, theme_name); - gtk_css_provider_load_from_file(fc_css_provider, g_file_new_for_path(buf), &error); + gtk_css_provider_load_from_file(theme_provider, g_file_new_for_path(buf), &error); - if (error) { + if (error != NULL) { g_warning("%s\n", error->message); } } @@ -84,16 +85,11 @@ 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_screen( + if (!theme_loaded && theme_provider != NULL) { + gtk_style_context_remove_provider_for_screen( gtk_widget_get_screen(toplevel), - GTK_STYLE_PROVIDER(default_provider), - GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + GTK_STYLE_PROVIDER(theme_provider)); + theme_provider = NULL; } } -- 2.40.1