2021-02-21 19:54:15 -07:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
#
|
|
|
|
# This script creates a custom layout, overriding the TDLE key with the first
|
|
|
|
# argument given.
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
import tempfile
|
|
|
|
from pathlib import Path
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# Template to force our key to TLDE
|
|
|
|
template = """
|
|
|
|
default
|
|
|
|
xkb_symbols "basic" {{
|
|
|
|
include "us(basic)"
|
|
|
|
replace key <TLDE> {{ [ {} ] }};
|
|
|
|
}};
|
|
|
|
"""
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(
|
2023-09-28 01:50:43 -06:00
|
|
|
description="Tool to verify whether a keysym is resolved"
|
|
|
|
)
|
|
|
|
parser.add_argument("keysym", type=str, help="XKB keysym")
|
|
|
|
parser.add_argument(
|
|
|
|
"--tool",
|
|
|
|
type=str,
|
|
|
|
nargs=1,
|
|
|
|
default=["xkbcli", "compile-keymap"],
|
|
|
|
help="Full path to the xkbcli-compile-keymap tool",
|
2021-02-21 19:54:15 -07:00
|
|
|
)
|
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
with tempfile.TemporaryDirectory() as tmpdir:
|
|
|
|
symfile = Path(tmpdir) / "symbols" / "keytest"
|
|
|
|
symfile.parent.mkdir()
|
2023-09-28 01:50:43 -06:00
|
|
|
with symfile.open(mode="w") as f:
|
2021-02-21 19:54:15 -07:00
|
|
|
f.write(template.format(args.keysym))
|
|
|
|
|
|
|
|
try:
|
|
|
|
cmd = [
|
|
|
|
*args.tool,
|
2023-09-28 01:50:43 -06:00
|
|
|
"--layout",
|
|
|
|
"keytest",
|
2021-02-21 19:54:15 -07:00
|
|
|
]
|
|
|
|
|
|
|
|
env = os.environ.copy()
|
2023-09-28 01:50:43 -06:00
|
|
|
env["XKB_CONFIG_EXTRA_PATH"] = tmpdir
|
2021-02-21 19:54:15 -07:00
|
|
|
|
2023-09-28 01:50:43 -06:00
|
|
|
result = subprocess.run(
|
|
|
|
cmd, env=env, capture_output=True, universal_newlines=True
|
|
|
|
)
|
2021-02-21 19:54:15 -07:00
|
|
|
if result.returncode != 0:
|
2023-09-28 01:50:43 -06:00
|
|
|
print("ERROR: Failed to compile:")
|
2021-02-21 19:54:15 -07:00
|
|
|
print(result.stderr)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
# grep for TLDE actually being remapped
|
2023-09-28 01:50:43 -06:00
|
|
|
for l in result.stdout.split("\n"):
|
|
|
|
match = re.match(r"\s+key \<TLDE\>\s+{\s+\[\s+(?P<keysym>\w+)\s+\]\s+}", l)
|
2021-02-21 19:54:15 -07:00
|
|
|
if match:
|
2023-09-28 01:50:43 -06:00
|
|
|
if args.keysym == match.group("keysym"):
|
2021-02-21 19:54:15 -07:00
|
|
|
sys.exit(0)
|
2023-09-28 01:50:43 -06:00
|
|
|
elif match.group("keysym") == "NoSymbol":
|
|
|
|
print("ERROR: key {} not resolved:".format(args.keysym), l)
|
2021-02-21 19:54:15 -07:00
|
|
|
else:
|
2023-09-28 01:50:43 -06:00
|
|
|
print("ERROR: key {} mapped to wrong key:".format(args.keysym), l)
|
2021-02-21 19:54:15 -07:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
print(result.stdout)
|
2023-09-28 01:50:43 -06:00
|
|
|
print("ERROR: above keymap is missing key mapping for {}".format(args.keysym))
|
2021-02-21 19:54:15 -07:00
|
|
|
sys.exit(1)
|
|
|
|
except FileNotFoundError as err:
|
2023-09-28 01:50:43 -06:00
|
|
|
print("ERROR: invalid or missing tool: {}".format(err))
|
2021-02-21 19:54:15 -07:00
|
|
|
sys.exit(1)
|