From ab864d10d886150799861fec4a2063cf288ce8fc Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Wed, 30 Sep 2020 10:12:12 +0200 Subject: [PATCH] [ion/events] Compare event for repetition This fixes the following bug : (Anywhere with a movable cursor, like a table, a text field or a curve) - press Alpha (once, or twice to activate the lock) - keep pressing a direction --> The cursor would only move once. Change-Id: I46115d1a31ced244615bfdfe08f37dfe7e918d6e --- ion/src/shared/events_keyboard.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ion/src/shared/events_keyboard.cpp b/ion/src/shared/events_keyboard.cpp index 009939ba3..2c1cba7e3 100644 --- a/ion/src/shared/events_keyboard.cpp +++ b/ion/src/shared/events_keyboard.cpp @@ -50,6 +50,10 @@ void resetLongRepetition() { ComputeAndSetRepetionFactor(sEventRepetitionCount); } +static Keyboard::Key keyFromState(Keyboard::State state) { + return static_cast(63 - __builtin_clzll(state)); +} + Event getEvent(int * timeout) { assert(*timeout > delayBeforeRepeat); assert(*timeout > delayBetweenRepeat); @@ -66,6 +70,11 @@ Event getEvent(int * timeout) { keysSeenUp |= ~state; keysSeenTransitionningFromUpToDown = keysSeenUp & state; + Keyboard::Key key; + bool shift = isShiftActive() || state.keyDown(Keyboard::Key::Shift); + bool alpha = isAlphaActive() || state.keyDown(Keyboard::Key::Alpha); + bool lock = isLockActive(); + if (keysSeenTransitionningFromUpToDown != 0) { sEventIsRepeating = false; resetLongRepetition(); @@ -75,10 +84,7 @@ Event getEvent(int * timeout) { * processors have an instruction (ARM thumb uses CLZ). * Unfortunately there's no way to express this in standard C, so we have * to resort to using a builtin function. */ - Keyboard::Key key = (Keyboard::Key)(63-__builtin_clzll(keysSeenTransitionningFromUpToDown)); - bool shift = isShiftActive() || state.keyDown(Keyboard::Key::Shift); - bool alpha = isAlphaActive() || state.keyDown(Keyboard::Key::Alpha); - bool lock = isLockActive(); + key = keyFromState(keysSeenTransitionningFromUpToDown); Event event(key, shift, alpha, lock); sLastEventShift = shift; sLastEventAlpha = alpha; @@ -97,10 +103,11 @@ Event getEvent(int * timeout) { // At this point, we know that keysSeenTransitionningFromUpToDown has *always* been zero // In other words, no new key has been pressed + key = keyFromState(state); + Event event(key, shift, alpha, lock); if (canRepeatEvent(sLastEvent) && state == sLastKeyboardState - && sLastEventShift == state.keyDown(Keyboard::Key::Shift) - && sLastEventAlpha == state.keyDown(Keyboard::Key::Alpha)) + && sLastEvent == event) { int delay = (sEventIsRepeating ? delayBetweenRepeat : delayBeforeRepeat); if (time >= delay) {