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