From 2e4d78a714b07181da843da6cea1457984557efb Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Fri, 10 Jul 2020 19:47:28 +0200 Subject: [PATCH] tweaks: fold translation of all modified keypad keystrokes together The escape-sequence codes for the different keypad keys are simply the relevant ASCII code plus 0x40, so they are easy to translate. Also, do not accept keypad keys with multiple modifiers (Shift+Alt, Shift+Ctrl, Alt+Ctrl, Shift+Alt+Ctrl) -- report "Unknown sequence" for those. --- src/winio.c | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/winio.c b/src/winio.c index ead5b018..67ea2432 100644 --- a/src/winio.c +++ b/src/winio.c @@ -369,22 +369,19 @@ int convert_sequence(const int *seq, size_t length, int *consumed) } break; case '2': /* Shift */ - case '4': /* Shift+Alt */ - case '6': /* Shift+Ctrl */ - if (length > 2) { - *consumed = 3; - /* Allow typing digits on the numeric keypad without - * engaging NumLock. Esc O 2 p == Shift-0, .... */ - return (seq[2] - 0x40); - } - break; case '3': /* Alt */ + case '4': /* Shift+Alt */ case '5': /* Ctrl */ + case '6': /* Shift+Ctrl */ case '7': /* Alt+Ctrl */ + case '8': /* Shift+Alt+Ctrl */ if (length > 2) { *consumed = 3; - switch (seq[2]) { + /* Do not accept multiple modifiers. */ + if (seq[1] == '4' || seq[1] > '5') + return FOREIGN_SEQUENCE; #ifndef NANO_TINY + switch (seq[2]) { case 'A': /* Esc O 5 A == Ctrl-Up on Haiku. */ return CONTROL_UP; case 'B': /* Esc O 5 B == Ctrl-Down on Haiku. */ @@ -393,18 +390,12 @@ int convert_sequence(const int *seq, size_t length, int *consumed) return CONTROL_RIGHT; case 'D': /* Esc O 5 D == Ctrl-Left on Haiku. */ return CONTROL_LEFT; -#endif - case 'M': /* Esc O . M == modified Enter on keypad. */ - return KEY_ENTER; - case 'j': /* Esc O . j == modified '*' on keypad. */ - return '*'; - case 'k': /* Esc O . k == modified '+' on keypad. */ - return '+'; - case 'm': /* Esc O . m == modified '-' on keypad. */ - return '-'; - case 'o': /* Esc O . o == modified '/' on keypad. */ - return '/'; } +#endif + /* Translate Shift+digit on the keypad to the digit + * (Esc O 2 p == Shift-0, ...), modifier+operator to + * the operator, and modifier+Enter to CR. */ + return (seq[2] - 0x40); } break; case 'A': /* Esc O A == Up on VT100/VT320. */