From 3a90ed61090fa3adfe5bd44c11a366108ca93a60 Mon Sep 17 00:00:00 2001 From: Gabriel Ozouf Date: Wed, 21 Oct 2020 14:21:46 +0200 Subject: [PATCH] [ion/events_keyboard] Fix selection on long press A previous fix to prevent AlphaLock from interfering with the long press feature broke the long press selection. Revert the changes and find another solution to the previous problem. We compare the alpha status to both the state of the Alpha key and the Lock, which makes sense : Lock is supposed to mimic Alpha being continuously pressed. Change-Id: I1349eb83f8971d3a5efcb10de020bb6c0aed64a1 --- ion/src/shared/events_keyboard.cpp | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/ion/src/shared/events_keyboard.cpp b/ion/src/shared/events_keyboard.cpp index 2c1cba7e3..2c7c91c56 100644 --- a/ion/src/shared/events_keyboard.cpp +++ b/ion/src/shared/events_keyboard.cpp @@ -50,10 +50,6 @@ 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); @@ -70,9 +66,6 @@ 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) { @@ -84,7 +77,9 @@ 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. */ - key = keyFromState(keysSeenTransitionningFromUpToDown); + 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); Event event(key, shift, alpha, lock); sLastEventShift = shift; sLastEventAlpha = alpha; @@ -103,11 +98,10 @@ 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 - && sLastEvent == event) + && sLastEventShift == state.keyDown(Keyboard::Key::Shift) + && sLastEventAlpha == (state.keyDown(Keyboard::Key::Alpha) || lock)) { int delay = (sEventIsRepeating ? delayBetweenRepeat : delayBeforeRepeat); if (time >= delay) {