Changeset View
Changeset View
Standalone View
Standalone View
src/rsitimer.cpp
Show First 20 Lines • Show All 115 Lines • ▼ Show 20 Line(s) | 106 | { | |||
---|---|---|---|---|---|
116 | emit breakNow(); | 116 | emit breakNow(); | ||
117 | } | 117 | } | ||
118 | 118 | | |||
119 | void RSITimer::resetAfterBreak() | 119 | void RSITimer::resetAfterBreak() | ||
120 | { | 120 | { | ||
121 | m_state = TimerState::Monitoring; | 121 | m_state = TimerState::Monitoring; | ||
122 | m_pauseCounter = nullptr; | 122 | m_pauseCounter = nullptr; | ||
123 | m_popupCounter = nullptr; | 123 | m_popupCounter = nullptr; | ||
124 | m_shortInputCounter = nullptr; | ||||
124 | defaultUpdateToolTip(); | 125 | defaultUpdateToolTip(); | ||
125 | emit updateIdleAvg( 0.0 ); | 126 | emit updateIdleAvg( 0.0 ); | ||
126 | emit relax( -1, false ); | 127 | emit relax( -1, false ); | ||
127 | emit minimize(); | 128 | emit minimize(); | ||
128 | if ( m_bigBreakCounter->isReset() ) { | 129 | if ( m_bigBreakCounter->isReset() ) { | ||
129 | emit endLongBreak(); | 130 | emit endLongBreak(); | ||
130 | } else { | 131 | } else { | ||
131 | emit endShortBreak(); | 132 | emit endShortBreak(); | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 249 | case TimerState::Suggesting: { | |||
251 | if ( breakTime > 0 ) { | 252 | if ( breakTime > 0 ) { | ||
252 | // User kept working throw the suggestion timeout. Well, their loss. | 253 | // User kept working throw the suggestion timeout. Well, their loss. | ||
253 | emit relax( -1, false ); | 254 | emit relax( -1, false ); | ||
254 | breakTime = m_pauseCounter->counterLeft(); | 255 | breakTime = m_pauseCounter->counterLeft(); | ||
255 | doBreakNow( breakTime, false ); | 256 | doBreakNow( breakTime, false ); | ||
256 | break; | 257 | break; | ||
257 | } | 258 | } | ||
258 | 259 | | |||
259 | int inverseTick = ( idleSeconds == 0 ) ? 1 : 0; // inverting as we account idle seconds here. | 260 | bool isInputLong = (m_shortInputCounter->tick(idleSeconds) > 0); | ||
261 | int inverseTick = ( idleSeconds == 0 && isInputLong) ? 1 : 0; // inverting as we account idle seconds here. | ||||
260 | breakTime = m_pauseCounter->tick( inverseTick ); | 262 | breakTime = m_pauseCounter->tick( inverseTick ); | ||
261 | if ( breakTime > 0 ) { | 263 | if ( breakTime > 0 ) { | ||
262 | // User has waited out the pause, back to monitoring. | 264 | // User has waited out the pause, back to monitoring. | ||
263 | resetAfterBreak(); | 265 | resetAfterBreak(); | ||
264 | break; | 266 | break; | ||
265 | } | 267 | } | ||
266 | emit relax( m_pauseCounter->counterLeft(), false ); | 268 | emit relax( m_pauseCounter->counterLeft(), false ); | ||
267 | emit updateWidget( m_pauseCounter->counterLeft() ); | 269 | emit updateWidget( m_pauseCounter->counterLeft() ); | ||
268 | break; | 270 | break; | ||
269 | } | 271 | } | ||
270 | case TimerState::Resting: { | 272 | case TimerState::Resting: { | ||
271 | int inverseTick = ( idleSeconds == 0 ) ? 1 : 0; // inverting as we account idle seconds here. | 273 | bool isInputLong = (m_shortInputCounter->tick(idleSeconds) > 0); | ||
274 | int inverseTick = ( idleSeconds == 0 && isInputLong > 0 ) ? 1 : 0; // inverting as we account idle seconds here. | ||||
272 | int breakTime = m_pauseCounter->tick( inverseTick ); | 275 | int breakTime = m_pauseCounter->tick( inverseTick ); | ||
273 | if ( breakTime > 0 ) { | 276 | if ( breakTime > 0 ) { | ||
274 | resetAfterBreak(); | 277 | resetAfterBreak(); | ||
275 | } else { | 278 | } else { | ||
276 | emit updateWidget( m_pauseCounter->counterLeft() ); | 279 | emit updateWidget( m_pauseCounter->counterLeft() ); | ||
277 | } | 280 | } | ||
278 | break; | 281 | break; | ||
279 | } | 282 | } | ||
Show All 24 Lines | 290 | { | |||
304 | // When pause is longer than patience, we need to reset patience timer so that we don't flip to break now in | 307 | // When pause is longer than patience, we need to reset patience timer so that we don't flip to break now in | ||
305 | // mid-pause. Patience / 2 is a good alternative to it by extending patience if user was idle long enough. | 308 | // mid-pause. Patience / 2 is a good alternative to it by extending patience if user was idle long enough. | ||
306 | m_popupCounter = std::unique_ptr<RSITimerCounter> { | 309 | m_popupCounter = std::unique_ptr<RSITimerCounter> { | ||
307 | new RSITimerCounter( m_intervals[PATIENCE_INTERVAL], breakTime, m_intervals[PATIENCE_INTERVAL] / 2 ) | 310 | new RSITimerCounter( m_intervals[PATIENCE_INTERVAL], breakTime, m_intervals[PATIENCE_INTERVAL] / 2 ) | ||
308 | }; | 311 | }; | ||
309 | // Threshold of one means the timer is reset on every non-zero tick. | 312 | // Threshold of one means the timer is reset on every non-zero tick. | ||
310 | m_pauseCounter = std::unique_ptr<RSITimerCounter> { new RSITimerCounter( breakTime, breakTime, 1 ) }; | 313 | m_pauseCounter = std::unique_ptr<RSITimerCounter> { new RSITimerCounter( breakTime, breakTime, 1 ) }; | ||
311 | 314 | | |||
315 | // For measuring input duration in order to limit influence of short inputs on resetting pause counter. | ||||
316 | // Example of short input is: mouse sent input due to accidental touch or desk vibration. | ||||
317 | m_shortInputCounter = std::unique_ptr<RSITimerCounter> { new RSITimerCounter( 2, 2, 1 ) }; | ||||
318 | | ||||
312 | emit relax( breakTime, nextOneIsBig ); | 319 | emit relax( breakTime, nextOneIsBig ); | ||
313 | } | 320 | } | ||
314 | 321 | | |||
315 | void RSITimer::defaultUpdateToolTip() | 322 | void RSITimer::defaultUpdateToolTip() | ||
316 | { | 323 | { | ||
317 | emit updateToolTip( m_tinyBreakCounter->counterLeft(), m_bigBreakCounter->counterLeft() ); | 324 | emit updateToolTip( m_tinyBreakCounter->counterLeft(), m_bigBreakCounter->counterLeft() ); | ||
318 | } | 325 | } |