check_layout: Stronger bottom row key check

This commit is contained in:
Jules Aguillon 2024-01-10 23:00:40 +01:00
parent cf9fd3a0db
commit 6725d3057b
2 changed files with 23 additions and 13 deletions

View File

@ -61,14 +61,15 @@ Layout doesn't define some important keys, missing: f11_placeholder, f12_placeho
1 warnings 1 warnings
# latn_bone # latn_bone
Layout includes some ASCII punctuation but not all, missing: $ Layout includes some ASCII punctuation but not all, missing: $
Layout redefines the bottom row but some important keys are missing, missing: switch_backward Layout redefines the bottom row but some important keys are missing, missing: cursor_left, cursor_right, loc end, loc home, loc page_down, loc page_up, loc switch_greekmath, loc voice_typing, switch_backward
2 warnings 2 warnings
# latn_colemak # latn_colemak
0 warnings 0 warnings
# latn_dvorak # latn_dvorak
0 warnings 0 warnings
# latn_neo2 # latn_neo2
0 warnings Layout redefines the bottom row but some important keys are missing, missing: loc end, loc home, loc page_down, loc page_up
1 warnings
# latn_qwerty_br # latn_qwerty_br
0 warnings 0 warnings
# latn_qwerty_cz # latn_qwerty_cz

View File

@ -34,6 +34,15 @@ def unexpected_keys(keys, symbols, msg):
if len(unexpected) > 0: if len(unexpected) > 0:
warn("%s, unexpected: %s" % (msg, key_list_str(unexpected))) warn("%s, unexpected: %s" % (msg, key_list_str(unexpected)))
# Write to [keys] and [dup].
def parse_row_from_et(row, keys, dup):
for key in row:
for attr in key.keys():
if attr.startswith("key"):
k = key.get(attr).removeprefix("\\")
if k in keys: dup.add(k)
keys.add(k)
def parse_layout(fname): def parse_layout(fname):
keys = set() keys = set()
dup = set() dup = set()
@ -41,12 +50,16 @@ def parse_layout(fname):
if root.tag != "keyboard": if root.tag != "keyboard":
return None return None
for row in root: for row in root:
for key in row: parse_row_from_et(row, keys, dup)
for attr in key.keys(): return root, keys, dup
if attr.startswith("key"):
k = key.get(attr).removeprefix("\\") def parse_row(fname):
if k in keys: dup.add(k) keys = set()
keys.add(k) dup = set()
root = ET.parse(fname).getroot()
if root.tag != "row":
return None
parse_row_from_et(root, keys, dup)
return root, keys, dup return root, keys, dup
def check_layout(layout): def check_layout(layout):
@ -68,11 +81,7 @@ def check_layout(layout):
"Layout contains function keys") "Layout contains function keys")
unexpected_keys(keys, [""], "Layout contains empty strings") unexpected_keys(keys, [""], "Layout contains empty strings")
bottom_row_keys = [ _, bottom_row_keys, _ = parse_row("res/xml/bottom_row.xml")
"ctrl", "fn", "switch_numeric", "change_method", "switch_emoji",
"config", "switch_forward", "switch_backward", "enter", "action",
"left", "up", "right", "down", "space"
]
if root.get("bottom_row") == "false": if root.get("bottom_row") == "false":
missing_required(keys, bottom_row_keys, missing_required(keys, bottom_row_keys,