From d5cbcb37e315a62b9e61873937bc4b38e4d0f5a7 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sun, 24 Sep 2023 16:35:24 +0200 Subject: Preferred position for locale `extra_keys` `method.xml` is now able to specify a preferred position for each extra keys in term of an other key to which it should be placed nearby. It's implemented for French as an example. --- srcs/juloo.keyboard2/KeyboardData.java | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'srcs/juloo.keyboard2/KeyboardData.java') diff --git a/srcs/juloo.keyboard2/KeyboardData.java b/srcs/juloo.keyboard2/KeyboardData.java index 94c1384..8ecd053 100644 --- a/srcs/juloo.keyboard2/KeyboardData.java +++ b/srcs/juloo.keyboard2/KeyboardData.java @@ -58,6 +58,13 @@ class KeyboardData [rows]. Returns [false] if it couldn't be placed. */ boolean add_key_to_preferred_pos(List rows, KeyValue kv, PreferredPos pos) { + if (pos.next_to != null) + { + KeyPos next_to_pos = getKeys().get(pos.next_to); + if (next_to_pos != null + && add_key_to_pos(rows, kv, next_to_pos.with_dir(-1))) + return true; + } for (KeyPos p : pos.positions) if (add_key_to_pos(rows, kv, p)) return true; @@ -521,6 +528,11 @@ class KeyboardData col = c; dir = d; } + + public KeyPos with_dir(int d) + { + return new KeyPos(row, col, d); + } } /** See [addExtraKeys()]. */ @@ -529,6 +541,10 @@ class KeyboardData public static final PreferredPos DEFAULT; public static final PreferredPos ANYWHERE; + /** Prefer the free position on the same keyboard key as the specified key. + Considered before [positions]. Might be [null]. */ + public KeyValue next_to = null; + /** Array of positions to try in order. The special value [-1] as [row], [col] or [dir] means that the field is unspecified. Every possible values are tried for unspecified fields. Unspecified fields are @@ -537,6 +553,12 @@ class KeyboardData public PreferredPos() {} + public PreferredPos(PreferredPos src) + { + next_to = src.next_to; + positions = src.positions; + } + static final KeyPos[] ANYWHERE_POSITIONS = new KeyPos[]{ new KeyPos(-1, -1, -1) }; -- cgit v1.2.3