From e604f6fd57d85f46dd46da9da192646660547bc2 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Mon, 18 Mar 2024 01:00:22 +0100 Subject: refactor: Implement Compose without global state Thanks to the previous commit, a modifier key can now be more complex than just a KeyValue.Modifier. This allows a more elegant implementation of the compose key, that could be taken as a base for other features (eg. unicode hex entry, hangul) The COMPOSE_PENDING modifier is removed as keys of kind Compose_pending can act as a modifier. This has the advantage of highlighting the key that was last pressed in the sequence. Rules are added to Pointers: Non-special but latchable keys must clear latches and cannot be locked with a long press. These rules were not needed before but were intended. --- srcs/juloo.keyboard2/Pointers.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'srcs/juloo.keyboard2/Pointers.java') diff --git a/srcs/juloo.keyboard2/Pointers.java b/srcs/juloo.keyboard2/Pointers.java index f7efb9e..4a1c2d0 100644 --- a/srcs/juloo.keyboard2/Pointers.java +++ b/srcs/juloo.keyboard2/Pointers.java @@ -19,6 +19,10 @@ public final class Pointers implements Handler.Callback public static final int FLAG_P_LOCKABLE = (1 << 3); public static final int FLAG_P_LOCKED = (1 << 4); public static final int FLAG_P_SLIDING = (1 << 5); + /** Clear latched (only if also FLAG_P_LATCHABLE set). */ + public static final int FLAG_P_CLEAR_LATCHED = (1 << 6); + /** Can't be locked, even when long pressing. */ + public static final int FLAG_P_CANT_LOCK = (1 << 7); private Handler _keyrepeat_handler; private ArrayList _ptrs = new ArrayList(); @@ -153,6 +157,9 @@ public final class Pointers implements Handler.Callback } else if ((ptr.flags & FLAG_P_LATCHABLE) != 0) { + // Latchable but non-special keys must clear latched. + if ((ptr.flags & FLAG_P_CLEAR_LATCHED) != 0) + clearLatched(); ptr.flags |= FLAG_P_LATCHED; ptr.pointerId = -1; _handler.onPointerFlagsChanged(false); @@ -395,7 +402,8 @@ public final class Pointers implements Handler.Callback // Long press toggle lock on modifiers if ((ptr.flags & FLAG_P_LATCHABLE) != 0) { - lockPointer(ptr, true); + if (!ptr.hasFlagsAny(FLAG_P_CANT_LOCK)) + lockPointer(ptr, true); return false; } // Stop repeating: Latched key, no key @@ -452,7 +460,12 @@ public final class Pointers implements Handler.Callback { int flags = 0; if (kv.hasFlagsAny(KeyValue.FLAG_LATCH)) + { + // Non-special latchable key must clear modifiers and can't be locked + if (!kv.hasFlagsAny(KeyValue.FLAG_SPECIAL)) + flags |= FLAG_P_CLEAR_LATCHED | FLAG_P_CANT_LOCK; flags |= FLAG_P_LATCHABLE; + } if (kv.hasFlagsAny(KeyValue.FLAG_LOCK)) flags |= FLAG_P_LOCKABLE; return flags; -- cgit v1.2.3