ref: f3ca0e5af8b0ccb7400accc946e0a32e290b0206
parent: 7cae89fb4b22c305b3fd98b4e1be065ad527a9f7
author: Simon Tatham <anakin@pobox.com>
date: Mon Feb 27 14:11:02 EST 2017
GTK API deprecation: use GtkCssProvider for window background. gdk_window_set_background_rgba is deprecated as of GTK 3.22, because apparently you can't just _say_ any more 'here is what I want my window's background colour to be in places where a widget isn't'. Instead you have to provide a GtkStyleProvider which can be slotted into a wobbly tower of other providers with associated priorities, so that the user can override your choices if they really want to. And the easiest way to constructc a GtkStyleProvider in turn is to write *actual CSS* and get GTK to parse it, so I end up converting my nice numeric RGB values into a complicated text format for another part of _the same process_ to parse back into numbers. Sigh.
--- a/gtk.c
+++ b/gtk.c
@@ -144,6 +144,9 @@
GtkWidget *area;
GtkWidget *statusbar;
GtkWidget *menubar;
+#if GTK_CHECK_VERSION(3,20,0)
+ GtkCssProvider *css_provider;
+#endif
guint statusctx;
int w, h;
midend *me;
@@ -290,7 +293,27 @@
static void set_window_background(frontend *fe, int colour)
{
-#if GTK_CHECK_VERSION(3,0,0)
+#if GTK_CHECK_VERSION(3,20,0)
+ char css_buf[512];
+ sprintf(css_buf, ".background { "
+ "background-color: #%02x%02x%02x; }",
+ (unsigned)(fe->colours[3*colour + 0] * 255),
+ (unsigned)(fe->colours[3*colour + 1] * 255),
+ (unsigned)(fe->colours[3*colour + 2] * 255));
+ if (!fe->css_provider)
+ fe->css_provider = gtk_css_provider_new();
+ 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);
+ 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)
GdkRGBA rgba;
rgba.red = fe->colours[3*colour + 0];
rgba.green = fe->colours[3*colour + 1];
@@ -2355,6 +2378,9 @@
extern const int n_xpm_icons;
fe = snew(frontend);
+#if GTK_CHECK_VERSION(3,20,0)
+ fe->css_provider = NULL;
+#endif
fe->timer_active = FALSE;
fe->timer_id = -1;