shithub: puzzles

Download patch

ref: 462a5450c6bd7d96a6051b37ceef1fd63426ddf8
parent: 3c6493e7b363400479fc163970acd930b0f5db59
author: Ben Harris <bjh21@bjh21.me.uk>
date: Sun Aug 13 21:49:24 EDT 2023

Flood: correctly handle clicks that only hide cursor

If you clicked somewhere that had no effect (outside the grid or on a
square matching the colour of the top-left corner), interpret_move()
would return MOVE_NO_EFFECT (previously NULL) even though it had unset
ui->cursor.  So the keyboard cursor would remain visible until the
next window resize (or similar) when it would vanish.  Now
interpret_move() correctly returns MOVE_UI_UPDATE in these cases, so
the cursor vanishes immediately.

--- a/flood.c
+++ b/flood.c
@@ -830,11 +830,15 @@
 {
     int w = state->w, h = state->h;
     int tx = -1, ty = -1, move = -1;
+    char *nullret = MOVE_NO_EFFECT;
 
     if (button == LEFT_BUTTON) {
 	tx = FROMCOORD(x);
         ty = FROMCOORD(y);
-        ui->cursor_visible = false;
+        if (ui->cursor_visible) {
+            ui->cursor_visible = false;
+            nullret = MOVE_UI_UPDATE;
+        }
     } else if (IS_CURSOR_MOVE(button)) {
         return move_cursor(button, &ui->cx, &ui->cy, w, h, false,
                            &ui->cursor_visible);
@@ -858,7 +862,7 @@
         return dupstr(buf);
     }
 
-    return MOVE_NO_EFFECT;
+    return nullret;
 }
 
 static game_state *execute_move(const game_state *state, const char *move)