aboutsummaryrefslogtreecommitdiff
path: root/midend.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-11-05 16:05:39 +0000
committerBen Harris <bjh21@bjh21.me.uk>2022-11-08 10:27:19 +0000
commit4a37f7cf782592b670d0180a38eb1fd680288421 (patch)
tree5ddcad0f237d79bd8de158c1cb840f7ad5301958 /midend.c
parent4fdcc5497503658324fda2e0073d830276b24b60 (diff)
downloadpuzzles-4a37f7cf782592b670d0180a38eb1fd680288421.zip
puzzles-4a37f7cf782592b670d0180a38eb1fd680288421.tar.gz
puzzles-4a37f7cf782592b670d0180a38eb1fd680288421.tar.bz2
puzzles-4a37f7cf782592b670d0180a38eb1fd680288421.tar.xz
Add a way for midend_process_key() to report whether it handled a keypress
This adds a new bool * argument, which can be NULL if front ends don't care whether the keypress was handled. Currently they all do that. Currently, "undo" and "redo" keys are treated as not handled if there's no move to undo or redo. This may be a little too strict.
Diffstat (limited to 'midend.c')
-rw-r--r--midend.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/midend.c b/midend.c
index a8f9cf3..8e63eb7 100644
--- a/midend.c
+++ b/midend.c
@@ -935,7 +935,8 @@ void midend_restart_game(midend *me)
midend_set_timer(me);
}
-static bool midend_really_process_key(midend *me, int x, int y, int button)
+static bool midend_really_process_key(midend *me, int x, int y, int button,
+ bool *handled)
{
game_state *oldstate =
me->ourgame->dup_game(me->states[me->statepos - 1].state);
@@ -956,6 +957,7 @@ static bool midend_really_process_key(midend *me, int x, int y, int button)
button == UI_NEWGAME) {
midend_new_game(me);
midend_redraw(me);
+ *handled = true;
goto done; /* never animate */
} else if (button == 'u' || button == 'U' ||
button == '\x1A' || button == '\x1F' ||
@@ -965,23 +967,28 @@ static bool midend_really_process_key(midend *me, int x, int y, int button)
gottype = true;
if (!midend_undo(me))
goto done;
+ *handled = true;
} else if (button == 'r' || button == 'R' ||
button == '\x12' || button == '\x19' ||
button == UI_REDO) {
midend_stop_anim(me);
if (!midend_redo(me))
goto done;
+ *handled = true;
} else if ((button == '\x13' || button == UI_SOLVE) &&
me->ourgame->can_solve) {
+ *handled = true;
if (midend_solve(me))
goto done;
} else if (button == 'q' || button == 'Q' || button == '\x11' ||
button == UI_QUIT) {
ret = false;
+ *handled = true;
goto done;
} else
goto done;
} else {
+ *handled = true;
if (movestr == UI_UPDATE)
s = me->states[me->statepos-1].state;
else {
@@ -1052,10 +1059,12 @@ static bool midend_really_process_key(midend *me, int x, int y, int button)
return ret;
}
-bool midend_process_key(midend *me, int x, int y, int button)
+bool midend_process_key(midend *me, int x, int y, int button, bool *handled)
{
- bool ret = true;
+ bool ret = true, dummy_handled;
+ if (handled == NULL) handled = &dummy_handled;
+ *handled = false;
/*
* Harmonise mouse drag and release messages.
*
@@ -1155,7 +1164,7 @@ bool midend_process_key(midend *me, int x, int y, int button)
*/
ret = ret && midend_really_process_key
(me, x, y, (me->pressed_mouse_button +
- (LEFT_RELEASE - LEFT_BUTTON)));
+ (LEFT_RELEASE - LEFT_BUTTON)), handled);
}
/*
@@ -1178,7 +1187,7 @@ bool midend_process_key(midend *me, int x, int y, int button)
/*
* Now send on the event we originally received.
*/
- ret = ret && midend_really_process_key(me, x, y, button);
+ ret = ret && midend_really_process_key(me, x, y, button, handled);
/*
* And update the currently pressed button.