diff --git a/srcs/juloo.keyboard2/prefs/ExtraKeysPreference.java b/srcs/juloo.keyboard2/prefs/ExtraKeysPreference.java index a0be7a9..49c7a99 100644 --- a/srcs/juloo.keyboard2/prefs/ExtraKeysPreference.java +++ b/srcs/juloo.keyboard2/prefs/ExtraKeysPreference.java @@ -306,77 +306,38 @@ public class ExtraKeysPreference extends PreferenceCategory + KeyValue.getKeyByName(key_name).getString(); } + /** Place an extra key next to the key specified by the first argument, on + bottom-right preferably or on the bottom-left. If the specified key is not + on the layout, place on the specified row and column. */ + static KeyboardData.PreferredPos mk_preferred_pos(String next_to_key, int row, int col, boolean prefer_bottom_right) + { + KeyValue next_to = (next_to_key == null) ? null : KeyValue.getKeyByName(next_to_key); + int d1, d2; // Preferred direction and fallback direction + if (prefer_bottom_right) { d1 = 4; d2 = 3; } else { d1 = 3; d2 = 4; } + return new KeyboardData.PreferredPos(next_to, + new KeyboardData.KeyPos[]{ + new KeyboardData.KeyPos(row, col, d1), + new KeyboardData.KeyPos(row, col, d2), + new KeyboardData.KeyPos(row, -1, d1), + new KeyboardData.KeyPos(row, -1, d2), + new KeyboardData.KeyPos(-1, -1, -1), + }); + } + static KeyboardData.PreferredPos key_preferred_pos(String key_name) { switch (key_name) { - case "cut": - return new KeyboardData.PreferredPos(KeyValue.getKeyByName("x"), - new KeyboardData.KeyPos[]{ - new KeyboardData.KeyPos(2, 2, 8), - new KeyboardData.KeyPos(2, -1, 8), - new KeyboardData.KeyPos(-1, -1, 8), - }); - case "copy": - return new KeyboardData.PreferredPos(KeyValue.getKeyByName("c"), - new KeyboardData.KeyPos[]{ - new KeyboardData.KeyPos(2, 3, 8), - new KeyboardData.KeyPos(2, -1, 8), - new KeyboardData.KeyPos(-1, -1, 8), - }); - case "paste": - return new KeyboardData.PreferredPos(KeyValue.getKeyByName("v"), - new KeyboardData.KeyPos[]{ - new KeyboardData.KeyPos(2, 4, 8), - new KeyboardData.KeyPos(2, -1, 8), - new KeyboardData.KeyPos(-1, -1, 8), - }); - case "undo": - return new KeyboardData.PreferredPos(KeyValue.getKeyByName("z"), - new KeyboardData.KeyPos[]{ - new KeyboardData.KeyPos(2, 1, 8), - new KeyboardData.KeyPos(2, -1, 8), - new KeyboardData.KeyPos(-1, -1, 8), - }); - case "selectAll": - return new KeyboardData.PreferredPos(KeyValue.getKeyByName("a"), - new KeyboardData.KeyPos[]{ - new KeyboardData.KeyPos(1, 0, 8), - new KeyboardData.KeyPos(1, -1, 8), - new KeyboardData.KeyPos(-1, -1, 8), - }); - case "redo": - return new KeyboardData.PreferredPos(KeyValue.getKeyByName("y"), - new KeyboardData.KeyPos[]{ - new KeyboardData.KeyPos(0, -1, 8), - new KeyboardData.KeyPos(-1, -1, 8), - }); - case "f11_placeholder": - return new KeyboardData.PreferredPos(KeyValue.getKeyByName("9"), - new KeyboardData.KeyPos[]{ - new KeyboardData.KeyPos(0, 8, 3), - new KeyboardData.KeyPos(0, 8, 4), - new KeyboardData.KeyPos(0, -1, 3), - new KeyboardData.KeyPos(0, -1, 4), - }); - case "f12_placeholder": - return new KeyboardData.PreferredPos(KeyValue.getKeyByName("0"), - new KeyboardData.KeyPos[]{ - new KeyboardData.KeyPos(0, 9, 3), - new KeyboardData.KeyPos(0, 9, 4), - new KeyboardData.KeyPos(0, -1, 3), - new KeyboardData.KeyPos(0, -1, 4), - }); - case "delete_word": - return new KeyboardData.PreferredPos(KeyValue.getKeyByName("backspace"), - new KeyboardData.KeyPos[]{ - new KeyboardData.KeyPos(-1, -1, 3), - }); - case "forward_delete_word": - return new KeyboardData.PreferredPos(KeyValue.getKeyByName("backspace"), - new KeyboardData.KeyPos[]{ - new KeyboardData.KeyPos(-1, -1, 4), - }); + case "cut": return mk_preferred_pos("x", 2, 2, true); + case "copy": return mk_preferred_pos("c", 2, 3, true); + case "paste": return mk_preferred_pos("v", 2, 4, true); + case "undo": return mk_preferred_pos("z", 2, 1, true); + case "selectAll": return mk_preferred_pos("a", 1, 0, true); + case "redo": return mk_preferred_pos("y", 0, 5, true); + case "f11_placeholder": return mk_preferred_pos("9", 0, 8, false); + case "f12_placeholder": return mk_preferred_pos("0", 0, 9, false); + case "delete_word": return mk_preferred_pos("backspace", -1, -1, false); + case "forward_delete_word": return mk_preferred_pos("backspace", -1, -1, true); } return KeyboardData.PreferredPos.DEFAULT; }