diff options
| author | Jules Aguillon | 2024-02-11 20:46:36 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2024-02-17 23:28:31 +0100 |
| commit | 8c290732607692cd94247f7e3e9c80fad1dfe516 (patch) | |
| tree | 1903ef13cc72626d0b12c712f9d15aede6fc67b4 /srcs/juloo.keyboard2/ComposeKey.java | |
| parent | 38deb810f94d0e2fea91add4cd53fdd615d19d64 (diff) | |
| download | unexpected-keyboard-8c290732607692cd94247f7e3e9c80fad1dfe516.tar.gz unexpected-keyboard-8c290732607692cd94247f7e3e9c80fad1dfe516.zip | |
Compose key
The COMPOSE_PENDING modifier indicate whether a compose sequence is in
progress. The new key of kind Compose_pending sets the current state of
the sequence.
The compose sequences are compiled into a state machine by a python
script into a compact encoding.
The state of the pending compose is determined by the index of a state.
Diffstat (limited to 'srcs/juloo.keyboard2/ComposeKey.java')
| -rw-r--r-- | srcs/juloo.keyboard2/ComposeKey.java | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/srcs/juloo.keyboard2/ComposeKey.java b/srcs/juloo.keyboard2/ComposeKey.java new file mode 100644 index 0000000..5b89560 --- /dev/null +++ b/srcs/juloo.keyboard2/ComposeKey.java @@ -0,0 +1,55 @@ +package juloo.keyboard2; + +import java.util.Arrays; + +public final class ComposeKey +{ + /** Apply the pending compose sequence to [kv]. Returns [null] if [kv] is not + part of the pending sequence. */ + public static KeyValue apply(int state, KeyValue kv) + { + switch (kv.getKind()) + { + case Char: return apply(state, kv.getChar()); + /* These keys must not be removed. */ + case Event: return kv; + case Modifier: return kv; + /* These keys cannot be part of sequences. */ + case String: return null; + case Keyevent: return null; + case Editing: return null; + case Placeholder: return null; + case Compose_pending: return null; + } + return null; + } + + /** Apply the pending compose sequence to char [c]. */ + static KeyValue apply(int state, char c) + { + char[] states = ComposeKeyData.states; + short[] edges = ComposeKeyData.edges; + int length = edges[state]; + int next = Arrays.binarySearch(states, state + 1, state + length, c); + if (next < 0) + return null; + next = edges[next]; + // The next state is the end of a sequence, show the result. + if (edges[next] == 1) + return KeyValue.makeCharKey(states[next]); + return KeyValue.makeComposePending(String.valueOf(c), next, 0); + } + + /** The [states] array represents the different states and their transition. + A state occupies one or several cells of the array: + - The first cell is the result of the conpose sequence if the state is of + size 1, [0] otherwise. + - The remaining cells are the transitions, sorted alphabetically. + + The [edges] array represents the transition state corresponding to each + accepted inputs. + Id [states[i]] is the first cell of a state, [edges[i]] is the number of + cells occupied by the state [i]. + If [states[i]] is a transition, [edges[i]] is the index of the state to + jump into. */ +} |
