Add some more functional keys

Also define aliases for XKB codes
This commit is contained in:
Kovid Goyal 2021-01-09 12:48:19 +05:30
parent 397d7d044b
commit eb8e2225e5
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 203 additions and 180 deletions

View File

@ -2,106 +2,135 @@
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
functional_key_names = ( # {{{ from typing import Dict, List
'escape',
'enter',
'tab', functional_key_defs = '''\
'backspace', # kitty XKB macOS
'insert', escape Escape -
'delete', enter Return -
'right', tab Tab -
'left', backspace Backspace -
'down', insert Insert -
'up', delete Delete -
'page_up', left Left -
'page_down', right Right -
'home', up Up -
'end', down Down -
'caps_lock', page_up Page_Up -
'scroll_lock', page_down Page_Down -
'num_lock', home Home -
'print_screen', end End -
'pause', caps_lock Caps_Lock -
'f1', scroll_lock Scroll_Lock -
'f2', num_lock Num_Lock -
'f3', print_screen Print -
'f4', pause Pause -
'f5', menu Menu -
'f6', f1 F1 -
'f7', f2 F2 -
'f8', f3 F3 -
'f9', f4 F4 -
'f10', f5 F5 -
'f11', f6 F6 -
'f12', f7 F7 -
'f13', f8 F8 -
'f14', f9 F9 -
'f15', f10 F10 -
'f16', f11 F11 -
'f17', f12 F12 -
'f18', f13 F13 -
'f19', f14 F14 -
'f20', f15 F15 -
'f21', f16 F16 -
'f22', f17 F17 -
'f23', f18 F18 -
'f24', f19 F19 -
'f25', f20 F20 -
'f26', f21 F21 -
'f27', f22 F22 -
'f28', f23 F23 -
'f29', f24 F24 -
'f30', f25 F25 -
'f31', f26 F26 -
'f32', f27 F27 -
'f33', f28 F28 -
'f34', f29 F29 -
'f35', f30 F30 -
'kp_0', f31 F31 -
'kp_1', f32 F32 -
'kp_2', f33 F33 -
'kp_3', f34 F34 -
'kp_4', f35 F35 -
'kp_5', kp_0 KP_0 -
'kp_6', kp_1 KP_1 -
'kp_7', kp_2 KP_2 -
'kp_8', kp_3 KP_3 -
'kp_9', kp_4 KP_4 -
'kp_decimal', kp_5 KP_5 -
'kp_divide', kp_6 KP_6 -
'kp_multiply', kp_7 KP_7 -
'kp_subtract', kp_8 KP_8 -
'kp_add', kp_9 KP_9 -
'kp_enter', kp_decimal KP_Decimal -
'kp_equal', kp_divide KP_Divide -
'left_shift', kp_multiply KP_Multiply -
'left_control', kp_subtract KP_Subtract -
'left_alt', kp_add KP_Add -
'left_super', kp_enter KP_Enter -
'right_shift', kp_equal KP_Equal -
'right_control', left_shift Shift_L -
'right_alt', left_control Control_L -
'right_super', left_alt Alt_L -
'media_play', left_super Super_L -
'media_pause', right_shift Shift_R -
'media_play_pause', right_control Control_R -
'media_reverse', right_alt Alt_R -
'media_stop', right_super Super_R -
'media_fast_forward', media_play XF86AudioPlay -
'media_rewind', media_pause XF86AudioPause -
'media_track_next', media_play_pause - -
'media_track_previous', media_reverse XF86AudioRewind -
'media_record', media_stop XF86AudioStop -
'menu', media_fast_forward XF86AudioForward -
) # }}} media_rewind XF86AudioRewind -
media_track_next XF86AudioNext -
media_track_previous XF86AudioPrev -
media_record XF86AudioRecord -
lower_volume XF86AudioLowerVolume -
raise_volume XF86AudioRaiseVolume -
mute_volume XF86AudioMute -
'''
functional_key_names: List[str] = []
name_to_code: Dict[str, int] = {}
start_code = 0xe000 start_code = 0xe000
for line in functional_key_defs.splitlines():
line = line.strip()
if not line or line.startswith('#'):
continue
parts = line.split()
name = parts[0]
functional_key_names.append(name)
name_to_code[name] = len(name_to_code) + start_code
last_code = start_code + len(functional_key_names) - 1 last_code = start_code + len(functional_key_names) - 1
name_to_code = {n: start_code + i for i, n in enumerate(functional_key_names)}
def patch_file(path: str, what: str, text: str, start_marker: str = '/* ', end_marker: str = ' */') -> None:
start_q = f'{start_marker}start {what}{end_marker}'
end_q = f'{start_marker}end {what}{end_marker}'
with open(path, 'r+') as f:
raw = f.read()
start = raw.index(start_q)
end = raw.index(end_q)
raw = raw[:start] + start_q + '\n' + text + '\n' + raw[end:]
f.seek(0)
f.truncate(0)
f.write(raw)
def generate_glfw_header() -> None: def generate_glfw_header() -> None:
lines = [ lines = [
'/* start functional key names */',
'typedef enum {', 'typedef enum {',
f' GLFW_FKEY_FIRST = 0x{start_code:x},', f' GLFW_FKEY_FIRST = 0x{start_code:x},',
] ]
@ -109,16 +138,7 @@ def generate_glfw_header() -> None:
lines.append(f' GLFW_FKEY_{name.upper()} = 0x{code:x},') lines.append(f' GLFW_FKEY_{name.upper()} = 0x{code:x},')
lines.append(f' GLFW_FKEY_LAST = 0x{last_code:x}') lines.append(f' GLFW_FKEY_LAST = 0x{last_code:x}')
lines.append('} GLFWFunctionKey;') lines.append('} GLFWFunctionKey;')
end_marker = '/* end functional key names */' patch_file('glfw/glfw3.h', 'functional key names', '\n'.join(lines))
with open('glfw/glfw3.h', 'r+') as f:
text = f.read()
start = text.index(lines[0])
end = text.index(end_marker)
ntext = text[:start] + '\n'.join(lines) + '\n' + text[end:]
f.seek(0)
f.truncate()
f.write(ntext)
def main() -> None: def main() -> None:

155
glfw/glfw3.h vendored
View File

@ -351,10 +351,10 @@ typedef enum {
GLFW_FKEY_BACKSPACE = 0xe003, GLFW_FKEY_BACKSPACE = 0xe003,
GLFW_FKEY_INSERT = 0xe004, GLFW_FKEY_INSERT = 0xe004,
GLFW_FKEY_DELETE = 0xe005, GLFW_FKEY_DELETE = 0xe005,
GLFW_FKEY_RIGHT = 0xe006, GLFW_FKEY_LEFT = 0xe006,
GLFW_FKEY_LEFT = 0xe007, GLFW_FKEY_RIGHT = 0xe007,
GLFW_FKEY_DOWN = 0xe008, GLFW_FKEY_UP = 0xe008,
GLFW_FKEY_UP = 0xe009, GLFW_FKEY_DOWN = 0xe009,
GLFW_FKEY_PAGE_UP = 0xe00a, GLFW_FKEY_PAGE_UP = 0xe00a,
GLFW_FKEY_PAGE_DOWN = 0xe00b, GLFW_FKEY_PAGE_DOWN = 0xe00b,
GLFW_FKEY_HOME = 0xe00c, GLFW_FKEY_HOME = 0xe00c,
@ -364,78 +364,81 @@ typedef enum {
GLFW_FKEY_NUM_LOCK = 0xe010, GLFW_FKEY_NUM_LOCK = 0xe010,
GLFW_FKEY_PRINT_SCREEN = 0xe011, GLFW_FKEY_PRINT_SCREEN = 0xe011,
GLFW_FKEY_PAUSE = 0xe012, GLFW_FKEY_PAUSE = 0xe012,
GLFW_FKEY_F1 = 0xe013, GLFW_FKEY_MENU = 0xe013,
GLFW_FKEY_F2 = 0xe014, GLFW_FKEY_F1 = 0xe014,
GLFW_FKEY_F3 = 0xe015, GLFW_FKEY_F2 = 0xe015,
GLFW_FKEY_F4 = 0xe016, GLFW_FKEY_F3 = 0xe016,
GLFW_FKEY_F5 = 0xe017, GLFW_FKEY_F4 = 0xe017,
GLFW_FKEY_F6 = 0xe018, GLFW_FKEY_F5 = 0xe018,
GLFW_FKEY_F7 = 0xe019, GLFW_FKEY_F6 = 0xe019,
GLFW_FKEY_F8 = 0xe01a, GLFW_FKEY_F7 = 0xe01a,
GLFW_FKEY_F9 = 0xe01b, GLFW_FKEY_F8 = 0xe01b,
GLFW_FKEY_F10 = 0xe01c, GLFW_FKEY_F9 = 0xe01c,
GLFW_FKEY_F11 = 0xe01d, GLFW_FKEY_F10 = 0xe01d,
GLFW_FKEY_F12 = 0xe01e, GLFW_FKEY_F11 = 0xe01e,
GLFW_FKEY_F13 = 0xe01f, GLFW_FKEY_F12 = 0xe01f,
GLFW_FKEY_F14 = 0xe020, GLFW_FKEY_F13 = 0xe020,
GLFW_FKEY_F15 = 0xe021, GLFW_FKEY_F14 = 0xe021,
GLFW_FKEY_F16 = 0xe022, GLFW_FKEY_F15 = 0xe022,
GLFW_FKEY_F17 = 0xe023, GLFW_FKEY_F16 = 0xe023,
GLFW_FKEY_F18 = 0xe024, GLFW_FKEY_F17 = 0xe024,
GLFW_FKEY_F19 = 0xe025, GLFW_FKEY_F18 = 0xe025,
GLFW_FKEY_F20 = 0xe026, GLFW_FKEY_F19 = 0xe026,
GLFW_FKEY_F21 = 0xe027, GLFW_FKEY_F20 = 0xe027,
GLFW_FKEY_F22 = 0xe028, GLFW_FKEY_F21 = 0xe028,
GLFW_FKEY_F23 = 0xe029, GLFW_FKEY_F22 = 0xe029,
GLFW_FKEY_F24 = 0xe02a, GLFW_FKEY_F23 = 0xe02a,
GLFW_FKEY_F25 = 0xe02b, GLFW_FKEY_F24 = 0xe02b,
GLFW_FKEY_F26 = 0xe02c, GLFW_FKEY_F25 = 0xe02c,
GLFW_FKEY_F27 = 0xe02d, GLFW_FKEY_F26 = 0xe02d,
GLFW_FKEY_F28 = 0xe02e, GLFW_FKEY_F27 = 0xe02e,
GLFW_FKEY_F29 = 0xe02f, GLFW_FKEY_F28 = 0xe02f,
GLFW_FKEY_F30 = 0xe030, GLFW_FKEY_F29 = 0xe030,
GLFW_FKEY_F31 = 0xe031, GLFW_FKEY_F30 = 0xe031,
GLFW_FKEY_F32 = 0xe032, GLFW_FKEY_F31 = 0xe032,
GLFW_FKEY_F33 = 0xe033, GLFW_FKEY_F32 = 0xe033,
GLFW_FKEY_F34 = 0xe034, GLFW_FKEY_F33 = 0xe034,
GLFW_FKEY_F35 = 0xe035, GLFW_FKEY_F34 = 0xe035,
GLFW_FKEY_KP_0 = 0xe036, GLFW_FKEY_F35 = 0xe036,
GLFW_FKEY_KP_1 = 0xe037, GLFW_FKEY_KP_0 = 0xe037,
GLFW_FKEY_KP_2 = 0xe038, GLFW_FKEY_KP_1 = 0xe038,
GLFW_FKEY_KP_3 = 0xe039, GLFW_FKEY_KP_2 = 0xe039,
GLFW_FKEY_KP_4 = 0xe03a, GLFW_FKEY_KP_3 = 0xe03a,
GLFW_FKEY_KP_5 = 0xe03b, GLFW_FKEY_KP_4 = 0xe03b,
GLFW_FKEY_KP_6 = 0xe03c, GLFW_FKEY_KP_5 = 0xe03c,
GLFW_FKEY_KP_7 = 0xe03d, GLFW_FKEY_KP_6 = 0xe03d,
GLFW_FKEY_KP_8 = 0xe03e, GLFW_FKEY_KP_7 = 0xe03e,
GLFW_FKEY_KP_9 = 0xe03f, GLFW_FKEY_KP_8 = 0xe03f,
GLFW_FKEY_KP_DECIMAL = 0xe040, GLFW_FKEY_KP_9 = 0xe040,
GLFW_FKEY_KP_DIVIDE = 0xe041, GLFW_FKEY_KP_DECIMAL = 0xe041,
GLFW_FKEY_KP_MULTIPLY = 0xe042, GLFW_FKEY_KP_DIVIDE = 0xe042,
GLFW_FKEY_KP_SUBTRACT = 0xe043, GLFW_FKEY_KP_MULTIPLY = 0xe043,
GLFW_FKEY_KP_ADD = 0xe044, GLFW_FKEY_KP_SUBTRACT = 0xe044,
GLFW_FKEY_KP_ENTER = 0xe045, GLFW_FKEY_KP_ADD = 0xe045,
GLFW_FKEY_KP_EQUAL = 0xe046, GLFW_FKEY_KP_ENTER = 0xe046,
GLFW_FKEY_LEFT_SHIFT = 0xe047, GLFW_FKEY_KP_EQUAL = 0xe047,
GLFW_FKEY_LEFT_CONTROL = 0xe048, GLFW_FKEY_LEFT_SHIFT = 0xe048,
GLFW_FKEY_LEFT_ALT = 0xe049, GLFW_FKEY_LEFT_CONTROL = 0xe049,
GLFW_FKEY_LEFT_SUPER = 0xe04a, GLFW_FKEY_LEFT_ALT = 0xe04a,
GLFW_FKEY_RIGHT_SHIFT = 0xe04b, GLFW_FKEY_LEFT_SUPER = 0xe04b,
GLFW_FKEY_RIGHT_CONTROL = 0xe04c, GLFW_FKEY_RIGHT_SHIFT = 0xe04c,
GLFW_FKEY_RIGHT_ALT = 0xe04d, GLFW_FKEY_RIGHT_CONTROL = 0xe04d,
GLFW_FKEY_RIGHT_SUPER = 0xe04e, GLFW_FKEY_RIGHT_ALT = 0xe04e,
GLFW_FKEY_MEDIA_PLAY = 0xe04f, GLFW_FKEY_RIGHT_SUPER = 0xe04f,
GLFW_FKEY_MEDIA_PAUSE = 0xe050, GLFW_FKEY_MEDIA_PLAY = 0xe050,
GLFW_FKEY_MEDIA_PLAY_PAUSE = 0xe051, GLFW_FKEY_MEDIA_PAUSE = 0xe051,
GLFW_FKEY_MEDIA_REVERSE = 0xe052, GLFW_FKEY_MEDIA_PLAY_PAUSE = 0xe052,
GLFW_FKEY_MEDIA_STOP = 0xe053, GLFW_FKEY_MEDIA_REVERSE = 0xe053,
GLFW_FKEY_MEDIA_FAST_FORWARD = 0xe054, GLFW_FKEY_MEDIA_STOP = 0xe054,
GLFW_FKEY_MEDIA_REWIND = 0xe055, GLFW_FKEY_MEDIA_FAST_FORWARD = 0xe055,
GLFW_FKEY_MEDIA_TRACK_NEXT = 0xe056, GLFW_FKEY_MEDIA_REWIND = 0xe056,
GLFW_FKEY_MEDIA_TRACK_PREVIOUS = 0xe057, GLFW_FKEY_MEDIA_TRACK_NEXT = 0xe057,
GLFW_FKEY_MEDIA_RECORD = 0xe058, GLFW_FKEY_MEDIA_TRACK_PREVIOUS = 0xe058,
GLFW_FKEY_MENU = 0xe059, GLFW_FKEY_MEDIA_RECORD = 0xe059,
GLFW_FKEY_LAST = 0xe059 GLFW_FKEY_LOWER_VOLUME = 0xe05a,
GLFW_FKEY_RAISE_VOLUME = 0xe05b,
GLFW_FKEY_MUTE_VOLUME = 0xe05c,
GLFW_FKEY_LAST = 0xe05c
} GLFWFunctionKey; } GLFWFunctionKey;
/* end functional key names */ /* end functional key names */