3 # This script creates a custom layout, overriding the TDLE key with the first
8 from pathlib import Path
14 # Template to force our key to TLDE
17 xkb_symbols "basic" {{
19 replace key <TLDE> {{ [ {} ] }};
23 parser = argparse.ArgumentParser(
24 description='Tool to verify whether a keysym is resolved'
26 parser.add_argument('keysym', type=str, help='XKB keysym')
27 parser.add_argument('--tool', type=str, nargs=1,
28 default=['xkbcli', 'compile-keymap'],
29 help='Full path to the xkbcli-compile-keymap tool')
30 args = parser.parse_args()
32 with tempfile.TemporaryDirectory() as tmpdir:
33 symfile = Path(tmpdir) / "symbols" / "keytest"
34 symfile.parent.mkdir()
35 with symfile.open(mode='w') as f:
36 f.write(template.format(args.keysym))
41 '--layout', 'keytest',
44 env = os.environ.copy()
45 env['XKB_CONFIG_EXTRA_PATH'] = tmpdir
47 result = subprocess.run(cmd, env=env, capture_output=True,
48 universal_newlines=True)
49 if result.returncode != 0:
50 print('ERROR: Failed to compile:')
54 # grep for TLDE actually being remapped
55 for l in result.stdout.split('\n'):
56 match = re.match(r'\s+key \<TLDE\>\s+{\s+\[\s+(?P<keysym>\w+)\s+\]\s+}', l)
58 if args.keysym == match.group('keysym'):
60 elif match.group('keysym') == 'NoSymbol':
61 print('ERROR: key {} not resolved:'.format(args.keysym), l)
63 print('ERROR: key {} mapped to wrong key:'.format(args.keysym), l)
67 print('ERROR: above keymap is missing key mapping for {}'.format(args.keysym))
69 except FileNotFoundError as err:
70 print('ERROR: invalid or missing tool: {}'.format(err))