diff --git a/src/rsiglobals.h b/src/rsiglobals.h --- a/src/rsiglobals.h +++ b/src/rsiglobals.h @@ -62,6 +62,7 @@ BIG_BREAK_THRESHOLD, POSTPONE_BREAK_INTERVAL, PATIENCE_INTERVAL, + SHORT_INPUT_INTERVAL, INTERVAL_COUNT }; diff --git a/src/rsiglobals.cpp b/src/rsiglobals.cpp --- a/src/rsiglobals.cpp +++ b/src/rsiglobals.cpp @@ -74,6 +74,7 @@ m_intervals[BIG_BREAK_THRESHOLD] = config.readEntry( "BigThreshold", 1 ) * 60; m_intervals[POSTPONE_BREAK_INTERVAL] = config.readEntry( "PostponeBreakDuration", 5 ) * 60; m_intervals[PATIENCE_INTERVAL] = config.readEntry( "Patience", 30 ); + m_intervals[SHORT_INPUT_INTERVAL] = config.readEntry( "ShortInputInterval", 2 ); if ( config.readEntry( "DEBUG", 0 ) > 0 ) { qDebug() << "Debug mode activated"; diff --git a/src/rsitimer.cpp b/src/rsitimer.cpp --- a/src/rsitimer.cpp +++ b/src/rsitimer.cpp @@ -107,6 +107,7 @@ m_state = TimerState::Resting; m_pauseCounter = std::unique_ptr { new RSITimerCounter( breakTime, breakTime, INT_MAX ) }; m_popupCounter = nullptr; + m_shortInputCounter = std::unique_ptr { new RSITimerCounter( m_intervals[SHORT_INPUT_INTERVAL], 1, 1 ) }; if ( nextBreakIsBig ) { emit startLongBreak(); } else { @@ -271,7 +272,7 @@ } case TimerState::Resting: { bool isInputLong = (m_shortInputCounter->tick(idleSeconds) > 0); - int inverseTick = ( idleSeconds == 0 && isInputLong > 0 ) ? 1 : 0; // inverting as we account idle seconds here. + int inverseTick = ( idleSeconds == 0 && isInputLong ) ? 1 : 0; // inverting as we account idle seconds here. int breakTime = m_pauseCounter->tick( inverseTick ); if ( breakTime > 0 ) { resetAfterBreak(); @@ -314,7 +315,7 @@ // For measuring input duration in order to limit influence of short inputs on resetting pause counter. // Example of short input is: mouse sent input due to accidental touch or desk vibration. - m_shortInputCounter = std::unique_ptr { new RSITimerCounter( 2, 2, 1 ) }; + m_shortInputCounter = std::unique_ptr { new RSITimerCounter( m_intervals[SHORT_INPUT_INTERVAL], 1, 1 ) }; emit relax( breakTime, nextOneIsBig ); } diff --git a/test/rsitimer_test.cpp b/test/rsitimer_test.cpp --- a/test/rsitimer_test.cpp +++ b/test/rsitimer_test.cpp @@ -32,6 +32,7 @@ m_intervals[BIG_BREAK_THRESHOLD] = 5 * 60; m_intervals[POSTPONE_BREAK_INTERVAL] = 3 * 60; m_intervals[PATIENCE_INTERVAL] = 30; + m_intervals[SHORT_INPUT_INTERVAL] = 2; } void RSITimerTest::triggerSimpleTinyBreak() @@ -168,7 +169,8 @@ int tinyBreaks = m_intervals[BIG_BREAK_INTERVAL] / ( m_intervals[TINY_BREAK_INTERVAL] + m_intervals[PATIENCE_INTERVAL] + m_intervals[TINY_BREAK_DURATION] ); // We don't tick big pause timer during tiny breaks and patience, so it will actually happen later. - int ticks = m_intervals[BIG_BREAK_INTERVAL] + tinyBreaks * ( m_intervals[PATIENCE_INTERVAL] + m_intervals[TINY_BREAK_DURATION] ); + // In time the patience wears out, the tiny break could already accumulate some seconds due to SHORT_INPUT_INTERVAL filter, so substract them. + int ticks = m_intervals[BIG_BREAK_INTERVAL] + tinyBreaks * ( m_intervals[PATIENCE_INTERVAL] + m_intervals[TINY_BREAK_DURATION] - (m_intervals[PATIENCE_INTERVAL] - 1) % m_intervals[SHORT_INPUT_INTERVAL] ); QSignalSpy spyEndLongBreak( &timer, SIGNAL(endLongBreak()) );