зеркало из https://github.com/github/putty.git
Fix handling of Return and keypad Enter.
The recent rewriting in both the GTK and Windows keyboard handlers left the keypad 'Enter' key in a bad state, when no override is enabled that causes it to generate an escape sequence. On Windows, a series of fallbacks was causing it to generate \r regardless of configuration, whereas in Telnet mode it should default to generating the special Telnet new-line sequence, and in response to ESC[20h (enabling term->cr_lf_return) it should generate \r\n. On GTK, it wasn't generating anything _at all_, and also, I can't see any evidence that the GTK keyboard handler had ever remembered to implement the cr_lf_return mode. Now Keypad Enter in non-escape-sequence mode should behave just like Return, on both platforms.
This commit is contained in:
Родитель
56198afb5c
Коммит
97a1021202
|
@ -993,6 +993,32 @@ char *dup_keyval_name(guint keyval)
|
|||
static void change_font_size(GtkFrontend *inst, int increment);
|
||||
static void key_pressed(GtkFrontend *inst);
|
||||
|
||||
/* Subroutine used in key_event */
|
||||
static int return_key(GtkFrontend *inst, char *output, bool *special)
|
||||
{
|
||||
int end;
|
||||
|
||||
/* Ugly label so we can come here as a fallback from
|
||||
* numeric keypad Enter handling */
|
||||
if (inst->term->cr_lf_return) {
|
||||
#ifdef KEY_EVENT_DIAGNOSTICS
|
||||
debug(" - Return in cr_lf_return mode, translating as 0d 0a\n");
|
||||
#endif
|
||||
output[1] = '\015';
|
||||
output[2] = '\012';
|
||||
end = 3;
|
||||
} else {
|
||||
#ifdef KEY_EVENT_DIAGNOSTICS
|
||||
debug(" - Return special case, translating as 0d + special\n");
|
||||
#endif
|
||||
output[1] = '\015';
|
||||
end = 2;
|
||||
*special = true;
|
||||
}
|
||||
|
||||
return end;
|
||||
}
|
||||
|
||||
gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
||||
{
|
||||
GtkFrontend *inst = (GtkFrontend *)data;
|
||||
|
@ -1688,13 +1714,8 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
|||
/* We handle Return ourselves, because it needs to be flagged as
|
||||
* special to ldisc. */
|
||||
if (event->keyval == GDK_KEY_Return) {
|
||||
#ifdef KEY_EVENT_DIAGNOSTICS
|
||||
debug(" - Return special case, translating as 0d + special\n");
|
||||
#endif
|
||||
output[1] = '\015';
|
||||
use_ucsoutput = false;
|
||||
end = 2;
|
||||
special = true;
|
||||
end = return_key(inst, output, &special);
|
||||
use_ucsoutput = false;
|
||||
}
|
||||
|
||||
/* Control-2, Control-Space and Control-@ are NUL */
|
||||
|
@ -1870,6 +1891,15 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
|||
#ifdef KEY_EVENT_DIAGNOSTICS
|
||||
debug(" - numeric keypad key");
|
||||
#endif
|
||||
|
||||
if (end == 1 && num_keypad_key == '\r') {
|
||||
/* Keypad Enter, lacking any other translation,
|
||||
* becomes the same special Return code as normal
|
||||
* Return. */
|
||||
end = return_key(inst, output, &special);
|
||||
use_ucsoutput = false;
|
||||
}
|
||||
|
||||
use_ucsoutput = false;
|
||||
goto done;
|
||||
}
|
||||
|
|
|
@ -4114,6 +4114,7 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
|
|||
bool no_applic_k = conf_get_bool(conf, CONF_no_applic_k);
|
||||
bool ctrlaltkeys = conf_get_bool(conf, CONF_ctrlaltkeys);
|
||||
bool nethack_keypad = conf_get_bool(conf, CONF_nethack_keypad);
|
||||
char keypad_key = '\0';
|
||||
|
||||
HKL kbd_layout = GetKeyboardLayout(0);
|
||||
|
||||
|
@ -4479,14 +4480,8 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
|
|||
*p++ = 0x1E; /* Ctrl-~ == Ctrl-^ in xterm at least */
|
||||
return p - output;
|
||||
}
|
||||
if (shift_state == 0 && wParam == VK_RETURN && term->cr_lf_return) {
|
||||
*p++ = '\r';
|
||||
*p++ = '\n';
|
||||
return p - output;
|
||||
}
|
||||
|
||||
switch (wParam) {
|
||||
char keypad_key;
|
||||
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;
|
||||
|
@ -4520,7 +4515,8 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
|
|||
(char *)p, term, keypad_key,
|
||||
shift_state & 1, shift_state & 2);
|
||||
if (!nchars) {
|
||||
/* If we didn't get an escape sequence out of the
|
||||
/*
|
||||
* If we didn't get an escape sequence out of the
|
||||
* numeric keypad key, then that must be because
|
||||
* we're in Num Lock mode without application
|
||||
* keypad enabled. In that situation we leave this
|
||||
|
@ -4528,7 +4524,16 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
|
|||
* below, which will translate it according to the
|
||||
* appropriate keypad layout (e.g. so that what a
|
||||
* Brit thinks of as keypad '.' can become ',' in
|
||||
* the German layout). */
|
||||
* the German layout).
|
||||
*
|
||||
* An exception is the keypad Return key: if we
|
||||
* didn't get an escape sequence for that, we
|
||||
* treat it like ordinary Return, taking into
|
||||
* account Telnet special new line codes and
|
||||
* config options.
|
||||
*/
|
||||
if (keypad_key == '\r')
|
||||
goto ordinary_return_key;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -4592,9 +4597,16 @@ static int TranslateKey(UINT message, WPARAM wParam, LPARAM lParam,
|
|||
keypad_key = '\r';
|
||||
goto numeric_keypad;
|
||||
}
|
||||
*p++ = 0x0D;
|
||||
*p++ = 0;
|
||||
return -2;
|
||||
ordinary_return_key:
|
||||
if (shift_state == 0 && term->cr_lf_return) {
|
||||
*p++ = '\r';
|
||||
*p++ = '\n';
|
||||
return p - output;
|
||||
} else {
|
||||
*p++ = 0x0D;
|
||||
*p++ = 0;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче