9
static struct timeval wait_over_time;
12
wait_x_loop(XEvent *e, const struct timeval *now)
16
if (e->type == KeyPress || e->type == MotionNotify
17
|| e->type == ButtonPress) {
18
xwSUBTIME(diff, *now, last_key_time);
21
/* if check_idle is on, long idle periods are the same as breaks */
22
if (check_idle && xwTIMEGEQ(diff, idle_time))
25
/* if check_quota is on, mini-breaks add up over time */
26
if (check_quota && xwTIMEGEQ(diff, quota_time)) {
27
xwADDTIME(quota_allotment, quota_allotment, diff);
28
if (check_idle && xwTIMEGEQ(quota_allotment, idle_time))
32
/* wake up if time to warn */
33
return (xwTIMEGEQ(*now, wait_over_time) ? TRAN_WARN : 0);
40
adjust_wait_time(struct timeval *wait_began_time, const struct timeval *type_time)
41
/* Adjust the time to wake up to reflect the length of the break, if
42
under check_quota. Want to be able to type for slightly longer if
43
you've been taking mini-breaks. */
45
struct timeval this_break_time;
46
struct timeval break_end_time;
49
/* Find the time when this break should end = beginning of wait + type delay
51
xwADDTIME(break_end_time, *wait_began_time, *type_time);
52
xwADDTIME(break_end_time, break_end_time, ocurrent->break_time);
54
/* Find the length of this break */
55
xwSUBTIME(this_break_time, ocurrent->break_time, quota_allotment);
56
if (xwTIMEGEQ(ocurrent->min_break_time, this_break_time))
57
this_break_time = ocurrent->min_break_time;
59
/* Subtract to find when we should start warning */
60
xwSUBTIME(break_end_time, break_end_time, this_break_time);
62
/* Check against wait_over_time; if <=, wait is over */
63
if (xwTIMEGEQ(wait_over_time, break_end_time))
66
/* Set wait_over_time and return 0 -- we still need to wait */
67
wait_over_time = break_end_time;
72
wait_for_break(const struct timeval *type_time)
75
struct timeval wait_began_time;
77
/* Schedule wait_over_time */
78
xwGETTIME(wait_began_time);
79
xwADDTIME(wait_over_time, wait_began_time, *type_time);
81
xwSETTIME(quota_allotment, 0, 0);
83
/* Pretend there's been a keystroke */
84
last_key_time = wait_began_time;
86
/* Clear slideshows */
87
/* Do this now so later set_slideshows start from scratch. */
88
for (i = 0; i < nports; i++) {
89
set_all_slideshows(ports[i]->hands, 0);
90
set_all_slideshows(ports[i]->icon_hands, 0);
94
while (val != TRAN_WARN && val != TRAN_REST) {
95
/* If !check_idle, we want to appear even if no keystroke happens, so
98
Alarm *a = new_alarm(A_AWAKE);
99
a->timer = wait_over_time;
105
val = loopmaster(0, wait_x_loop);
106
if (val == TRAN_AWAKE) val = TRAN_WARN; /* patch A_AWAKE case */
108
/* Adjust the wait time if necessary */
109
assert(val == TRAN_WARN || val == TRAN_REST);
110
if (val == TRAN_WARN && check_quota)
111
val = adjust_wait_time(&wait_began_time, type_time);
114
unschedule(A_FLASH | A_AWAKE);
115
assert(val == TRAN_WARN || val == TRAN_REST);
122
static int current_cheats;
123
static struct timeval break_over_time;
126
rest_x_loop(XEvent *e, const struct timeval *now)
128
/* If the break is over, wake up. */
129
if (xwTIMEGEQ(*now, break_over_time))
132
if (e->type == Xw_DeleteWindow && active_hands() == 0)
133
/* Window manager deleted last xwrits window. Consider break over. */
135
else if (e->type == KeyPress || e->type == MotionNotify
136
|| e->type == ButtonPress) {
137
last_key_time = *now;
139
return (current_cheats > max_cheats ? TRAN_FAIL : 0);
145
calculate_break_time(struct timeval *break_over_time, const struct timeval *now)
147
struct timeval this_break_time;
149
/* determine length of this break. usually break_time; can be different if
151
this_break_time = ocurrent->break_time;
153
xwSUBTIME(this_break_time, this_break_time, quota_allotment);
154
if (xwTIMEGEQ(ocurrent->min_break_time, this_break_time))
155
this_break_time = ocurrent->min_break_time;
158
/* determine when to end the break */
160
xwADDTIME(*break_over_time, *now, this_break_time);
162
xwADDTIME(*break_over_time, last_key_time, this_break_time);
172
/* set up pictures */
173
/* Do this first so later set_slideshows start from scratch. */
174
for (i = 0; i < nports; i++) {
175
set_all_slideshows(ports[i]->hands, resting_slideshow);
176
set_all_slideshows(ports[i]->icon_hands, resting_icon_slideshow);
177
find_one_hand(ports[i], 1);
181
/* calculate time when break is over */
183
calculate_break_time(&break_over_time, &now);
185
/* if break already over, return */
186
if (xwTIMEGEQ(now, break_over_time))
189
/* schedule wakeup */
190
a = new_alarm(A_AWAKE);
191
a->timer = break_over_time;
194
/* reschedule mouse position query timing: allow 5 seconds for people to
195
jiggle the mouse before we save its position */
197
a = grab_alarm_data(A_MOUSE, 0, 0);
199
a->timer.tv_sec += 5;
201
for (i = 0; i < nports; i++)
202
ports[i]->last_mouse_root = None;
205
if (ocurrent->break_clock) {
206
clock_zero_time = break_over_time;
207
draw_all_clocks(&now);
208
a = new_alarm(A_CLOCK);
209
xwADDTIME(a->timer, now, clock_tick);
213
for (i = 0; i < nports; i++)
214
XFlush(ports[i]->display);
215
tran = loopmaster(0, rest_x_loop);
217
unschedule(A_FLASH | A_AWAKE | A_CLOCK);
219
assert(tran == TRAN_CANCEL || tran == TRAN_AWAKE || tran == TRAN_FAIL);
227
ready_x_loop(XEvent *e, const struct timeval *now)
229
if (e->type == KeyPress || e->type == MotionNotify
230
|| e->type == ButtonPress) {
231
/* if they typed, disappear automatically */
232
last_key_time = *now;
242
for (i = 0; i < nports; i++) {
243
set_all_slideshows(ports[i]->hands, ready_slideshow);
244
set_all_slideshows(ports[i]->icon_hands, ready_icon_slideshow);
245
find_one_hand(ports[i], 1);
247
XBell(ports[i]->display, 0);
248
XFlush(ports[i]->display);
250
loopmaster(0, ready_x_loop);