diff --git a/src/rsitimer.h b/src/rsitimer.h --- a/src/rsitimer.h +++ b/src/rsitimer.h @@ -186,6 +186,7 @@ std::unique_ptr m_tinyBreakCounter; std::unique_ptr m_pauseCounter; std::unique_ptr m_popupCounter; + std::unique_ptr m_shortInputCounter; void hibernationDetector( const int totalIdle ); void suggestBreak( const int time ); diff --git a/src/rsitimer.cpp b/src/rsitimer.cpp --- a/src/rsitimer.cpp +++ b/src/rsitimer.cpp @@ -121,6 +121,7 @@ m_state = TimerState::Monitoring; m_pauseCounter = nullptr; m_popupCounter = nullptr; + m_shortInputCounter = nullptr; defaultUpdateToolTip(); emit updateIdleAvg( 0.0 ); emit relax( -1, false ); @@ -256,7 +257,8 @@ break; } - int inverseTick = ( idleSeconds == 0 ) ? 1 : 0; // inverting as we account idle seconds here. + bool isInputLong = (m_shortInputCounter->tick(idleSeconds) > 0); + int inverseTick = ( idleSeconds == 0 && isInputLong) ? 1 : 0; // inverting as we account idle seconds here. breakTime = m_pauseCounter->tick( inverseTick ); if ( breakTime > 0 ) { // User has waited out the pause, back to monitoring. @@ -268,7 +270,8 @@ break; } case TimerState::Resting: { - int inverseTick = ( idleSeconds == 0 ) ? 1 : 0; // inverting as we account idle seconds here. + bool isInputLong = (m_shortInputCounter->tick(idleSeconds) > 0); + int inverseTick = ( idleSeconds == 0 && isInputLong > 0 ) ? 1 : 0; // inverting as we account idle seconds here. int breakTime = m_pauseCounter->tick( inverseTick ); if ( breakTime > 0 ) { resetAfterBreak(); @@ -309,6 +312,10 @@ // Threshold of one means the timer is reset on every non-zero tick. m_pauseCounter = std::unique_ptr { new RSITimerCounter( breakTime, breakTime, 1 ) }; + // 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 ) }; + emit relax( breakTime, nextOneIsBig ); }