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
# License: GPLv3 Copyright: 2021, Kovid Goyal <kovid at kovidgoyal.net>
functional_key_names = ( # {{{
'escape',
'enter',
'tab',
'backspace',
'insert',
'delete',
'right',
'left',
'down',
'up',
'page_up',
'page_down',
'home',
'end',
'caps_lock',
'scroll_lock',
'num_lock',
'print_screen',
'pause',
'f1',
'f2',
'f3',
'f4',
'f5',
'f6',
'f7',
'f8',
'f9',
'f10',
'f11',
'f12',
'f13',
'f14',
'f15',
'f16',
'f17',
'f18',
'f19',
'f20',
'f21',
'f22',
'f23',
'f24',
'f25',
'f26',
'f27',
'f28',
'f29',
'f30',
'f31',
'f32',
'f33',
'f34',
'f35',
'kp_0',
'kp_1',
'kp_2',
'kp_3',
'kp_4',
'kp_5',
'kp_6',
'kp_7',
'kp_8',
'kp_9',
'kp_decimal',
'kp_divide',
'kp_multiply',
'kp_subtract',
'kp_add',
'kp_enter',
'kp_equal',
'left_shift',
'left_control',
'left_alt',
'left_super',
'right_shift',
'right_control',
'right_alt',
'right_super',
'media_play',
'media_pause',
'media_play_pause',
'media_reverse',
'media_stop',
'media_fast_forward',
'media_rewind',
'media_track_next',
'media_track_previous',
'media_record',
'menu',
) # }}}
from typing import Dict, List
functional_key_defs = '''\
# kitty XKB macOS
escape Escape -
enter Return -
tab Tab -
backspace Backspace -
insert Insert -
delete Delete -
left Left -
right Right -
up Up -
down Down -
page_up Page_Up -
page_down Page_Down -
home Home -
end End -
caps_lock Caps_Lock -
scroll_lock Scroll_Lock -
num_lock Num_Lock -
print_screen Print -
pause Pause -
menu Menu -
f1 F1 -
f2 F2 -
f3 F3 -
f4 F4 -
f5 F5 -
f6 F6 -
f7 F7 -
f8 F8 -
f9 F9 -
f10 F10 -
f11 F11 -
f12 F12 -
f13 F13 -
f14 F14 -
f15 F15 -
f16 F16 -
f17 F17 -
f18 F18 -
f19 F19 -
f20 F20 -
f21 F21 -
f22 F22 -
f23 F23 -
f24 F24 -
f25 F25 -
f26 F26 -
f27 F27 -
f28 F28 -
f29 F29 -
f30 F30 -
f31 F31 -
f32 F32 -
f33 F33 -
f34 F34 -
f35 F35 -
kp_0 KP_0 -
kp_1 KP_1 -
kp_2 KP_2 -
kp_3 KP_3 -
kp_4 KP_4 -
kp_5 KP_5 -
kp_6 KP_6 -
kp_7 KP_7 -
kp_8 KP_8 -
kp_9 KP_9 -
kp_decimal KP_Decimal -
kp_divide KP_Divide -
kp_multiply KP_Multiply -
kp_subtract KP_Subtract -
kp_add KP_Add -
kp_enter KP_Enter -
kp_equal KP_Equal -
left_shift Shift_L -
left_control Control_L -
left_alt Alt_L -
left_super Super_L -
right_shift Shift_R -
right_control Control_R -
right_alt Alt_R -
right_super Super_R -
media_play XF86AudioPlay -
media_pause XF86AudioPause -
media_play_pause - -
media_reverse XF86AudioRewind -
media_stop XF86AudioStop -
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
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
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:
lines = [
'/* start functional key names */',
'typedef enum {',
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_LAST = 0x{last_code:x}')
lines.append('} GLFWFunctionKey;')
end_marker = '/* end functional key names */'
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)
patch_file('glfw/glfw3.h', 'functional key names', '\n'.join(lines))
def main() -> None:

155
glfw/glfw3.h vendored
View File

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