Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Compat with Ctrl while on other keyboard layouts
Browse files Browse the repository at this point in the history
When using a different layout other than qwerty some Ctrl commands may
be interpreted as the hardware key it is usually tied to. This is worked
by working on "key" and "char" callback on glfw, where "key" is the
hardware key and "char" is the layout-translated actual key.
This key can be gathered by using (taken from glfw tests/events.c)
```c
glfwGetKeyName(key, scancode)
```
  • Loading branch information
sebosp committed Jan 8, 2017
1 parent 935e7a9 commit 802333c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
10 changes: 8 additions & 2 deletions kitty/boss.py
Expand Up @@ -254,7 +254,7 @@ def on_text_input(self, window, codepoint, mods):
w.write_to_child(data)

@callback
def on_key(self, window, key, scancode, action, mods):
def on_key(self, window, key, scancode, action, mods, name):
is_key_pressed[key] = action == GLFW_PRESS
self.start_cursor_blink()
self.cursor_blink_zero_time = monotonic()
Expand All @@ -281,7 +281,13 @@ def on_key(self, window, key, scancode, action, mods):
if window.screen.auto_repeat_enabled or action == GLFW_PRESS:
if window.char_grid.scrolled_by and key not in MODIFIER_KEYS:
window.scroll_end()
data = interpret_key_event(key, scancode, mods)
# name variable comes with effective casing but the control codes
# are set towards strictly upppercase letters, so we uppercase them:
data = None
if name is not None:
data = interpret_key_event(ord(name.upper()), scancode, mods, name)
else:
data = interpret_key_event(key, scancode, mods, name)
if data:
window.write_to_child(data)

Expand Down
2 changes: 1 addition & 1 deletion kitty/glfw.c
Expand Up @@ -59,7 +59,7 @@ char_mods_callback(GLFWwindow *w, unsigned int codepoint, int mods) {

static void
key_callback(GLFWwindow *w, int key, int scancode, int action, int mods) {
WINDOW_CALLBACK(key_callback, "iiii", key, scancode, action, mods);
WINDOW_CALLBACK(key_callback, "iiiis", key, scancode, action, mods, glfwGetKeyName(key, scancode));
}

static void
Expand Down
2 changes: 1 addition & 1 deletion kitty/keys.py
Expand Up @@ -48,7 +48,7 @@
alt_codes = {k: (0x1b, k) for i, k in enumerate(range(defines.GLFW_KEY_SPACE, defines.GLFW_KEY_RIGHT_BRACKET + 1))}


def interpret_key_event(key, scancode, mods):
def interpret_key_event(key, scancode, mods, name):
data = bytearray()
if mods == defines.GLFW_MOD_CONTROL and key in control_codes:
# Map Ctrl-key to ascii control code
Expand Down

0 comments on commit 802333c

Please sign in to comment.