diff options
| author | Jules Aguillon | 2025-02-23 18:00:44 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2025-02-23 18:00:44 +0100 |
| commit | ca25cc55f6bc2c7b3100da2f7bf18a078a23f55e (patch) | |
| tree | e3e94c2fa073e44063b66d86f8be4789620714ad /srcs/juloo.keyboard2/KeyModifier.java | |
| parent | 68be82a4f92f47300b9960cf9cf65040c96f17ed (diff) | |
| download | unexpected-keyboard-ca25cc55f6bc2c7b3100da2f7bf18a078a23f55e.tar.gz unexpected-keyboard-ca25cc55f6bc2c7b3100da2f7bf18a078a23f55e.zip | |
Apply compose sequences to String keys
This is mostly useful for characters that do not fit on a single 16-bit
char.
Shift sequences for 𝕨𝕩𝕗𝕘𝕤 are added for illustration.
Diffstat (limited to 'srcs/juloo.keyboard2/KeyModifier.java')
| -rw-r--r-- | srcs/juloo.keyboard2/KeyModifier.java | 60 |
1 files changed, 38 insertions, 22 deletions
diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java index fcb0793..c9de407 100644 --- a/srcs/juloo.keyboard2/KeyModifier.java +++ b/srcs/juloo.keyboard2/KeyModifier.java @@ -36,7 +36,7 @@ public final class KeyModifier case Modifier: return modify(k, mod.getModifier()); case Compose_pending: - return ComposeKey.apply(mod.getPendingCompose(), k); + return apply_compose_pending(mod.getPendingCompose(), k); case Hangul_initial: if (k.equals(mod)) // Allow typing the initial in letter form return KeyValue.makeStringKey(k.getString(), KeyValue.FLAG_GREYED); @@ -122,30 +122,44 @@ public final class KeyModifier } } - /** Apply the given compose state or fallback to the dead_char. */ - private static KeyValue apply_compose_or_dead_char(KeyValue k, int state, char dead_char) + /** Keys that do not match any sequence are greyed. */ + private static KeyValue apply_compose_pending(int state, KeyValue kv) { - switch (k.getKind()) + switch (kv.getKind()) { case Char: - char c = k.getChar(); - KeyValue r = ComposeKey.apply(state, c); - if (r != null) - return r; + case String: + KeyValue res = ComposeKey.apply(state, kv); + // Grey-out characters not part of any sequence. + if (res == null) + return kv.withFlags(kv.getFlags() | KeyValue.FLAG_GREYED); + return res; + /* Tapping compose again exits the pending sequence. */ + case Compose_pending: + return KeyValue.getKeyByName("compose_cancel"); + /* These keys are not greyed. */ + case Event: + case Modifier: + return kv; + /* Other keys cannot be part of sequences. */ + default: + return kv.withFlags(kv.getFlags() | KeyValue.FLAG_GREYED); } + } + + /** Apply the given compose state or fallback to the dead_char. */ + private static KeyValue apply_compose_or_dead_char(KeyValue k, int state, char dead_char) + { + KeyValue r = ComposeKey.apply(state, k); + if (r != null) + return r; return apply_dead_char(k, dead_char); } private static KeyValue apply_compose(KeyValue k, int state) { - switch (k.getKind()) - { - case Char: - KeyValue r = ComposeKey.apply(state, k.getChar()); - if (r != null) - return r; - } - return k; + KeyValue r = ComposeKey.apply(state, k); + return (r != null) ? r : k; } private static KeyValue apply_dead_char(KeyValue k, char dead_char) @@ -179,18 +193,19 @@ public final class KeyModifier if (mapped != null) return mapped; } + KeyValue r = ComposeKey.apply(ComposeKeyData.shift, k); + if (r != null) + return r; switch (k.getKind()) { case Char: char kc = k.getChar(); - KeyValue r = ComposeKey.apply(ComposeKeyData.shift, kc); - if (r != null) - return r; char c = Character.toUpperCase(kc); return (kc == c) ? k : k.withChar(c); case String: - String s = Utils.capitalize_string(k.getString()); - return KeyValue.makeStringKey(s, k.getFlags()); + String ks = k.getString(); + String s = Utils.capitalize_string(ks); + return s.equals(ks) ? k : KeyValue.makeStringKey(s, k.getFlags()); default: return k; } } @@ -207,7 +222,8 @@ public final class KeyModifier switch (k.getKind()) { case Char: - KeyValue r = ComposeKey.apply(ComposeKeyData.fn, k.getChar()); + case String: + KeyValue r = ComposeKey.apply(ComposeKeyData.fn, k); return (r != null) ? r : k; case Keyevent: name = apply_fn_keyevent(k.getKeyevent()); break; case Event: name = apply_fn_event(k.getEvent()); break; |
