From b33b83429f043c79f3562a22a192ab34d2d3fcca Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 18 Oct 2015 14:22:27 +0100 Subject: [PATCH] Fix GTK puzzle resizing, *again*. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Jonas Kölker points out that commit a800ff16b (which fixed a bug in the previous attempt) left in another bug: if the puzzle size was changed while the window was maximised, the system would fail to recompute the tile size and would redraw completely wrongly. So it's not optional after all to run midend_size(), even if the drawing area size hasn't changed. I've reverted that code to be unconditional, and now only the refresh of the Cairo-side backing store system is conditionalised - and that's conditionalised on changes to either the size of the actual window _or_ the size of the contained pixmap. (The latter should defend against redraw failure in the case where the puzzle aspect ratio changes, so that neither the window size nor the tile size changes but a recentre is still needed.) I _think_ this now fixes all the cases of resizing: this time I've tested making an unmaximised puzzle window bigger or smaller, and within a maximised window, forcing the puzzle to scale up, scale down, or change its aspect ratio without changing its tile size. All work, on GTK2 and GTK3, and yet we still don't get the visible flicker on status line updates that was the reason I started fiddling with this code in the first place. (We _do_ still call configure_area on every update of the status line, at least under GTK3; that's going to cause a forced full redraw on every timer tick in Mines, which is wasteful of CPU, so it would still be nice to find a better way of identifying the cases in which no resizing at all was necessary and we could avoid renewing the game drawstate. But the current code at least doesn't have any display _errors_ that I know of, which is an improvement on its previous state.) --- gtk.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/gtk.c b/gtk.c index 37eb509..a8416b0 100644 --- a/gtk.c +++ b/gtk.c @@ -1310,22 +1310,22 @@ static gint configure_area(GtkWidget *widget, { frontend *fe = (frontend *)data; int x, y; + int oldw = fe->w, oldpw = fe->pw, oldh = fe->h, oldph = fe->ph; x = event->width; y = event->height; - - if (x != fe->w || y != fe->h || !backing_store_ok(fe)) { + fe->w = x; + fe->h = y; + midend_size(fe->me, &x, &y, TRUE); + fe->pw = x; + fe->ph = y; + fe->ox = (fe->w - fe->pw) / 2; + fe->oy = (fe->h - fe->ph) / 2; + + if (oldw != fe->w || oldpw != fe->pw || + oldh != fe->h || oldph != fe->ph || !backing_store_ok(fe)) { if (backing_store_ok(fe)) teardown_backing_store(fe); - - fe->w = x; - fe->h = y; - midend_size(fe->me, &x, &y, TRUE); - fe->pw = x; - fe->ph = y; - fe->ox = (fe->w - fe->pw) / 2; - fe->oy = (fe->h - fe->ph) / 2; - setup_backing_store(fe); } -- 2.30.2