From ff9d2e7d31aea2fb08e1390b245a212185eac1f2 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 11 May 2025 22:55:05 +0200 Subject: [PATCH] check_layout: Check for unknown keys This can spot mispelled special keys. --- check_layout.output | 1 + check_layout.py | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/check_layout.output b/check_layout.output index 25a7609..1752ce7 100644 --- a/check_layout.output +++ b/check_layout.output @@ -26,6 +26,7 @@ latn_bone: Missing important key, missing: loc capslock latn_colemak: Some keys contain whitespaces, unexpected: ́ latn_dvorak: Missing important key, missing: loc capslock latn_neo2: Layout redefines the bottom row but some important keys are missing, missing: loc switch_clipboard +latn_qwerty_jp: Layout contains unknown keys: accent-macron latn_qwerty_se: Duplicate keys: !, ', ,, -, ., ? latn_qwerty_tly: Duplicate keys: a, c, j, q latn_qwerty_tly: Missing programming keys, missing: loc esc, loc tab diff --git a/check_layout.py b/check_layout.py index ee1cbc9..0208a97 100644 --- a/check_layout.py +++ b/check_layout.py @@ -1,5 +1,5 @@ import xml.etree.ElementTree as ET -import sys, os, glob +import sys, os, glob, re layout_file_name = 0 warnings = [] @@ -15,6 +15,9 @@ KEY_ATTRIBUTES = set([ "c", "nw", "ne", "sw", "se", "w", "e", "n", "s" ]) +# Keys defined in KeyValue.java +known_keys = set() + def warn(msg): global warnings warnings.append("%s: %s" % (layout_file_name, msg)) @@ -103,6 +106,23 @@ def check_layout(layout): if root.get("script") == None: warn("Layout doesn't specify a script.") + keys_without_loc = set(( k.removeprefix("loc ") for k in keys )) + # Keys with a len under 3 are often composed characters + special_keys = set(( k for k in keys_without_loc if len(k) > 3 and ":" not in k )) + unknown = special_keys.difference(known_keys) + if len(unknown) > 0: + warn("Layout contains unknown keys: %s" % key_list_str(unknown)) + +# Fill 'known_keys', which is used for some checks +def parse_known_keys(): + global known_keys + with open("srcs/juloo.keyboard2/KeyValue.java", "r") as f: + known_keys = set( + ( m.group(1) for m in re.finditer('case "([^"]+)":', f.read()) ) + ) + +parse_known_keys() + for fname in sorted(glob.glob("srcs/layouts/*.xml")): layout_id, _ = os.path.splitext(os.path.basename(fname)) if layout_id in KNOWN_NOT_LAYOUT: