Rename all uses of 'scancode' to 'native_key' where relevant
This commit is contained in:
@@ -512,27 +512,27 @@ class Boss:
|
||||
if t is not None:
|
||||
return t.active_window
|
||||
|
||||
def dispatch_special_key(self, key, scancode, action, mods):
|
||||
def dispatch_special_key(self, key, native_key, action, mods):
|
||||
# Handles shortcuts, return True if the key was consumed
|
||||
key_action = get_shortcut(self.keymap, mods, key, scancode)
|
||||
key_action = get_shortcut(self.keymap, mods, key, native_key)
|
||||
if key_action is None:
|
||||
sequences = get_shortcut(self.opts.sequence_map, mods, key, scancode)
|
||||
sequences = get_shortcut(self.opts.sequence_map, mods, key, native_key)
|
||||
if sequences:
|
||||
self.pending_sequences = sequences
|
||||
set_in_sequence_mode(True)
|
||||
return True
|
||||
else:
|
||||
self.current_key_press_info = key, scancode, action, mods
|
||||
self.current_key_press_info = key, native_key, action, mods
|
||||
return self.dispatch_action(key_action)
|
||||
|
||||
def process_sequence(self, key, scancode, action, mods):
|
||||
def process_sequence(self, key, native_key, action, mods):
|
||||
if not self.pending_sequences:
|
||||
set_in_sequence_mode(False)
|
||||
|
||||
remaining = {}
|
||||
matched_action = None
|
||||
for seq, key_action in self.pending_sequences.items():
|
||||
if shortcut_matches(seq[0], mods, key, scancode):
|
||||
if shortcut_matches(seq[0], mods, key, native_key):
|
||||
seq = seq[1:]
|
||||
if seq:
|
||||
remaining[seq] = key_action
|
||||
|
||||
6
kitty/glfw-wrapper.c
generated
6
kitty/glfw-wrapper.c
generated
@@ -245,8 +245,8 @@ load_glfw(const char* path) {
|
||||
*(void **) (&glfwGetKeyName_impl) = dlsym(handle, "glfwGetKeyName");
|
||||
if (glfwGetKeyName_impl == NULL) fail("Failed to load glfw function glfwGetKeyName with error: %s", dlerror());
|
||||
|
||||
*(void **) (&glfwGetKeyScancode_impl) = dlsym(handle, "glfwGetKeyScancode");
|
||||
if (glfwGetKeyScancode_impl == NULL) fail("Failed to load glfw function glfwGetKeyScancode with error: %s", dlerror());
|
||||
*(void **) (&glfwGetNativeKeyForKey_impl) = dlsym(handle, "glfwGetNativeKeyForKey");
|
||||
if (glfwGetNativeKeyForKey_impl == NULL) fail("Failed to load glfw function glfwGetNativeKeyForKey with error: %s", dlerror());
|
||||
|
||||
*(void **) (&glfwGetKey_impl) = dlsym(handle, "glfwGetKey");
|
||||
if (glfwGetKey_impl == NULL) fail("Failed to load glfw function glfwGetKey with error: %s", dlerror());
|
||||
@@ -401,7 +401,7 @@ load_glfw(const char* path) {
|
||||
|
||||
*(void **) (&glfwGetPrimarySelectionString_impl) = dlsym(handle, "glfwGetPrimarySelectionString");
|
||||
|
||||
*(void **) (&glfwGetXKBScancode_impl) = dlsym(handle, "glfwGetXKBScancode");
|
||||
*(void **) (&glfwGetNativeKeyForName_impl) = dlsym(handle, "glfwGetNativeKeyForName");
|
||||
|
||||
*(void **) (&glfwRequestWaylandFrameEvent_impl) = dlsym(handle, "glfwRequestWaylandFrameEvent");
|
||||
|
||||
|
||||
18
kitty/glfw-wrapper.h
generated
18
kitty/glfw-wrapper.h
generated
@@ -971,8 +971,8 @@ typedef struct GLFWkeyevent
|
||||
// The [keyboard key](@ref keys) that was pressed or released.
|
||||
int key;
|
||||
|
||||
// The system-specific scancode of the key.
|
||||
int scancode;
|
||||
// The native key identifier of the key.
|
||||
int native_key;
|
||||
|
||||
// The event action. Either `GLFW_PRESS`, `GLFW_RELEASE` or `GLFW_REPEAT`.
|
||||
int action;
|
||||
@@ -1325,7 +1325,7 @@ typedef void (* GLFWscrollfun)(GLFWwindow*,double,double,int);
|
||||
* This is the function pointer type for key callbacks. A keyboard
|
||||
* key callback function has the following signature:
|
||||
* @code
|
||||
* void function_name(GLFWwindow* window, int key, int scancode, int action, int mods)
|
||||
* void function_name(GLFWwindow* window, int key, int native_key, int action, int mods)
|
||||
* @endcode
|
||||
* The semantics of this function are that the key that is interacted with on the
|
||||
* keyboard is reported, and the text, if any generated by the key is reported.
|
||||
@@ -1889,9 +1889,9 @@ typedef const char* (*glfwGetKeyName_func)(int, int);
|
||||
glfwGetKeyName_func glfwGetKeyName_impl;
|
||||
#define glfwGetKeyName glfwGetKeyName_impl
|
||||
|
||||
typedef int (*glfwGetKeyScancode_func)(int);
|
||||
glfwGetKeyScancode_func glfwGetKeyScancode_impl;
|
||||
#define glfwGetKeyScancode glfwGetKeyScancode_impl
|
||||
typedef int (*glfwGetNativeKeyForKey_func)(int);
|
||||
glfwGetNativeKeyForKey_func glfwGetNativeKeyForKey_impl;
|
||||
#define glfwGetNativeKeyForKey glfwGetNativeKeyForKey_impl
|
||||
|
||||
typedef int (*glfwGetKey_func)(GLFWwindow*, int);
|
||||
glfwGetKey_func glfwGetKey_impl;
|
||||
@@ -2113,9 +2113,9 @@ typedef const char* (*glfwGetPrimarySelectionString_func)(GLFWwindow*);
|
||||
glfwGetPrimarySelectionString_func glfwGetPrimarySelectionString_impl;
|
||||
#define glfwGetPrimarySelectionString glfwGetPrimarySelectionString_impl
|
||||
|
||||
typedef int (*glfwGetXKBScancode_func)(const char*, int);
|
||||
glfwGetXKBScancode_func glfwGetXKBScancode_impl;
|
||||
#define glfwGetXKBScancode glfwGetXKBScancode_impl
|
||||
typedef int (*glfwGetNativeKeyForName_func)(const char*, int);
|
||||
glfwGetNativeKeyForName_func glfwGetNativeKeyForName_impl;
|
||||
#define glfwGetNativeKeyForName glfwGetNativeKeyForName_impl
|
||||
|
||||
typedef void (*glfwRequestWaylandFrameEvent_func)(GLFWwindow*, unsigned long long, GLFWwaylandframecallbackfunc);
|
||||
glfwRequestWaylandFrameEvent_func glfwRequestWaylandFrameEvent_impl;
|
||||
|
||||
@@ -451,7 +451,7 @@ toggle_maximized_for_os_window(OSWindow *w) {
|
||||
|
||||
#ifdef __APPLE__
|
||||
static int
|
||||
filter_option(int key UNUSED, int mods, unsigned int scancode UNUSED, unsigned long flags) {
|
||||
filter_option(int key UNUSED, int mods, unsigned int native_key UNUSED, unsigned long flags) {
|
||||
if ((mods == GLFW_MOD_ALT) || (mods == (GLFW_MOD_ALT | GLFW_MOD_SHIFT))) {
|
||||
if (OPT(macos_option_as_alt) == 3) return 1;
|
||||
if (cocoa_alt_option_key_pressed(flags)) return 1;
|
||||
@@ -830,9 +830,9 @@ glfw_get_physical_dpi(PYNOARG) {
|
||||
|
||||
static PyObject*
|
||||
glfw_get_key_name(PyObject UNUSED *self, PyObject *args) {
|
||||
int key, scancode;
|
||||
if (!PyArg_ParseTuple(args, "ii", &key, &scancode)) return NULL;
|
||||
return Py_BuildValue("s", glfwGetKeyName(key, scancode));
|
||||
int key, native_key;
|
||||
if (!PyArg_ParseTuple(args, "ii", &key, &native_key)) return NULL;
|
||||
return Py_BuildValue("s", glfwGetKeyName(key, native_key));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
|
||||
27
kitty/keys.c
27
kitty/keys.c
@@ -26,7 +26,7 @@ key_to_bytes(int glfw_key, bool smkx, bool extended, int mods, int action) {
|
||||
#define SPECIAL_INDEX(key) ((key & 0x7f) | ( (mods & 0xF) << 7))
|
||||
#define IS_ALT_MODS(mods) (mods == GLFW_MOD_ALT || mods == (GLFW_MOD_ALT | GLFW_MOD_SHIFT))
|
||||
|
||||
typedef struct { int mods, scancode; } NativeKey;
|
||||
typedef struct { int mods, native_key; } NativeKey;
|
||||
static NativeKey *native_special_keys = NULL;
|
||||
static size_t native_special_keys_capacity = 0, native_special_keys_count = 0;
|
||||
|
||||
@@ -39,7 +39,7 @@ set_special_key_combo(int glfw_key, int mods, bool is_native) {
|
||||
if (native_special_keys == NULL) fatal("Out of memory");
|
||||
}
|
||||
native_special_keys[native_special_keys_count].mods = mods;
|
||||
native_special_keys[native_special_keys_count++].scancode = glfw_key;
|
||||
native_special_keys[native_special_keys_count++].native_key = glfw_key;
|
||||
} else {
|
||||
uint16_t key = key_map[glfw_key];
|
||||
if (key != UINT8_MAX) {
|
||||
@@ -96,7 +96,7 @@ is_ascii_control_char(char c) {
|
||||
}
|
||||
|
||||
static inline bool
|
||||
check_if_special(int key, int mods, int scancode) {
|
||||
check_if_special(int key, int mods, int native_key) {
|
||||
uint16_t qkey = (0 <= key && key < (ssize_t)arraysz(key_map)) ? key_map[key] : UINT8_MAX;
|
||||
bool special = false;
|
||||
if (qkey != UINT8_MAX) {
|
||||
@@ -104,7 +104,8 @@ check_if_special(int key, int mods, int scancode) {
|
||||
special = needs_special_handling[qkey];
|
||||
}
|
||||
for (size_t i = 0; !special && i < native_special_keys_count; i++) {
|
||||
if (scancode == native_special_keys[i].scancode && mods == native_special_keys[i].mods) special = true;
|
||||
if (native_key == native_special_keys[i].native_key && mods == native_special_keys[i].mods)
|
||||
special = true;
|
||||
}
|
||||
return special;
|
||||
}
|
||||
@@ -123,11 +124,11 @@ update_ime_position(OSWindow *os_window, Window* w, Screen *screen) {
|
||||
void
|
||||
on_key_input(GLFWkeyevent *ev) {
|
||||
Window *w = active_window();
|
||||
int action = ev->action, scancode = ev->scancode, key = ev->key, mods = ev->mods;
|
||||
int action = ev->action, native_key = ev->native_key, key = ev->key, mods = ev->mods;
|
||||
const char *text = ev->text ? ev->text : "";
|
||||
|
||||
debug("on_key_input: glfw key: %d native_code: 0x%x action: %s mods: 0x%x text: '%s' state: %d ",
|
||||
key, scancode,
|
||||
debug("on_key_input: glfw key: %d native_key: 0x%x action: %s mods: 0x%x text: '%s' state: %d ",
|
||||
key, native_key,
|
||||
(action == GLFW_RELEASE ? "RELEASE" : (action == GLFW_PRESS ? "PRESS" : "REPEAT")),
|
||||
mods, text, ev->ime_state);
|
||||
if (!w) { debug("no active window, ignoring\n"); return; }
|
||||
@@ -161,13 +162,13 @@ on_key_input(GLFWkeyevent *ev) {
|
||||
if (
|
||||
action != GLFW_RELEASE &&
|
||||
key != GLFW_KEY_LEFT_SHIFT && key != GLFW_KEY_RIGHT_SHIFT && key != GLFW_KEY_LEFT_ALT && key != GLFW_KEY_RIGHT_ALT && key != GLFW_KEY_LEFT_CONTROL && key != GLFW_KEY_RIGHT_CONTROL
|
||||
) call_boss(process_sequence, "iiii", key, scancode, action, mods);
|
||||
) call_boss(process_sequence, "iiii", key, native_key, action, mods);
|
||||
return;
|
||||
}
|
||||
bool has_text = text[0] && !is_ascii_control_char(text[0]);
|
||||
if (action == GLFW_PRESS || action == GLFW_REPEAT) {
|
||||
if (check_if_special(key, mods, scancode)) {
|
||||
PyObject *ret = PyObject_CallMethod(global_state.boss, "dispatch_special_key", "iiii", key, scancode, action, mods);
|
||||
if (check_if_special(key, mods, native_key)) {
|
||||
PyObject *ret = PyObject_CallMethod(global_state.boss, "dispatch_special_key", "iiii", key, native_key, action, mods);
|
||||
if (ret == NULL) { PyErr_Print(); }
|
||||
else {
|
||||
bool consumed = ret == Py_True;
|
||||
@@ -228,9 +229,9 @@ PYWRAP1(key_for_native_key_name) {
|
||||
int case_sensitive = 0;
|
||||
PA("s|p", &name, &case_sensitive);
|
||||
#ifndef __APPLE__
|
||||
if (glfwGetXKBScancode) { // if this function is called before GLFW is initialized glfwGetXKBScancode will be NULL
|
||||
int scancode = glfwGetXKBScancode(name, case_sensitive);
|
||||
if (scancode) return Py_BuildValue("i", scancode);
|
||||
if (glfwGetNativeKeyForName) { // if this function is called before GLFW is initialized glfwGetNativeKeyForName will be NULL
|
||||
int native_key = glfwGetNativeKeyForName(name, case_sensitive);
|
||||
if (native_key) return Py_BuildValue("i", native_key);
|
||||
}
|
||||
#endif
|
||||
Py_RETURN_NONE;
|
||||
|
||||
@@ -264,7 +264,7 @@ def key_to_bytes(key, smkx, extended, mods, action):
|
||||
return bytes(data)
|
||||
|
||||
|
||||
def interpret_key_event(key, scancode, mods, window, action):
|
||||
def interpret_key_event(key, native_key, mods, window, action):
|
||||
screen = window.screen
|
||||
if (
|
||||
action == defines.GLFW_PRESS or
|
||||
@@ -275,17 +275,17 @@ def interpret_key_event(key, scancode, mods, window, action):
|
||||
return b''
|
||||
|
||||
|
||||
def get_shortcut(keymap, mods, key, scancode):
|
||||
def get_shortcut(keymap, mods, key, native_key):
|
||||
mods &= 0b1111
|
||||
ans = keymap.get((mods, False, key))
|
||||
if ans is None:
|
||||
ans = keymap.get((mods, True, scancode))
|
||||
ans = keymap.get((mods, True, native_key))
|
||||
return ans
|
||||
|
||||
|
||||
def shortcut_matches(s, mods, key, scancode):
|
||||
def shortcut_matches(s, mods, key, native_key):
|
||||
mods &= 0b1111
|
||||
q = scancode if s[1] else key
|
||||
q = native_key if s[1] else key
|
||||
return s[0] & 0b1111 == mods & 0b1111 and s[2] == q
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user