diff --git a/ion/include/ion/events.h b/ion/include/ion/events.h index 9e3d7b72f..b58727399 100644 --- a/ion/include/ion/events.h +++ b/ion/include/ion/events.h @@ -57,7 +57,7 @@ void removeShift(); bool isShiftActive(); bool isAlphaActive(); bool isLockActive(); -void setLongRepetition(bool longRepetition); +void setLongRepetition(int longRepetition); int repetitionFactor(); void updateModifiersFromEvent(Event e); void didPressNewKey(); diff --git a/ion/src/shared/events_keyboard.cpp b/ion/src/shared/events_keyboard.cpp index ad356b126..009939ba3 100644 --- a/ion/src/shared/events_keyboard.cpp +++ b/ion/src/shared/events_keyboard.cpp @@ -25,7 +25,6 @@ bool sEventIsRepeating = 0; int sEventRepetitionCount = 0; constexpr int delayBeforeRepeat = 200; constexpr int delayBetweenRepeat = 50; -constexpr int numberOfRepetitionsBeforeLongRepetition = 20; static bool canRepeatEvent(Event e) { return e == Events::Left @@ -41,9 +40,14 @@ static bool canRepeatEvent(Event e) { Event getPlatformEvent(); +void ComputeAndSetRepetionFactor(int eventRepetitionCount) { + // The Repetition factor is increased by 4 every 20 loops in getEvent(2 sec) + setLongRepetition((eventRepetitionCount / 20) * 4 + 1); +} + void resetLongRepetition() { sEventRepetitionCount = 0; - setLongRepetition(false); + ComputeAndSetRepetionFactor(sEventRepetitionCount); } Event getEvent(int * timeout) { @@ -85,7 +89,7 @@ Event getEvent(int * timeout) { } if (sleepWithTimeout(10, timeout)) { - // Timeout occured + // Timeout occurred resetLongRepetition(); return Events::None; } @@ -101,12 +105,8 @@ Event getEvent(int * timeout) { int delay = (sEventIsRepeating ? delayBetweenRepeat : delayBeforeRepeat); if (time >= delay) { sEventIsRepeating = true; - if (sEventRepetitionCount < numberOfRepetitionsBeforeLongRepetition) { - sEventRepetitionCount++; - if (sEventRepetitionCount == numberOfRepetitionsBeforeLongRepetition) { - setLongRepetition(true); - } - } + sEventRepetitionCount++; + ComputeAndSetRepetionFactor(sEventRepetitionCount); return sLastEvent; } } diff --git a/ion/src/shared/events_modifier.cpp b/ion/src/shared/events_modifier.cpp index 79be23553..7cccc2877 100644 --- a/ion/src/shared/events_modifier.cpp +++ b/ion/src/shared/events_modifier.cpp @@ -5,7 +5,7 @@ namespace Ion { namespace Events { static ShiftAlphaStatus sShiftAlphaStatus = ShiftAlphaStatus::Default; -static bool sLongRepetition = false; +static int sLongRepetition = 1; ShiftAlphaStatus shiftAlphaStatus() { return sShiftAlphaStatus; @@ -33,12 +33,12 @@ bool isLockActive() { return sShiftAlphaStatus == ShiftAlphaStatus::AlphaLock || sShiftAlphaStatus == ShiftAlphaStatus::ShiftAlphaLock; } -void setLongRepetition(bool longRepetition) { +void setLongRepetition(int longRepetition) { sLongRepetition = longRepetition; } int repetitionFactor() { - return sLongRepetition ? 5 : 1; + return sLongRepetition; }; void setShiftAlphaStatus(ShiftAlphaStatus s) {