From b2391553f97e89ced6f1e90bae0bb54b1127a57a Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 18 Feb 2024 11:12:24 +0530 Subject: [PATCH] Keyboard protocol: Fix the Enter Tab and Backspace keys generating spurious release events even when report all keys as escape codes is not set Fixes #7136 --- docs/changelog.rst | 8 ++++++++ docs/keyboard-protocol.rst | 7 +++++++ kitty/key_encoding.c | 6 +++--- kitty_tests/keys.py | 3 +++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index f57829b25..de4d3f39d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -43,6 +43,14 @@ The :doc:`ssh kitten ` is redesigned with powerful new features: Detailed list of changes ------------------------------------- +0.33.0 [future] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +- Keyboard protocol: Fix the :kbd:`Enter`, :kbd:`Tab` and :kbd:`Backspace` keys + generating spurious release events even when report all keys as escape codes + is not set (:iss:`7136`) + + 0.32.2 [2024-02-12] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/keyboard-protocol.rst b/docs/keyboard-protocol.rst index e72ecccb3..55019b4c2 100644 --- a/docs/keyboard-protocol.rst +++ b/docs/keyboard-protocol.rst @@ -348,6 +348,13 @@ and key release events. Normally only key press events are reported and key repeat events are treated as key press events. See :ref:`event_types` for details on how these are reported. +.. note:: + + The :kbd:`Enter`, :kbd:`Tab` and :kbd:`Backspace` keys will not have release + events unless :ref:`report_all_keys` is also set, so that the user can still + type reset at a shell prompt when a program that sets this mode ends without + resetting it. + .. _report_alternates: Report alternate keys diff --git a/kitty/key_encoding.c b/kitty/key_encoding.c index 366b39fe6..7e416341e 100644 --- a/kitty/key_encoding.c +++ b/kitty/key_encoding.c @@ -176,9 +176,9 @@ encode_function_key(const KeyEvent *ev, char *output) { } 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"); + case GLFW_FKEY_ENTER: if (ev->action == RELEASE) return -1; SIMPLE("\r"); + case GLFW_FKEY_BACKSPACE: if (ev->action == RELEASE) return -1; SIMPLE("\x7f"); + case GLFW_FKEY_TAB: if (ev->action == RELEASE) return -1; SIMPLE("\t"); default: break; } } diff --git a/kitty_tests/keys.py b/kitty_tests/keys.py index ae1c8c292..76f8799fd 100644 --- a/kitty_tests/keys.py +++ b/kitty_tests/keys.py @@ -438,6 +438,9 @@ class TestKeys(BaseTest): ae(tq(ord('a'), action=defines.GLFW_REPEAT), csi(num='a', action=2)) ae(tq(ord('a'), action=defines.GLFW_RELEASE), csi(num='a', action=3)) ae(tq(ord('a'), action=defines.GLFW_RELEASE, mods=shift), csi(shift, num='a', action=3)) + tq = partial(enc, key_encoding_flags=0b11) + ae(tq(defines.GLFW_FKEY_BACKSPACE), '\x7f') + ae(tq(defines.GLFW_FKEY_BACKSPACE, action=release), '') # test alternate key reporting aq = partial(enc, key_encoding_flags=0b100)