From c60b2832f41fa2abbb576291efdb57dfa8819152 Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Wed, 30 Apr 2025 23:27:43 +0100 Subject: [PATCH] GTK: flush target Cairo surface in 'draw' handler In 687efc3a5da1fb85c86a3c871b00a7234b97c2e9, Simon noted that when PuTTY was running under X and using an RGB24 image surface as its backing surface, it would fail to draw on its window. Changing the backing image to ARGB32 caused the problem to go away. If you set GDK_BACKEND=x11 and GDK_RENDERING=image, then PuTTY's gdk_window_create_similar_surface() returns an RGB24 image surface, and it appears to have precisely the same problem. Dumping the surfaces to PNG files revealed that Cairo thought they had the right context. But xtruss didn't show any actual requests to write to the window. So on a hunch approximately as well-informed as Simon's, I added a call to cairo_flush(), to explicitly ask Cairo to flush its changes to the underlying surface. I would have hoped that GTK would do something like this for us, but adding that call seems to have made things work properly. Like Simon, I have no idea if this is the correct fix, but it seems like a reasonable one and the problem is no longer occurring for me. --- unix/window.c | 1 + 1 file changed, 1 insertion(+) diff --git a/unix/window.c b/unix/window.c index b3baf4af..a37b55de 100644 --- a/unix/window.c +++ b/unix/window.c @@ -953,6 +953,7 @@ static gint draw_area(GtkWidget *widget, cairo_t *cr, gpointer data) if (inst->surface) { cairo_set_source_surface(cr, inst->surface, 0, 0); cairo_paint(cr); + cairo_surface_flush(cairo_get_target(cr)); } return true;