From 9ff8179d490c9385df01b82ce8855956dced69cb Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Tue, 26 Dec 2023 17:05:51 +0100 Subject: [PATCH] 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'. --- srcs/juloo.keyboard2/Config.java | 11 +++++------ srcs/juloo.keyboard2/KeyModifier.java | 6 +++--- srcs/juloo.keyboard2/Keyboard2.java | 3 +-- srcs/juloo.keyboard2/KeyboardData.java | 25 ++++++++++++++++++------- 4 files changed, 27 insertions(+), 18 deletions(-) diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 94b0861..31fe0b0 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -268,7 +268,7 @@ final class Config } }); if (show_numpad) - kw = kw.addNumPad(modify_numpad(KeyboardData.num_pad, kw.script)); + kw = kw.addNumPad(modify_numpad(KeyboardData.num_pad, kw)); if (number_row) kw = kw.addNumberRow(); if (extra_keys.size() > 0) @@ -276,13 +276,12 @@ final class Config return kw; } - /** - * Handle the numpad layout. - */ - public KeyboardData modify_numpad(KeyboardData kw, String script) + /** Handle the numpad layout. The [main_kw] is used to adapt the numpad to + the main layout's script. */ + public KeyboardData modify_numpad(KeyboardData kw, KeyboardData main_kw) { final KeyValue action_key = action_key(); - final KeyModifier.Map_char map_digit = KeyModifier.modify_numpad_script(script); + final KeyModifier.Map_char map_digit = KeyModifier.modify_numpad_script(main_kw.numpad_script); return kw.mapKeys(new KeyboardData.MapKeyValues() { public KeyValue apply(KeyValue key, boolean localized) { diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java index 9ec34b8..ba3af2e 100644 --- a/srcs/juloo.keyboard2/KeyModifier.java +++ b/srcs/juloo.keyboard2/KeyModifier.java @@ -83,11 +83,11 @@ class KeyModifier return k; } - public static Map_char modify_numpad_script(String script) + public static Map_char modify_numpad_script(String numpad_script) { - if (script == null) + if (numpad_script == null) return map_char_none; - switch (script) + switch (numpad_script) { case "arabic": return map_char_numpad_arabic; case "bengali": return map_char_numpad_bengali; diff --git a/srcs/juloo.keyboard2/Keyboard2.java b/srcs/juloo.keyboard2/Keyboard2.java index 1330b96..d045396 100644 --- a/srcs/juloo.keyboard2/Keyboard2.java +++ b/srcs/juloo.keyboard2/Keyboard2.java @@ -89,9 +89,8 @@ public class Keyboard2 extends InputMethodService /** Load a layout that contains a numpad (eg. the pin entry). */ KeyboardData loadNumpad(int layout_id) { - String current_script = current_layout_unmodified().script; return _config.modify_numpad(KeyboardData.load(getResources(), layout_id), - current_script); + current_layout_unmodified()); } @Override 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 _key_pos = null; @@ -33,7 +35,7 @@ class KeyboardData ArrayList rows_ = new ArrayList(); 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 rows_ = new ArrayList(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 rows = new ArrayList(); 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 rows) @@ -262,7 +266,7 @@ class KeyboardData return Row.parse(parser); } - protected KeyboardData(List rows_, float kw, Modmap mm, String sc) + protected KeyboardData(List 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 rows) + { + this(rows, compute_max_width(rows), src.modmap, src.script, src.numpad_script); + } + public static class Row { public final List keys;