mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 10:41:58 +02:00
A spot of refactoring
This commit is contained in:
@@ -144,7 +144,7 @@ action_map = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def extended_key_event(key, scancode, mods, action):
|
def extended_key_event(key, mods, action):
|
||||||
if key >= defines.GLFW_KEY_LAST or key == defines.GLFW_KEY_UNKNOWN or (
|
if key >= defines.GLFW_KEY_LAST or key == defines.GLFW_KEY_UNKNOWN or (
|
||||||
# Shifted printable key should be handled by interpret_text_event()
|
# Shifted printable key should be handled by interpret_text_event()
|
||||||
mods == defines.GLFW_MOD_SHIFT and 32 <= key <= 126
|
mods == defines.GLFW_MOD_SHIFT and 32 <= key <= 126
|
||||||
@@ -162,29 +162,36 @@ def extended_key_event(key, scancode, mods, action):
|
|||||||
).encode('ascii')
|
).encode('ascii')
|
||||||
|
|
||||||
|
|
||||||
|
def key_to_bytes(key, smkx, extended, mods, action):
|
||||||
|
if extended:
|
||||||
|
return extended_key_event(key, mods, action)
|
||||||
|
data = bytearray()
|
||||||
|
if mods == defines.GLFW_MOD_CONTROL and key in control_codes:
|
||||||
|
# Map Ctrl-key to ascii control code
|
||||||
|
data.extend(control_codes[key])
|
||||||
|
elif mods in alt_mods and key in alt_codes:
|
||||||
|
# Printable keys handled by interpret_text_event()
|
||||||
|
data.extend((alt_codes if mods == defines.GLFW_MOD_ALT else shift_alt_codes)[key])
|
||||||
|
else:
|
||||||
|
key_map = cursor_key_mode_map[smkx]
|
||||||
|
x = key_map.get(key)
|
||||||
|
if x is not None:
|
||||||
|
if mods == defines.GLFW_MOD_SHIFT:
|
||||||
|
x = SHIFTED_KEYS.get(key, x)
|
||||||
|
data.extend(x)
|
||||||
|
return bytes(data)
|
||||||
|
|
||||||
|
|
||||||
def interpret_key_event(key, scancode, mods, window, action, get_localized_key=get_localized_key):
|
def interpret_key_event(key, scancode, mods, window, action, get_localized_key=get_localized_key):
|
||||||
screen = window.screen
|
screen = window.screen
|
||||||
key = get_localized_key(key, scancode)
|
if (
|
||||||
if screen.extended_keyboard:
|
action == defines.GLFW_PRESS or
|
||||||
return extended_key_event(key, scancode, mods, action)
|
(action == defines.GLFW_REPEAT and screen.auto_repeat_enabled) or
|
||||||
data = bytearray()
|
screen.extended_keyboard
|
||||||
if action == defines.GLFW_PRESS or (
|
|
||||||
action == defines.GLFW_REPEAT and screen.auto_repeat_enabled
|
|
||||||
):
|
):
|
||||||
if mods == defines.GLFW_MOD_CONTROL and key in control_codes:
|
key = get_localized_key(key, scancode)
|
||||||
# Map Ctrl-key to ascii control code
|
return key_to_bytes(key, screen.cursor_key_mode, screen.extended_keyboard, mods, action)
|
||||||
data.extend(control_codes[key])
|
return b''
|
||||||
elif mods in alt_mods and key in alt_codes:
|
|
||||||
# Printable keys handled by interpret_text_event()
|
|
||||||
data.extend((alt_codes if mods == defines.GLFW_MOD_ALT else shift_alt_codes)[key])
|
|
||||||
else:
|
|
||||||
key_map = get_key_map(screen)
|
|
||||||
x = key_map.get(key)
|
|
||||||
if x is not None:
|
|
||||||
if mods == defines.GLFW_MOD_SHIFT:
|
|
||||||
x = SHIFTED_KEYS.get(key, x)
|
|
||||||
data.extend(x)
|
|
||||||
return bytes(data)
|
|
||||||
|
|
||||||
|
|
||||||
def interpret_text_event(codepoint, mods, window):
|
def interpret_text_event(codepoint, mods, window):
|
||||||
|
|||||||
Reference in New Issue
Block a user