From a40b581fc1df99bba6bfba42c777122ce9bc8f6b Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 23 Oct 2021 10:52:11 +0100 Subject: [PATCH] Fix Alt handling in the new shifted-arrow-key support. As well as affecting the bitmap field in the escape sequence, it was _also_ having its otherwise standard effect of prefixing Esc to the whole sequence. It shouldn't do both. --- putty.h | 2 +- terminal/terminal.c | 8 +++++--- unix/window.c | 8 +++++++- windows/window.c | 7 ++++++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/putty.h b/putty.h index 77301bf8..1719e8db 100644 --- a/putty.h +++ b/putty.h @@ -1945,7 +1945,7 @@ typedef enum SmallKeypadKey { SKK_HOME, SKK_END, SKK_INSERT, SKK_DELETE, SKK_PGUP, SKK_PGDN, } SmallKeypadKey; int format_arrow_key(char *buf, Terminal *term, int xkey, - bool shift, bool ctrl, bool alt); + bool shift, bool ctrl, bool alt, bool *consumed_alt); int format_function_key(char *buf, Terminal *term, int key_number, bool shift, bool ctrl); int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key); diff --git a/terminal/terminal.c b/terminal/terminal.c index da255550..dc12755c 100644 --- a/terminal/terminal.c +++ b/terminal/terminal.c @@ -7241,16 +7241,18 @@ void term_mouse(Terminal *term, Mouse_Button braw, Mouse_Button bcooked, term_schedule_update(term); } -static int shift_bitmap(bool shift, bool ctrl, bool alt) +static int shift_bitmap(bool shift, bool ctrl, bool alt, bool *consumed_alt) { int bitmap = (shift ? 1 : 0) + (alt ? 2 : 0) + (ctrl ? 4 : 0); if (bitmap) bitmap++; + if (alt && consumed_alt) + *consumed_alt = true; return bitmap; } int format_arrow_key(char *buf, Terminal *term, int xkey, - bool shift, bool ctrl, bool alt) + bool shift, bool ctrl, bool alt, bool *consumed_alt) { char *p = buf; @@ -7283,7 +7285,7 @@ int format_arrow_key(char *buf, Terminal *term, int xkey, app_flg = !app_flg; break; case SHARROW_BITMAP: - bitmap = shift_bitmap(shift, ctrl, alt); + bitmap = shift_bitmap(shift, ctrl, alt, consumed_alt); break; } diff --git a/unix/window.c b/unix/window.c index 9f5948f4..73ff5760 100644 --- a/unix/window.c +++ b/unix/window.c @@ -1808,6 +1808,8 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) switch (event->keyval) { int fkey_number; + bool consumed_meta_key; + case GDK_KEY_F1: fkey_number = 1; goto numbered_function_key; case GDK_KEY_F2: fkey_number = 2; goto numbered_function_key; case GDK_KEY_F3: fkey_number = 3; goto numbered_function_key; @@ -1875,10 +1877,14 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data) case GDK_KEY_Begin: case GDK_KEY_KP_Begin: xkey = 'G'; goto arrow_key; arrow_key: + consumed_meta_key = false; end = 1 + format_arrow_key(output+1, inst->term, xkey, event->state & GDK_SHIFT_MASK, event->state & GDK_CONTROL_MASK, - event->state & GDK_META_MASK); + event->state & inst->meta_mod_mask, + &consumed_meta_key); + if (consumed_meta_key) + start = 1; /* supersedes the usual prefixing of Esc */ #ifdef KEY_EVENT_DIAGNOSTICS debug(" - arrow key"); #endif diff --git a/windows/window.c b/windows/window.c index 3b00ad96..a5bad374 100644 --- a/windows/window.c +++ b/windows/window.c @@ -4429,6 +4429,8 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, } switch (wParam) { + bool consumed_alt; + case VK_NUMPAD0: keypad_key = '0'; goto numeric_keypad; case VK_NUMPAD1: keypad_key = '1'; goto numeric_keypad; case VK_NUMPAD2: keypad_key = '2'; goto numeric_keypad; @@ -4536,8 +4538,11 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam, case VK_LEFT: xkey = 'D'; goto arrow_key; case VK_CLEAR: xkey = 'G'; goto arrow_key; /* close enough */ arrow_key: + consumed_alt = false; p += format_arrow_key((char *)p, term, xkey, shift_state & 1, - shift_state & 2, left_alt); + shift_state & 2, left_alt, &consumed_alt); + if (consumed_alt) + left_alt = false; /* supersedes the usual prefixing of Esc */ return p - output; case VK_RETURN: