replay modifier key as well

This commit is contained in:
Yuxin Wu
2022-12-30 22:41:18 -08:00
parent 510c5bd73b
commit 1c10c5fcc4
3 changed files with 26 additions and 16 deletions

View File

@@ -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():

11
kitty/key_encoding.py generated
View File

@@ -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

View File

@@ -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;
}