aboutsummaryrefslogtreecommitdiff
path: root/emcc.c
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-06-07 23:03:30 +0100
committerBen Harris <bjh21@bjh21.me.uk>2023-06-11 00:33:28 +0100
commit1547154efbfcf0bd8f6fc4f91fe99c26371fe0ee (patch)
treef7fcd5d3a658deaa559031ae31a38381c92f428f /emcc.c
parent87e98e67158326a7dd94fd8fa255e3695898ecf3 (diff)
downloadpuzzles-1547154efbfcf0bd8f6fc4f91fe99c26371fe0ee.zip
puzzles-1547154efbfcf0bd8f6fc4f91fe99c26371fe0ee.tar.gz
puzzles-1547154efbfcf0bd8f6fc4f91fe99c26371fe0ee.tar.bz2
puzzles-1547154efbfcf0bd8f6fc4f91fe99c26371fe0ee.tar.xz
Expose the NO_EFFECT/UNUSED distinction through midend_process_key()
This removed the "handled" pointer and instead extends the existing boolean return value (quit or don't quit) into an enumeration. One of the values still quits the program, but now there are different values for keys that had an effect, had no effect, and are not used by the puzzle at all. The mapping from interpret_move results to process_key results is roughly: move string -> PKR_SOME_EFFECT MOVE_UI_UPDATE -> PKR_SOME_EFFECT MOVE_NO_EFFECT -> PKR_NO_EFFECT MOVE_UNUSED -> PKR_UNUSED The mid-end can also generate results internally, and is the only place that PKR_QUIT can arise. For compatibility, PKR_QUIT is zero, so anything expecting a false return value to mean quit will be unsurprised. The other values are ordered so that lower values indicate a greater amount of handling of the key.
Diffstat (limited to 'emcc.c')
-rw-r--r--emcc.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/emcc.c b/emcc.c
index 60ef8c8..7d7a09b 100644
--- a/emcc.c
+++ b/emcc.c
@@ -295,7 +295,7 @@ bool mousedown(int x, int y, int button)
button = (button == 0 ? LEFT_BUTTON :
button == 1 ? MIDDLE_BUTTON : RIGHT_BUTTON);
- midend_process_key(me, x, y, button, &handled);
+ handled = midend_process_key(me, x, y, button) != PKR_UNUSED;
post_move();
return handled;
}
@@ -306,7 +306,7 @@ bool mouseup(int x, int y, int button)
button = (button == 0 ? LEFT_RELEASE :
button == 1 ? MIDDLE_RELEASE : RIGHT_RELEASE);
- midend_process_key(me, x, y, button, &handled);
+ handled = midend_process_key(me, x, y, button) != PKR_UNUSED;
post_move();
return handled;
}
@@ -317,7 +317,7 @@ bool mousemove(int x, int y, int buttons)
buttons & 4 ? RIGHT_DRAG : LEFT_DRAG);
bool handled;
- midend_process_key(me, x, y, button, &handled);
+ handled = midend_process_key(me, x, y, button) != PKR_UNUSED;
post_move();
return handled;
}
@@ -335,7 +335,7 @@ bool key(int keycode, const char *key, const char *chr, int location,
#define DOM_KEY_LOCATION_RIGHT 2
#define DOM_KEY_LOCATION_NUMPAD 3
int keyevent = -1;
- bool handled;
+ int process_key_result;
if (!strnullcmp(key, "Backspace") || !strnullcmp(key, "Delete") ||
!strnullcmp(key, "Del"))
@@ -422,9 +422,16 @@ bool key(int keycode, const char *key, const char *chr, int location,
if (ctrl) keyevent |= MOD_CTRL;
if (location == DOM_KEY_LOCATION_NUMPAD) keyevent |= MOD_NUM_KEYPAD;
- midend_process_key(me, 0, 0, keyevent, &handled);
+ process_key_result = midend_process_key(me, 0, 0, keyevent);
post_move();
- return handled;
+ /*
+ * Treat Backspace specially because that's expected on KaiOS.
+ * https://developer.kaiostech.com/docs/design-guide/key
+ */
+ if (process_key_result == PKR_NO_EFFECT &&
+ !strnullcmp(key, "Backspace"))
+ return false;
+ return process_key_result != PKR_UNUSED;
}
return false; /* Event not handled, because we don't even recognise it. */
}
@@ -839,7 +846,7 @@ void command(int n)
post_move();
break;
case 5: /* New Game */
- midend_process_key(me, 0, 0, UI_NEWGAME, NULL);
+ midend_process_key(me, 0, 0, UI_NEWGAME);
post_move();
js_focus_canvas();
break;
@@ -849,12 +856,12 @@ void command(int n)
js_focus_canvas();
break;
case 7: /* Undo */
- midend_process_key(me, 0, 0, UI_UNDO, NULL);
+ midend_process_key(me, 0, 0, UI_UNDO);
post_move();
js_focus_canvas();
break;
case 8: /* Redo */
- midend_process_key(me, 0, 0, UI_REDO, NULL);
+ midend_process_key(me, 0, 0, UI_REDO);
post_move();
js_focus_canvas();
break;