[gimp] app, libgimp: communicate dark-theme preference to plug-ins through theme.css
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] app, libgimp: communicate dark-theme preference to plug-ins through theme.css
- Date: Wed, 20 Feb 2019 19:40:36 +0000 (UTC)
commit 8c96c3d1bbb29fd181328dd6ca6afc3ade1b2257
Author: Ell <ell_se yahoo com>
Date: Wed Feb 20 14:27:59 2019 -0500
app, libgimp: communicate dark-theme preference to plug-ins through theme.css
The GUI implementation of gimp_wait() relies on the ability to run
plug-ins (namely, the busy-dialog plug-in) without entering the
main loop. This prohibits the said plug-ins from making any PDB
calls, which would result in a deadlock. However, we're currently
calling gimp_gimprc_query() to fetch the prefer-dark-theme option
during gimp_ui_init() (or any time the theme.css file changes).
Instead, communicate this preference through the theme.css file
itself, by writing a /* prefer-dark-theme */ comment to the file
when the option is set. Yes, it's a bit of a hack :P
app/gui/themes.c | 4 +++-
libgimp/gimpui.c | 28 ++++++++++++++++++++--------
2 files changed, 23 insertions(+), 9 deletions(-)
---
diff --git a/app/gui/themes.c b/app/gui/themes.c
index c79a4e275d..f022c7ac3d 100644
--- a/app/gui/themes.c
+++ b/app/gui/themes.c
@@ -285,11 +285,13 @@ themes_apply_theme (Gimp *gimp,
"\n"
"* { -gtk-icon-style: %s; }\n"
"\n"
+ "%s"
"/* end of theme.css */\n",
gimp_file_get_utf8_name (css_user),
esc_css_theme,
esc_css_user,
- config->prefer_symbolic_icons ? "symbolic" : "regular"))
+ config->prefer_symbolic_icons ? "symbolic" : "regular",
+ config->prefer_dark_theme ? "/* prefer-dark-theme */\n\n" : ""))
{
GCancellable *cancellable = g_cancellable_new ();
diff --git a/libgimp/gimpui.c b/libgimp/gimpui.c
index 2083dddd47..018cecc84a 100644
--- a/libgimp/gimpui.c
+++ b/libgimp/gimpui.c
@@ -349,17 +349,29 @@ gimp_ui_theme_changed (GFileMonitor *monitor,
GFileMonitorEvent event_type,
GtkCssProvider *css_provider)
{
- gchar *dark = gimp_gimprc_query ("prefer-dark-theme");
- gboolean setting = dark && ! strcmp (dark, "yes");
- GError *error = NULL;
+ GError *error = NULL;
+ gchar *contents;
- g_object_set (gtk_settings_get_for_screen (gdk_screen_get_default ()),
- "gtk-application-prefer-dark-theme", setting,
- NULL);
+ file = gimp_directory_file ("theme.css", NULL);
- g_free (dark);
+ if (g_file_load_contents (file, NULL, &contents, NULL, NULL, &error))
+ {
+ gboolean prefer_dark_theme;
- file = gimp_directory_file ("theme.css", NULL);
+ prefer_dark_theme = strstr (contents, "/* prefer-dark-theme */") != NULL;
+
+ g_object_set (gtk_settings_get_for_screen (gdk_screen_get_default ()),
+ "gtk-application-prefer-dark-theme", prefer_dark_theme,
+ NULL);
+
+ g_free (contents);
+ }
+ else
+ {
+ g_printerr ("%s: error loading %s: %s\n", G_STRFUNC,
+ gimp_file_get_utf8_name (file), error->message);
+ g_clear_error (&error);
+ }
if (! gtk_css_provider_load_from_file (css_provider, file, &error))
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]