From 4906f8105f9f831b5977d4935f90ef26b8afdafd Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 25 May 2024 21:19:44 +0200 Subject: Circle and round trip gestures (#640) This implements clockwise/anticlockwise circle and round trip gestures inspired by Messagease. The circle gestures start after a small threshold to avoid making the regular swipe too hard to aim. The gestures do: - circle: The center symbol with Shift applied, with a fallback on Fn - round trip: Same as the circle gesture but applied to a side symbol - anticlockwise circle: Nothing currently. It is intended to be made configurable per-layout in the future. The new Gesture class keeps track of what the pointer is doing while it moves on a key. It replaces the 'selected_direction' integer. --- srcs/juloo.keyboard2/KeyModifier.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'srcs/juloo.keyboard2/KeyModifier.java') diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java index f358e97..a320ec5 100644 --- a/srcs/juloo.keyboard2/KeyModifier.java +++ b/srcs/juloo.keyboard2/KeyModifier.java @@ -33,7 +33,6 @@ public final class KeyModifier if (r == null) { r = k; - /* Order: Fn, Shift, accents */ for (int i = 0; i < n_mods; i++) r = modify(r, mods.get(i)); ks.put(mods, r); @@ -70,6 +69,7 @@ public final class KeyModifier case ALT: case META: return turn_into_keyevent(k); case FN: return apply_fn(k); + case GESTURE: return apply_gesture(k); case SHIFT: return apply_shift(k); case GRAVE: return apply_map_char(k, map_char_grave); case AIGU: return apply_map_char(k, map_char_aigu); @@ -139,11 +139,10 @@ public final class KeyModifier case Char: char kc = k.getChar(); String modified = map.apply(kc); - if (modified == null) - return k; - return KeyValue.makeStringKey(modified, k.getFlags()); - default: return k; + if (modified != null) + return KeyValue.makeStringKey(modified, k.getFlags()); } + return k; } private static KeyValue apply_shift(KeyValue k) @@ -482,6 +481,15 @@ public final class KeyModifier return k.withKeyevent(e); } + /** Modify a key affected by a round-trip or a clockwise circle gesture. */ + private static KeyValue apply_gesture(KeyValue k) + { + KeyValue shifted = apply_shift(k); + if (shifted == null || shifted.equals(k)) + return apply_fn(k); + return shifted; + } + /* Lookup the cache entry for a key. Create it needed. */ private static HashMap cacheEntry(KeyValue k) { -- cgit v1.2.3