~ubuntu-branches/ubuntu/maverick/xwrits/maverick

« back to all changes in this revision

Viewing changes to .pc/debian-changes-2.21-6.1/rest.c

  • Committer: Bazaar Package Importer
  • Author(s): Jari Aalto, Jari Aalto
  • Date: 2010-05-04 21:39:32 UTC
  • Revision ID: james.westby@ubuntu.com-20100504213932-xr0zn8k1xe99bx54
Tags: 2.21-6.1
[ Jari Aalto ]
* Non-maintainer upload.
  - Move to packaging format "3.0 (quilt)".
* debian/clean
  - Mew file.
* debian/compat
  - New file.
* debian/control
  - (Build-Depends): update obsolete xutils to xutils-dev.
    (important; Closes: #579038). Remove *-1 version suffix
    from texinfo dependency. Update to debhelper 7.1.
  - (Depends): add ${misc:Depends}.
  - (Homepage): New field.
  - (Standards-Version): update to 3.8.4.
* debian/copyright
  - Update layout and point to GPL-2.
* debian/rules
  - Delete EOL whitespaces.
  - (DH_COMPAT): Remove.
  - (install): Update dh_clean to dh_prep.
  - (clean): Fix lintian debian-rules-ignores-make-clean-error.
* debian/source/format
  - New file.
* debian/watch
  - New file.
* xwrits.1
  - Fix hyphens.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <config.h>
 
2
#include "xwrits.h"
 
3
#include <stdlib.h>
 
4
#include <assert.h>
 
5
 
 
6
 
 
7
/* wait for break */
 
8
 
 
9
static struct timeval wait_over_time;
 
10
 
 
11
static int
 
12
wait_x_loop(XEvent *e, const struct timeval *now)
 
13
{
 
14
  struct timeval diff;
 
15
  
 
16
  if (e->type == KeyPress || e->type == MotionNotify
 
17
      || e->type == ButtonPress) {
 
18
    xwSUBTIME(diff, *now, last_key_time);
 
19
    last_key_time = *now;
 
20
    
 
21
    /* if check_idle is on, long idle periods are the same as breaks */
 
22
    if (check_idle && xwTIMEGEQ(diff, idle_time))
 
23
      return TRAN_REST;
 
24
    
 
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))
 
29
        return TRAN_REST;
 
30
    }
 
31
    
 
32
    /* wake up if time to warn */
 
33
    return (xwTIMEGEQ(*now, wait_over_time) ? TRAN_WARN : 0);
 
34
    
 
35
  } else
 
36
    return 0;
 
37
}
 
38
 
 
39
static int
 
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. */
 
44
{
 
45
  struct timeval this_break_time;
 
46
  struct timeval break_end_time;
 
47
  assert(check_quota);
 
48
 
 
49
  /* Find the time when this break should end = beginning of wait + type delay
 
50
     + break delay */
 
51
  xwADDTIME(break_end_time, *wait_began_time, *type_time);
 
52
  xwADDTIME(break_end_time, break_end_time, ocurrent->break_time);
 
53
  
 
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;
 
58
  
 
59
  /* Subtract to find when we should start warning */
 
60
  xwSUBTIME(break_end_time, break_end_time, this_break_time);
 
61
  
 
62
  /* Check against wait_over_time; if <=, wait is over */
 
63
  if (xwTIMEGEQ(wait_over_time, break_end_time))
 
64
    return TRAN_WARN;
 
65
  
 
66
  /* Set wait_over_time and return 0 -- we still need to wait */
 
67
  wait_over_time = break_end_time;
 
68
  return 0;
 
69
}
 
70
 
 
71
int
 
72
wait_for_break(const struct timeval *type_time)
 
73
{
 
74
  int val, i;
 
75
  struct timeval wait_began_time;
 
76
 
 
77
  /* Schedule wait_over_time */
 
78
  xwGETTIME(wait_began_time);
 
79
  xwADDTIME(wait_over_time, wait_began_time, *type_time);
 
80
  if (check_quota)
 
81
    xwSETTIME(quota_allotment, 0, 0);
 
82
 
 
83
  /* Pretend there's been a keystroke */
 
84
  last_key_time = wait_began_time;
 
85
 
 
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);
 
91
  }
 
92
  
 
93
  val = 0;
 
94
  while (val != TRAN_WARN && val != TRAN_REST) {
 
95
    /* If !check_idle, we want to appear even if no keystroke happens, so
 
96
       schedule an alarm */
 
97
    if (!check_idle) {
 
98
      Alarm *a = new_alarm(A_AWAKE);
 
99
      a->timer = wait_over_time;
 
100
      unschedule(A_AWAKE);
 
101
      schedule(a);
 
102
    }
 
103
    
 
104
    /* Wait */
 
105
    val = loopmaster(0, wait_x_loop);
 
106
    if (val == TRAN_AWAKE) val = TRAN_WARN; /* patch A_AWAKE case */
 
107
    
 
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);
 
112
  }
 
113
  
 
114
  unschedule(A_FLASH | A_AWAKE);
 
115
  assert(val == TRAN_WARN || val == TRAN_REST);
 
116
  return val;
 
117
}
 
118
 
 
119
 
 
120
/* rest */
 
121
 
 
122
static int current_cheats;
 
123
static struct timeval break_over_time;
 
124
 
 
125
static int
 
126
rest_x_loop(XEvent *e, const struct timeval *now)
 
127
{
 
128
  /* If the break is over, wake up. */
 
129
  if (xwTIMEGEQ(*now, break_over_time))
 
130
    return TRAN_AWAKE;
 
131
  
 
132
  if (e->type == Xw_DeleteWindow && active_hands() == 0)
 
133
    /* Window manager deleted last xwrits window. Consider break over. */
 
134
    return TRAN_CANCEL;
 
135
  else if (e->type == KeyPress || e->type == MotionNotify
 
136
           || e->type == ButtonPress) {
 
137
    last_key_time = *now;
 
138
    current_cheats++;
 
139
    return (current_cheats > max_cheats ? TRAN_FAIL : 0);
 
140
  } else
 
141
    return 0;
 
142
}
 
143
 
 
144
void
 
145
calculate_break_time(struct timeval *break_over_time, const struct timeval *now)
 
146
{
 
147
  struct timeval this_break_time;
 
148
  
 
149
  /* determine length of this break. usually break_time; can be different if
 
150
     check_quota is on */
 
151
  this_break_time = ocurrent->break_time;
 
152
  if (check_quota) {
 
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;
 
156
  }
 
157
  
 
158
  /* determine when to end the break */
 
159
  if (!check_idle)
 
160
    xwADDTIME(*break_over_time, *now, this_break_time);
 
161
  else
 
162
    xwADDTIME(*break_over_time, last_key_time, this_break_time);
 
163
}
 
164
 
 
165
int
 
166
rest(void)
 
167
{
 
168
  struct timeval now;
 
169
  Alarm *a;
 
170
  int tran, i;
 
171
 
 
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);
 
178
  }
 
179
  current_cheats = 0;
 
180
  
 
181
  /* calculate time when break is over */
 
182
  xwGETTIME(now);
 
183
  calculate_break_time(&break_over_time, &now);
 
184
  
 
185
  /* if break already over, return */
 
186
  if (xwTIMEGEQ(now, break_over_time))
 
187
    return TRAN_AWAKE;
 
188
 
 
189
  /* schedule wakeup */
 
190
  a = new_alarm(A_AWAKE);
 
191
  a->timer = break_over_time;
 
192
  schedule(a);
 
193
  
 
194
  /* reschedule mouse position query timing: allow 5 seconds for people to
 
195
     jiggle the mouse before we save its position */
 
196
  if (check_mouse) {
 
197
    a = grab_alarm_data(A_MOUSE, 0, 0);
 
198
    a->timer = now;
 
199
    a->timer.tv_sec += 5;
 
200
    schedule(a);
 
201
    for (i = 0; i < nports; i++)
 
202
      ports[i]->last_mouse_root = None;
 
203
  }
 
204
  
 
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);
 
210
    schedule(a);
 
211
  }
 
212
 
 
213
  for (i = 0; i < nports; i++)
 
214
    XFlush(ports[i]->display);
 
215
  tran = loopmaster(0, rest_x_loop);
 
216
  
 
217
  unschedule(A_FLASH | A_AWAKE | A_CLOCK);
 
218
  erase_all_clocks();
 
219
  assert(tran == TRAN_CANCEL || tran == TRAN_AWAKE || tran == TRAN_FAIL);
 
220
  return tran;
 
221
}
 
222
 
 
223
 
 
224
/* ready */
 
225
 
 
226
static int
 
227
ready_x_loop(XEvent *e, const struct timeval *now)
 
228
{
 
229
  if (e->type == KeyPress || e->type == MotionNotify
 
230
      || e->type == ButtonPress) {
 
231
    /* if they typed, disappear automatically */
 
232
    last_key_time = *now;
 
233
    return 1;
 
234
  } else
 
235
    return 0;
 
236
}
 
237
 
 
238
void
 
239
ready(void)
 
240
{
 
241
  int i;
 
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);
 
246
    if (ocurrent->beep)
 
247
      XBell(ports[i]->display, 0);
 
248
    XFlush(ports[i]->display);
 
249
  }
 
250
  loopmaster(0, ready_x_loop);
 
251
}