shithub: puzzles

Download patch

ref: 6dac51795e5672f32bba787c0f011cb01e464a96
parent: 09c15f206edac18bd2158c189c821b9ba85d3939
author: Ben Harris <bjh21@bjh21.me.uk>
date: Wed Mar 22 12:58:22 EDT 2023

Add an environment variable to control initial cursor visibility

If you define PUZZLES_INITIAL_CURSOR=y, puzzles that have a keyboard
cursor will default to making it visible rather than invisible at the
start of a new game.  Behaviour is otherwise the same, so mouse actions
will cause the cursor to vanish and keyboard actions will cause it to
appear.  It's just the default that has changed.

The purpose of this is for use on devices and platforms where the
primary or only means of interaction is keyboard-based.  In those cases,
starting with the keyboard cursor invisible is weird and a bit
confusing.

--- a/blackbox.c
+++ b/blackbox.c
@@ -485,7 +485,7 @@
     ui->newmove = false;
 
     ui->cur_x = ui->cur_y = 1;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
 
     ui->flash_laser = 0;
 
--- a/bridges.c
+++ b/bridges.c
@@ -2127,7 +2127,7 @@
     ui_cancel_drag(ui);
     ui->cur_x = state->islands[0].x;
     ui->cur_y = state->islands[0].y;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->show_hints = false;
     return ui;
 }
--- a/dominosa.c
+++ b/dominosa.c
@@ -2713,7 +2713,7 @@
 {
     game_ui *ui = snew(game_ui);
     ui->cur_x = ui->cur_y = 0;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->highlight_1 = ui->highlight_2 = -1;
     return ui;
 }
--- a/filling.c
+++ b/filling.c
@@ -1396,7 +1396,7 @@
 
     ui->sel = NULL;
     ui->cur_x = ui->cur_y = 0;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->keydragging = false;
 
     return ui;
--- a/flip.c
+++ b/flip.c
@@ -913,7 +913,7 @@
 {
     game_ui *ui = snew(game_ui);
     ui->cx = ui->cy = 0;
-    ui->cdraw = false;
+    ui->cdraw = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     return ui;
 }
 
--- a/flood.c
+++ b/flood.c
@@ -775,7 +775,7 @@
 static game_ui *new_ui(const game_state *state)
 {
     struct game_ui *ui = snew(struct game_ui);
-    ui->cursor_visible = false;
+    ui->cursor_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->cx = FILLX;
     ui->cy = FILLY;
     return ui;
--- a/galaxies.c
+++ b/galaxies.c
@@ -2688,7 +2688,7 @@
     game_ui *ui = snew(game_ui);
     ui->dragging = false;
     ui->cur_x = ui->cur_y = 1;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     return ui;
 }
 
--- a/guess.c
+++ b/guess.c
@@ -410,6 +410,7 @@
     ui->params = state->params;        /* structure copy */
     ui->curr_pegs = new_pegrow(state->params.npegs);
     ui->holds = snewn(state->params.npegs, bool);
+    ui->display_cur = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     memset(ui->holds, 0, sizeof(bool)*state->params.npegs);
     ui->drag_opeg = -1;
     return ui;
--- a/keen.c
+++ b/keen.c
@@ -1530,8 +1530,7 @@
 
     ui->hx = ui->hy = 0;
     ui->hpencil = false;
-    ui->hshow = false;
-    ui->hcursor = false;
+    ui->hshow = ui->hcursor = getenv_bool("PUZZLES_SHOW_CURSOR", false);
 
     return ui;
 }
--- a/lightup.c
+++ b/lightup.c
@@ -1835,7 +1835,7 @@
 {
     game_ui *ui = snew(game_ui);
     ui->cur_x = ui->cur_y = 0;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     return ui;
 }
 
--- a/magnets.c
+++ b/magnets.c
@@ -1730,7 +1730,7 @@
 {
     game_ui *ui = snew(game_ui);
     ui->cur_x = ui->cur_y = 0;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     return ui;
 }
 
--- a/map.c
+++ b/map.c
@@ -2287,7 +2287,7 @@
     ui->drag_pencil = 0;
     ui->show_numbers = false;
     ui->cur_x = ui->cur_y = 0;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->cur_moved = false;
     ui->cur_lastmove = 0;
     return ui;
--- a/mines.c
+++ b/mines.c
@@ -2387,7 +2387,7 @@
     ui->completed = false;
     ui->flash_is_death = false;	       /* *shrug* */
     ui->cur_x = ui->cur_y = 0;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     return ui;
 }
 
--- a/mosaic.c
+++ b/mosaic.c
@@ -1009,7 +1009,7 @@
     ui->last_state = 0;
     ui->solved = false;
     ui->cur_x = ui->cur_y = 0;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     return ui;
 }
 
--- a/net.c
+++ b/net.c
@@ -2010,7 +2010,7 @@
     ui->org_x = ui->org_y = 0;
     ui->cur_x = ui->cx = state->width / 2;
     ui->cur_y = ui->cy = state->height / 2;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     get_random_seed(&seed, &seedsize);
     ui->rs = random_new(seed, seedsize);
     sfree(seed);
--- a/netslide.c
+++ b/netslide.c
@@ -969,7 +969,7 @@
     game_ui *ui = snew(game_ui);
     ui->cur_x = 0;
     ui->cur_y = -1;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
 
     return ui;
 }
--- a/palisade.c
+++ b/palisade.c
@@ -878,7 +878,7 @@
 {
     game_ui *ui = snew(game_ui);
     ui->x = ui->y = 0;
-    ui->show = false;
+    ui->show = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     return ui;
 }
 
--- a/pattern.c
+++ b/pattern.c
@@ -1236,7 +1236,7 @@
     ret = snew(game_ui);
     ret->dragging = false;
     ret->cur_x = ret->cur_y = 0;
-    ret->cur_visible = false;
+    ret->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
 
     return ret;
 }
--- a/pearl.c
+++ b/pearl.c
@@ -1862,7 +1862,7 @@
 
     ui->ndragcoords = -1;
     ui->dragcoords = snewn(sz, int);
-    ui->cursor_active = false;
+    ui->cursor_active = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->curx = ui->cury = 0;
 
     return ui;
--- a/pegs.c
+++ b/pegs.c
@@ -785,7 +785,7 @@
 
     ui->sx = ui->sy = ui->dx = ui->dy = 0;
     ui->dragging = false;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->cur_jumping = false;
 
     /* make sure we start the cursor somewhere on the grid. */
--- a/range.c
+++ b/range.c
@@ -1227,7 +1227,7 @@
 {
     struct game_ui *ui = snew(game_ui);
     ui->r = ui->c = 0;
-    ui->cursor_show = false;
+    ui->cursor_show = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     return ui;
 }
 
--- a/rect.c
+++ b/rect.c
@@ -2206,7 +2206,7 @@
     reset_ui(ui);
     ui->erasing = false;
     ui->cur_x = ui->cur_y = 0;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->cur_dragging = false;
     return ui;
 }
--- a/samegame.c
+++ b/samegame.c
@@ -1062,7 +1062,7 @@
     ui->nselected = 0;
 
     ui->xsel = ui->ysel = 0;
-    ui->displaysel = false;
+    ui->displaysel = getenv_bool("PUZZLES_SHOW_CURSOR", false);
 
     return ui;
 }
--- a/signpost.c
+++ b/signpost.c
@@ -1393,7 +1393,7 @@
      * copy to clone, there's code that needs fixing in game_redraw too. */
 
     ui->cx = ui->cy = 0;
-    ui->cshow = false;
+    ui->cshow = getenv_bool("PUZZLES_SHOW_CURSOR", false);
 
     ui->dragging = false;
     ui->sx = ui->sy = ui->dx = ui->dy = 0;
--- a/singles.c
+++ b/singles.c
@@ -1446,7 +1446,7 @@
     game_ui *ui = snew(game_ui);
 
     ui->cx = ui->cy = 0;
-    ui->cshow = false;
+    ui->cshow = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->show_black_nums = false;
 
     return ui;
--- a/sixteen.c
+++ b/sixteen.c
@@ -569,7 +569,7 @@
     game_ui *ui = snew(game_ui);
     ui->cur_x = 0;
     ui->cur_y = 0;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->cur_mode = unlocked;
 
     return ui;
--- a/slant.c
+++ b/slant.c
@@ -1582,7 +1582,7 @@
 {
     game_ui *ui = snew(game_ui);
     ui->cur_x = ui->cur_y = 0;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     return ui;
 }
 
--- a/solo.c
+++ b/solo.c
@@ -4559,8 +4559,7 @@
 
     ui->hx = ui->hy = 0;
     ui->hpencil = false;
-    ui->hshow = false;
-    ui->hcursor = false;
+    ui->hshow = ui->hcursor = getenv_bool("PUZZLES_SHOW_CURSOR", false);
 
     return ui;
 }
--- a/tents.c
+++ b/tents.c
@@ -1455,7 +1455,7 @@
     ui->drag_button = -1;
     ui->drag_ok = false;
     ui->cx = ui->cy = 0;
-    ui->cdisp = false;
+    ui->cdisp = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     return ui;
 }
 
--- a/towers.c
+++ b/towers.c
@@ -1163,8 +1163,7 @@
 
     ui->hx = ui->hy = 0;
     ui->hpencil = false;
-    ui->hshow = false;
-    ui->hcursor = false;
+    ui->hshow = ui->hcursor = getenv_bool("PUZZLES_SHOW_CURSOR", false);
 
     return ui;
 }
--- a/tracks.c
+++ b/tracks.c
@@ -2018,7 +2018,7 @@
     ui->notrack = false;
     ui->dragging = false;
     ui->drag_sx = ui->drag_sy = ui->drag_ex = ui->drag_ey = -1;
-    ui->cursor_active = false;
+    ui->cursor_active = getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->curx = ui->cury = 1;
 
     return ui;
--- a/twiddle.c
+++ b/twiddle.c
@@ -618,7 +618,7 @@
 
     ui->cur_x = 0;
     ui->cur_y = 0;
-    ui->cur_visible = false;
+    ui->cur_visible = getenv_bool("PUZZLES_SHOW_CURSOR", false);
 
     return ui;
 }
--- a/undead.c
+++ b/undead.c
@@ -1645,10 +1645,9 @@
 static game_ui *new_ui(const game_state *state)
 {
     game_ui *ui = snew(game_ui);
-    ui->hx = ui->hy = 0;
     ui->hpencil = false;
-    ui->hshow = false;
-    ui->hcursor = false;
+    ui->hx = ui->hy = ui->hshow = ui->hcursor =
+        getenv_bool("PUZZLES_SHOW_CURSOR", false);
     ui->ascii = false;
     return ui;
 }
--- a/unequal.c
+++ b/unequal.c
@@ -1440,8 +1440,7 @@
 
     ui->hx = ui->hy = 0;
     ui->hpencil = false;
-    ui->hshow = false;
-    ui->hcursor = false;
+    ui->hshow = ui->hcursor = getenv_bool("PUZZLES_SHOW_CURSOR", false);
 
     return ui;
 }
--- a/unruly.c
+++ b/unruly.c
@@ -1513,7 +1513,7 @@
     game_ui *ret = snew(game_ui);
 
     ret->cx = ret->cy = 0;
-    ret->cursor = false;
+    ret->cursor = getenv_bool("PUZZLES_SHOW_CURSOR", false);
 
     return ret;
 }