mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 19:21:38 +02:00
Cleanup previous PR
This commit is contained in:
@@ -79,6 +79,8 @@ Detailed list of changes
|
|||||||
|
|
||||||
- macOS: Allow to customize :sc:`Hide <hide_macos_app>`, :sc:`Hide Others <hide_macos_other_apps>`, :sc:`Minimize <minimize_macos_window>`, and :sc:`Quit <quit>` global menu shortcuts. Note that :opt:`clear_all_shortcuts` will remove these shortcuts now (:iss:`948`)
|
- macOS: Allow to customize :sc:`Hide <hide_macos_app>`, :sc:`Hide Others <hide_macos_other_apps>`, :sc:`Minimize <minimize_macos_window>`, and :sc:`Quit <quit>` global menu shortcuts. Note that :opt:`clear_all_shortcuts` will remove these shortcuts now (:iss:`948`)
|
||||||
|
|
||||||
|
- When a multi-key sequence does not match any action, send all key events to the child program (:pull:`5841`)
|
||||||
|
|
||||||
|
|
||||||
0.26.5 [2022-11-07]
|
0.26.5 [2022-11-07]
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ from .fast_data_types import (
|
|||||||
cocoa_minimize_os_window, cocoa_set_menubar_title, create_os_window,
|
cocoa_minimize_os_window, cocoa_set_menubar_title, create_os_window,
|
||||||
current_application_quit_request, current_focused_os_window_id, current_os_window,
|
current_application_quit_request, current_focused_os_window_id, current_os_window,
|
||||||
destroy_global_data, focus_os_window, get_boss, get_options, get_os_window_size,
|
destroy_global_data, focus_os_window, get_boss, get_options, get_os_window_size,
|
||||||
glfw_is_modifier_key, global_font_size, last_focused_os_window_id, mark_os_window_for_close,
|
is_modifier_key, global_font_size, last_focused_os_window_id, mark_os_window_for_close,
|
||||||
os_window_font_size, patch_global_colors, redirect_mouse_handling, ring_bell,
|
os_window_font_size, patch_global_colors, redirect_mouse_handling, ring_bell,
|
||||||
run_with_activation_token, safe_pipe, send_data_to_peer,
|
run_with_activation_token, safe_pipe, send_data_to_peer,
|
||||||
set_application_quit_request, set_background_image, set_boss, set_in_sequence_mode,
|
set_application_quit_request, set_background_image, set_boss, set_in_sequence_mode,
|
||||||
@@ -1191,9 +1191,9 @@ class Boss:
|
|||||||
set_in_sequence_mode(False)
|
set_in_sequence_mode(False)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if len(self.current_sequence):
|
if self.current_sequence:
|
||||||
self.current_sequence.append(ev)
|
self.current_sequence.append(ev)
|
||||||
if ev.action == GLFW_RELEASE or glfw_is_modifier_key(ev.key):
|
if ev.action == GLFW_RELEASE or is_modifier_key(ev.key):
|
||||||
return True
|
return True
|
||||||
# For a press/repeat event that's not a modifier, try matching with
|
# For a press/repeat event that's not a modifier, try matching with
|
||||||
# kitty bindings:
|
# kitty bindings:
|
||||||
@@ -1210,19 +1210,16 @@ class Boss:
|
|||||||
if remaining:
|
if remaining:
|
||||||
self.pending_sequences = remaining
|
self.pending_sequences = remaining
|
||||||
return True
|
return True
|
||||||
else:
|
matched_action = matched_action or self.default_pending_action
|
||||||
matched_action = matched_action or self.default_pending_action
|
if 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
|
||||||
return True
|
w = self.active_window
|
||||||
else:
|
if w is not None:
|
||||||
w = self.active_window
|
w.write_to_child(b''.join(w.encoded_key(ev) for ev in self.current_sequence))
|
||||||
if w is not None:
|
self.clear_pending_sequences()
|
||||||
for ev in self.current_sequence:
|
return False
|
||||||
w.write_to_child(w.encoded_key(ev))
|
|
||||||
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:
|
||||||
|
|||||||
@@ -313,10 +313,6 @@ def glfw_get_key_name(key: int, native_key: int) -> Optional[str]:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def glfw_is_modifier_key(key: int) -> bool:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
StartupCtx = NewType('StartupCtx', int)
|
StartupCtx = NewType('StartupCtx', int)
|
||||||
Display = NewType('Display', int)
|
Display = NewType('Display', int)
|
||||||
|
|
||||||
@@ -1515,3 +1511,4 @@ def wrapped_kitten_names() -> List[str]: ...
|
|||||||
def expand_ansi_c_escapes(test: str) -> str: ...
|
def expand_ansi_c_escapes(test: str) -> str: ...
|
||||||
def update_tab_bar_edge_colors(os_window_id: int) -> bool: ...
|
def update_tab_bar_edge_colors(os_window_id: int) -> bool: ...
|
||||||
def mask_kitty_signals_process_wide() -> None: ...
|
def mask_kitty_signals_process_wide() -> None: ...
|
||||||
|
def is_modifier_key(key: int) -> bool: ...
|
||||||
|
|||||||
27
kitty/glfw.c
27
kitty/glfw.c
@@ -1257,32 +1257,6 @@ glfw_get_key_name(PyObject UNUSED *self, PyObject *args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool
|
|
||||||
is_modifier_key(const uint32_t key) {
|
|
||||||
START_ALLOW_CASE_RANGE
|
|
||||||
switch (key) {
|
|
||||||
case GLFW_FKEY_LEFT_SHIFT ... GLFW_FKEY_ISO_LEVEL5_SHIFT:
|
|
||||||
case GLFW_FKEY_CAPS_LOCK:
|
|
||||||
case GLFW_FKEY_SCROLL_LOCK:
|
|
||||||
case GLFW_FKEY_NUM_LOCK:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
END_ALLOW_CASE_RANGE
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static PyObject*
|
|
||||||
glfw_is_modifier_key(PyObject UNUSED *self, PyObject *args) {
|
|
||||||
uint32_t key;
|
|
||||||
if (!PyArg_ParseTuple(args, "I", &key)) return NULL;
|
|
||||||
PyObject *ans = is_modifier_key(key) ? Py_True : Py_False;
|
|
||||||
Py_INCREF(ans);
|
|
||||||
return ans;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
glfw_window_hint(PyObject UNUSED *self, PyObject *args) {
|
glfw_window_hint(PyObject UNUSED *self, PyObject *args) {
|
||||||
int key, val;
|
int key, val;
|
||||||
@@ -1789,7 +1763,6 @@ static PyMethodDef module_methods[] = {
|
|||||||
{"glfw_terminate", (PyCFunction)glfw_terminate, METH_NOARGS, ""},
|
{"glfw_terminate", (PyCFunction)glfw_terminate, METH_NOARGS, ""},
|
||||||
{"glfw_get_physical_dpi", (PyCFunction)glfw_get_physical_dpi, METH_NOARGS, ""},
|
{"glfw_get_physical_dpi", (PyCFunction)glfw_get_physical_dpi, METH_NOARGS, ""},
|
||||||
{"glfw_get_key_name", (PyCFunction)glfw_get_key_name, METH_VARARGS, ""},
|
{"glfw_get_key_name", (PyCFunction)glfw_get_key_name, METH_VARARGS, ""},
|
||||||
METHODB(glfw_is_modifier_key, METH_VARARGS),
|
|
||||||
{"glfw_primary_monitor_size", (PyCFunction)primary_monitor_size, METH_NOARGS, ""},
|
{"glfw_primary_monitor_size", (PyCFunction)primary_monitor_size, METH_NOARGS, ""},
|
||||||
{"glfw_primary_monitor_content_scale", (PyCFunction)primary_monitor_content_scale, METH_NOARGS, ""},
|
{"glfw_primary_monitor_content_scale", (PyCFunction)primary_monitor_content_scale, METH_NOARGS, ""},
|
||||||
{NULL, NULL, 0, NULL} /* Sentinel */
|
{NULL, NULL, 0, NULL} /* Sentinel */
|
||||||
|
|||||||
65
kitty/keys.c
65
kitty/keys.c
@@ -30,6 +30,21 @@ new(PyTypeObject *type UNUSED, PyObject *args, PyObject *kw) {
|
|||||||
return convert_glfw_key_event_to_python(&ev);
|
return convert_glfw_key_event_to_python(&ev);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
is_modifier_key(const uint32_t key) {
|
||||||
|
START_ALLOW_CASE_RANGE
|
||||||
|
switch (key) {
|
||||||
|
case GLFW_FKEY_LEFT_SHIFT ... GLFW_FKEY_ISO_LEVEL5_SHIFT:
|
||||||
|
case GLFW_FKEY_CAPS_LOCK:
|
||||||
|
case GLFW_FKEY_SCROLL_LOCK:
|
||||||
|
case GLFW_FKEY_NUM_LOCK:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
END_ALLOW_CASE_RANGE
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dealloc(PyKeyEvent* self) {
|
dealloc(PyKeyEvent* self) {
|
||||||
Py_CLEAR(self->key); Py_CLEAR(self->shifted_key); Py_CLEAR(self->alternate_key);
|
Py_CLEAR(self->key); Py_CLEAR(self->shifted_key); Py_CLEAR(self->alternate_key);
|
||||||
@@ -164,22 +179,20 @@ on_key_input(GLFWkeyevent *ev) {
|
|||||||
debug("invalid state, ignoring\n");
|
debug("invalid state, ignoring\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PyObject *ke = NULL;
|
bool dispatch_ok = true, consumed = false;
|
||||||
#define create_key_event() { ke = convert_glfw_key_event_to_python(ev); if (!ke) { PyErr_Print(); return; } }
|
#define dispatch_key_event(name) { \
|
||||||
|
PyObject *ke = NULL, *ret = NULL; \
|
||||||
|
ke = convert_glfw_key_event_to_python(ev); if (!ke) { PyErr_Print(); return; }; \
|
||||||
|
ret = PyObject_CallMethod(global_state.boss, #name, "O", ke); Py_CLEAR(ke); \
|
||||||
|
if (ret == NULL) { PyErr_Print(); dispatch_ok = false; } \
|
||||||
|
else { consumed = ret == Py_True; Py_CLEAR(ret); } \
|
||||||
|
w = window_for_window_id(active_window_id); \
|
||||||
|
}
|
||||||
if (global_state.in_sequence_mode) {
|
if (global_state.in_sequence_mode) {
|
||||||
debug("in sequence mode, handling as a potential shortcut\n");
|
debug("in sequence mode, handling as a potential shortcut\n");
|
||||||
create_key_event();
|
dispatch_key_event(process_sequence);
|
||||||
PyObject *ret = PyObject_CallMethod(
|
if (dispatch_ok) {
|
||||||
global_state.boss, "process_sequence", "O", ke);
|
if (consumed && action != GLFW_RELEASE && w && !is_modifier_key(key)) {
|
||||||
Py_CLEAR(ke);
|
|
||||||
// the shortcut could have created a new window or closed the
|
|
||||||
// window, rendering the pointer no longer valid
|
|
||||||
w = window_for_window_id(active_window_id);
|
|
||||||
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;
|
w->last_special_key_pressed = key;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -187,18 +200,9 @@ on_key_input(GLFWkeyevent *ev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (action == GLFW_PRESS || action == GLFW_REPEAT) {
|
if (action == GLFW_PRESS || action == GLFW_REPEAT) {
|
||||||
create_key_event();
|
|
||||||
w->last_special_key_pressed = 0;
|
w->last_special_key_pressed = 0;
|
||||||
PyObject *ret = PyObject_CallMethod(global_state.boss, "dispatch_possible_special_key", "O", ke);
|
dispatch_key_event(dispatch_possible_special_key);
|
||||||
Py_CLEAR(ke);
|
if (dispatch_ok) {
|
||||||
bool consumed = false;
|
|
||||||
// the shortcut could have created a new window or closed the
|
|
||||||
// window, rendering the pointer no longer valid
|
|
||||||
w = window_for_window_id(active_window_id);
|
|
||||||
if (ret == NULL) { PyErr_Print(); }
|
|
||||||
else {
|
|
||||||
consumed = ret == Py_True;
|
|
||||||
Py_DECREF(ret);
|
|
||||||
if (consumed) {
|
if (consumed) {
|
||||||
debug("handled as shortcut\n");
|
debug("handled as shortcut\n");
|
||||||
if (w) w->last_special_key_pressed = key;
|
if (w) w->last_special_key_pressed = key;
|
||||||
@@ -211,7 +215,7 @@ on_key_input(GLFWkeyevent *ev) {
|
|||||||
debug("ignoring release event for previous press that was handled as shortcut\n");
|
debug("ignoring release event for previous press that was handled as shortcut\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#undef create_key_event
|
#undef dispatch_key_event
|
||||||
if (action == GLFW_REPEAT && !screen->modes.mDECARM) {
|
if (action == GLFW_REPEAT && !screen->modes.mDECARM) {
|
||||||
debug("discarding repeat key event as DECARM is off\n");
|
debug("discarding repeat key event as DECARM is off\n");
|
||||||
return;
|
return;
|
||||||
@@ -293,9 +297,18 @@ pyencode_key_for_tty(PyObject *self UNUSED, PyObject *args, PyObject *kw) {
|
|||||||
return PyUnicode_FromStringAndSize(output, MAX(0, num));
|
return PyUnicode_FromStringAndSize(output, MAX(0, num));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
pyis_modifier_key(PyObject *self UNUSED, PyObject *a) {
|
||||||
|
unsigned long key = PyLong_AsUnsignedLong(a);
|
||||||
|
if (PyErr_Occurred()) return NULL;
|
||||||
|
if (is_modifier_key(key)) { Py_RETURN_TRUE; }
|
||||||
|
Py_RETURN_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static PyMethodDef module_methods[] = {
|
static PyMethodDef module_methods[] = {
|
||||||
M(key_for_native_key_name, METH_VARARGS),
|
M(key_for_native_key_name, METH_VARARGS),
|
||||||
M(encode_key_for_tty, METH_VARARGS | METH_KEYWORDS),
|
M(encode_key_for_tty, METH_VARARGS | METH_KEYWORDS),
|
||||||
|
M(is_modifier_key, METH_O),
|
||||||
{0}
|
{0}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -18,6 +18,5 @@
|
|||||||
int
|
int
|
||||||
encode_glfw_key_event(const GLFWkeyevent *e, const bool cursor_key_mode, const unsigned flags, char *output);
|
encode_glfw_key_event(const GLFWkeyevent *e, const bool cursor_key_mode, const unsigned flags, char *output);
|
||||||
|
|
||||||
// Defined in glfw.c
|
bool
|
||||||
extern bool
|
|
||||||
is_modifier_key(const uint32_t key);
|
is_modifier_key(const uint32_t key);
|
||||||
|
|||||||
Reference in New Issue
Block a user