abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/Config.java
diff options
context:
space:
mode:
authorJules Aguillon2023-01-30 23:46:02 +0100
committerJules Aguillon2023-01-30 23:46:02 +0100
commit78a461f7406a5ac76b686c646e8229fc8bb2a0d0 (patch)
treed39a0aa97789bafee10ee61fd4bf7506f3432702 /srcs/juloo.keyboard2/Config.java
parent90b7944129ae0facc5c789f0a416f7ff36925a90 (diff)
downloadunexpected-keyboard-78a461f7406a5ac76b686c646e8229fc8bb2a0d0.tar.gz
unexpected-keyboard-78a461f7406a5ac76b686c646e8229fc8bb2a0d0.zip
Modification step for the special layout
Refactor, follow up of 90b7944. Add a modification step to the "special" layouts: numpad, greekmath, pin entry. Remove the apply_key0 function, which is not expressive enough. Add an enum instead of yet an other "switch_" function.
Diffstat (limited to 'srcs/juloo.keyboard2/Config.java')
-rw-r--r--srcs/juloo.keyboard2/Config.java69
1 files changed, 47 insertions, 22 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java
index 691a424..db570e1 100644
--- a/srcs/juloo.keyboard2/Config.java
+++ b/srcs/juloo.keyboard2/Config.java
@@ -153,6 +153,13 @@ final class Config
extra_keys_param = ExtraKeyCheckBoxPreference.get_extra_keys(_prefs);
}
+ KeyValue action_key()
+ {
+ // Update the name to avoid caching in KeyModifier
+ return (actionLabel == null) ? null :
+ KeyValue.getKeyByName("action").withSymbol(actionLabel);
+ }
+
/** Update the layout according to the configuration.
* - Remove the switching key if it isn't needed
* - Remove "localized" keys from other locales (not in 'extra_keys')
@@ -161,9 +168,7 @@ final class Config
*/
public KeyboardData modify_layout(KeyboardData kw)
{
- // Update the name to avoid caching in KeyModifier
- final KeyValue action_key = (actionLabel == null) ? null :
- KeyValue.getKeyByName("action").withSymbol(actionLabel);
+ final KeyValue action_key = action_key();
// Extra keys are removed from the set as they are encountered during the
// first iteration then automatically added.
final Set<KeyValue> extra_keys = new HashSet<KeyValue>();
@@ -173,25 +178,6 @@ final class Config
if (show_numpad)
kw = kw.addNumPad();
kw = kw.mapKeys(new KeyboardData.MapKeyValues() {
- /** Apply to the center value only. Partial match, fallback to [apply]. */
- public KeyboardData.Corner apply_key0(KeyboardData.Corner corner)
- {
- if (corner == null)
- return null;
- KeyValue kv = corner.kv;
- switch (kv.getKind())
- {
- case Char:
- char c = kv.getChar();
- if (inverse_numpad)
- c = inverse_numpad_char(c);
- if (c != kv.getChar())
- return KeyboardData.Corner.of_kv(kv.withChar(c));
- break;
- }
- return super.apply(corner);
- }
-
public KeyValue apply(KeyValue key, boolean localized)
{
boolean is_extra_key = extra_keys.contains(key);
@@ -237,6 +223,45 @@ final class Config
return kw;
}
+ /**
+ * Handle the numpad layout.
+ */
+ public KeyboardData modify_numpad(KeyboardData kw)
+ {
+ final KeyValue action_key = action_key();
+ return kw.mapKeys(new KeyboardData.MapKeyValues() {
+ public KeyValue apply(KeyValue key, boolean localized)
+ {
+ switch (key.getKind())
+ {
+ case Event:
+ switch (key.getEvent())
+ {
+ case ACTION:
+ return (swapEnterActionKey && action_key != null) ?
+ KeyValue.getKeyByName("enter") : action_key;
+ }
+ break;
+ case Keyevent:
+ switch (key.getKeyevent())
+ {
+ case KeyEvent.KEYCODE_ENTER:
+ return (swapEnterActionKey && action_key != null) ? action_key : key;
+ }
+ break;
+ case Char:
+ char a = key.getChar(), b = a;
+ if (inverse_numpad)
+ b = inverse_numpad_char(a);
+ if (a != b)
+ return key.withChar(b);
+ break;
+ }
+ return key;
+ }
+ });
+ }
+
/** Modify a layout to turn it into a secondary layout by changing the
"switch_second" key. */
KeyboardData tweak_secondary_layout(KeyboardData layout)