From 1c10c5fcc41d6cb5f9415e6e9b6028e020fbe3bf Mon Sep 17 00:00:00 2001 From: Yuxin Wu Date: Fri, 30 Dec 2022 22:41:18 -0800 Subject: [PATCH] replay modifier key as well --- kitty/boss.py | 7 ++++--- kitty/key_encoding.py | 11 +++++++++++ kitty/keys.c | 24 +++++++++++------------- 3 files changed, 26 insertions(+), 16 deletions(-) diff --git a/kitty/boss.py b/kitty/boss.py index d955632ee..17503d6c5 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -47,7 +47,7 @@ from .fast_data_types import ( set_options, set_os_window_size, set_os_window_title, thread_write, toggle_fullscreen, toggle_maximized, toggle_secure_input, ) -from .key_encoding import get_name_to_functional_number_map +from .key_encoding import get_name_to_functional_number_map, is_modifier_key from .keys import get_shortcut, shortcut_matches from .layout.base import set_layout_options from .notify import notification_activated @@ -1193,9 +1193,10 @@ class Boss: if len(self.current_sequence): self.current_sequence.append(ev) - if ev.action == GLFW_RELEASE: + if ev.action == GLFW_RELEASE or is_modifier_key(ev.key): return True - # For a press/repeat event, try matching with kitty bindings: + # For a press/repeat event that's not a modifier, try matching with + # kitty bindings: remaining = {} matched_action = None for seq, key_action in self.pending_sequences.items(): diff --git a/kitty/key_encoding.py b/kitty/key_encoding.py index 110359b61..99b65819c 100644 --- a/kitty/key_encoding.py +++ b/kitty/key_encoding.py @@ -426,3 +426,14 @@ def decode_key_event_as_window_system_key(text: str) -> Optional[WindowSystemKey except Exception: return None return k.as_window_system_event() + + +# The same as `bool is_modifier_key(key)` in key_encoding.c +def is_modifier_key(key: int) -> bool: + if defines.GLFW_FKEY_LEFT_SHIFT <= key <= defines.GLFW_FKEY_ISO_LEVEL5_SHIFT: + return True + if key == defines.GLFW_FKEY_CAPS_LOCK or \ + key == defines.GLFW_FKEY_SCROLL_LOCK or \ + key == defines.GLFW_FKEY_NUM_LOCK: + return True + return False diff --git a/kitty/keys.c b/kitty/keys.c index 07b6504f3..e251065aa 100644 --- a/kitty/keys.c +++ b/kitty/keys.c @@ -168,19 +168,17 @@ on_key_input(GLFWkeyevent *ev) { #define create_key_event() { ke = convert_glfw_key_event_to_python(ev); if (!ke) { PyErr_Print(); return; } } if (global_state.in_sequence_mode) { debug("in sequence mode, handling as a potential shortcut\n"); - if (!is_modifier_key(key)) { - create_key_event(); - PyObject *ret = PyObject_CallMethod( - global_state.boss, "process_sequence", "O", ke); - Py_CLEAR(ke); - if (ret == NULL) { PyErr_Print(); } - else { - bool consumed = ret == Py_True; - Py_DECREF(ret); - if (consumed && action != GLFW_RELEASE && w) { - w->last_special_key_pressed = key; - } - } + create_key_event(); + PyObject *ret = PyObject_CallMethod( + global_state.boss, "process_sequence", "O", ke); + Py_CLEAR(ke); + if (ret == NULL) { PyErr_Print(); } + else { + bool consumed = ret == Py_True; + Py_DECREF(ret); + if (consumed && action != GLFW_RELEASE && w) { + w->last_special_key_pressed = key; + } } return; }