2 from __future__ import print_function
7 # #define XF86XK_FooBar _EVDEVK(0x123) /* some optional comment */
8 evdev_pattern = re.compile(r'^#define\s+XF86XK_(?P<name>\w+)\s+_EVDEVK\((?P<value>0x[0-9A-Fa-f]+)\)')
10 prefix = os.environ.get('X11_HEADERS_PREFIX', '/usr')
12 prefix + '/include/X11/keysymdef.h',
13 prefix + '/include/X11/XF86keysym.h',
14 prefix + '/include/X11/Sunkeysym.h',
15 prefix + '/include/X11/DECkeysym.h',
16 prefix + '/include/X11/HPkeysym.h',
19 print('''#ifndef _XKBCOMMON_KEYSYMS_H
20 #define _XKBCOMMON_KEYSYMS_H
22 /* This file is autogenerated; please do not commit directly. */
26 * Key symbols (keysyms) definitions.
29 #define XKB_KEY_NoSymbol 0x000000 /* Special KeySym */
32 with open(path) as header:
34 if '#ifdef' in line or '#ifndef' in line or '#endif' in line:
37 # Remove #define _OSF_Keysyms and such.
38 if '#define _' in line:
41 # Handle a duplicate definition in HPkeysyms.h which kicks in if
42 # it's not already defined.
43 if 'XK_Ydiaeresis' in line and '0x100000ee' in line:
46 # Replace the xorgproto _EVDEVK macro with the actual value
47 # 0x10081000 is the base, the evdev hex code is added to that.
48 # We replace to make parsing of the keys later easier.
49 match = re.match(evdev_pattern, line)
51 value = 0x10081000 + int(match.group('value'), 16)
52 line = re.sub(r'_EVDEVK\(0x([0-9A-Fa-f]+)\)', '{:#x}'.format(value), line)
54 line = re.sub(r'#define\s*(\w*)XK_', r'#define XKB_KEY_\1', line)