Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 36 additions & 19 deletions check_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,37 +40,50 @@ def unexpected_keys(keys, symbols, msg):
if len(unexpected) > 0:
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():
def duplicates(keys):
dup = [ k for k, key_elts in keys.items() if len(key_elts) >= 2 ]
if len(dup) > 0:
warn("Duplicate keys: " + key_list_str(dup))

def should_have_role(keys_map, role, keys):
def is_center_key(key):
def center(key_elt): return key_elt.get("key0", key_elt.get("c"))
return any(( center(key_elt) == key for key_elt in keys_map.get(key, []) ))
def key_roles(key):
return ( key_elt.get("role", "normal") for key_elt in keys_map[key] )
for key in keys:
if is_center_key(key) and role not in key_roles(key):
warn("Key '%s' is not on a key with role=\"%s\"" % (key, role))

# Write to [keys], dict of keyvalue to the key elements they appear in
def parse_row_from_et(row, keys):
for key_elt in row:
for attr in key_elt.keys():
if attr in KEY_ATTRIBUTES:
k = key.get(attr).removeprefix("\\")
if k in keys: dup.add(k)
keys.add(k)
k = key_elt.get(attr).removeprefix("\\")
keys.setdefault(k, []).append(key_elt)

def parse_layout(fname):
keys = set()
dup = set()
keys = {}
root = ET.parse(fname).getroot()
if root.tag != "keyboard":
return None
for row in root:
parse_row_from_et(row, keys, dup)
return root, keys, dup
parse_row_from_et(row, keys)
return root, keys

def parse_row(fname):
keys = set()
dup = set()
keys = {}
root = ET.parse(fname).getroot()
if root.tag != "row":
return None
parse_row_from_et(root, keys, dup)
return root, keys, dup
parse_row_from_et(root, keys)
return root, keys

def check_layout(layout):
root, keys, dup = layout
if len(dup) > 0: warn("Duplicate keys: " + key_list_str(dup))
root, keys_map = layout
keys = set(keys_map.keys())
duplicates(keys_map)
missing_some_of(keys, "~!@#$%^&*(){}`[]=\\-_;:/.,?<>'\"+|", "ASCII punctuation")
missing_some_of(keys, "0123456789", "digits")
missing_required(keys, ["backspace", "delete"], "Layout doesn't define some important keys")
Expand All @@ -91,8 +104,8 @@ def check_layout(layout):
missing_required(keys, ["shift", "loc capslock"], "Missing important key")
missing_required(keys, ["loc esc", "loc tab"], "Missing programming keys")

_, bottom_row_keys, _ = parse_row("res/xml/bottom_row.xml")

_, bottom_row_keys_map = parse_row("res/xml/bottom_row.xml")
bottom_row_keys = set(bottom_row_keys_map.keys())
if root.get("bottom_row") == "false":
missing_required(keys, bottom_row_keys,
"Layout redefines the bottom row but some important keys are missing")
Expand All @@ -103,6 +116,10 @@ def check_layout(layout):
if root.get("script") == None:
warn("Layout doesn't specify a script.")

should_have_role(keys_map, "action",
[ "shift", "ctrl", "fn", "backspace", "enter" ])
should_have_role(keys_map, "space_bar", [ "space" ])

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:
Expand Down
33 changes: 32 additions & 1 deletion res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<attr name="colorKey" format="color"/>
<!-- Background of the keys when pressed -->
<attr name="colorKeyActivated" format="color"/>
<!-- Adjust the lightness of keys depending on their role. -->
<attr name="colorKeyAction" format="color"/>
<attr name="colorKeySpaceBar" format="color"/>
<!-- Label colors -->
<attr name="colorLabel" format="color"/>
<attr name="colorLabelActivated" format="color"/>
Expand All @@ -19,6 +22,8 @@
<attr name="keyBorderRadius" format="dimension"/>
<attr name="keyBorderWidth" format="dimension"/>
<attr name="keyBorderWidthActivated" format="dimension"/>
<attr name="keyBorderWidthAction" format="dimension"/>
<attr name="keyBorderWidthSpaceBar" format="dimension"/>
<attr name="keyBorderColorLeft" format="color"/>
<attr name="keyBorderColorTop" format="color"/>
<attr name="keyBorderColorRight" format="color"/>
Expand All @@ -42,6 +47,8 @@
<item name="keyBorderRadius">5dp</item>
<item name="keyBorderWidth">0dp</item>
<item name="keyBorderWidthActivated">0dp</item>
<item name="keyBorderWidthAction">?attr/keyBorderWidth</item>
<item name="keyBorderWidthSpaceBar">?attr/keyBorderWidth</item>
<item name="secondaryDimming">0.25</item>
<item name="greyedDimming">0.5</item>
<item name="emoji_key_bg" type="color">?attr/emoji_button_bg</item>
Expand All @@ -54,8 +61,12 @@
<item name="colorKeyboard">#1b1b1b</item>
<item name="colorKey">#333333</item>
<item name="colorKeyActivated">#1b1b1b</item>
<item name="colorKeyAction">#262626</item>
<item name="colorKeySpaceBar">#2b2b2b</item>
<item name="keyBorderWidth">1.2dp</item>
<item name="keyBorderWidthActivated">0dp</item>
<item name="keyBorderWidthAction">0dp</item>
<item name="keyBorderWidthSpaceBar">0dp</item>
<item name="keyBorderColorBottom">#404040</item>
<item name="colorLabel">#ffffff</item>
<item name="colorLabelActivated">#3399ff</item>
Expand All @@ -69,8 +80,12 @@
<item name="colorKeyboard">#e3e3e3</item>
<item name="colorKey">#cccccc</item>
<item name="colorKeyActivated">#e3e3e3</item>
<item name="colorKeyAction">#d9d9d9</item>
<item name="colorKeySpaceBar">#dedede</item>
<item name="keyBorderWidth">0.6dp</item>
<item name="keyBorderWidthActivated">0dp</item>
<item name="keyBorderWidthAction">0dp</item>
<item name="keyBorderWidthSpaceBar">0dp</item>
<item name="keyBorderColorLeft">#cccccc</item>
<item name="keyBorderColorTop">#eeeeee</item>
<item name="keyBorderColorRight">#cccccc</item>
Expand All @@ -87,6 +102,8 @@
<item name="colorKeyboard">#000000</item>
<item name="colorKey">#000000</item>
<item name="colorKeyActivated">#333333</item>
<item name="colorKeyAction">#000000</item>
<item name="colorKeySpaceBar">#000000</item>
<item name="keyBorderWidth">0dp</item>
<item name="keyBorderWidthActivated">1dp</item>
<item name="keyBorderColorLeft">#2a2a2a</item>
Expand All @@ -108,6 +125,8 @@
<item name="android:isLightTheme">true</item>
<item name="colorKeyboard">#ffffff</item>
<item name="colorKey">#ffffff</item>
<item name="colorKeyAction">#ffffff</item>
<item name="colorKeySpaceBar">#ffffff</item>
<item name="keyBorderWidth">1dp</item>
<item name="keyBorderWidthActivated">1dp</item>
<item name="keyBorderColorLeft">#f0f0f0</item>
Expand All @@ -127,6 +146,8 @@
<item name="android:isLightTheme">true</item>
<item name="colorKeyboard">#ffffff</item>
<item name="colorKey">#ffffff</item>
<item name="colorKeyAction">#ffffff</item>
<item name="colorKeySpaceBar">#ffffff</item>
<item name="keyBorderWidth">2dp</item>
<item name="keyBorderWidthActivated">5dp</item>
<item name="keyBorderColorLeft">#000000</item>
Expand All @@ -148,6 +169,8 @@
<item name="colorKeyboard">#ffe0b2</item>
<item name="colorKey">#fff3e0</item>
<item name="colorKeyActivated">#ffcc80</item>
<item name="colorKeyAction">#ffe9c6</item>
<item name="colorKeySpaceBar">#ffedd0</item>
<item name="colorLabel">#000000</item>
<item name="colorLabelActivated">#ffffff</item>
<item name="colorLabelLocked">#e65100</item>
Expand All @@ -166,6 +189,8 @@
<item name="colorKeyboard">#4db6ac</item>
<item name="colorKey">#e0f2f1</item>
<item name="colorKeyActivated">#00695c</item>
<item name="colorKeyAction">#b8e3de</item>
<item name="colorKeySpaceBar">#c3e7e3</item>
<item name="colorLabel">#000000</item>
<item name="colorLabelActivated">#ffffff</item>
<item name="colorLabelLocked">#64ffda</item>
Expand All @@ -184,6 +209,8 @@
<item name="colorKeyboard">@android:color/system_accent1_100</item>
<item name="colorKey">@android:color/system_accent1_0</item>
<item name="colorKeyActivated">@android:color/system_accent1_300</item>
<item name="colorKeyAction">@android:color/system_accent1_100</item>
<item name="colorKeySpaceBar">@android:color/system_accent1_200</item>
<item name="colorLabel">@android:color/system_accent1_1000</item>
<item name="colorLabelActivated">@android:color/system_accent1_1000</item>
<item name="colorLabelLocked">@android:color/system_accent1_500</item>
Expand All @@ -195,7 +222,9 @@
<item name="android:isLightTheme">false</item>
<item name="colorKeyboard">@android:color/system_neutral1_900</item>
<item name="colorKey">@android:color/system_accent2_800</item>
<item name="colorKeyActivated">@android:color/system_accent1_800</item>
<item name="colorKeyActivated">@android:color/system_accent1_700</item>
<item name="colorKeyAction">@android:color/system_accent2_900</item>
<item name="colorKeySpaceBar">@android:color/system_accent2_900</item>
<item name="colorLabel">@android:color/system_neutral1_0</item>
<item name="colorLabelActivated">@android:color/system_accent1_400</item>
<item name="colorLabelLocked">@android:color/system_accent1_100</item>
Expand All @@ -208,6 +237,8 @@
<item name="colorKeyboard">#191724</item>
<item name="colorKey">#26233a</item>
<item name="colorKeyActivated">#403d52</item>
<item name="colorKeyAction">#2a2740</item>
<item name="colorKeySpaceBar">#2e2b47</item>
<item name="keyBorderWidth">0dp</item>
<item name="keyBorderWidthActivated">1dp</item>
<item name="keyBorderColorLeft">#6e6a86</item>
Expand Down
10 changes: 5 additions & 5 deletions res/xml/bottom_row.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<row height="0.95">
<key width="1.7" key0="ctrl" key1="loc switch_greekmath" key2="loc meta" key3="loc switch_clipboard" key4="switch_numeric"/>
<key width="1.1" key0="fn" key1="loc alt" key2="loc change_method" key3="switch_emoji" key4="config"/>
<key width="4.4" key0="space" key7="switch_forward" key8="switch_backward" key5="cursor_left" key6="cursor_right"/>
<key width="1.1" key0="loc compose" key7="up" key6="right" key5="left" key8="down" key1="loc home" key2="loc page_up" key3="loc end" key4="loc page_down"/>
<key width="1.7" key0="enter" key1="loc voice_typing" key2="action"/>
<key width="1.7" role="action" key0="ctrl" key1="loc switch_greekmath" key2="loc meta" key3="loc switch_clipboard" key4="switch_numeric"/>
<key width="1.1" role="action" key0="fn" key1="loc alt" key2="loc change_method" key3="switch_emoji" key4="config"/>
<key width="4.4" role="space_bar" key0="space" key7="switch_forward" key8="switch_backward" key5="cursor_left" key6="cursor_right"/>
<key width="1.1" role="action" key0="loc compose" key7="up" key6="right" key5="left" key8="down" key1="loc home" key2="loc page_up" key3="loc end" key4="loc page_down"/>
<key width="1.7" role="action" key0="enter" key1="loc voice_typing" key2="action"/>
</row>
8 changes: 4 additions & 4 deletions res/xml/clipboard_bottom_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- The bottom row used in the clipboard history pane. -->
<keyboard bottom_row="false">
<row height="0.95">
<key key0="switch_back_clipboard"/>
<key width="3" key0="space" key5="cursor_left" key6="cursor_right"/>
<key key0="backspace" key2="delete"/>
<key key0="enter" key2="action"/>
<key role="action" key0="switch_back_clipboard"/>
<key width="3" role="space_bar" key0="space" key5="cursor_left" key6="cursor_right"/>
<key role="action" key0="backspace" key2="delete"/>
<key role="action" key0="enter" key2="action"/>
</row>
</keyboard>
8 changes: 4 additions & 4 deletions res/xml/emoji_bottom_row.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<!-- The bottom row used in the emoji pane. -->
<keyboard bottom_row="false">
<row height="0.95">
<key key0="switch_back_emoji"/>
<key width="3" key0="space" key5="cursor_left" key6="cursor_right"/>
<key key0="backspace" key2="delete"/>
<key key0="enter" key2="action"/>
<key role="action" key0="switch_back_emoji"/>
<key role="space_bar" width="3" key0="space" key5="cursor_left" key6="cursor_right"/>
<key role="action" key0="backspace" key2="delete"/>
<key role="action" key0="enter" key2="action"/>
</row>
</keyboard>
18 changes: 9 additions & 9 deletions res/xml/greekmath.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,23 @@
<key key0="ϡ" key1="⌀"/>
</row>
<row>
<key width="1.5" key0="shift" key2="loc capslock"/>
<key width="1.5" role="action" key0="shift" key2="loc capslock"/>
<key key0="ζ" key3="⇌" key4="√"/>
<key key0="χ" key3="accent_arrow_right" key4="∪"/>
<key key0="ϛ" key4="∩"/>
<key key0="ϟ" key3="∇" key4="ℵ"/>
<key key0="β" key1="≤" key3="ℤ" key4="1"/>
<key key0="ν" key1="≠" key3="ℚ" key4="2"/>
<key key0="μ" key1="≥" key3="×" key4="3"/>
<key width="1.5" key0="backspace" key3="delete"/>
<key width="1.5" role="action" key0="backspace" key3="delete"/>
</row>
<row height="0.95">
<key width="1.2" key0="switch_text" key2="loc esc"/>
<key width="1.2" key0="switch_numeric" key2="loc tab"/>
<key width="1.2" key0="fn"/>
<key width="2.8" key0="space" key1="superscript" key3="subscript"/>
<key width="1.2" key0="0" key2="."/>
<key width="1.2" key0="loc compose" key7="up" key6="right" key5="left" key8="down"/>
<key width="1.2" key0="enter" key1="=" key2="action"/>
<key width="1.2" role="action" key0="switch_text" key2="loc esc"/>
<key width="1.2" role="action" key0="switch_numeric" key2="loc tab"/>
<key width="1.2" role="action" key0="fn"/>
<key width="2.8" role="space_bar" key0="space" key1="superscript" key3="subscript"/>
<key width="1.2" role="action" key0="0" key2="."/>
<key width="1.2" role="action" key0="loc compose" key7="up" key6="right" key5="left" key8="down"/>
<key width="1.2" role="action" key0="enter" key1="=" key2="action"/>
</row>
</keyboard>
20 changes: 10 additions & 10 deletions res/xml/number_row.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<row height="0.75">
<key key0="1" se="!"/>
<key key0="2" se="@"/>
<key key0="3" se="#"/>
<key key0="4" se="$"/>
<key key0="5" se="%"/>
<key key0="6" sw="^"/>
<key key0="7" sw="&amp;"/>
<key key0="8" sw="*"/>
<key key0="9" sw="("/>
<key key0="0" sw=")"/>
<key role="action" key0="1" se="!"/>
<key role="action" key0="2" se="@"/>
<key role="action" key0="3" se="#"/>
<key role="action" key0="4" se="$"/>
<key role="action" key0="5" se="%"/>
<key role="action" key0="6" sw="^"/>
<key role="action" key0="7" sw="&amp;"/>
<key role="action" key0="8" sw="*"/>
<key role="action" key0="9" sw="("/>
<key role="action" key0="0" sw=")"/>
</row>
30 changes: 15 additions & 15 deletions res/xml/numeric.xml
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<keyboard bottom_row="false">
<row>
<key width="0.75" key0="loc esc" key2="~" key4="!"/>
<key width="0.75" key0="(" key2="[" key4="{"/>
<key width="0.75" role="action" key0="loc esc" key2="~" key4="!"/>
<key width="0.75" role="action" key0="(" key2="[" key4="{"/>
<key key0="7" key1="&lt;" key2="&gt;"/>
<key key0="8" key2="∞"/>
<key key0="9" key2="π"/>
<key width="0.75" key0="*" key1="√" key2="×" key3="\#"/>
<key width="0.75" key0="/" key1="%" key3="÷"/>
<key width="0.75" role="action" key0="*" key1="√" key2="×" key3="\#"/>
<key width="0.75" role="action" key0="/" key1="%" key3="÷"/>
</row>
<row>
<key width="0.75" key0="loc tab" key2="|" key4="\\"/>
<key width="0.75" key0=")" key2="]" key4="}"/>
<key width="0.75" role="action" key0="loc tab" key2="|" key4="\\"/>
<key width="0.75" role="action" key0=")" key2="]" key4="}"/>
<key key0="4" key1="box" key3="arrows"/>
<key key0="5" key7="up" key6="right" key5="left" key8="down"/>
<key key0="6"/>
<key width="0.75" key0="+" key1="Σ" key2="$"/>
<key width="0.75" key0="-" key1="^"/>
<key width="0.75" role="action" key0="+" key1="Σ" key2="$"/>
<key width="0.75" role="action" key0="-" key1="^"/>
</row>
<row>
<key width="0.75" key0="switch_greekmath"/>
<key width="0.75" key0="shift" key2="fn" key4="loc alt"/>
<key width="0.75" role="action" key0="switch_greekmath"/>
<key width="0.75" role="action" key0="shift" key2="fn" key4="loc alt"/>
<key key0="1" key1="superscript" key2="ordinal" key3="subscript"/>
<key key0="2"/>
<key key0="3"/>
<key width="1.5" key0="backspace" key2="delete"/>
<key width="1.5" role="action" key0="backspace" key2="delete"/>
</row>
<row height="0.95">
<key width="1.5" key0="switch_text" key2="ctrl"/>
<key width="1.5" role="action" key0="switch_text" key2="ctrl"/>
<key width="1.5" key0="0"/>
<key width="0.75" key0="." key1=":" key2="," key3=";"/>
<key width="0.75" key0="space" key1="&quot;" key2="'" key3="loc compose" key4="_"/>
<key width="1.5" key0="enter" key1="±" key2="action" key3="="/>
<key width="0.75" role="action" key0="." key1=":" key2="," key3=";"/>
<key width="0.75" role="action" key0="action" key1="&quot;" key2="'" key3="loc compose" key4="_"/>
<key width="1.5" role="action" key0="enter" key1="±" key2="action" key3="="/>
</row>
</keyboard>
Loading
Loading