From 0163bf3edb8dd2314470d1a92e1ca23f21b05757 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 15 Jan 2021 11:50:51 +0530 Subject: [PATCH] Fix enter/tab/backspace not being reported in all keys mode --- docs/keyboard-protocol.rst | 2 ++ kitty/key_encoding.c | 15 +++++++-------- kitty_tests/keys.py | 3 +++ kitty_tests/layout.py | 2 +- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/docs/keyboard-protocol.rst b/docs/keyboard-protocol.rst index 0760e0741..60c1de955 100644 --- a/docs/keyboard-protocol.rst +++ b/docs/keyboard-protocol.rst @@ -326,6 +326,8 @@ only key events are sent. If the text is needed as well, combine with the Report associated text enhancement below. Additionally, with this mode, events for pressing modifier keys are reported. +Note that *all* keys are reported as escape codes, including :kbd:`Enter, Tab, +Backspace` etc. .. _report_text: diff --git a/kitty/key_encoding.c b/kitty/key_encoding.c index 92ca43147..4d9fdc602 100644 --- a/kitty/key_encoding.c +++ b/kitty/key_encoding.c @@ -143,15 +143,14 @@ encode_function_key(const KeyEvent *ev, char *output) { } } if (!ev->mods.value) { - switch(key_number) { - case GLFW_FKEY_ENTER: SIMPLE("\r"); - case GLFW_FKEY_ESCAPE: { - if (ev->disambiguate) { return encode_csi_string('u', "27", output); } - SIMPLE("\x1b"); + if (!ev->disambiguate && !ev->report_text && key_number == GLFW_FKEY_ESCAPE) SIMPLE("\x1b"); + if (!ev->report_text) { + switch(key_number) { + case GLFW_FKEY_ENTER: SIMPLE("\r"); + case GLFW_FKEY_BACKSPACE: SIMPLE("\x7f"); + case GLFW_FKEY_TAB: SIMPLE("\t"); + default: break; } - case GLFW_FKEY_BACKSPACE: SIMPLE("\x7f"); - case GLFW_FKEY_TAB: SIMPLE("\t"); - default: break; } } if (ev->mods.value == ALT && !ev->disambiguate) { diff --git a/kitty_tests/keys.py b/kitty_tests/keys.py index 7760eddfb..27d5cfa8f 100644 --- a/kitty_tests/keys.py +++ b/kitty_tests/keys.py @@ -437,6 +437,9 @@ class TestKeys(BaseTest): ae(kq(ord('a'), mods=ctrl), csi(ctrl, num='a')) ae(kq(defines.GLFW_FKEY_UP), '\x1b[A') ae(kq(defines.GLFW_FKEY_LEFT_SHIFT), csi(num=defines.GLFW_FKEY_LEFT_SHIFT)) + ae(kq(defines.GLFW_FKEY_ENTER), '\x1b[13u') + ae(kq(defines.GLFW_FKEY_TAB), '\x1b[9u') + ae(kq(defines.GLFW_FKEY_BACKSPACE), '\x1b[127u') # test embed text eq = partial(enc, key_encoding_flags=0b11000) diff --git a/kitty_tests/layout.py b/kitty_tests/layout.py index 7d82f372d..6de3a1e65 100644 --- a/kitty_tests/layout.py +++ b/kitty_tests/layout.py @@ -3,7 +3,7 @@ # License: GPL v3 Copyright: 2018, Kovid Goyal from kitty.config import defaults -from kitty.constants import WindowGeometry +from kitty.types import WindowGeometry from kitty.layout.interface import Grid, Horizontal, Splits, Stack, Tall from kitty.window import EdgeWidths from kitty.window_list import WindowList, reset_group_id_counter