From 39f41faf9f027023e9632404f647237c15257b44 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 14 Jan 2021 04:31:55 +0530 Subject: [PATCH] Dont send events for modifier keys unless in all key mode --- docs/keyboard-protocol.rst | 4 +++- kitty/key_encoding.c | 5 +++++ kitty_tests/keys.py | 2 ++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/keyboard-protocol.rst b/docs/keyboard-protocol.rst index 8574ce98c..b2d9e6832 100644 --- a/docs/keyboard-protocol.rst +++ b/docs/keyboard-protocol.rst @@ -315,10 +315,12 @@ be notified of key repeat/release events. These types of events are needed for some applications, such as games (think of movement using the ``WASD`` keys). This progressive enhancement (``0b1000``) turns on key reporting even for key -events that generate next. When it is enabled, text will not be sent, instead +events that generate text. When it is enabled, text will not be sent, instead 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. + .. _report_text: Report associated text diff --git a/kitty/key_encoding.c b/kitty/key_encoding.c index ddfb92874..a30726fc2 100644 --- a/kitty/key_encoding.c +++ b/kitty/key_encoding.c @@ -31,6 +31,10 @@ typedef struct { KeyAction action; } EncodingData; +static inline bool +is_modifier_key(uint32_t key) { + return GLFW_FKEY_LEFT_SHIFT <= key && key <= GLFW_FKEY_RIGHT_SUPER; +} static inline void convert_glfw_mods(int mods, KeyEvent *ev) { @@ -344,6 +348,7 @@ encode_glfw_key_event(const GLFWkeyevent *e, const bool cursor_key_mode, const u .report_text = key_encoding_flags & 8, .embed_text = key_encoding_flags & 16 }; + if (!ev.report_text && is_modifier_key(e->key)) return 0; ev.has_text = e->text && !is_ascii_control_char(e->text[0]); bool send_text_standalone = !ev.report_text; if (!ev.disambiguate && GLFW_FKEY_KP_0 <= ev.key && ev.key <= GLFW_FKEY_KP_DELETE) { diff --git a/kitty_tests/keys.py b/kitty_tests/keys.py index b50449d14..5db6736df 100644 --- a/kitty_tests/keys.py +++ b/kitty_tests/keys.py @@ -389,6 +389,7 @@ class TestKeys(BaseTest): ae(enc(key=ord(' ')), ' ') ae(enc(key=ord(' '), mods=ctrl), '\0') ae(enc(key=ord('i'), mods=ctrl | shift), csi(ctrl | shift, ord('i'))) + ae(enc(key=defines.GLFW_FKEY_LEFT_SHIFT), '') q = partial(enc, key=ord('a')) ae(q(), 'a') @@ -434,6 +435,7 @@ class TestKeys(BaseTest): ae(kq(ord('a'), action=defines.GLFW_REPEAT), csi(num='a')) 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)) # test embed text eq = partial(enc, key_encoding_flags=0b11000)