diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 8859a58b..5ab06e90 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -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; } diff --git a/windows/window.c b/windows/window.c index 3fc51974..2c387098 100644 --- a/windows/window.c +++ b/windows/window.c @@ -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; + } } }