From b72635b8875e25dd6da7f42d05aac77468db85a2 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 30 Apr 2022 23:36:17 +0200 Subject: Fix modifiers not cleared when presses overlap When typing fast, a second key might be pressed before the first is released. Clearing modifiers earlier would prevent this but would break modifiers placed in corners (especially the accent keys). Instead, don't take latched modifiers into account when registering the second press. A new flag is needed to not interfere with holding modifers, which is merged with the norepeat flag. --- srcs/juloo.keyboard2/Pointers.java | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'srcs/juloo.keyboard2/Pointers.java') diff --git a/srcs/juloo.keyboard2/Pointers.java b/srcs/juloo.keyboard2/Pointers.java index 6368918..0d0e0fc 100644 --- a/srcs/juloo.keyboard2/Pointers.java +++ b/srcs/juloo.keyboard2/Pointers.java @@ -23,10 +23,19 @@ public final class Pointers implements Handler.Callback } public int getFlags() + { + return getFlags(false); + } + + /* When [skip_latched] is true, don't take flags of latched keys into account. */ + private int getFlags(boolean skip_latched) { int flags = 0; for (Pointer p : _ptrs) - flags |= p.flags; + { + if (!(skip_latched && p.pointerId == -1 && (p.flags & KeyValue.FLAG_LOCKED) == 0)) + flags |= p.flags; + } return flags; } @@ -107,6 +116,15 @@ public final class Pointers implements Handler.Callback _handler.onPointerFlagsChanged(); } + /* Whether an other pointer is down on a non-special key. */ + private boolean isOtherPointerDown() + { + for (Pointer p : _ptrs) + if (p.pointerId != -1 && (p.flags & KeyValue.FLAG_SPECIAL) == 0) + return true; + return false; + } + public void onTouchDown(float x, float y, int pointerId, KeyboardData.Key key) { // Ignore new presses while a modulated key is active. On some devices, @@ -114,11 +132,11 @@ public final class Pointers implements Handler.Callback // keys. if (isModulatedKeyPressed()) return; - int mflags = getFlags(); + int mflags = getFlags(isOtherPointerDown()); KeyValue value = _handler.onPointerDown(key.key0, mflags); Pointer ptr = new Pointer(pointerId, key, 0, value, x, y, mflags); _ptrs.add(ptr); - if (value != null && (value.flags & KeyValue.FLAG_NOREPEAT) == 0) + if (value != null && (value.flags & KeyValue.FLAG_SPECIAL) == 0) startKeyRepeat(ptr); } @@ -164,7 +182,7 @@ public final class Pointers implements Handler.Callback if ((old_flags & newValue.flags & KeyValue.FLAG_PRECISE_REPEAT) == 0) { stopKeyRepeat(ptr); - if ((newValue.flags & KeyValue.FLAG_NOREPEAT) == 0) + if ((newValue.flags & KeyValue.FLAG_SPECIAL) == 0) startKeyRepeat(ptr); } } -- cgit v1.2.3