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")
31 default=["xkbcli", "compile-keymap"],
32 help="Full path to the xkbcli-compile-keymap tool",
34 args = parser.parse_args()
36 with tempfile.TemporaryDirectory() as tmpdir:
37 symfile = Path(tmpdir) / "symbols" / "keytest"
38 symfile.parent.mkdir()
39 with symfile.open(mode="w") as f:
40 f.write(template.format(args.keysym))
49 env = os.environ.copy()
50 env["XKB_CONFIG_EXTRA_PATH"] = tmpdir
52 result = subprocess.run(
53 cmd, env=env, capture_output=True, universal_newlines=True
55 if result.returncode != 0:
56 print("ERROR: Failed to compile:")
60 # grep for TLDE actually being remapped
61 for l in result.stdout.split("\n"):
62 match = re.match(r"\s+key \<TLDE\>\s+{\s+\[\s+(?P<keysym>\w+)\s+\]\s+}", l)
64 if args.keysym == match.group("keysym"):
66 elif match.group("keysym") == "NoSymbol":
67 print("ERROR: key {} not resolved:".format(args.keysym), l)
69 print("ERROR: key {} mapped to wrong key:".format(args.keysym), l)
73 print("ERROR: above keymap is missing key mapping for {}".format(args.keysym))
75 except FileNotFoundError as err:
76 print("ERROR: invalid or missing tool: {}".format(err))