1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Send xterm 216+ modifiers in small-keypad key escape sequences.

In the 'xterm 216+' function key mode, a function key pressed with a
combination of Shift, Ctrl and Alt has its usual sequence like
ESC[n~ (for some integer n) turned into ESC[n;m~ where m-1 is a 3-bit
bitmap of currently pressed modifier keys.

This mode now also applies to the keys on the small keypad above the
arrow keys (Ins, Home, PgUp etc). If xterm 216+ mode is selected,
those keys are modified in the same way as the function keys.

As with the function keys, this doesn't guarantee that PuTTY will
_receive_ any particular shifted key of this kind, and not repurpose
it. Just as Alt+F4 still closes the window (at least on Windows)
rather than sending a modified F4 sequence, Shift+Ins will still
perform a paste action rather than sending a modified Ins sequence,
Shift-PgUp will still scroll the scrollback, etc. But the keys not
already used by PuTTY for other purposes should now have their
modern-xterm behaviour in modern-xterm mode.

Thanks to H.Merijn Brand for developing and testing a version of this
patch.
This commit is contained in:
Simon Tatham 2022-07-24 13:54:32 +01:00
parent 810e21de82
commit c88b6d1853
4 changed files with 29 additions and 5 deletions

View File

@ -2225,7 +2225,9 @@ int format_arrow_key(char *buf, Terminal *term, int xkey,
bool shift, bool ctrl, bool alt, bool *consumed_alt);
int format_function_key(char *buf, Terminal *term, int key_number,
bool shift, bool ctrl, bool alt, bool *consumed_alt);
int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key);
int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key,
bool shift, bool ctrl, bool alt,
bool *consumed_alt);
int format_numeric_keypad_key(char *buf, Terminal *term, char key,
bool shift, bool ctrl);

View File

@ -7477,7 +7477,9 @@ int format_function_key(char *buf, Terminal *term, int key_number,
return p - buf;
}
int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key)
int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key,
bool shift, bool ctrl, bool alt,
bool *consumed_alt)
{
char *p = buf;
@ -7508,7 +7510,17 @@ int format_small_keypad_key(char *buf, Terminal *term, SmallKeypadKey key)
} else if ((code == 1 || code == 4) && term->rxvt_homeend) {
p += sprintf(p, code == 1 ? "\x1B[H" : "\x1BOw");
} else {
p += sprintf(p, "\x1B[%d~", code);
if (term->vt52_mode) {
p += sprintf(p, "\x1B[%d~", code);
} else {
int bitmap = 0;
if (term->funky_type == FUNKY_XTERM_216)
bitmap = shift_bitmap(shift, ctrl, alt, consumed_alt);
if (bitmap)
p += sprintf(p, "\x1B[%d;%d~", code, bitmap);
else
p += sprintf(p, "\x1B[%d~", code);
}
}
return p - buf;

View File

@ -1914,7 +1914,13 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
if (event->state & GDK_CONTROL_MASK)
break;
end = 1 + format_small_keypad_key(output+1, inst->term, sk_key);
end = 1 + format_small_keypad_key(output+1, inst->term, sk_key,
event->state & GDK_SHIFT_MASK,
event->state & GDK_CONTROL_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(" - small keypad key");
#endif

View File

@ -4627,7 +4627,11 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
if (shift_state & 2)
break;
p += format_small_keypad_key((char *)p, term, sk_key);
p += format_small_keypad_key((char *)p, term, sk_key,
shift_state & 1, shift_state & 2,
left_alt, &consumed_alt);
if (consumed_alt)
left_alt = false; /* supersedes the usual prefixing of Esc */
return p - output;
char xkey;