From 5fc68373d3ee0ce61cfb819f0e623e3a3f63c374 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 10 Jun 2023 10:59:25 +0200 Subject: [PATCH] Allow to specify a layout script Add the `script` attribute, which will be used to implement script-specific extra keys. --- check_layout.output | 115 +++++++++++++++++-------- check_layout.py | 3 + srcs/juloo.keyboard2/KeyboardData.java | 16 ++-- 3 files changed, 91 insertions(+), 43 deletions(-) diff --git a/check_layout.output b/check_layout.output index 361ce7c..fbeb8f4 100644 --- a/check_layout.output +++ b/check_layout.output @@ -1,100 +1,141 @@ # res/xml/ar_alt.xml Layout includes some ASCII punctuation but not all, missing: !, ", ', +, -, /, :, ;, <, =, >, ?, [, \, ], _, |, ~ -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/ar_pc.xml Layout includes some ASCII punctuation but not all, missing: !, ', +, ;, ?, \, | -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/azerty.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/bangla.xml Layout includes some ASCII punctuation but not all, missing: $ -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/bone.xml Layout includes some ASCII punctuation but not all, missing: $ -1 warnings +Layout doesn't specify a script. +2 warnings Not a layout file: res/xml/bottom_row.xml # res/xml/colemak.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/devanagari_1.xml Layout includes some ASCII punctuation but not all, missing: ", $, ', ^, _, `, | -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/devanagari_2.xml Layout includes some ASCII punctuation but not all, missing: #, $, %, &, ', (, ), *, +, ., /, :, <, =, >, @, [, \, ], ^, _, `, {, |, }, ~ -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/dvorak.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/greekmath.xml Layout includes some ASCII punctuation but not all, missing: !, ", #, $, %, &, ', (, ), *, +, ,, -, /, :, ;, <, >, ?, @, [, \, ], _, `, {, |, }, ~ Layout redefines the bottom row but some important keys are missing, missing: change_method, config, ctrl, switch_emoji, switch_second -2 warnings +Layout doesn't specify a script. +3 warnings # res/xml/he_il_1452_1.xml Layout includes some ASCII punctuation but not all, missing: (, ), <, >, [, ], {, } -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/he_il_1452_2.xml Layout includes some ASCII punctuation but not all, missing: (, ), <, >, [, ], {, } -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/jcuken_ua.xml -0 warnings +Layout doesn't specify a script. +1 warnings +# res/xml/kurdish.xml +Layout includes some ASCII punctuation but not all, missing: ", %, ', +, ,, ., :, ;, <, =, >, ?, `, |, ~ +Layout doesn't specify a script. +2 warnings # res/xml/local_bgph1.xml Layout includes some ASCII punctuation but not all, missing: ~ -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/local_ru_jcuken.xml -0 warnings +Layout doesn't specify a script. +1 warnings Not a layout file: res/xml/method.xml # res/xml/neo2.xml -0 warnings +Layout doesn't specify a script. +1 warnings Not a layout file: res/xml/number_row.xml # res/xml/numeric.xml Layout includes some ASCII punctuation but not all, missing: &, ?, @, ` Layout redefines the bottom row but some important keys are missing, missing: change_method, config, switch_emoji, switch_numeric, switch_second -2 warnings +Layout doesn't specify a script. +3 warnings # res/xml/numpad.xml Layout includes some ASCII punctuation but not all, missing: !, ", #, $, %, &, ', (, ), ,, :, ;, <, >, ?, @, [, \, ], ^, _, `, {, |, }, ~ Layout doesn't define some important keys, missing: backspace, delete Layout redefines the bottom row but some important keys are missing, missing: action, change_method, config, ctrl, down, enter, fn, left, right, space, switch_emoji, switch_numeric, switch_second, up -3 warnings +Layout doesn't specify a script. +4 warnings # res/xml/persian.xml Layout includes some ASCII punctuation but not all, missing: ", $, %, ', *, ,, /, ;, <, =, >, ?, [, \, ], ^, _, `, {, |, }, ~ -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/pin.xml Layout includes some ASCII punctuation but not all, missing: !, ", $, %, &, ', ;, <, =, >, ?, @, [, \, ], ^, _, `, {, |, }, ~ Layout redefines the bottom row but some important keys are missing, missing: change_method, config, ctrl, fn, switch_emoji, switch_second -2 warnings +Layout doesn't specify a script. +3 warnings # res/xml/qwerty_el.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwerty_es.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwerty_hu.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwerty_ko.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwerty_lv.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwerty_no.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwerty_pl.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwerty_pt.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwerty_sv_se.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwerty_tr.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwerty_vi.xml Layout includes some ASCII punctuation but not all, missing: \ -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/qwerty.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwertz_cs.xml Layout includes some ASCII punctuation but not all, missing: ` -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/qwertz_de.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwertz_hu.xml -0 warnings +Layout doesn't specify a script. +1 warnings # res/xml/qwertz_sk.xml Layout includes some ASCII punctuation but not all, missing: \, ` -1 warnings +Layout doesn't specify a script. +2 warnings # res/xml/qwertz.xml -0 warnings +Layout doesn't specify a script. +1 warnings Not a layout file: res/xml/settings.xml diff --git a/check_layout.py b/check_layout.py index c38705e..f0c1a34 100644 --- a/check_layout.py +++ b/check_layout.py @@ -61,6 +61,9 @@ def check_layout(layout): unexpected_keys(keys, bottom_row_keys, "Layout contains keys present in the bottom row") + if root.get("script") == None: + warn("Layout doesn't specify a script.") + for fname in sys.argv[1:]: layout = parse_layout(fname) if layout == None: diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index bc78f23..e66f1c7 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -23,13 +23,15 @@ class KeyboardData public final float keysHeight; /** Might be null. */ public final Modmap modmap; + /** Might be null. */ + public final String script; public KeyboardData mapKeys(MapKey f) { ArrayList rows_ = new ArrayList(); for (Row r : rows) rows_.add(r.mapKeys(f)); - return new KeyboardData(rows_, keysWidth, modmap); + return new KeyboardData(rows_, keysWidth, modmap, script); } /** Add keys from the given iterator into the keyboard. Extra keys are added @@ -49,7 +51,7 @@ class KeyboardData for (int c = 1; c <= 4; c++) addExtraKeys_to_row(rows, k, r, c); } - return new KeyboardData(rows, keysWidth, modmap); + return new KeyboardData(rows, keysWidth, modmap, script); } public KeyboardData addNumPad() @@ -73,14 +75,14 @@ class KeyboardData extendedRows.add(new Row(keys, row.height, row.shift)); } return new - KeyboardData(extendedRows, compute_max_width(extendedRows), modmap); + KeyboardData(extendedRows, compute_max_width(extendedRows), modmap, script); } public KeyboardData addNumberRow() { ArrayList rows_ = new ArrayList(this.rows); rows_.add(0, number_row.updateWidth(keysWidth)); - return new KeyboardData(rows_, keysWidth, modmap); + return new KeyboardData(rows_, keysWidth, modmap, script); } public Key findKeyWithValue(KeyValue kv) @@ -175,6 +177,7 @@ class KeyboardData throw new Exception("Empty layout file"); boolean add_bottom_row = attribute_bool(parser, "bottom_row", true); float specified_kw = attribute_float(parser, "width", 0f); + String script = parser.getAttributeValue(null, "script"); ArrayList rows = new ArrayList(); Modmap modmap = null; while (next_tag(parser)) @@ -194,7 +197,7 @@ class KeyboardData float kw = (specified_kw != 0f) ? specified_kw : compute_max_width(rows); if (add_bottom_row) rows.add(bottom_row.updateWidth(kw)); - return new KeyboardData(rows, kw, modmap); + return new KeyboardData(rows, kw, modmap, script); } private static float compute_max_width(List rows) @@ -212,13 +215,14 @@ class KeyboardData return Row.parse(parser); } - protected KeyboardData(List rows_, float kw, Modmap mm) + protected KeyboardData(List rows_, float kw, Modmap mm, String sc) { float kh = 0.f; for (Row r : rows_) kh += r.height + r.shift; rows = rows_; modmap = mm; + script = sc; keysWidth = kw; keysHeight = kh; }