aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2023-06-25 13:54:21 +0100
committerBen Harris <bjh21@bjh21.me.uk>2023-06-25 13:54:21 +0100
commitc224416c76e41f284b318adc51f08c3ed11de8e2 (patch)
treeac5e94231756df65163df9ef52f4801923146b23
parent88f86918bfca1935c07eee7f84d98e32ccc2f593 (diff)
downloadpuzzles-c224416c76e41f284b318adc51f08c3ed11de8e2.zip
puzzles-c224416c76e41f284b318adc51f08c3ed11de8e2.tar.gz
puzzles-c224416c76e41f284b318adc51f08c3ed11de8e2.tar.bz2
puzzles-c224416c76e41f284b318adc51f08c3ed11de8e2.tar.xz
Reduce the set of keys from which we generate control characters
midend_process_key() has some generic code for converting MOD_CTRL along with a printing character into a control character. This is derived from the Emscripten front-end because browsers don't do this themselves. Most other front ends seem to depend on the platform for this mapping. The mapping was applied to all printable ASCII characters, but this meant that Ctrl+-, which is commonly used by browsers to mean "zoom out" got converted into CR and then CURSOR_SELECT. That was confusing to say the least. So now, the CTRL mapping is only applied to characters in the roughly alphabetic range (0x40 to 0x7f), and MOD_CTRL applied to a character in the range 0x20 to 0x3f gets a return of PKR_UNUSED instead. That means that Ctrl+- in browsers now works properly. I don't think this will affect other front-ends because they're generally a lot less generous about passing MOD_CTRL to the mid-end. I've tested the GTK port nonetheless and not found any problems.
-rw-r--r--midend.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/midend.c b/midend.c
index f9ebf77..7a6aa92 100644
--- a/midend.c
+++ b/midend.c
@@ -1213,15 +1213,21 @@ int midend_process_key(midend *me, int x, int y, int button)
}
/* Canonicalise CTRL+ASCII. */
- if ((button & MOD_CTRL) && (button & ~MOD_MASK) < 0x80)
+ if ((button & MOD_CTRL) &&
+ (button & ~MOD_MASK) >= 0x40 && (button & ~MOD_MASK) < 0x80)
button = button & (0x1f | (MOD_MASK & ~MOD_CTRL));
/* Special handling to make CTRL+SHFT+Z into REDO. */
if ((button & (~MOD_MASK | MOD_SHFT)) == (MOD_SHFT | '\x1A'))
button = UI_REDO;
/* interpret_move() expects CTRL and SHFT only on cursor keys. */
- if (!IS_CURSOR_MOVE(button & ~MOD_MASK))
+ if (!IS_CURSOR_MOVE(button & ~MOD_MASK)) {
+ /* reject CTRL+anything odd */
+ if ((button & MOD_CTRL) && (button & ~MOD_MASK) >= 0x20)
+ printf(" -> %d\n", PKR_UNUSED);
+ /* otherwise strip them */
button &= ~(MOD_CTRL | MOD_SHFT);
- /* ... and NUM_KEYPAD only on numbers. */
+ }
+ /* interpret_move() expects NUM_KEYPAD only on numbers. */
if ((button & ~MOD_MASK) < '0' || (button & ~MOD_MASK) > '9')
button &= ~MOD_NUM_KEYPAD;
/*