shithub: puzzles

Download patch

ref: 229d062d6ce63f0a5e00d2de62ee0fb389ccfdb6
parent: cb6cead7a905eeb00b861f45e6f2c3f0cc60105d
author: Simon Tatham <anakin@pobox.com>
date: Sat Jan 8 09:43:01 EST 2022

Windows: reinstate SetWindowPos in check_window_size.

The purpose of check_window_size is to be run after we try to resize
the puzzle window, decide whether the window size needs a further
update, and if so, make it. But the SetWindowPos call that actually
made the update (triggered by the subroutine check_window_resize
returning true to indicate that a change was needed) had mysteriously
gone missing.

An example case where this goes wrong: start up a puzzle at a game
size large enough to need a tile size smaller than default. Then
change the setting to one so small that the menu bar is now the
limiting factor on how small the window can be. (For example, changing
Mosaic from its 50x50 preset to 3x3, if your monitor isn't so huge
that the former fits.) The window comes out the wrong size, and with
this SetWindowPos reinstated, now it gets corrected.

What seems to have happened was that the SetWindowPos was originally
under #ifndef _WIN32_WCE, i.e. we only want to do it on desktop
Windows, not on CE. Then commit 39d299f579da3e9 (introducing manual
window resizing in the Windows front end) moved the call into a
different function, and in the process, accidentally reversed the
sense of the #ifdef. And then commit ff3e762fd007883 (removing the
bit-rotted Windows CE support completely) removed it, along with
everything else under #ifndef _WIN32_WCE!

It was originally supposed to be _enabled_ on desktop Windows, not
disabled. So I've put it back now.

--- a/windows.c
+++ b/windows.c
@@ -1323,7 +1323,8 @@
     cx = r.right - r.left;
     cy = r.bottom - r.top;
 
-    check_window_resize(fe, cx, cy, px, py, &wx, &wy);
+    if (check_window_resize(fe, cx, cy, px, py, &wx, &wy))
+        SetWindowPos(fe->hwnd, NULL, 0, 0, wx, wy, SWP_NOMOVE | SWP_NOZORDER);
 
     GetClientRect(fe->hwnd, &r);
     adjust_statusbar(fe, &r);