handle release

This commit is contained in:
Yuxin Wu 2022-12-30 11:30:39 -08:00
parent 774fdd7e94
commit 510c5bd73b
2 changed files with 23 additions and 9 deletions

View File

@ -33,7 +33,7 @@ from .constants import (
) )
from .fast_data_types import ( from .fast_data_types import (
CLOSE_BEING_CONFIRMED, GLFW_MOD_ALT, GLFW_MOD_CONTROL, GLFW_MOD_SHIFT, CLOSE_BEING_CONFIRMED, GLFW_MOD_ALT, GLFW_MOD_CONTROL, GLFW_MOD_SHIFT,
GLFW_MOD_SUPER, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS, IMPERATIVE_CLOSE_REQUESTED, GLFW_MOD_SUPER, GLFW_MOUSE_BUTTON_LEFT, GLFW_PRESS, GLFW_RELEASE, IMPERATIVE_CLOSE_REQUESTED,
NO_CLOSE_REQUESTED, ChildMonitor, Color, EllipticCurveKey, KeyEvent, SingleKey, NO_CLOSE_REQUESTED, ChildMonitor, Color, EllipticCurveKey, KeyEvent, SingleKey,
add_timer, apply_options_update, background_opacity_of, change_background_opacity, add_timer, apply_options_update, background_opacity_of, change_background_opacity,
change_os_window_state, cocoa_hide_app, cocoa_hide_other_apps, change_os_window_state, cocoa_hide_app, cocoa_hide_other_apps,
@ -1184,13 +1184,18 @@ class Boss:
self.default_pending_action = '' self.default_pending_action = ''
set_in_sequence_mode(False) set_in_sequence_mode(False)
def process_sequence(self, ev: KeyEvent) -> None: def process_sequence(self, ev: KeyEvent) -> bool:
# Process an event as part of a sequence. Returns whether the key
# is consumed as part of a kitty sequence keybinding.
if not self.pending_sequences: if not self.pending_sequences:
set_in_sequence_mode(False) set_in_sequence_mode(False)
return return False
if len(self.current_sequence): if len(self.current_sequence):
self.current_sequence.append(ev) self.current_sequence.append(ev)
if ev.action == GLFW_RELEASE:
return True
# For a press/repeat event, try matching with kitty bindings:
remaining = {} remaining = {}
matched_action = None matched_action = None
for seq, key_action in self.pending_sequences.items(): for seq, key_action in self.pending_sequences.items():
@ -1203,17 +1208,20 @@ class Boss:
if remaining: if remaining:
self.pending_sequences = remaining self.pending_sequences = remaining
return True
else: else:
matched_action = matched_action or self.default_pending_action matched_action = matched_action or self.default_pending_action
if matched_action is not None and matched_action != '': if matched_action is not None and matched_action != '':
self.clear_pending_sequences() self.clear_pending_sequences()
self.combine(matched_action) self.combine(matched_action)
return True
else: else:
w = self.active_window w = self.active_window
if w is not None: if w is not None:
for ev in self.current_sequence: for ev in self.current_sequence:
w.write_to_child(w.encoded_key(ev)) w.write_to_child(w.encoded_key(ev))
self.clear_pending_sequences() self.clear_pending_sequences()
return False
def cancel_current_visual_select(self) -> None: def cancel_current_visual_select(self) -> None:
if self.current_visual_select: if self.current_visual_select:

View File

@ -167,14 +167,20 @@ on_key_input(GLFWkeyevent *ev) {
PyObject *ke = NULL; PyObject *ke = NULL;
#define create_key_event() { ke = convert_glfw_key_event_to_python(ev); if (!ke) { PyErr_Print(); return; } } #define create_key_event() { ke = convert_glfw_key_event_to_python(ev); if (!ke) { PyErr_Print(); return; } }
if (global_state.in_sequence_mode) { if (global_state.in_sequence_mode) {
debug("in sequence mode, handling as shortcut\n"); debug("in sequence mode, handling as a potential shortcut\n");
if ( if (!is_modifier_key(key)) {
action != GLFW_RELEASE && !is_modifier_key(key)
) {
w->last_special_key_pressed = key;
create_key_event(); create_key_event();
call_boss(process_sequence, "O", ke); PyObject *ret = PyObject_CallMethod(
global_state.boss, "process_sequence", "O", ke);
Py_CLEAR(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; return;
} }