aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Hutchings <benh@debian.org>2022-02-13 22:23:31 +0100
committerSimon Tatham <anakin@pobox.com>2022-07-31 08:53:08 +0100
commit3d0c734e433972d6a9421ebd58763ca5bf1f1355 (patch)
tree75033cdb4b46f60b25530cda9661e855aa9d1760
parent4c1e47b272274972556d7790384998e593d0ae57 (diff)
downloadpuzzles-3d0c734e433972d6a9421ebd58763ca5bf1f1355.zip
puzzles-3d0c734e433972d6a9421ebd58763ca5bf1f1355.tar.gz
puzzles-3d0c734e433972d6a9421ebd58763ca5bf1f1355.tar.bz2
puzzles-3d0c734e433972d6a9421ebd58763ca5bf1f1355.tar.xz
gtk: Do not override window background colour when using a dark theme
When the user chooses a global dark theme, the window background will be dark and the default text colour light. Overriding the window background to be light grey can make the menu and status bars unreadable. In case a dark theme is used, only set the background colour for the content area. References: https://bugs.debian.org/944237
-rw-r--r--gtk.c36
1 files changed, 30 insertions, 6 deletions
diff --git a/gtk.c b/gtk.c
index c3ab732..a935a56 100644
--- a/gtk.c
+++ b/gtk.c
@@ -2,6 +2,10 @@
* gtk.c: GTK front end for my puzzle collection.
*/
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE 1 /* for strcasestr */
+#endif
+
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
@@ -389,6 +393,21 @@ static void print_set_colour(frontend *fe, int colour)
static void set_window_background(frontend *fe, int colour)
{
+#if GTK_CHECK_VERSION(3,0,0)
+ /* In case the user's chosen theme is dark, we should not override
+ * the background colour for the whole window as this makes the
+ * menu and status bars unreadable. This might be visible through
+ * the gtk-application-prefer-dark-theme flag or else we have to
+ * work it out from the name. */
+ gboolean dark_theme = FALSE;
+ char *theme_name = NULL;
+ g_object_get(gtk_settings_get_default(),
+ "gtk-application-prefer-dark-theme", &dark_theme,
+ "gtk-theme-name", &theme_name,
+ NULL);
+ if (theme_name && strcasestr(theme_name, "-dark"))
+ dark_theme = TRUE;
+ g_free(theme_name);
#if GTK_CHECK_VERSION(3,20,0)
char css_buf[512];
sprintf(css_buf, ".background { "
@@ -401,22 +420,27 @@ static void set_window_background(frontend *fe, int colour)
if (!gtk_css_provider_load_from_data(
GTK_CSS_PROVIDER(fe->css_provider), css_buf, -1, NULL))
assert(0 && "Couldn't load CSS");
- gtk_style_context_add_provider(
- gtk_widget_get_style_context(fe->window),
- GTK_STYLE_PROVIDER(fe->css_provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ if (!dark_theme) {
+ gtk_style_context_add_provider(
+ gtk_widget_get_style_context(fe->window),
+ GTK_STYLE_PROVIDER(fe->css_provider),
+ GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+ }
gtk_style_context_add_provider(
gtk_widget_get_style_context(fe->area),
GTK_STYLE_PROVIDER(fe->css_provider),
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-#elif GTK_CHECK_VERSION(3,0,0)
+#else
GdkRGBA rgba;
rgba.red = fe->colours[3*colour + 0];
rgba.green = fe->colours[3*colour + 1];
rgba.blue = fe->colours[3*colour + 2];
rgba.alpha = 1.0;
gdk_window_set_background_rgba(gtk_widget_get_window(fe->area), &rgba);
- gdk_window_set_background_rgba(gtk_widget_get_window(fe->window), &rgba);
+ if (!dark_theme)
+ gdk_window_set_background_rgba(gtk_widget_get_window(fe->window),
+ &rgba);
+#endif
#else
GdkColormap *colmap;