diff options
| author | Haibo Huang <hhb@google.com> | 2020-09-08 17:10:03 -0700 |
|---|---|---|
| committer | Haibo Huang <hhb@google.com> | 2020-09-10 22:20:42 +0000 |
| commit | bffa8499cb8ce3cc4366055be8fe62d501d6a8e5 (patch) | |
| tree | 648dfaada5799a6227dd5f1af43d89ed8d71d96d /scripts/makekeys | |
| parent | e4e474780d90ed6166f7113a7464371baa275007 (diff) | |
| download | platform_external_libxkbcommon-master.tar.gz platform_external_libxkbcommon-master.tar.bz2 platform_external_libxkbcommon-master.zip | |
1. Run meson build locally:
meson config -Denable-x11=false -Denable-wayland=false -Denable-docs=false
2. Copy over generated parser.h / parser.c
3. Copy over config.h, and remove defines for not supported functions.
Change-Id: Id7f3c822c1d958fa541685344961507bcfa03b17
Diffstat (limited to 'scripts/makekeys')
| -rwxr-xr-x | scripts/makekeys | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/scripts/makekeys b/scripts/makekeys new file mode 100755 index 0000000..f6a0280 --- /dev/null +++ b/scripts/makekeys @@ -0,0 +1,55 @@ +#!/usr/bin/env python + +import re, sys, itertools + +pattern = re.compile(r'^#define\s+XKB_KEY_(?P<name>\w+)\s+(?P<value>0x[0-9a-fA-F]+)\s') +matches = [pattern.match(line) for line in open(sys.argv[1])] +entries = [(m.group("name"), int(m.group("value"), 16)) for m in matches if m] + +print(''' +/** + * This file comes from libxkbcommon and was generated by makekeys.py + * You can always fetch the latest version from: + * https://raw.github.com/xkbcommon/libxkbcommon/master/src/ks_tables.h + */ +''') + +entry_offsets = {} + +print(''' +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Woverlength-strings" +#endif +static const char *keysym_names = +'''.strip()) +offs = 0 +for (name, _) in sorted(entries, key=lambda e: e[0].lower()): + entry_offsets[name] = offs + print(' "{name}\\0"'.format(name=name)) + offs += len(name) + 1 +print(''' +; +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif +'''.strip()) + +print(''' +struct name_keysym { + xkb_keysym_t keysym; + uint32_t offset; +};\n''') + +def print_entries(x): + for (name, value) in x: + print(' {{ 0x{value:08x}, {offs} }}, /* {name} */'.format(offs=entry_offsets[name], value=value, name=name)) + +print('static const struct name_keysym name_to_keysym[] = {') +print_entries(sorted(entries, key=lambda e: e[0].lower())) +print('};\n') + +# *.sort() is stable so we always get the first keysym for duplicate +print('static const struct name_keysym keysym_to_name[] = {') +print_entries(next(g[1]) for g in itertools.groupby(sorted(entries, key=lambda e: e[1]), key=lambda e: e[1])) +print('};') |
