diff options
| author | Ben Harris <bjh21@bjh21.me.uk> | 2022-11-05 17:15:52 +0000 |
|---|---|---|
| committer | Ben Harris <bjh21@bjh21.me.uk> | 2022-11-08 10:27:19 +0000 |
| commit | c5a2446fae603a480de58b912fa349549bd9f247 (patch) | |
| tree | 3d71feca6cde2cb4ab53f0b599e46ec39202de27 /emcc.c | |
| parent | 4a37f7cf782592b670d0180a38eb1fd680288421 (diff) | |
| download | puzzles-c5a2446fae603a480de58b912fa349549bd9f247.zip puzzles-c5a2446fae603a480de58b912fa349549bd9f247.tar.gz puzzles-c5a2446fae603a480de58b912fa349549bd9f247.tar.bz2 puzzles-c5a2446fae603a480de58b912fa349549bd9f247.tar.xz | |
js: Cancel UI events when the mid end says they've been handled
This means that if a key doesn't do anything in a puzzle, it can operate
the browser instead.
Diffstat (limited to 'emcc.c')
| -rw-r--r-- | emcc.c | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -246,28 +246,37 @@ static void update_undo_redo(void) /* * Mouse event handlers called from JS. */ -void mousedown(int x, int y, int button) +bool mousedown(int x, int y, int button) { + bool handled; + button = (button == 0 ? LEFT_BUTTON : button == 1 ? MIDDLE_BUTTON : RIGHT_BUTTON); - midend_process_key(me, x, y, button, NULL); + midend_process_key(me, x, y, button, &handled); update_undo_redo(); + return handled; } -void mouseup(int x, int y, int button) +bool mouseup(int x, int y, int button) { + bool handled; + button = (button == 0 ? LEFT_RELEASE : button == 1 ? MIDDLE_RELEASE : RIGHT_RELEASE); - midend_process_key(me, x, y, button, NULL); + midend_process_key(me, x, y, button, &handled); update_undo_redo(); + return handled; } -void mousemove(int x, int y, int buttons) +bool mousemove(int x, int y, int buttons) { int button = (buttons & 2 ? MIDDLE_DRAG : buttons & 4 ? RIGHT_DRAG : LEFT_DRAG); - midend_process_key(me, x, y, button, NULL); + bool handled; + + midend_process_key(me, x, y, button, &handled); update_undo_redo(); + return handled; } /* @@ -283,6 +292,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; if (!strnullcmp(key, "Backspace") || !strnullcmp(key, "Delete") || !strnullcmp(key, "Del")) @@ -379,9 +389,9 @@ bool key(int keycode, const char *key, const char *chr, int location, location == DOM_KEY_LOCATION_NUMPAD) keyevent |= MOD_NUM_KEYPAD; - midend_process_key(me, 0, 0, keyevent, NULL); + midend_process_key(me, 0, 0, keyevent, &handled); update_undo_redo(); - return true; /* We've probably handled the event. */ + return handled; } return false; /* Event not handled, because we don't even recognise it. */ } |