diff options
| author | Jules Aguillon | 2023-12-26 17:05:51 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2023-12-26 17:05:51 +0100 |
| commit | 9ff8179d490c9385df01b82ce8855956dced69cb (patch) | |
| tree | 2be95e5ca48ca80bf344d7ebb87691c7be0954d2 /srcs/juloo.keyboard2/KeyboardData.java | |
| parent | 1af4e451175e5c5ae6fceee158519aa774118e99 (diff) | |
| download | unexpected-keyboard-9ff8179d490c9385df01b82ce8855956dced69cb.tar.gz unexpected-keyboard-9ff8179d490c9385df01b82ce8855956dced69cb.zip | |
Add layout attribute 'numpad_script'
This new attribute is now used instead of 'script' for modifying the
numpad according to the selected layout's script.
If not provided, it defaults to the value of 'script'.
Diffstat (limited to 'srcs/juloo.keyboard2/KeyboardData.java')
| -rw-r--r-- | srcs/juloo.keyboard2/KeyboardData.java | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index 989c5f6..ed5aa9a 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -25,6 +25,8 @@ class KeyboardData public final Modmap modmap; /** Might be null. */ public final String script; + /** Might be different from [script]. Might be null. */ + public final String numpad_script; /** Position of every keys on the layout, see [getKeys()]. */ private Map<KeyValue, KeyPos> _key_pos = null; @@ -33,7 +35,7 @@ class KeyboardData ArrayList<Row> rows_ = new ArrayList<Row>(); for (Row r : rows) rows_.add(r.mapKeys(f)); - return new KeyboardData(rows_, keysWidth, modmap, script); + return new KeyboardData(this, rows_); } /** Add keys from the given iterator into the keyboard. Preferred position is @@ -51,7 +53,7 @@ class KeyboardData } for (KeyValue kv : unplaced_keys) add_key_to_preferred_pos(rows, kv, PreferredPos.ANYWHERE); - return new KeyboardData(rows, keysWidth, modmap, script); + return new KeyboardData(this, rows); } /** Place a key on the keyboard according to its preferred position. Mutates @@ -125,15 +127,14 @@ class KeyboardData } extendedRows.add(new Row(keys, row.height, row.shift)); } - return new - KeyboardData(extendedRows, compute_max_width(extendedRows), modmap, script); + return new KeyboardData(this, extendedRows); } public KeyboardData addNumberRow() { ArrayList<Row> rows_ = new ArrayList<Row>(this.rows); rows_.add(0, number_row.updateWidth(keysWidth)); - return new KeyboardData(rows_, keysWidth, modmap, script); + return new KeyboardData(this, rows_); } public Key findKeyWithValue(KeyValue kv) @@ -225,6 +226,9 @@ class KeyboardData boolean add_bottom_row = attribute_bool(parser, "bottom_row", true); float specified_kw = attribute_float(parser, "width", 0f); String script = parser.getAttributeValue(null, "script"); + String numpad_script = parser.getAttributeValue(null, "numpad_script"); + if (numpad_script == null) + numpad_script = script; ArrayList<Row> rows = new ArrayList<Row>(); Modmap modmap = null; while (next_tag(parser)) @@ -244,7 +248,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, script); + return new KeyboardData(rows, kw, modmap, script, numpad_script); } private static float compute_max_width(List<Row> rows) @@ -262,7 +266,7 @@ class KeyboardData return Row.parse(parser); } - protected KeyboardData(List<Row> rows_, float kw, Modmap mm, String sc) + protected KeyboardData(List<Row> rows_, float kw, Modmap mm, String sc, String npsc) { float kh = 0.f; for (Row r : rows_) @@ -270,10 +274,17 @@ class KeyboardData rows = rows_; modmap = mm; script = sc; + numpad_script = npsc; keysWidth = kw; keysHeight = kh; } + /** Copies the fields of an other keyboard, with rows changed. */ + protected KeyboardData(KeyboardData src, List<Row> rows) + { + this(rows, compute_max_width(rows), src.modmap, src.script, src.numpad_script); + } + public static class Row { public final List<Key> keys; |
