ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/rclock.C
(Generate patch)

Comparing rxvt-unicode/src/rclock.C (file contents):
Revision 1.2 by root, Mon May 10 00:36:58 2021 UTC vs.
Revision 1.11 by root, Sun Nov 14 18:39:16 2021 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * Copyright 2021 Marc Lehmann <schmorp@schmorp.de>
3 * Copyright Wolfgang Pietsch
2 * Copyright 1997 1998 Oezguer Kesim <kesim@math.fu-berlin.de> 4 * Copyright 1997 1998 Oezguer Kesim <kesim@math.fu-berlin.de>
3 * Copyright 1992, 1993 Robert Nation <nation@rocket.sanders.lockheed.com> 5 * Copyright 1992, 1993 Robert Nation <nation@rocket.sanders.lockheed.com>
4 * 6 *
5 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
14 * 16 *
15 * You should have received a copy of the GNU General Public License 17 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 *----------------------------------------------------------------------*/ 20 *----------------------------------------------------------------------*/
19#ifdef HAVE_CONFIG_H
20# include <config.h>
21#else
22/* # define STDC_HEADERS */
23# define HAVE_UNISTD_H
24# define TIME_WITH_SYS_TIME
25# define HAVE_SYS_TIME_H
26# ifdef _AIX
27# define HAVE_SYS_SELECT_H
28# endif
29#endif
30
31#include "../src/version.h"
32#include "feature.h"
33
34#include <ctype.h> 21#include <ctype.h>
35/* #ifdef STDC_HEADERS */ 22
36# include <stdarg.h> 23#include <stdarg.h>
37# include <stdio.h> 24#include <stdio.h>
38# include <stdlib.h> 25#include <stdlib.h>
39# include <string.h> 26#include <string.h>
40/* #endif */
41 27
42#ifdef HAVE_UNISTD_H
43# include <unistd.h> 28#include <unistd.h>
44#endif
45 29
46#ifdef TIME_WITH_SYS_TIME
47# include <sys/time.h> 30#include <sys/types.h>
48# include <time.h>
49#else
50# ifdef HAVE_SYS_TIME_H
51# include <sys/time.h>
52# else
53# include <time.h>
54# endif
55#endif
56
57#if defined (__svr4__)
58# include <sys/resource.h> /* for struct rlimit */
59#endif
60
61#ifdef HAVE_SYS_SELECT_H
62# include <sys/select.h> 31#include <sys/select.h>
63#endif
64#include <sys/stat.h> 32#include <sys/stat.h>
65 33
66#ifdef MAIL 34#include <sys/time.h>
35#include <time.h>
36
67#include <dirent.h> 37#include <dirent.h>
68#endif
69 38
70#include <X11/Intrinsic.h> /* Xlib, Xutil, Xresource, Xfuncproto */ 39#include <X11/Xlib.h>
40#include <X11/Xutil.h>
41
42#include "ecb.h"
43
44#include "version.h"
71 45
72#define APL_CLASS "Clock" 46#define APL_CLASS "Clock"
73#define APL_NAME "rclock" 47#define APL_NAME "rclock"
74#define MSG_CLASS "Appointment" 48#define MSG_CLASS "Appointment"
75#define MSG_NAME "Appointment" 49#define MSG_NAME "Appointment"
76#define CONFIG_FILE ".rclock" 50#define CONFIG_FILE ".rclock"
77 51
78#ifndef EXIT_SUCCESS /* missed from <stdlib.h> ? */ 52#ifndef EXIT_SUCCESS /* missed from <stdlib.h> ? */
79# define EXIT_SUCCESS 0 53# define EXIT_SUCCESS 0
80# define EXIT_FAILURE 1 54# define EXIT_FAILURE 1
81#endif 55#endif
82 56
57/*--------------------------------*-C-*---------------------------------*
58 * Compile-time configuration.
59 *----------------------------------------------------------------------*
60 * Copyright (C) 1997 1998 mj olesen <olesen@me.QueensU.CA>
61 *
62 * This program is free software; you can redistribute it and/or modify
63 * it under the terms of the GNU General Public License as published by
64 * the Free Software Foundation; either version 2 of the License, or
65 * (at your option) any later version.
66 *
67 * This program is distributed in the hope that it will be useful,
68 * but WITHOUT ANY WARRANTY; without even the implied warranty of
69 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
70 * GNU General Public License for more details.
71 *
72 * You should have received a copy of the GNU General Public License
73 * along with this program; if not, write to the Free Software
74 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
75 *----------------------------------------------------------------------*/
76
77/*----------------------------------------------------------------------*
78 * #define ICONWIN
79 * to enable fancy (active) icon
80 *
81 * #define REMINDERS
82 * to enable the appointment reminder functions
83 *
84 * #define NO_REMINDER_EXEC
85 * to disable the execution of a program on an appointment
86 *
87 * #define DATE_ON_CLOCK_FACE
88 * to display today's date on the face of the clock
89 * Note: this requires REMINDERS since it uses the same font
90 *
91 * #define MAIL
92 * to enable xbiff-type mail reminders
93 *
94 * #define MAIL_BELL
95 * to enable xbiff-type mail reminders with a beep
96 *
97 * #define MAIL_SPAWN "xmh\ -font\ 7x14\&"
98 * to define a mail program to run
99 *
100 * #define MAIL_SPOOL "/var/spool/mail/"
101 * to define the mail spool when the $MAIL variable isn't set
102 *
103 * program size approximately doubles from no options to all options
104 *----------------------------------------------------------------------*/
105#define ICONWIN
106#define REMINDERS
107
108/* #define NO_REMINDER_EXEC */
109#define DATE_ON_CLOCK_FACE
110#define MAIL
111
112/* #define MAIL_BELL */ /* TODO: command line switch */
113
114/* #define MAIL_SPAWN "xmh\ -font\ 7x14\&" */ /* TODO: command line switch */
115#define MAIL_SPOOL "/var/spool/mail/"
116
117/*----------------------------------------------------------------------*
118 * #define CLOCKUPDATE 30
119 * to define the frequency (seconds) to update the clock
120 *
121 * #define MAILUPDATE 60
122 * to define the frequency (seconds) to check for new mail
123 *
124 * #define REMINDERS_TIME 10
125 * to define the frequency (minutes) to check ~/.rclock
126 *
127 * #define DEFER_TIME 3
128 * to define the amount (minutes) to defer a message
129 *
130 * #define ADJUST_TIME
131 * to add -adjust command-line option
132 *
133 * #define CENTURY 2000
134 * to set the base century for 2 digit year short-hand
135 *----------------------------------------------------------------------*/
136#define CLOCKUPDATE 30
137#define MAILUPDATE 60
138#define REMINDERS_TIME 10
139#define DEFER_TIME 3
140#define ADJUST_TIME
141
142#define CENTURY 2000 /* TODO: verify */
143
144/*----------------------------------------------------------------------*
145 * #define FONT_NAME "7x14"
146 * to define the font to be used for appointment reminders
147 *
148 * #define FG_COLOR_NAME "black"
149 * #define BG_COLOR_NAME "white"
150 * to define the foreground/background colors to use
151 *----------------------------------------------------------------------*/
152#define FONT_NAME "7x14"
153#define FG_COLOR_NAME "black"
154#define BG_COLOR_NAME "white"
155
156/*----------------------------------------------------------------------*
157 * #define DAY_NAMES "umtwrfs*"
158 * define this string appropriate for any language.
159 *
160 * It starts with a symbol for Sunday, ends with Saturday, then '*'
161 * NOTE: 8 characters total - 7 days of the week plus '*'
162 *----------------------------------------------------------------------*/
163#define DAY_NAMES "umtwrfs*"
164
165/*----------------------------------------------------------------------*
166 * #define SUBTICKS
167 * to show additional minute/second markings
168 *----------------------------------------------------------------------*/
169#define SUBTICKS
170
171/*----------------------------------------------------------------------*
172 * sort out conflicts
173 *----------------------------------------------------------------------*/
174#if defined (MAIL_BELL) || defined (MAIL_SPAWN) || defined (MAIL_SPOOL)
175# ifndef MAIL
176# define MAIL
177# endif
178#endif
179
83/*----------------------------------------------------------------------*/ 180/*----------------------------------------------------------------------*/
181// fourth-order fixed point sine approximation,
182// adapted from https://www.coranac.com/2009/07/sines/
84 183
184static int32_t
185Sin (int32_t arg)
186{
187 int32_t x = (arg - 360) * 16384 / 360;
188
189 int c, y;
190 static const int qN = 13, qA = 12, B = 19900, C = 3516;
191
192 c = x << (30 - qN); // Semi-circle info into carry.
193 x -= 1 << qN; // sine -> cosine calc
194
195 x = x << (31 - qN); // Mask with PI
196 x = x >> (31 - qN); // Note: SIGNED shift! (to qN)
197 x = x * x >> (2 * qN - 14); // x=x^2 To Q14
198
199 y = B - (x * C >> 14); // B - x^2*C
200 y = (1 << qA) - (x * y >> 16); // A - x^2*(B-x^2*C)
201
202 x = c < 0 ? y : -y;
203
204 return x;
205}
206
207/*----------------------------------------------------------------------*/
208
85static Display* Xdisplay; /* X display */ 209static Display *Xdisplay; /* X display */
86static int Xfd; /* file descriptor of server connection */ 210static int Xfd; /* file descriptor of server connection */
87static GC Xgc, Xrvgc; /* normal, reverse video GC */ 211static GC Xgc, Xrvgc; /* normal, reverse video GC */
88 212
89#define Xscreen DefaultScreen (Xdisplay) 213#define Xscreen DefaultScreen (Xdisplay)
90#define Xcmap DefaultColormap (Xdisplay, Xscreen) 214#define Xcmap DefaultColormap (Xdisplay, Xscreen)
91#define Xroot DefaultRootWindow (Xdisplay) 215#define Xroot DefaultRootWindow (Xdisplay)
92 216
93/* windows and their sizes */ 217/* windows and their sizes */
94typedef struct { 218typedef struct
219{
95 Window win; 220 Window win;
96 int width, height; 221 int width, height;
97} mywindow_t; 222} mywindow_t;
98 223
99static mywindow_t Clock = {None, 80, 80}; /* parent window */ 224static mywindow_t Clock = { None, 80, 80 }; /* parent window */
100 225
101#define fgColor 0 226#define fgColor 0
102#define bgColor 1 227#define bgColor 1
103static const char * rs_color [2] = { FG_COLOR_NAME, BG_COLOR_NAME }; 228static const char *rs_color[2] = { FG_COLOR_NAME, BG_COLOR_NAME };
104static Pixel PixColors [2]; 229
230static unsigned long PixColors[2];
105static const char * rs_geometry = NULL; 231static const char *rs_geometry = NULL;
106 232
107#ifdef ICONWIN 233#ifdef ICONWIN
108static const char * rs_iconGeometry = NULL; 234static const char *rs_iconGeometry = NULL;
109static mywindow_t Icon = {None, 65, 65}; /* icon window */ 235static mywindow_t Icon = { None, 65, 65 }; /* icon window */
236
110static int iconic_state = NormalState; /* iconic startup? */ 237static int iconic_state = NormalState; /* iconic startup? */
111#endif 238#endif
112 239
113#ifdef REMINDERS 240#ifdef REMINDERS
114static mywindow_t Msg = {0, 0, 0}; /* message window */ 241static mywindow_t Msg = { 0, 0, 0 }; /* message window */
242
115static struct { 243static struct
244{
116 Window 245 Window
117# ifndef NO_REMINDER_EXEC 246# ifndef NO_REMINDER_EXEC
118 Start, 247 Start,
119# endif 248# endif
120 Dismiss, 249 Dismiss, Defer;
121 Defer;
122 int width, height; 250 int width, height;
123} msgButton; 251} msgButton;
124 252
125static XFontStruct * Xfont; 253static XFontStruct *Xfont;
254
126#define FontHeight() (Xfont->ascent + Xfont->descent) 255# define FontHeight() (Xfont->ascent + Xfont->descent)
127static int Msg_Mapped = 0; /* message window mapped? */ 256static int Msg_Mapped = 0; /* message window mapped? */
128static int reminderTime = -1; 257static int reminderTime = -1;
129static char message [256] = ""; 258static char message[256] = "";
259
130#ifndef NO_REMINDER_EXEC 260# ifndef NO_REMINDER_EXEC
131static char execPrgm [256] = ""; 261static char execPrgm[256] = "";
132#endif 262# endif
133static const char * reminders_file = NULL; /* name of ~/.rclock file */ 263static const char *reminders_file = NULL; /* name of ~/.rclock file */
264
134#ifdef DATE_ON_CLOCK_FACE 265# ifdef DATE_ON_CLOCK_FACE
135static int show_date = 1; /* show date on face of clock */ 266static int show_date = 1; /* show date on face of clock */
136#endif 267# endif
137#endif 268#endif
138 269
139#ifdef ADJUST_TIME 270#ifdef ADJUST_TIME
140static int adjustTime = 0; 271static int adjustTime = 0;
141#else 272#else
142# define adjustTime 0 273# define adjustTime 0
143#endif 274#endif
144 275
145#ifdef CENTURY 276#ifdef CENTURY
146# if (CENTURY < 1900) 277# if (CENTURY < 1900)
147Error, Cenury incorrectly set. 278Error, Century incorrectly set.
148# endif 279# endif
149#else 280#else
150# define CENTURY 1900 281# define CENTURY 1900
151#endif 282#endif
152 283
153static int clockUpdate = CLOCKUPDATE; 284static int clockUpdate = CLOCKUPDATE;
154 285
155#ifdef MAIL 286#ifdef MAIL
156static int mailUpdate = MAILUPDATE; 287static int mailUpdate = MAILUPDATE;
157static char * mail_file = NULL; 288static char *mail_file = NULL;
289
158#ifndef MAIL_SPAWN 290# ifndef MAIL_SPAWN
159static char * mail_spawn = NULL; 291static char *mail_spawn = NULL;
160#endif 292# endif
161static int is_maildir = 0; 293static int is_maildir = 0;
162#endif 294#endif
163 295
164static XSizeHints szHint = { 296static XSizeHints szHint = {
165 PMinSize | PResizeInc | PBaseSize | PWinGravity, 297 PMinSize | PResizeInc | PBaseSize | PWinGravity,
166 0, 0, 80, 80, /* x, y, width and height */ 298 0, 0, 80, 80, /* x, y, width and height */
167 1, 1, /* Min width and height */ 299 1, 1, /* Min width and height */
168 0, 0, /* Max width and height */ 300 0, 0, /* Max width and height */
169 1, 1, /* Width and height increments */ 301 1, 1, /* Width and height increments */
170 {1, 1}, /* x, y increments */ 302 {1, 1}, /* x, y increments */
171 {1, 1}, /* Aspect ratio - not used */ 303 {1, 1}, /* Aspect ratio - not used */
172 0, 0, /* base size */ 304 0, 0, /* base size */
173 NorthWestGravity /* gravity */ 305 NorthWestGravity /* gravity */
174}; 306};
175 307
176/* subroutine declarations */ 308/* subroutine declarations */
177static void geometry2sizehint (mywindow_t * /* win */, 309static void geometry2sizehint (mywindow_t *win, const char *geom);
178 const char * /* geom */);
179static void Create_Windows (int /* argc */, 310static void Create_Windows (int argc, char *argv[]);
180 char * /* argv */ []);
181static void getXevent (void); 311static void getXevent ();
182static void print_error (const char * /* fmt */, ...); 312static void print_error (const char *fmt, ...);
183 313
184static void Draw_Window (mywindow_t * /* this_win */, 314static void Draw_Window (mywindow_t *this_win, int full_redraw);
185 int /* full_redraw */);
186static void Reminder (void); 315static void Reminder ();
187static void Next_Reminder (int /* update_only */); 316static void Next_Reminder (int update_only);
188 317
189/* Arguments for Next_Reminder() */ 318/* Arguments for Next_Reminder() */
190#define REPLACE 0 319#define REPLACE 0
191#define UPDATE 1 320#define UPDATE 1
192 321
193/*----------------------------------------------------------------------*/ 322/*----------------------------------------------------------------------*/
194 323
195static void 324static void
196usage (void) 325usage ()
197{ 326{
198 int i; 327 int i;
199 struct { 328 struct
329 {
200 const char * const opt; 330 const char *const opt;
201 const char * const desc; 331 const char *const desc;
202 } optList[] = { 332 } optList[] = {
203#define optList_size() (sizeof(optList)/sizeof(optList[0])) 333#define optList_size() (sizeof (optList) / sizeof (optList[0]))
204 { "-display displayname", "X server to contact" }, 334 {"-display displayname", "X server to contact"},
205 { "-geometry geom", "size (in pixels) and position" }, 335 {"-geometry geom", "size (in pixels) and position"},
206 { "-bg color", "background color" }, 336 {"-bg color", "background color"},
207 { "-fg color", "foreground color" }, 337 {"-fg color", "foreground color"},
208#ifdef REMINDERS 338#ifdef REMINDERS
209 { "-fn fontname", "normal font for messages" }, 339 {"-fn fontname", "normal font for messages"},
210#ifdef DATE_ON_CLOCK_FACE 340# ifdef DATE_ON_CLOCK_FACE
211 { "-nodate", "do not display date on the clock face" }, 341 {"-nodate", "do not display date on the clock face"},
212#endif 342# endif
213#endif 343#endif
214#ifdef ICONWIN 344#ifdef ICONWIN
215 { "-iconic", "start iconic" }, 345 {"-iconic", "start iconic"},
216#endif 346#endif
217#ifdef ADJUST_TIME 347#ifdef ADJUST_TIME
218 { "-adjust +/-ddhhmm", "adjust clock time" }, 348 {"-adjust +/-ddhhmm", "adjust clock time"},
219#endif 349#endif
220 { "-update seconds", "clock update interval" }, 350 {"-update seconds", "clock update interval"},
221#ifdef MAIL 351#ifdef MAIL
222 { "-mail seconds", "check $MAIL interval" }, 352 {"-mail seconds", "check $MAIL interval"},
223 { "-mailfile file", "file to use for mail checking" }, 353 {"-mailfile file", "file to use for mail checking"},
224#ifndef MAIL_SPAWN 354# ifndef MAIL_SPAWN
225 { "-mailspawn cmd", "execute `cmd` when clock is clicked" }, 355 {"-mailspawn cmd", "execute `cmd` when clock is clicked"},
226#endif 356# endif
227#endif 357#endif
228 { "#geom", "icon window geometry" } 358 {"#geom", "icon window geometry"}
229 }; 359 };
230 360
231 fprintf (stderr, "\nUsage v" VERSION ":\n " APL_NAME " [options]\n\n" 361 fprintf (stderr, "\nUsage for urclock version " VERSION "\n\n urclock [options]\n\n" "where options include:\n");
232 "where options include:\n");
233 362
234 for (i = 0; i < optList_size(); i++) 363 for (i = 0; i < (int)optList_size (); i++)
235 fprintf (stderr, " %-29s%s\n", optList[i].opt, optList[i].desc); 364 fprintf (stderr, " %-29s%s\n", optList[i].opt, optList[i].desc);
236} 365}
237 366
238 367
239/**************** 368/****************
240 * Check out if we are using a maildir drop (qmail) 369 * Check out if we are using a maildir drop (qmail)
241 * Note: this changes mail_dir to hold the "new" diretory 370 * Note: this changes mail_dir to hold the "new" diretory
242 */ 371 */
243#ifdef MAIL 372#ifdef MAIL
244static void 373static void
245CheckMaildir() 374CheckMaildir ()
246{ 375{
247 struct stat st; 376 struct stat st;
248 char *buf, *p; 377 char *buf, *p;
249 378
250 if( !*mail_file || stat(mail_file, &st) || !S_ISDIR(st.st_mode) ) 379 if (!*mail_file || stat (mail_file, &st) || !S_ISDIR (st.st_mode))
251 return; /* no */ 380 return; /* no */
252 381
253 if( !(buf = malloc(strlen(mail_file)+5)) ) { 382 if (!(buf = (char *) malloc (strlen (mail_file) + 5)))
383 {
254 print_error ("malloc error"); 384 print_error ("malloc error");
255 exit( EXIT_FAILURE ); 385 exit (EXIT_FAILURE);
256 } 386 }
257 strcpy(buf,mail_file); 387 strcpy (buf, mail_file);
258 p = buf+strlen(buf); 388 p = buf + strlen (buf);
259 if( p[-1] != '/' ) 389 if (p[-1] != '/')
260 *p++ = '/'; 390 *p++ = '/';
261 391
262 strcpy(p, "tmp" ); 392 strcpy (p, "tmp");
263 if( stat(buf, &st) || !S_ISDIR(st.st_mode ) ) 393 if (stat (buf, &st) || !S_ISDIR (st.st_mode))
264 goto leave; 394 goto leave;
265 strcpy(p, "cur" ); 395 strcpy (p, "cur");
266 if( stat(buf, &st) || !S_ISDIR(st.st_mode ) ) 396 if (stat (buf, &st) || !S_ISDIR (st.st_mode))
267 goto leave; 397 goto leave;
268 strcpy(p, "new" ); 398 strcpy (p, "new");
269 if( stat(buf, &st) || !S_ISDIR(st.st_mode ) ) 399 if (stat (buf, &st) || !S_ISDIR (st.st_mode))
270 goto leave; 400 goto leave;
271 401
272 mail_file = buf; 402 mail_file = buf;
273 is_maildir = 1; 403 is_maildir = 1;
274 return; 404 return;
275 leave: 405leave:
276 free(buf); 406 free (buf);
277} 407}
278#endif 408#endif
279 409
280/*----------------------------------------------------------------------* 410/*----------------------------------------------------------------------*
281 * rclock - Rob's clock 411 * rclock - Rob's clock
282 * simple X windows clock with appointment reminder 412 * simple X windows clock with appointment reminder
283 *----------------------------------------------------------------------*/ 413 *----------------------------------------------------------------------*/
284int 414int
285main (int argc, char * argv []) 415main (int argc, char *argv[])
286{ 416{
287 int i; 417 int i;
288 char * opt, * val; 418 char *opt, *val;
289 const char * display_name = NULL; 419 const char *display_name = NULL;
290 XGCValues gcv; 420 XGCValues gcv;
291 421
292#ifdef REMINDERS 422#ifdef REMINDERS
293 const char * rs_font = FONT_NAME; 423 const char *rs_font = FONT_NAME;
294 424
295 /* find the ~/.rclock file */ 425 /* find the ~/.rclock file */
296 if ((val = getenv ("HOME")) != NULL) 426 if ((val = getenv ("HOME")) != NULL)
297 { 427 {
298 char * p = malloc (strlen (CONFIG_FILE) + strlen (val) + 2); 428 char *p = (char *) malloc (strlen (CONFIG_FILE) + strlen (val) + 2);
429
299 if (p == NULL) 430 if (p == NULL)
300 goto Malloc_Error; 431 goto Malloc_Error;
301 432
302 strcpy (p, val); 433 strcpy (p, val);
303 strcat (p, "/" CONFIG_FILE); 434 strcat (p, "/" CONFIG_FILE);
304 435
305 reminders_file = p; 436 reminders_file = p;
306 } 437 }
307#endif 438#endif
308#ifdef MAIL 439#ifdef MAIL
309 val = getenv ("MAIL"); /* get the mail spool file name */ 440 val = getenv ("MAIL"); /* get the mail spool file name */
310#ifdef MAIL_SPOOL 441# ifdef MAIL_SPOOL
311 if (val == NULL) /* csh doesn't set $MAIL */ 442 if (val == NULL) /* csh doesn't set $MAIL */
312 { 443 {
313 const char * spool = MAIL_SPOOL; 444 const char *spool = MAIL_SPOOL;
314 char * user = getenv ("USER"); /* assume this works */ 445 char *user = getenv ("USER"); /* assume this works */
446
315 if (user != NULL) { 447 if (user != NULL)
448 {
316 val = malloc (strlen (spool) + strlen (user) + 1); 449 val = (char *) malloc (strlen (spool) + strlen (user) + 1);
317 if (val == NULL) 450 if (val == NULL)
318 goto Malloc_Error; 451 goto Malloc_Error;
319 strcpy (val, spool); 452 strcpy (val, spool);
320 strcat (val, user); 453 strcat (val, user);
321 } 454 }
322 } 455 }
323#endif 456# endif
324 mail_file = val; 457 mail_file = val;
325 if( mail_file ) 458 if (mail_file)
326 CheckMaildir(); 459 CheckMaildir ();
327#endif 460#endif
328 461
329 /* parse the command line */ 462 /* parse the command line */
330 for (i = 1; i < argc; i += 2) 463 for (i = 1; i < argc; i += 2)
331 { 464 {
332 opt = argv [i]; 465 opt = argv[i];
333 val = argv [i+1]; 466 val = argv[i + 1];
334 467
335 switch (*opt++) { 468 switch (*opt++)
336 case '-': 469 {
337 break; 470 case '-':
471 break;
338 472
339 case '#': 473 case '#':
340#ifdef ICONWIN 474#ifdef ICONWIN
341 rs_iconGeometry = opt; /* drop */ 475 rs_iconGeometry = opt; /* drop */
342#endif 476#endif
343 default: 477 default:
344 continue; 478 continue;
345 break; 479 break;
346 } 480 }
347 481
348 if (*opt == 'd' && val) display_name = val; /* "d", "display" */ 482 if (*opt == 'd' && val)
349 else if (*opt == 'g' && val) rs_geometry = val; /* "g", "geometry" */ 483 display_name = val; /* "d", "display" */
484 else if (*opt == 'g' && val)
485 rs_geometry = val; /* "g", "geometry" */
350#ifdef ICONWIN 486#ifdef ICONWIN
351 else if (*opt == 'i') /* "ic", "iconic" */ 487 else if (*opt == 'i') /* "ic", "iconic" */
352 { 488 {
353 iconic_state = IconicState; 489 iconic_state = IconicState;
354 i--; /* no argument */ 490 i--; /* no argument */
355 } 491 }
356#endif 492#endif
357 else if (!strcmp (opt, "fg") && val) rs_color [fgColor] = val; 493 else if (!strcmp (opt, "fg") && val)
358 else if (!strcmp (opt, "bg") && val) rs_color [bgColor] = val; 494 rs_color[fgColor] = val;
495 else if (!strcmp (opt, "bg") && val)
496 rs_color[bgColor] = val;
359#ifdef REMINDERS 497#ifdef REMINDERS
360 else if (!strcmp (opt, "fn") && val) rs_font = val; 498 else if (!strcmp (opt, "fn") && val)
499 rs_font = val;
361#ifdef DATE_ON_CLOCK_FACE 500# ifdef DATE_ON_CLOCK_FACE
362 else if (!strcmp (opt, "nodate")) 501 else if (!strcmp (opt, "nodate"))
363 { 502 {
364 show_date = 0; 503 show_date = 0;
365 i--; /* no argument */ 504 i--; /* no argument */
366 } 505 }
367#endif 506# endif
368#endif 507#endif
369 else if (!strcmp (opt, "update") && val) 508 else if (!strcmp (opt, "update") && val)
370 { 509 {
371 int x = atoi (val); 510 int x = atoi (val);
511
372 if (x < 1 || x > 60) 512 if (x < 1 || x > 60)
373 print_error ("update: %d sec", clockUpdate); 513 print_error ("update: %d sec", clockUpdate);
374 else 514 else
375 clockUpdate = x; 515 clockUpdate = x;
376 } 516 }
377#ifdef MAIL 517#ifdef MAIL
378 else if (!strcmp (opt, "mail") && val) 518 else if (!strcmp (opt, "mail") && val)
379 { 519 {
380 int x = atoi (val); 520 int x = atoi (val);
521
381 if (x < 1) 522 if (x < 1)
382 print_error ("mail update: %d sec", mailUpdate); 523 print_error ("mail update: %d sec", mailUpdate);
383 else 524 else
384 mailUpdate = x; 525 mailUpdate = x;
385 } 526 }
386 else if (!strcmp (opt, "mailfile") && val) 527 else if (!strcmp (opt, "mailfile") && val)
387 { 528 {
388 /* If the mail environment is not set, then mail_file was created 529 /* If the mail environment is not set, then mail_file was created
389 * with a malloc. We need to free it. 530 * with a malloc. We need to free it.
390 */ 531 */
391 if( getenv ("MAIL") == NULL) 532 if (getenv ("MAIL") == NULL)
392 free( mail_file); 533 free (mail_file);
393 /* assume user knows what he's doing, don't check that file is valid...*/ 534 /* assume user knows what he's doing, don't check that file is valid... */
394 mail_file = val; 535 mail_file = val;
395 } 536 }
396#ifndef MAIL_SPAWN 537# ifndef MAIL_SPAWN
397 else if (!strcmp (opt, "mailspawn") && val) 538 else if (!strcmp (opt, "mailspawn") && val)
398 { 539 {
399 mail_spawn = val; 540 mail_spawn = val;
400 } 541 }
401#endif 542# endif
402#endif /* MAIL */ 543#endif /* MAIL */
403#ifdef ADJUST_TIME 544#ifdef ADJUST_TIME
404 else if (!strcmp (opt, "adjust") && val) 545 else if (!strcmp (opt, "adjust") && val)
405 { 546 {
406 /* convert ddhhmm to seconds, minimal error checking */ 547 /* convert ddhhmm to seconds, minimal error checking */
407 int x = atoi (val); 548 int x = atoi (val);
549
408 adjustTime = ((((abs (x) / 10000) % 100) * 24 /* days */ 550 adjustTime = ((((abs (x) / 10000) % 100) * 24 /* days */
409 + ((abs (x) / 100) % 100)) * 60 /* hours */ 551 + ((abs (x) / 100) % 100)) * 60 /* hours */
410 + (abs (x) % 100)) * 60; /* minutes */ 552 + (abs (x) % 100)) * 60; /* minutes */
411 if (x < 0) 553 if (x < 0)
412 adjustTime = -adjustTime; 554 adjustTime = -adjustTime;
413 } 555 }
414#endif /* ADJUST_TIME */ 556#endif /* ADJUST_TIME */
415 else 557 else
416 { 558 {
417 usage (); 559 usage ();
418 goto Abort; 560 goto Abort;
419 } 561 }
420 } 562 }
421 563
422 /* open display */ 564 /* open display */
423 Xdisplay = XOpenDisplay (display_name); 565 Xdisplay = XOpenDisplay (display_name);
424 if (!Xdisplay) 566 if (!Xdisplay)
425 { 567 {
426 print_error ("can't open display %s", display_name?display_name: 568 print_error ("can't open display %s", display_name ? display_name :
427 getenv("DISPLAY")?getenv("DISPLAY"): 569 getenv ("DISPLAY") ? getenv ("DISPLAY") : "as no -d given and DISPLAY not set");
428 "as no -d given and DISPLAY not set");
429 goto Abort; 570 goto Abort;
430 } 571 }
431 572
432 /* get display info */ 573 /* get display info */
433 Xfd = XConnectionNumber (Xdisplay); 574 Xfd = XConnectionNumber (Xdisplay);
434 { 575 {
435 const char * const color_msg = "can't load color \"%s\""; 576 const char *const color_msg = "can't load color \"%s\"";
436 XColor xcol; 577 XColor xcol;
437 578
438 /* allocate foreground/background colors */ 579 /* allocate foreground/background colors */
439 if (!XParseColor (Xdisplay, Xcmap, rs_color [fgColor], &xcol) || 580 if (!XParseColor (Xdisplay, Xcmap, rs_color[fgColor], &xcol) || !XAllocColor (Xdisplay, Xcmap, &xcol))
440 !XAllocColor (Xdisplay, Xcmap, &xcol)) 581 {
441 {
442 print_error (color_msg, rs_color [fgColor]); 582 print_error (color_msg, rs_color[fgColor]);
443 goto Abort; 583 goto Abort;
444 } 584 }
445 PixColors [fgColor] = xcol.pixel; 585 PixColors[fgColor] = xcol.pixel;
446 586
447 if (!XParseColor (Xdisplay, Xcmap, rs_color [bgColor], &xcol) || 587 if (!XParseColor (Xdisplay, Xcmap, rs_color[bgColor], &xcol) || !XAllocColor (Xdisplay, Xcmap, &xcol))
448 !XAllocColor (Xdisplay, Xcmap, &xcol)) 588 {
449 {
450 print_error (color_msg, rs_color [bgColor]); 589 print_error (color_msg, rs_color[bgColor]);
451 goto Abort; 590 goto Abort;
452 }
453 PixColors [bgColor] = xcol.pixel;
454 } 591 }
592 PixColors[bgColor] = xcol.pixel;
593 }
455 594
456#ifdef REMINDERS 595#ifdef REMINDERS
457 /* load the font for messages */ 596 /* load the font for messages */
458 if ((Xfont = XLoadQueryFont (Xdisplay, rs_font)) == NULL) 597 if ((Xfont = XLoadQueryFont (Xdisplay, rs_font)) == NULL)
459 { 598 {
460 print_error ("can't load font \"%s\"", rs_font); 599 print_error ("can't load font \"%s\"", rs_font);
461 goto Abort; 600 goto Abort;
462 } 601 }
463 gcv.font = Xfont->fid; 602 gcv.font = Xfont->fid;
464#endif 603#endif
465 604
466 Create_Windows (argc, argv); 605 Create_Windows (argc, argv);
467 /* Create the graphics contexts */ 606 /* Create the graphics contexts */
468 gcv.foreground = PixColors [fgColor]; 607 gcv.foreground = PixColors[fgColor];
469 gcv.background = PixColors [bgColor]; 608 gcv.background = PixColors[bgColor];
470 609
471 Xgc = XCreateGC (Xdisplay, Clock.win, 610 Xgc = XCreateGC (Xdisplay, Clock.win,
472#ifdef REMINDERS 611#ifdef REMINDERS
473 GCFont | 612 GCFont |
474#endif 613#endif
475 GCForeground | GCBackground, &gcv); 614 GCForeground | GCBackground, &gcv);
476 615
477 gcv.foreground = PixColors [bgColor]; 616 gcv.foreground = PixColors[bgColor];
478 gcv.background = PixColors [fgColor]; 617 gcv.background = PixColors[fgColor];
479 Xrvgc = XCreateGC (Xdisplay, Clock.win, 618 Xrvgc = XCreateGC (Xdisplay, Clock.win,
480#ifdef REMINDERS 619#ifdef REMINDERS
481 GCFont | 620 GCFont |
482#endif 621#endif
483 GCForeground | GCBackground, &gcv); 622 GCForeground | GCBackground, &gcv);
484 623
485 getXevent (); 624 getXevent ();
486 return EXIT_SUCCESS; 625 return EXIT_SUCCESS;
487 626
488 Malloc_Error: 627Malloc_Error:
489 print_error ("malloc error"); 628 print_error ("malloc error");
490 Abort: 629Abort:
491 print_error ("aborting"); 630 print_error ("aborting");
492 return EXIT_FAILURE; 631 return EXIT_FAILURE;
493} 632}
494 633
495/* 634/*
496 * translate geometry string to appropriate sizehint 635 * translate geometry string to appropriate sizehint
497 */ 636 */
498static void 637static void
499geometry2sizehint (mywindow_t * win, const char * geom) 638geometry2sizehint (mywindow_t *win, const char *geom)
500{ 639{
501 int x, y, flags; 640 int x, y, flags;
502 unsigned int width, height; 641 unsigned int width, height;
503 642
504 /* copy in values */ 643 /* copy in values */
505 szHint.width = win->width; 644 szHint.width = win->width;
506 szHint.height = win->height; 645 szHint.height = win->height;
507 646
508 if (geom == NULL) 647 if (geom == NULL)
509 return; 648 return;
510 649
511 flags = XParseGeometry (geom, &x, &y, &width, &height); 650 flags = XParseGeometry (geom, &x, &y, &width, &height);
512 651
513 if (flags & WidthValue) 652 if (flags & WidthValue)
514 { 653 {
515 szHint.width = width + szHint.base_width; 654 szHint.width = width + szHint.base_width;
516 szHint.flags |= USSize; 655 szHint.flags |= USSize;
517 } 656 }
518 if (flags & HeightValue) 657 if (flags & HeightValue)
519 { 658 {
520 szHint.height = height + szHint.base_height; 659 szHint.height = height + szHint.base_height;
521 szHint.flags |= USSize; 660 szHint.flags |= USSize;
522 } 661 }
523 662
524 if (flags & XValue) 663 if (flags & XValue)
525 { 664 {
526 if (flags & XNegative) 665 if (flags & XNegative)
527 { 666 {
528 x += (DisplayWidth (Xdisplay, Xscreen) - szHint.width); 667 x += (DisplayWidth (Xdisplay, Xscreen) - szHint.width);
529 szHint.win_gravity = NorthEastGravity; 668 szHint.win_gravity = NorthEastGravity;
530 } 669 }
531 szHint.x = x; 670 szHint.x = x;
532 szHint.flags |= USPosition; 671 szHint.flags |= USPosition;
533 } 672 }
534 if (flags & YValue) 673 if (flags & YValue)
535 { 674 {
536 if (flags & YNegative) 675 if (flags & YNegative)
537 { 676 {
538 y += (DisplayHeight (Xdisplay, Xscreen) - szHint.height); 677 y += (DisplayHeight (Xdisplay, Xscreen) - szHint.height);
539 szHint.win_gravity = (szHint.win_gravity == NorthEastGravity ? 678 szHint.win_gravity = (szHint.win_gravity == NorthEastGravity ? SouthEastGravity : SouthWestGravity);
540 SouthEastGravity : SouthWestGravity); 679 }
541 }
542 szHint.y = y; 680 szHint.y = y;
543 szHint.flags |= USPosition; 681 szHint.flags |= USPosition;
544 } 682 }
545 683
546 /* copy out values */ 684 /* copy out values */
547 win->width = szHint.width; 685 win->width = szHint.width;
548 win->height = szHint.height; 686 win->height = szHint.height;
549} 687}
550 688
551/* 689/*
552 * Open and map the windows 690 * Open and map the windows
553 */ 691 */
554static void 692static void
555Create_Windows (int argc, char * argv []) 693Create_Windows (int argc, char *argv[])
556{ 694{
557 XClassHint classHint; 695 XClassHint classHint;
558 XWMHints wmHint; 696 XWMHints wmHint;
559 697
560 geometry2sizehint (&Clock, rs_geometry); 698 geometry2sizehint (&Clock, rs_geometry);
561 Clock.win = XCreateSimpleWindow (Xdisplay, Xroot, 699 Clock.win = XCreateSimpleWindow (Xdisplay, Xroot,
562 szHint.x, szHint.y, 700 szHint.x, szHint.y, Clock.width, Clock.height, 0, PixColors[fgColor], PixColors[bgColor]);
563 Clock.width, Clock.height,
564 0,
565 PixColors [fgColor],
566 PixColors [bgColor]);
567 701
568#ifdef ICONWIN 702#ifdef ICONWIN
569 geometry2sizehint (&Icon, rs_iconGeometry); 703 geometry2sizehint (&Icon, rs_iconGeometry);
570 Icon.win = XCreateSimpleWindow (Xdisplay, Xroot, 704 Icon.win = XCreateSimpleWindow (Xdisplay, Xroot, szHint.x, szHint.y, Icon.width, Icon.height, 0, PixColors[fgColor], PixColors[bgColor]);
571 szHint.x, szHint.y,
572 Icon.width, Icon.height,
573 0,
574 PixColors [fgColor],
575 PixColors [bgColor]);
576 wmHint.initial_state = iconic_state; 705 wmHint.initial_state = iconic_state;
577 wmHint.icon_window = Icon.win; 706 wmHint.icon_window = Icon.win;
578 wmHint.flags = InputHint | StateHint | IconWindowHint; 707 wmHint.flags = InputHint | StateHint | IconWindowHint;
579#else 708#else
580 wmHint.flags = InputHint; 709 wmHint.flags = InputHint;
581#endif 710#endif
582 wmHint.input = True; 711 wmHint.input = True;
583 712
584 /* ignore warning about discarded `const' */
585 classHint.res_name = APL_NAME; 713 classHint.res_name = (char *)APL_NAME;
586 classHint.res_class = APL_CLASS; 714 classHint.res_class = (char *)APL_CLASS;
587 XSetWMProperties (Xdisplay, Clock.win, NULL, NULL, argv, argc, 715 XSetWMProperties (Xdisplay, Clock.win, NULL, NULL, argv, argc, &szHint, &wmHint, &classHint);
588 &szHint, &wmHint, &classHint);
589 716
590 XSelectInput (Xdisplay, Clock.win, 717 XSelectInput (Xdisplay, Clock.win, (ExposureMask | StructureNotifyMask | ButtonPressMask));
591 (ExposureMask|StructureNotifyMask|ButtonPressMask));
592 718
593#ifdef ICONWIN 719#ifdef ICONWIN
594 XSelectInput (Xdisplay, Icon.win, 720 XSelectInput (Xdisplay, Icon.win, (ExposureMask | ButtonPressMask));
595 (ExposureMask|ButtonPressMask));
596#endif 721#endif
597 XMapWindow (Xdisplay, Clock.win); 722 XMapWindow (Xdisplay, Clock.win);
598 723
599 /* create, but don't map a window for appointment reminders */ 724 /* create, but don't map a window for appointment reminders */
600#ifdef REMINDERS 725#ifdef REMINDERS
601 Msg.win = XCreateSimpleWindow (Xdisplay, Xroot, 726 Msg.win = XCreateSimpleWindow (Xdisplay, Xroot,
602 szHint.x, szHint.y, 727 szHint.x, szHint.y, szHint.width, szHint.height, 0, PixColors[fgColor], PixColors[bgColor]);
603 szHint.width, szHint.height,
604 0,
605 PixColors [fgColor],
606 PixColors [bgColor]);
607 728
608 szHint.flags |= USPosition; 729 szHint.flags |= USPosition;
609 /* ignore warning about discarded `const' */ 730 /* ignore warning about discarded `const' */
610 classHint.res_name = MSG_NAME; 731 classHint.res_name = (char *)MSG_NAME;
611 classHint.res_class = MSG_CLASS; 732 classHint.res_class = (char *)MSG_CLASS;
612 wmHint.input = True; 733 wmHint.input = True;
613 wmHint.flags = InputHint; 734 wmHint.flags = InputHint;
614 735
615 XSetWMProperties (Xdisplay, Msg.win, NULL, NULL, argv, argc, 736 XSetWMProperties (Xdisplay, Msg.win, NULL, NULL, argv, argc, &szHint, &wmHint, &classHint);
616 &szHint, &wmHint, &classHint); 737
617 { 738 {
618 char * str = MSG_NAME; 739 const char *str = MSG_NAME;
740
619 XStoreName (Xdisplay, Msg.win, str); 741 XStoreName (Xdisplay, Msg.win, str);
620 XSetIconName (Xdisplay, Msg.win, str); 742 XSetIconName (Xdisplay, Msg.win, str);
621 } 743 }
622 744
623 XSelectInput (Xdisplay, Msg.win, 745 XSelectInput (Xdisplay, Msg.win, (ExposureMask | ButtonPressMask | KeyPressMask));
624 (ExposureMask|ButtonPressMask|KeyPressMask));
625 746
626 /* font already loaded */ 747 /* font already loaded */
627 748
628 msgButton.width = 4 + 5 * XTextWidth (Xfont, "M", 1); 749 msgButton.width = 4 + 5 * XTextWidth (Xfont, "M", 1);
629 msgButton.height = 4 + FontHeight (); 750 msgButton.height = 4 + FontHeight ();
630 751
631 msgButton.Dismiss = XCreateSimpleWindow (Xdisplay, Msg.win, 752 msgButton.Dismiss = XCreateSimpleWindow (Xdisplay, Msg.win,
632 0, 0, 753 0, 0, msgButton.width, msgButton.height, 0, PixColors[bgColor], PixColors[fgColor]);
633 msgButton.width, msgButton.height,
634 0,
635 PixColors [bgColor],
636 PixColors [fgColor]);
637 754
638 XMapWindow (Xdisplay, msgButton.Dismiss); 755 XMapWindow (Xdisplay, msgButton.Dismiss);
639 756
640 msgButton.Defer = XCreateSimpleWindow (Xdisplay, Msg.win, 757 msgButton.Defer = XCreateSimpleWindow (Xdisplay, Msg.win,
641 0, 0, 758 0, 0, msgButton.width, msgButton.height, 0, PixColors[bgColor], PixColors[fgColor]);
642 msgButton.width, msgButton.height,
643 0,
644 PixColors [bgColor],
645 PixColors [fgColor]);
646 XMapWindow (Xdisplay, msgButton.Defer); 759 XMapWindow (Xdisplay, msgButton.Defer);
647 760
648#ifndef NO_REMINDER_EXEC 761# ifndef NO_REMINDER_EXEC
649 msgButton.Start = XCreateSimpleWindow (Xdisplay, Msg.win, 762 msgButton.Start = XCreateSimpleWindow (Xdisplay, Msg.win,
650 0, 0, 763 0, 0, msgButton.width, msgButton.height, 0, PixColors[bgColor], PixColors[fgColor]);
651 msgButton.width, msgButton.height,
652 0,
653 PixColors [bgColor],
654 PixColors [fgColor]);
655 XMapWindow (Xdisplay, msgButton.Start); 764 XMapWindow (Xdisplay, msgButton.Start);
656#endif /* NO_REMINDER_EXEC */ 765# endif/* NO_REMINDER_EXEC */
657#endif 766#endif
658} 767}
659 768
660static time_t 769static time_t
661mk_time (struct tm * tmval) 770mk_time (struct tm *tmval)
662{ 771{
663 return (tmval->tm_min 772 return (tmval->tm_min
664 + 60 * (tmval->tm_hour 773 + 60 * (tmval->tm_hour
665 + 24 * (tmval->tm_mday 774 + 24 * (tmval->tm_mday
666 + 31 * ((tmval->tm_mon+1) 775 + 31 * ((tmval->tm_mon + 1)
667 + 12 * tmval->tm_year)))); 776 + 12 * tmval->tm_year))));
668} 777}
669
670 778
671#ifdef MAIL 779#ifdef MAIL
672static int 780static int
673MailAvailable() 781MailAvailable ()
674{ 782{
675 struct stat st; 783 struct stat st;
676 784
677 if( is_maildir ) { 785 if (is_maildir)
678 DIR *dirp; 786 {
787 DIR *dirp;
679 struct dirent *d; 788 struct dirent *d;
680 789
681 if( (dirp=opendir( mail_file )) ) { 790 if ((dirp = opendir (mail_file)))
791 {
682 while( (d=readdir(dirp)) ) { 792 while ((d = readdir (dirp)))
683 if( *d->d_name == '.' ) 793 {
684 continue; 794 if (*d->d_name == '.')
685 if( isdigit(*d->d_name) ) { 795 continue;
796 if (isdigit (*d->d_name))
797 {
798 closedir (dirp);
799 return 1;
800 }
801 }
686 closedir(dirp); 802 closedir (dirp);
803 }
687 return 1; 804 return 0;
688 }
689 } 805 }
690 closedir(dirp);
691 }
692 return 0;
693 }
694 else 806 else
695 return !stat(mail_file, &st) && 807 return !stat (mail_file, &st) && (st.st_size > 0) && (st.st_mtime >= st.st_atime);
696 (st.st_size > 0) && (st.st_mtime >= st.st_atime);
697} 808}
698#endif 809#endif
699 810
700/*----------------------------------------------------------------------* 811/*----------------------------------------------------------------------*
701 * Redraw the whole window after an exposure or size change. 812 * Redraw the whole window after an exposure or size change.
702 * After a timeout, only redraw the hands. 813 * After a timeout, only redraw the hands.
703 * Provide reminder if needed. 814 * Provide reminder if needed.
704 *----------------------------------------------------------------------*/ 815 *----------------------------------------------------------------------*/
705static void 816static void
706Draw_Window (mywindow_t * W, int full_redraw) 817Draw_Window (mywindow_t *W, int full_redraw)
707{ 818{
708 /* pre-computed values for sin() x1000, to avoid using floats */
709 static const short Sin [720] = {
710 0,
711 9, 17, 26, 35, 44, 52, 61, 70, 78, 87, 96, 105,
712 113, 122, 131, 139, 148, 156, 165, 174, 182, 191, 199, 208,
713 216, 225, 233, 242, 250, 259, 267, 276, 284, 292, 301, 309,
714 317, 326, 334, 342, 350, 358, 367, 375, 383, 391, 399, 407,
715 415, 423, 431, 438, 446, 454, 462, 469, 477, 485, 492, 500,
716 508, 515, 522, 530, 537, 545, 552, 559, 566, 574, 581, 588,
717 595, 602, 609, 616, 623, 629, 636, 643, 649, 656, 663, 669,
718 676, 682, 688, 695, 701, 707, 713, 719, 725, 731, 737, 743,
719 749, 755, 760, 766, 772, 777, 783, 788, 793, 799, 804, 809,
720 814, 819, 824, 829, 834, 839, 843, 848, 853, 857, 862, 866,
721 870, 875, 879, 883, 887, 891, 895, 899, 903, 906, 910, 914,
722 917, 921, 924, 927, 930, 934, 937, 940, 943, 946, 948, 951,
723 954, 956, 959, 961, 964, 966, 968, 970, 972, 974, 976, 978,
724 980, 982, 983, 985, 986, 988, 989, 990, 991, 993, 994, 995,
725 995, 996, 997, 998, 998, 999, 999, 999, 1000, 1000, 1000, 1000,
726 1000, 1000, 1000, 999, 999, 999, 998, 998, 997, 996, 995, 995,
727 994, 993, 991, 990, 989, 988, 986, 985, 983, 982, 980, 978,
728 976, 974, 972, 970, 968, 966, 964, 961, 959, 956, 954, 951,
729 948, 946, 943, 940, 937, 934, 930, 927, 924, 921, 917, 914,
730 910, 906, 903, 899, 895, 891, 887, 883, 879, 875, 870, 866,
731 862, 857, 853, 848, 843, 839, 834, 829, 824, 819, 814, 809,
732 804, 799, 793, 788, 783, 777, 772, 766, 760, 755, 749, 743,
733 737, 731, 725, 719, 713, 707, 701, 695, 688, 682, 676, 669,
734 663, 656, 649, 643, 636, 629, 623, 616, 609, 602, 595, 588,
735 581, 574, 566, 559, 552, 545, 537, 530, 523, 515, 508, 500,
736 492, 485, 477, 469, 462, 454, 446, 438, 431, 423, 415, 407,
737 399, 391, 383, 375, 367, 358, 350, 342, 334, 326, 317, 309,
738 301, 292, 284, 276, 267, 259, 250, 242, 233, 225, 216, 208,
739 199, 191, 182, 174, 165, 156, 148, 139, 131, 122, 113, 105,
740 96, 87, 78, 70, 61, 52, 44, 35, 26, 17, 9, 0,
741 -9, -17, -26, -35, -44, -52, -61, -70, -78, -87, -96, -105,
742 -113, -122, -131, -139, -148, -156, -165, -174, -182, -191, -199, -208,
743 -216, -225, -233, -242, -250, -259, -267, -276, -284, -292, -301, -309,
744 -317, -326, -334, -342, -350, -358, -366, -375, -383, -391, -399, -407,
745 -415, -423, -431, -438, -446, -454, -462, -469, -477, -485, -492, -500,
746 -508, -515, -522, -530, -537, -545, -552, -559, -566, -574, -581, -588,
747 -595, -602, -609, -616, -623, -629, -636, -643, -649, -656, -663, -669,
748 -676, -682, -688, -695, -701, -707, -713, -719, -725, -731, -737, -743,
749 -749, -755, -760, -766, -772, -777, -783, -788, -793, -799, -804, -809,
750 -814, -819, -824, -829, -834, -839, -843, -848, -853, -857, -862, -866,
751 -870, -875, -879, -883, -887, -891, -895, -899, -903, -906, -910, -914,
752 -917, -921, -924, -927, -930, -934, -937, -940, -943, -946, -948, -951,
753 -954, -956, -959, -961, -964, -966, -968, -970, -972, -974, -976, -978,
754 -980, -982, -983, -985, -986, -988, -989, -990, -991, -993, -994, -995,
755 -995, -996, -997, -998, -998, -999, -999, -999, -1000, -1000, -1000, -1000,
756 -1000, -1000, -1000, -999, -999, -999, -998, -998, -997, -996, -995, -995,
757 -994, -993, -991, -990, -989, -988, -986, -985, -983, -982, -980, -978,
758 -976, -974, -972, -970, -968, -966, -964, -961, -959, -956, -954, -951,
759 -948, -946, -943, -940, -937, -934, -930, -927, -924, -921, -917, -914,
760 -910, -906, -903, -899, -895, -891, -887, -883, -879, -875, -870, -866,
761 -862, -857, -853, -848, -843, -839, -834, -829, -824, -819, -814, -809,
762 -804, -799, -793, -788, -783, -777, -772, -766, -760, -755, -749, -743,
763 -737, -731, -725, -719, -713, -707, -701, -695, -688, -682, -676, -669,
764 -663, -656, -649, -643, -636, -629, -623, -616, -609, -602, -595, -588,
765 -581, -574, -566, -559, -552, -545, -537, -530, -523, -515, -508, -500,
766 -492, -485, -477, -469, -462, -454, -446, -438, -431, -423, -415, -407,
767 -399, -391, -383, -375, -367, -358, -350, -342, -334, -326, -317, -309,
768 -301, -292, -284, -276, -267, -259, -250, -242, -233, -225, -216, -208,
769 -199, -191, -182, -174, -165, -156, -148, -139, -131, -122, -113, -105,
770 -96, -87, -78, -70, -61, -52, -44, -35, -26, -17, -9,
771 };
772
773 static int savedDay = -1; 819 static int savedDay = -1;
774 820
775 time_t currentTime; 821 time_t currentTime;
776 struct tm * tmval; 822 struct tm *tmval;
777 int ctr_x, ctr_y; 823 int ctr_x, ctr_y;
778 824
779 typedef struct { 825 typedef struct
780 int h_x, h_y; /* hour */ 826 {
827 int h_x, h_y; /* hour */
781 int m_x, m_y; /* minute */ 828 int m_x, m_y; /* minute */
782 int s_x, s_y; /* second */ 829 int s_x, s_y; /* second */
783 } hands_t; /* hand positions (x,y) */ 830 } hands_t; /* hand positions (x,y) */
784 831
785 hands_t HandsNow, * pHandsOld; 832 hands_t HandsNow, *pHandsOld;
786 833
787 GC X_gc, X_rvgc; 834 GC X_gc, X_rvgc;
788 835
789 static hands_t HandsOld = { -1 }; 836 static hands_t HandsOld = { -1 };
790#ifdef ICONWIN 837#ifdef ICONWIN
791 static hands_t HandsOld_icon = { -1 }; 838 static hands_t HandsOld_icon = { -1 };
792#endif 839#endif
793#ifdef REMINDERS 840#ifdef REMINDERS
794 static int lastUpdateTime = -10; 841 static int lastUpdateTime = -10;
795#endif 842#endif
796 843
797#ifdef MAIL 844#ifdef MAIL
798 static time_t mailTime = 0; 845 static time_t mailTime = 0;
799 static int MailUp = 0, MailUp_rvideo = 0; 846 static int MailUp = 0, MailUp_rvideo = 0;
847
848# ifdef ICONWIN
849 static int MailUp_icon = 0;
850# endif
851#endif /* MAIL */
852
853 currentTime = time (NULL) + adjustTime; /* get the current time */
854 tmval = localtime (&currentTime);
855
856#ifdef MAIL
857# ifdef REMINDERS
858 if (W->win != Msg.win)
859# endif
860 {
861 int *pMailUp = (
862# ifdef ICONWIN
863 W->win == Icon.win ? &MailUp_icon :
864# endif
865 &MailUp);
866
867 if ((currentTime - mailTime) >= mailUpdate)
868 {
869 if (
870# ifdef ICONWIN
871 MailUp != MailUp_icon ? MailUp :
872# endif
873 ((mail_file != NULL) && MailAvailable ()))
874 {
875 if (!*pMailUp)
876 {
877 *pMailUp = 1;
878 full_redraw = 1;
879 XSetWindowBackground (Xdisplay, W->win, PixColors[fgColor]);
880# ifdef MAIL_BELL
881 XBell (Xdisplay, 0);
882# endif
883 }
884 }
885 else
886 {
887 if (*pMailUp)
888 {
889 *pMailUp = 0;
890 full_redraw = 1;
891 XSetWindowBackground (Xdisplay, W->win, PixColors[bgColor]);
892 }
893 }
894# ifdef ICONWIN
895 if (MailUp == MailUp_icon)
896# endif
897 mailTime = currentTime;
898
899 MailUp_rvideo = *pMailUp;
900 }
901 }
902#endif /* MAIL */
903
904 /* once every day, update the window and icon name */
905 if (tmval->tm_yday != savedDay)
906 {
907 char str[20];
908
909 savedDay = tmval->tm_yday;
910 strftime (str, sizeof (str), "%a %h %d", tmval);
911 XStoreName (Xdisplay, Clock.win, str);
912 XSetIconName (Xdisplay, Clock.win, str);
913 }
914
915 if (full_redraw)
916 XClearWindow (Xdisplay, W->win);
917
918#ifdef REMINDERS
919 /* for a message window, just re-draw the message */
920 if (W->win == Msg.win)
921 {
922 char *beg, *next;
923 int lines;
924
925 for (beg = message, lines = 0; beg; beg = next, lines++)
926 {
927 char *end;
928
929 if ((end = strstr (beg, "\\n")) == NULL)
930 {
931 end = beg + strlen (beg);
932 next = NULL;
933 }
934 else
935 {
936 next = end + 2;
937 }
938
939 XDrawString (Xdisplay, Msg.win,
940 Xgc,
941 (Msg.width -
942 XTextWidth (Xfont, beg, (end - beg))) / 2, 10 + Xfont->ascent + FontHeight () * lines, beg, (end - beg));
943 }
944
945 XDrawString (Xdisplay, msgButton.Dismiss, Xrvgc, (msgButton.width - XTextWidth (Xfont, "Done" , 4)) / 2, Xfont->ascent + 2, "Done" , 4);
946
947 XDrawString (Xdisplay, msgButton.Defer , Xrvgc, (msgButton.width - XTextWidth (Xfont, "Defer", 5)) / 2, Xfont->ascent + 2, "Defer", 5);
948
949# ifndef NO_REMINDER_EXEC
950 XDrawString (Xdisplay, msgButton.Start , Xrvgc, (msgButton.width - XTextWidth (Xfont, "Start", 5)) / 2, Xfont->ascent + 2, "Start", 5);
951
952 if (strlen (execPrgm) > 1)
953 XMapWindow (Xdisplay, msgButton.Start);
954 else
955 XUnmapWindow (Xdisplay, msgButton.Start);
956# endif /* NO_REMINDER_EXEC */
957 return;
958 }
959
960 /*
961 * Convert multi-field time info to a single integer with a resolution
962 * in minutes.
963 */
964 currentTime = mk_time (tmval);
965
966 /* is there a reminder pending? */
967 if (reminderTime >= 0 && currentTime >= reminderTime)
968 Reminder ();
969
970 /* every 10 minutes, or at start of day, check for revised entries */
971 if (!Msg_Mapped &&
972 (currentTime > lastUpdateTime + REMINDERS_TIME || (currentTime != lastUpdateTime && tmval->tm_hour == 0 && tmval->tm_min == 0)))
973 {
974 Next_Reminder (UPDATE);
975 lastUpdateTime = currentTime;
976 }
977#endif
978
979 /*
980 * draw clock
981 */
982
983 ctr_x = W->width / 2;
984 ctr_y = W->height / 2;
985
986#define XPOS(i,val) (ctr_x + (W->width * Sin (i ) + 4096) / (819200 / (val)))
987#define YPOS(i,val) (ctr_y - (W->height * Sin (i + 180) + 4096) / (819200 / (val)))
988 /*
989 * how to draw the clock face
990 */
991
992 /* calculate the positions of the hands */
993 {
994 int angle = (tmval->tm_hour % 12) * 60 + tmval->tm_min;
995
996 HandsNow.h_x = XPOS (angle, 60);
997 HandsNow.h_y = YPOS (angle, 60);
998 }
999 {
1000 int angle = (tmval->tm_min * 12);
1001
1002 HandsNow.m_x = XPOS (angle, 80);
1003 HandsNow.m_y = YPOS (angle, 80);
1004 }
1005 if (clockUpdate == 1)
1006 {
1007 int angle = (tmval->tm_sec * 12);
1008
1009 HandsNow.s_x = XPOS (angle, 85);
1010 HandsNow.s_y = YPOS (angle, 85);
1011 }
1012
1013 pHandsOld = (
800#ifdef ICONWIN 1014#ifdef ICONWIN
801 static int MailUp_icon = 0; 1015 W->win == Icon.win ? &HandsOld_icon :
802#endif 1016#endif
803#endif /* MAIL */ 1017 &HandsOld);
804
805 currentTime = time (NULL) + adjustTime; /* get the current time */
806 tmval = localtime (&currentTime);
807 1018
808#ifdef MAIL 1019#ifdef MAIL
1020 if (MailUp_rvideo)
1021 {
1022 X_gc = Xrvgc;
1023 X_rvgc = Xgc;
1024 }
1025 else
1026#endif
1027 {
1028 X_gc = Xgc;
1029 X_rvgc = Xrvgc;
1030 }
1031
1032 /*
1033 * Draw the date in the lower half of the clock window.
1034 * The code is enclosed in REMINDERS because it uses the same
1035 * font as the reminders code.
1036 * I believe this should be drawn always so it does not get
1037 * "swept away" by the minute hand.
1038 */
1039#if defined(REMINDERS) && defined(DATE_ON_CLOCK_FACE)
1040 if (show_date)
1041 {
1042 char date[10];
1043
1044 strftime (date, sizeof (date), "%d", tmval);
1045 XDrawString (Xdisplay, W->win, X_gc,
1046 ctr_x - XTextWidth (Xfont, date, strlen (date)) / 2,
1047 ctr_y + FontHeight () + (ctr_y - FontHeight ()) / 2, date, strlen (date));
1048 }
1049#endif
1050
1051 if (full_redraw)
1052 {
1053 int mintick;
1054
1055 /*
1056 * draw clock face
1057 */
1058#ifdef SUBTICKS
1059 for (mintick = 0; mintick < 60; mintick++)
1060 XDrawPoint (Xdisplay, W->win, X_gc, XPOS ((mintick * 12), 95), YPOS ((mintick * 12), 95));
1061#endif
1062 for (mintick = 0; mintick < 60; mintick += 5)
1063 XDrawLine (Xdisplay, W->win, X_gc,
1064 XPOS ((mintick * 12), 90), YPOS ((mintick * 12), 90), XPOS ((mintick * 12), 100), YPOS ((mintick * 12), 100));
1065 }
1066 else if (memcmp (pHandsOld, &HandsNow, sizeof (hands_t)))
1067 {
1068 int i, j;
1069
1070 /*
1071 * erase old hands
1072 */
1073 for (i = -1; i < 2; i++)
1074 for (j = -1; j < 2; j++)
1075 {
1076 /* hour/minute hands */
1077 XDrawLine (Xdisplay, W->win, X_rvgc, ctr_x + i, ctr_y + j, pHandsOld->h_x, pHandsOld->h_y);
1078 XDrawLine (Xdisplay, W->win, X_rvgc, ctr_x + i, ctr_y + j, pHandsOld->m_x, pHandsOld->m_y);
1079 }
1080
1081 if (clockUpdate == 1) /* seconds hand */
1082 XDrawLine (Xdisplay, W->win, X_rvgc, ctr_x, ctr_y, pHandsOld->s_x, pHandsOld->s_y);
1083 }
1084
1085 if (full_redraw || memcmp (pHandsOld, &HandsNow, sizeof (hands_t)))
1086 {
1087 int i, j;
1088
1089 /*
1090 * draw new hands
1091 */
1092 for (i = -1; i < 2; i++)
1093 for (j = -1; j < 2; j++)
1094 {
1095 /* hour/minute hands */
1096 XDrawLine (Xdisplay, W->win, X_gc, ctr_x + i, ctr_y + j, HandsNow.h_x, HandsNow.h_y);
1097
1098 XDrawLine (Xdisplay, W->win, X_gc, ctr_x + i, ctr_y + j, HandsNow.m_x, HandsNow.m_y);
1099 }
1100 if (clockUpdate == 1) /* seconds hand */
1101 XDrawLine (Xdisplay, W->win, X_gc, ctr_x, ctr_y, HandsNow.s_x, HandsNow.s_y);
1102
1103 *pHandsOld = HandsNow;
1104 }
1105}
1106
809#ifdef REMINDERS 1107#ifdef REMINDERS
810 if (W->win != Msg.win)
811#endif
812 {
813 int * pMailUp = (
814#ifdef ICONWIN
815 W->win == Icon.win ? &MailUp_icon :
816#endif
817 &MailUp);
818 1108
819 if ((currentTime - mailTime) >= mailUpdate)
820 {
821 struct stat st;
822
823 if (
824#ifdef ICONWIN
825 MailUp != MailUp_icon ? MailUp :
826#endif
827 ((mail_file != NULL) && MailAvailable() ) )
828 {
829 if (!*pMailUp)
830 {
831 *pMailUp = 1;
832 full_redraw = 1;
833 XSetWindowBackground (Xdisplay, W->win,
834 PixColors [fgColor]);
835#ifdef MAIL_BELL
836 XBell (Xdisplay, 0);
837#endif
838 }
839 }
840 else
841 {
842 if (*pMailUp)
843 {
844 *pMailUp = 0;
845 full_redraw = 1;
846 XSetWindowBackground (Xdisplay, W->win,
847 PixColors [bgColor]);
848 }
849 }
850#ifdef ICONWIN
851 if (MailUp == MailUp_icon)
852#endif
853 mailTime = currentTime;
854
855 MailUp_rvideo = *pMailUp;
856 }
857 }
858#endif /* MAIL */
859
860 /* once every day, update the window and icon name */
861 if (tmval->tm_yday != savedDay)
862 {
863 char str [20];
864
865 savedDay = tmval->tm_yday;
866 strftime (str, sizeof(str), "%a %h %d", tmval);
867 XStoreName (Xdisplay, Clock.win, str);
868 XSetIconName (Xdisplay, Clock.win, str);
869 }
870
871 if (full_redraw)
872 XClearWindow (Xdisplay, W->win);
873
874#ifdef REMINDERS
875 /* for a message window, just re-draw the message */
876 if (W->win == Msg.win)
877 {
878 char * beg, * next;
879 int lines;
880
881 for (beg = message, lines = 0; beg; beg = next, lines++)
882 {
883 char * end;
884
885 if ((end = strstr (beg, "\\n")) == NULL)
886 {
887 end = beg + strlen (beg);
888 next = NULL;
889 }
890 else
891 {
892 next = end + 2;
893 }
894
895 XDrawString (Xdisplay, Msg.win,
896 Xgc,
897 (Msg.width -
898 XTextWidth (Xfont, beg, (end-beg))) / 2,
899 10 + Xfont->ascent + FontHeight () * lines,
900 beg, (end-beg));
901 }
902
903 XDrawString (Xdisplay, msgButton.Dismiss,
904 Xrvgc,
905 (msgButton.width - XTextWidth (Xfont, "Done", 4)) / 2,
906 Xfont->ascent + 2,
907 "Done", 4);
908
909 XDrawString (Xdisplay, msgButton.Defer,
910 Xrvgc,
911 (msgButton.width - XTextWidth (Xfont, "Defer", 5)) / 2,
912 Xfont->ascent + 2,
913 "Defer", 5);
914
915# ifndef NO_REMINDER_EXEC
916 XDrawString (Xdisplay, msgButton.Start,
917 Xrvgc,
918 (msgButton.width - XTextWidth (Xfont, "Start", 5)) / 2,
919 Xfont->ascent + 2,
920 "Start", 5);
921
922 if (strlen (execPrgm) > 1)
923 XMapWindow (Xdisplay, msgButton.Start);
924 else
925 XUnmapWindow (Xdisplay, msgButton.Start);
926# endif /* NO_REMINDER_EXEC */
927 return;
928 }
929
930 /*
931 * Convert multi-field time info to a single integer with a resolution
932 * in minutes.
933 */
934 currentTime = mk_time (tmval);
935
936 /* is there a reminder pending? */
937 if (reminderTime >= 0 && currentTime >= reminderTime)
938 Reminder ();
939
940 /* every 10 minutes, or at start of day, check for revised entries */
941 if (!Msg_Mapped &&
942 (currentTime > lastUpdateTime + REMINDERS_TIME ||
943 (currentTime != lastUpdateTime &&
944 tmval->tm_hour == 0 && tmval->tm_min == 0)))
945 {
946 Next_Reminder (UPDATE);
947 lastUpdateTime = currentTime;
948 }
949#endif
950
951 /*
952 * draw clock
953 */
954
955 ctr_x = (W->width / 2);
956 ctr_y = (W->height / 2);
957
958#define XPOS(i,val) (ctr_x + (W->width * Sin[i%720] * (val) + 100000) / 200000)
959#define YPOS(i,val) (ctr_y - (W->height * Sin[(i+180)%720] * (val) + 100000) / 200000)
960 /*
961 * how to draw the clock face
962 */
963
964 /* calculate the positions of the hands */
965 {
966 int angle = (tmval->tm_hour % 12) * 60 + tmval->tm_min;
967 HandsNow.h_x = XPOS (angle, 60);
968 HandsNow.h_y = YPOS (angle, 60);
969 }
970 {
971 int angle = (tmval->tm_min * 12);
972 HandsNow.m_x = XPOS (angle, 80);
973 HandsNow.m_y = YPOS (angle, 80);
974 }
975 if (clockUpdate == 1)
976 {
977 int angle = (tmval->tm_sec * 12);
978 HandsNow.s_x = XPOS (angle, 85);
979 HandsNow.s_y = YPOS (angle, 85);
980 }
981
982 pHandsOld = (
983#ifdef ICONWIN
984 W->win == Icon.win ? &HandsOld_icon :
985#endif
986 &HandsOld);
987
988#ifdef MAIL
989 if (MailUp_rvideo)
990 {
991 X_gc = Xrvgc;
992 X_rvgc = Xgc;
993 }
994 else
995#endif
996 {
997 X_gc = Xgc;
998 X_rvgc = Xrvgc;
999 }
1000
1001 /*
1002 * Draw the date in the lower half of the clock window.
1003 * The code is enclosed in REMINDERS because it uses the same
1004 * font as the reminders code.
1005 * I believe this should be drawn always so it does not get
1006 * "swept away" by the minute hand.
1007 */
1008#if defined(REMINDERS) && defined(DATE_ON_CLOCK_FACE)
1009 if( show_date)
1010 {
1011 char date[10];
1012 currentTime = time (NULL) + adjustTime; /* get the current time */
1013 tmval = localtime (&currentTime);
1014 strftime (date, sizeof(date), "%d", tmval);
1015 XDrawString (Xdisplay, W->win, X_gc,
1016 ctr_x - XTextWidth(Xfont, date, strlen(date))/2,
1017 ctr_y + FontHeight() + (ctr_y - FontHeight())/2,
1018 date, strlen(date));
1019 }
1020#endif
1021
1022 if (full_redraw)
1023 {
1024 int mintick;
1025 /*
1026 * draw clock face
1027 */
1028#ifdef SUBTICKS
1029 for (mintick = 0; mintick < 60; mintick++)
1030 XDrawPoint (Xdisplay, W->win, X_gc,
1031 XPOS ((mintick * 12), 95),
1032 YPOS ((mintick * 12), 95));
1033#endif
1034 for (mintick = 0; mintick < 60; mintick += 5)
1035 XDrawLine (Xdisplay, W->win, X_gc,
1036 XPOS ((mintick * 12), 90),
1037 YPOS ((mintick * 12), 90),
1038 XPOS ((mintick * 12), 100),
1039 YPOS ((mintick * 12), 100));
1040 }
1041 else if (memcmp (pHandsOld, &HandsNow, sizeof(hands_t)))
1042 {
1043 int i, j;
1044 /*
1045 * erase old hands
1046 */
1047 for (i = -1; i < 2; i++) for (j = -1; j < 2; j++)
1048 {
1049 /* hour/minute hands */
1050 XDrawLine (Xdisplay, W->win, X_rvgc,
1051 ctr_x + i,
1052 ctr_y + j,
1053 pHandsOld->h_x, pHandsOld->h_y);
1054 XDrawLine (Xdisplay, W->win, X_rvgc,
1055 ctr_x + i,
1056 ctr_y + j,
1057 pHandsOld->m_x, pHandsOld->m_y);
1058 }
1059
1060 if (clockUpdate == 1) /* seconds hand */
1061 XDrawLine (Xdisplay,
1062 W->win, X_rvgc,
1063 ctr_x,
1064 ctr_y,
1065 pHandsOld->s_x, pHandsOld->s_y);
1066 }
1067
1068 if (full_redraw || memcmp (pHandsOld, &HandsNow, sizeof(hands_t)))
1069 {
1070 int i, j;
1071 /*
1072 * draw new hands
1073 */
1074 for (i = -1; i < 2; i++) for (j = -1; j < 2; j++)
1075 {
1076 /* hour/minute hands */
1077 XDrawLine (Xdisplay, W->win, X_gc,
1078 ctr_x + i,
1079 ctr_y + j,
1080 HandsNow.h_x, HandsNow.h_y);
1081
1082 XDrawLine (Xdisplay, W->win, X_gc,
1083 ctr_x + i,
1084 ctr_y + j,
1085 HandsNow.m_x, HandsNow.m_y);
1086 }
1087 if (clockUpdate == 1) /* seconds hand */
1088 XDrawLine (Xdisplay, W->win, X_gc,
1089 ctr_x,
1090 ctr_y,
1091 HandsNow.s_x, HandsNow.s_y);
1092
1093 *pHandsOld = HandsNow;
1094 }
1095}
1096
1097#ifdef REMINDERS
1098/* 1109/*
1099 * Read a single integer from *pstr, returns default value if it finds "*" 1110 * Read a single integer from *pstr, returns default value if it finds "*"
1100 * DELIM = trailing delimiter to skip 1111 * DELIM = trailing delimiter to skip
1101 */ 1112 */
1102static int 1113static int
1103GetOneNum (char ** pstr, int def) 1114GetOneNum (char **pstr, int def)
1104{ 1115{
1105 int num, hit = 0; 1116 int num, hit = 0;
1106 1117
1107 for (num = 0; isdigit (**pstr); (*pstr)++) 1118 for (num = 0; isdigit (**pstr); (*pstr)++)
1108 { 1119 {
1109 num = num * 10 + (**pstr - '0'); 1120 num = num * 10 + (**pstr - '0');
1110 hit = 1; 1121 hit = 1;
1111 } 1122 }
1112 if (!hit) 1123 if (!hit)
1113 { 1124 {
1114 num = def; 1125 num = def;
1115 while (**pstr == '*') (*pstr)++; 1126 while (**pstr == '*')
1127 (*pstr)++;
1116 } 1128 }
1117 return num; 1129 return num;
1118} 1130}
1119 1131
1120/* 1132/*
1121 * find if TODAY is found in PSTR 1133 * find if TODAY is found in PSTR
1122 */ 1134 */
1123static int 1135static int
1124isToday (char ** pstr, int wday) 1136isToday (char **pstr, int wday)
1125{ 1137{
1126 const char * dayNames = DAY_NAMES; 1138 const char *dayNames = DAY_NAMES;
1127 int rval, today; 1139 int rval, today;
1128 1140
1129 today = dayNames [wday]; 1141 today = dayNames[wday];
1130 /* no day specified is same as wildcard */ 1142 /* no day specified is same as wildcard */
1131 if (!strchr (dayNames, tolower (**pstr))) 1143 if (!strchr (dayNames, tolower (**pstr)))
1132 return 1; 1144 return 1;
1133 1145
1134 for (rval = 0; strchr (dayNames, tolower (**pstr)); (*pstr)++) 1146 for (rval = 0; strchr (dayNames, tolower (**pstr)); (*pstr)++)
1135 { 1147 {
1136 if (today == tolower (**pstr) || **pstr == '*') 1148 if (today == tolower (**pstr) || **pstr == '*')
1137 rval = 1; /* found it */ 1149 rval = 1; /* found it */
1138 } 1150 }
1139 return rval; 1151 return rval;
1140} 1152}
1141 1153
1142static char * 1154static char *
1143trim_string (char * str) 1155trim_string (char *str)
1144{ 1156{
1145 if (str && *str) 1157 if (str && *str)
1146 { 1158 {
1147 int n; 1159 int n;
1160
1148 while (*str && isspace (*str)) str++; 1161 while (*str && isspace (*str))
1162 str++;
1149 1163
1150 n = strlen (str) - 1; 1164 n = strlen (str) - 1;
1151 while (n > 0 && isspace (str [n])) n--; 1165 while (n > 0 && isspace (str[n]))
1166 n--;
1152 str [n+1] = '\0'; 1167 str[n + 1] = '\0';
1153 } 1168 }
1154 return str; 1169 return str;
1155} 1170}
1156 1171
1157# ifndef NO_REMINDER_EXEC 1172# ifndef NO_REMINDER_EXEC
1158static char * 1173static char *
1159extract_program (char * text) 1174extract_program (char *text)
1160{ 1175{
1161 char * prgm = text; 1176 char *prgm = text;
1177
1162 while ((prgm = strchr (prgm, ';')) != NULL) 1178 while ((prgm = strchr (prgm, ';')) != NULL)
1163 { 1179 {
1164 if (*(prgm-1) == '\\') /* backslash escaped */ 1180 if (*(prgm - 1) == '\\') /* backslash escaped */
1165 { 1181 {
1166 /* remove backslash - avoid memmove() */ 1182 /* remove backslash - avoid memmove() */
1167 int i, n = strlen (prgm); 1183 int i, n = strlen (prgm);
1184
1168 for (i = 0; i <= n; i++) 1185 for (i = 0; i <= n; i++)
1169 prgm [i - 1] = prgm [i]; 1186 prgm[i - 1] = prgm[i];
1170 } 1187 }
1171 else 1188 else
1172 { 1189 {
1173 *prgm++ = '\0'; 1190 *prgm++ = '\0';
1174 /* remove leading/trailing space */ 1191 /* remove leading/trailing space */
1175 prgm = trim_string (prgm); 1192 prgm = trim_string (prgm);
1176 break; 1193 break;
1177 } 1194 }
1178 } 1195 }
1179 return prgm; 1196 return prgm;
1180} 1197}
1181# endif /* NO_REMINDER_EXEC */ 1198# endif /* NO_REMINDER_EXEC */
1182 1199
1183/* 1200/*
1184 * Read the ~/.rclock file and find the next reminder 1201 * Read the ~/.rclock file and find the next reminder
1185 * 1202 *
1186 * update_only = 1 1203 * update_only = 1
1192 * just went off 1209 * just went off
1193 */ 1210 */
1194static void 1211static void
1195Next_Reminder (int update_only) 1212Next_Reminder (int update_only)
1196{ 1213{
1197 struct tm * tmval; 1214 struct tm *tmval;
1198 char buffer [256]; 1215 char buffer[256];
1216
1199#ifndef INT_MAX 1217# ifndef INT_MAX
1200# define INT_MAX 1e8 1218# define INT_MAX 1e8
1201#endif 1219# endif
1202 time_t currentTime; 1220 time_t currentTime;
1203 int savedTime = INT_MAX; 1221 int savedTime = INT_MAX;
1204 FILE * fd; 1222 FILE *fd;
1205 1223
1206 if (reminders_file == NULL || (fd = fopen (reminders_file, "r")) == NULL) 1224 if (reminders_file == NULL || (fd = fopen (reminders_file, "r")) == NULL)
1207 { 1225 {
1208 reminderTime = -1; /* no config file, no reminders */ 1226 reminderTime = -1; /* no config file, no reminders */
1209 return; 1227 return;
1210 } 1228 }
1211 1229
1212 currentTime = time (NULL) + adjustTime; /* get the current time */ 1230 currentTime = time (NULL) + adjustTime; /* get the current time */
1213 tmval = localtime (&currentTime); 1231 tmval = localtime (&currentTime);
1214 currentTime = mk_time (tmval); 1232 currentTime = mk_time (tmval);
1215 1233
1216 /* initial startup*/ 1234 /* initial startup */
1217 if (reminderTime < 0) 1235 if (reminderTime < 0)
1218 { 1236 {
1219 /* ignore reminders that have already occurred */ 1237 /* ignore reminders that have already occurred */
1220 reminderTime = currentTime; 1238 reminderTime = currentTime;
1221# ifndef NO_REMINDER_EXEC 1239# ifndef NO_REMINDER_EXEC
1222 /* scan for programs run on start-up */ 1240 /* scan for programs run on start-up */
1223 while (fgets (buffer, sizeof(buffer), fd)) 1241 while (fgets (buffer, sizeof (buffer), fd))
1224 { 1242 {
1225 char * prgm, * text; 1243 char *prgm, *text;
1226 1244
1227 text = trim_string (buffer); 1245 text = trim_string (buffer);
1228 if (*text != ';') continue; 1246 if (*text != ';')
1247 continue;
1229 1248
1230 prgm = extract_program (text); 1249 prgm = extract_program (text);
1231 if (prgm != NULL && strlen (prgm) > 1) 1250 if (prgm != NULL && strlen (prgm) > 1)
1232 system (prgm); 1251 system (prgm);
1233 } 1252 }
1234 rewind (fd); 1253 rewind (fd);
1235# endif /* NO_REMINDER_EXEC */ 1254# endif /* NO_REMINDER_EXEC */
1236 } 1255 }
1237 1256
1238 /* now scan for next reminder */ 1257 /* now scan for next reminder */
1239 while (fgets (buffer, sizeof(buffer), fd)) 1258 while (fgets (buffer, sizeof (buffer), fd))
1240 { 1259 {
1241 int testTime, hh, mm, mo, dd, yy; 1260 int testTime, hh, mm, mo, dd, yy;
1242 char * text; 1261 char *text;
1243 1262
1244 text = trim_string (buffer); 1263 text = trim_string (buffer);
1245 if (*text == '#') continue; /* comment */ 1264 if (*text == '#')
1246 if (*text == ';') continue; /* program run on startup */ 1265 continue; /* comment */
1247 /* 1266 if (*text == ';')
1267 continue; /* program run on startup */
1268 /*
1248 * parse the line, format is hh:mm mo/dd/yr message; program 1269 * parse the line, format is hh:mm mo/dd/yr message; program
1249 * any of hh, mm, mo, dd, yr could be a wildcard `*' 1270 * any of hh, mm, mo, dd, yr could be a wildcard `*'
1250 */ 1271 */
1251 hh = GetOneNum (&text, tmval->tm_hour); if (*text == ':') text++; 1272 hh = GetOneNum (&text, tmval->tm_hour);
1273 if (*text == ':')
1274 text++;
1252 mm = GetOneNum (&text, 0); 1275 mm = GetOneNum (&text, 0);
1253 1276
1254 while (isspace (*text)) text++; 1277 while (isspace (*text))
1278 text++;
1255 if (!isToday (&text, tmval->tm_wday)) continue; 1279 if (!isToday (&text, tmval->tm_wday))
1280 continue;
1256 while (isspace (*text)) text++; 1281 while (isspace (*text))
1282 text++;
1257 1283
1258 mo = GetOneNum (&text, tmval->tm_mon+1); if (*text == '/') text++; 1284 mo = GetOneNum (&text, tmval->tm_mon + 1);
1259 dd = GetOneNum (&text, tmval->tm_mday); if (*text == '/') text++; 1285 if (*text == '/')
1286 text++;
1287 dd = GetOneNum (&text, tmval->tm_mday);
1288 if (*text == '/')
1289 text++;
1260 yy = GetOneNum (&text, tmval->tm_year); 1290 yy = GetOneNum (&text, tmval->tm_year);
1261 1291
1262 /* handle 20th/21st centuries */ 1292 /* handle 20th/21st centuries */
1263 if (yy > CENTURY) 1293 if (yy > CENTURY)
1264 yy -= 1900; 1294 yy -= 1900;
1265 else if (yy < CENTURY) 1295 else if (yy < CENTURY)
1266 yy += (CENTURY - 1900); 1296 yy += (CENTURY - 1900);
1267 1297
1268 while (isspace (*text)) text++; 1298 while (isspace (*text))
1269 if (!*text) continue; 1299 text++;
1300 if (!*text)
1301 continue;
1270 1302
1271 testTime = (mm + 60 * (hh + 24 * (dd + 31 * (mo + 12 * yy)))); 1303 testTime = (mm + 60 * (hh + 24 * (dd + 31 * (mo + 12 * yy))));
1272 1304
1273 if (testTime > (update_only ? currentTime : reminderTime)) 1305 if (testTime > (update_only ? currentTime : reminderTime))
1274 { 1306 {
1275#ifndef NO_REMINDER_EXEC 1307# ifndef NO_REMINDER_EXEC
1276 char * prgm = extract_program (text); 1308 char *prgm = extract_program (text);
1277#endif /* NO_REMINDER_EXEC */ 1309# endif/* NO_REMINDER_EXEC */
1278 /* trim leading/trailing space */ 1310 /* trim leading/trailing space */
1279 text = trim_string (text); 1311 text = trim_string (text);
1280 1312
1281 /* 1313 /*
1282 * have a reminder whose time is greater than the last 1314 * have a reminder whose time is greater than the last
1283 * reminder, now make sure it is the smallest available 1315 * reminder, now make sure it is the smallest available
1284 */ 1316 */
1285 if (testTime < savedTime) 1317 if (testTime < savedTime)
1286 { 1318 {
1287 savedTime = testTime; 1319 savedTime = testTime;
1288 strncpy (message, text, sizeof(message)); 1320 strncpy (message, text, sizeof (message));
1289#ifndef NO_REMINDER_EXEC 1321# ifndef NO_REMINDER_EXEC
1290 strncpy (execPrgm, (prgm ? prgm : ""), sizeof(execPrgm)); 1322 strncpy (execPrgm, (prgm ? prgm : ""), sizeof (execPrgm));
1291#endif 1323# endif
1292 } 1324 }
1293 else if (testTime == savedTime) 1325 else if (testTime == savedTime)
1294 { 1326 {
1295 if (strlen (text)) 1327 if (strlen (text))
1296 { 1328 {
1297 int n = (sizeof(message) - strlen (message) - 3); 1329 int n = (sizeof (message) - strlen (message) - 3);
1298 if (n > 0) 1330
1299 { 1331 if (n > 0)
1332 {
1300 /* for co-occurring events */ 1333 /* for co-occurring events */
1301 strcat (message, "\\n"); 1334 strcat (message, "\\n");
1302 strncat (message, text, n); 1335 strncat (message, text, n);
1303 } 1336 }
1304 } 1337 }
1305#ifndef NO_REMINDER_EXEC 1338# ifndef NO_REMINDER_EXEC
1306 if (prgm != NULL) 1339 if (prgm != NULL)
1307 { 1340 {
1308 int n = (sizeof(execPrgm) - strlen (execPrgm) - 2); 1341 int n = (sizeof (execPrgm) - strlen (execPrgm) - 2);
1342
1309 if ((n > 0) && (n >= strlen (prgm))) 1343 if ((n > 0) && (n >= strlen (prgm)))
1310 { 1344 {
1311 /* for co-occurring programs */ 1345 /* for co-occurring programs */
1312 switch (execPrgm[strlen (execPrgm)-1]) 1346 switch (execPrgm[strlen (execPrgm) - 1])
1313 { 1347 {
1314 case '&': 1348 case '&':
1315 case ';': 1349 case ';':
1316 break; 1350 break;
1317 default: 1351 default:
1318 strcat (execPrgm, ";"); 1352 strcat (execPrgm, ";");
1319 break; 1353 break;
1320 } 1354 }
1321 strncat (execPrgm, prgm, n); 1355 strncat (execPrgm, prgm, n);
1322 } 1356 }
1323 } 1357 }
1324#endif /* NO_REMINDER_EXEC */ 1358# endif/* NO_REMINDER_EXEC */
1359 }
1325 } 1360 }
1326 }
1327 } 1361 }
1328 1362
1329 reminderTime = (savedTime < INT_MAX) ? savedTime : -1; 1363 reminderTime = (savedTime < INT_MAX) ? savedTime : -1;
1330 fclose (fd); 1364 fclose (fd);
1331} 1365}
1332 1366
1333/* 1367/*
1334 * Provide reminder by mapping the message window 1368 * Provide reminder by mapping the message window
1335 */ 1369 */
1336static void 1370static void
1337Reminder (void) 1371Reminder ()
1338{ 1372{
1339 char * beg, * next; 1373 char *beg, *next;
1340 int lines; 1374 int lines;
1341 1375
1342 if (Msg_Mapped) 1376 if (Msg_Mapped)
1343 return; 1377 return;
1344 1378
1345#ifndef NO_REMINDER_EXEC 1379# ifndef NO_REMINDER_EXEC
1346 if (strlen (message) == 0) 1380 if (strlen (message) == 0)
1347 { 1381 {
1348 if (strlen (execPrgm) > 1) 1382 if (strlen (execPrgm) > 1)
1349 { 1383 {
1350 system (execPrgm); 1384 system (execPrgm);
1351 Next_Reminder (REPLACE); 1385 Next_Reminder (REPLACE);
1352 } 1386 }
1353 return; /* some sort of error */ 1387 return; /* some sort of error */
1354 } 1388 }
1355#endif 1389# endif
1356 1390
1357 /* compute the window size */ 1391 /* compute the window size */
1358#ifdef NO_REMINDER_EXEC 1392# ifdef NO_REMINDER_EXEC
1359 Msg.width = 10 * XTextWidth (Xfont, "M", 1); 1393 Msg.width = 10 * XTextWidth (Xfont, "M", 1);
1360#else 1394# else
1361 Msg.width = 18 * XTextWidth (Xfont, "M", 1); 1395 Msg.width = 18 * XTextWidth (Xfont, "M", 1);
1362#endif 1396# endif
1363 1397
1364 for (beg = message, lines = 1; beg; beg = next, lines++) 1398 for (beg = message, lines = 1; beg; beg = next, lines++)
1365 { 1399 {
1366 int width; 1400 int width;
1367 char * end; 1401 char *end;
1368 1402
1369 if ((end = strstr (beg, "\\n")) == NULL) 1403 if ((end = strstr (beg, "\\n")) == NULL)
1370 { 1404 {
1371 end = beg + strlen (beg); 1405 end = beg + strlen (beg);
1372 next = NULL; 1406 next = NULL;
1373 } 1407 }
1374 else 1408 else
1375 { 1409 {
1376 next = end + 2; 1410 next = end + 2;
1377 } 1411 }
1378 1412
1379 width = XTextWidth (Xfont, beg, (end-beg)); 1413 width = XTextWidth (Xfont, beg, (end - beg));
1380 if (Msg.width < width) 1414 if (Msg.width < width)
1381 Msg.width = width; 1415 Msg.width = width;
1382 } 1416 }
1383 1417
1384 Msg.width += 30; 1418 Msg.width += 30;
1385 Msg.height = (lines+1) * FontHeight () + 30; 1419 Msg.height = (lines + 1) * FontHeight () + 30;
1386 1420
1387 /* resize and centre the window */ 1421 /* resize and centre the window */
1388 XMoveResizeWindow (Xdisplay, Msg.win, 1422 XMoveResizeWindow (Xdisplay, Msg.win,
1389 (DisplayWidth (Xdisplay, Xscreen) - Msg.width ) / 2, 1423 (DisplayWidth (Xdisplay, Xscreen) - Msg.width) / 2,
1390 (DisplayHeight (Xdisplay, Xscreen) - Msg.height) / 2, 1424 (DisplayHeight (Xdisplay, Xscreen) - Msg.height) / 2, Msg.width, Msg.height);
1391 Msg.width, Msg.height);
1392 1425
1393#define BUTTON_MARGIN 8 1426# define BUTTON_MARGIN 8
1394 1427
1395 XMoveWindow (Xdisplay, msgButton.Dismiss, 1428 XMoveWindow (Xdisplay, msgButton.Dismiss, BUTTON_MARGIN, (Msg.height - msgButton.height - BUTTON_MARGIN));
1396 BUTTON_MARGIN, 1429 XMoveWindow (Xdisplay, msgButton.Defer, (Msg.width - msgButton.width - BUTTON_MARGIN), (Msg.height - msgButton.height - BUTTON_MARGIN));
1397 (Msg.height - msgButton.height - BUTTON_MARGIN));
1398 XMoveWindow (Xdisplay, msgButton.Defer,
1399 (Msg.width - msgButton.width - BUTTON_MARGIN),
1400 (Msg.height - msgButton.height - BUTTON_MARGIN));
1401#ifndef NO_REMINDER_EXEC 1430# ifndef NO_REMINDER_EXEC
1402 XMoveWindow (Xdisplay, msgButton.Start, 1431 XMoveWindow (Xdisplay, msgButton.Start, (Msg.width - msgButton.width) / 2, (Msg.height - msgButton.height - BUTTON_MARGIN));
1403 (Msg.width - msgButton.width) / 2,
1404 (Msg.height - msgButton.height - BUTTON_MARGIN));
1405#endif 1432# endif
1406 1433
1407 XMapRaised (Xdisplay, Msg.win); 1434 XMapRaised (Xdisplay, Msg.win);
1408 XBell (Xdisplay, 0); 1435 XBell (Xdisplay, 0);
1409 Msg_Mapped = 1; 1436 Msg_Mapped = 1;
1410} 1437}
1411#endif /* REMINDERS */ 1438#endif /* REMINDERS */
1412
1413#ifndef _POSIX_VERSION
1414# if defined (__svr4__)
1415static int
1416getdtablesize (void)
1417{
1418 struct rlimit rlim;
1419 getrlimit (RLIMIT_NOFILE, &rlim);
1420 return rlim.rlim_cur;
1421}
1422# endif
1423#endif
1424 1439
1425/* 1440/*
1426 * Loops forever, looking for stuff to do. Sleeps 1 minute if nothing to do 1441 * Loops forever, looking for stuff to do. Sleeps 1 minute if nothing to do
1427 */ 1442 */
1428static void 1443static void
1429getXevent (void) 1444getXevent ()
1430{ 1445{
1431 XEvent ev; 1446 XEvent ev;
1432 int num_fds; /* number of file descriptors being used */ 1447 int num_fds; /* number of file descriptors being used */
1433 struct timeval tm; 1448 struct timeval tm;
1434 struct tm * tmval; 1449 struct tm *tmval;
1435 Atom wmDeleteWindow; 1450 Atom wmDeleteWindow;
1436 fd_set in_fdset; 1451 fd_set in_fdset;
1437 1452
1438 /* Enable delete window protocol */ 1453 /* Enable delete window protocol */
1439 wmDeleteWindow = XInternAtom (Xdisplay, "WM_DELETE_WINDOW", False); 1454 wmDeleteWindow = XInternAtom (Xdisplay, "WM_DELETE_WINDOW", False);
1440 XSetWMProtocols (Xdisplay, Clock.win, &wmDeleteWindow, 1); 1455 XSetWMProtocols (Xdisplay, Clock.win, &wmDeleteWindow, 1);
1441#ifdef ICONWIN 1456#ifdef ICONWIN
1442 XSetWMProtocols (Xdisplay, Icon.win, &wmDeleteWindow, 1); 1457 XSetWMProtocols (Xdisplay, Icon.win, &wmDeleteWindow, 1);
1443#endif 1458#endif
1444#ifdef REMINDERS 1459#ifdef REMINDERS
1445 XSetWMProtocols (Xdisplay, Msg.win, &wmDeleteWindow, 1); 1460 XSetWMProtocols (Xdisplay, Msg.win, &wmDeleteWindow, 1);
1446#endif 1461#endif
1447 1462
1448#ifdef _POSIX_VERSION
1449 num_fds = sysconf (_SC_OPEN_MAX); 1463 num_fds = sysconf (_SC_OPEN_MAX);
1450#else
1451 num_fds = getdtablesize ();
1452#endif
1453#ifdef FD_SETSIZE 1464#ifdef FD_SETSIZE
1454 if (num_fds > FD_SETSIZE) 1465 if (num_fds > FD_SETSIZE)
1455 num_fds = FD_SETSIZE; 1466 num_fds = FD_SETSIZE;
1456#endif 1467#endif
1457 1468
1458 while (1) { 1469 while (1)
1470 {
1459 /* take care of all pending X events */ 1471 /* take care of all pending X events */
1460 while (XPending (Xdisplay)) { 1472 while (XPending (Xdisplay))
1473 {
1461 XNextEvent (Xdisplay, &ev); 1474 XNextEvent (Xdisplay, &ev);
1462 switch (ev.type) { 1475 switch (ev.type)
1476 {
1463 case ClientMessage: 1477 case ClientMessage:
1464 /* check for delete window requests */ 1478 /* check for delete window requests */
1465 if ((ev.xclient.format == 32) && 1479 if ((ev.xclient.format == 32) && (ev.xclient.data.l[0] == (long)wmDeleteWindow))
1466 (ev.xclient.data.l[0] == wmDeleteWindow)) 1480 {
1467 {
1468#ifdef REMINDERS 1481#ifdef REMINDERS
1469 if (ev.xany.window == Msg.win) 1482 if (ev.xany.window == Msg.win)
1470 { 1483 {
1471 XUnmapWindow (Xdisplay, Msg.win); 1484 XUnmapWindow (Xdisplay, Msg.win);
1472 Msg_Mapped = 0; 1485 Msg_Mapped = 0;
1473 Next_Reminder (REPLACE); 1486 Next_Reminder (REPLACE);
1474 } 1487 }
1475 else 1488 else
1476#endif 1489#endif
1477 return; /* delete window is how this terminates */ 1490 return; /* delete window is how this terminates */
1478 } 1491 }
1479 break; 1492 break;
1480 1493
1481 case Expose: 1494 case Expose:
1482 case GraphicsExpose: 1495 case GraphicsExpose:
1483 /* need to re-draw a window */ 1496 /* need to re-draw a window */
1484 if (ev.xany.window == Clock.win) 1497 if (ev.xany.window == Clock.win)
1485 Draw_Window (&Clock, 1); 1498 Draw_Window (&Clock, 1);
1486#ifdef ICONWIN 1499#ifdef ICONWIN
1487 else if (ev.xany.window == Icon.win) 1500 else if (ev.xany.window == Icon.win)
1488 Draw_Window (&Icon, 1); 1501 Draw_Window (&Icon, 1);
1489#endif 1502#endif
1490#ifdef REMINDERS 1503#ifdef REMINDERS
1491 else 1504 else
1492 Draw_Window (&Msg, 1); 1505 Draw_Window (&Msg, 1);
1493#endif 1506#endif
1494 break; 1507 break;
1495 1508
1496 case ConfigureNotify: 1509 case ConfigureNotify:
1497 /* window has been re-sized */ 1510 /* window has been re-sized */
1498 if (ev.xany.window == Clock.win) 1511 if (ev.xany.window == Clock.win)
1499 { 1512 {
1500 Clock.width = ev.xconfigure.width; 1513 Clock.width = ev.xconfigure.width;
1501 Clock.height = ev.xconfigure.height; 1514 Clock.height = ev.xconfigure.height;
1502 } 1515 }
1503 break; 1516 break;
1504 1517
1505#ifdef REMINDERS 1518#ifdef REMINDERS
1506 case KeyPress: 1519 case KeyPress:
1507 /* any key press to dismiss message window */ 1520 /* any key press to dismiss message window */
1508 if (ev.xany.window == Msg.win) 1521 if (ev.xany.window == Msg.win)
1509 { 1522 {
1510 Next_Reminder (REPLACE); 1523 Next_Reminder (REPLACE);
1511 Msg_Mapped = 0; 1524 Msg_Mapped = 0;
1512 XUnmapWindow (Xdisplay, Msg.win); 1525 XUnmapWindow (Xdisplay, Msg.win);
1513 } 1526 }
1514 break; 1527 break;
1515#endif 1528#endif
1516 1529
1517 case ButtonPress: 1530 case ButtonPress:
1518#ifdef REMINDERS 1531#ifdef REMINDERS
1519 /* button press to dismiss message window */ 1532 /* button press to dismiss message window */
1520 if (ev.xany.window == Msg.win) 1533 if (ev.xany.window == Msg.win)
1521 {
1522 if (ev.xbutton.subwindow == msgButton.Dismiss)
1523 {
1524 Next_Reminder (REPLACE);
1525 Msg_Mapped = 0;
1526 XUnmapWindow (Xdisplay, Msg.win);
1527 }
1528 else if (ev.xbutton.subwindow == msgButton.Defer)
1529 {
1530 time_t t = time (NULL) + adjustTime;
1531 tmval = localtime (&t);
1532 reminderTime = mk_time (tmval) + DEFER_TIME;
1533 Msg_Mapped = 0;
1534 XUnmapWindow (Xdisplay, Msg.win);
1535 }
1536#ifndef NO_REMINDER_EXEC
1537 else if (ev.xbutton.subwindow == msgButton.Start)
1538 { 1534 {
1539 system (execPrgm); 1535 if (ev.xbutton.subwindow == msgButton.Dismiss)
1536 {
1540 Next_Reminder (REPLACE); 1537 Next_Reminder (REPLACE);
1541 Msg_Mapped = 0; 1538 Msg_Mapped = 0;
1542 XUnmapWindow (Xdisplay, Msg.win); 1539 XUnmapWindow (Xdisplay, Msg.win);
1540 }
1541 else if (ev.xbutton.subwindow == msgButton.Defer)
1542 {
1543 time_t t = time (NULL) + adjustTime;
1544
1545 tmval = localtime (&t);
1546 reminderTime = mk_time (tmval) + DEFER_TIME;
1547 Msg_Mapped = 0;
1548 XUnmapWindow (Xdisplay, Msg.win);
1549 }
1550# ifndef NO_REMINDER_EXEC
1551 else if (ev.xbutton.subwindow == msgButton.Start)
1552 {
1553 system (execPrgm);
1554 Next_Reminder (REPLACE);
1555 Msg_Mapped = 0;
1556 XUnmapWindow (Xdisplay, Msg.win);
1557 }
1558# endif/* NO_REMINDER_EXEC */
1543 } 1559 }
1544#endif /* NO_REMINDER_EXEC */
1545 }
1546#endif 1560#endif
1547#ifdef MAIL 1561#ifdef MAIL
1548 if (ev.xany.window == Clock.win) 1562 if (ev.xany.window == Clock.win)
1549 { 1563 {
1550#ifdef MAIL_SPAWN 1564# ifdef MAIL_SPAWN
1551 /* left button action - spawn a mail reader */ 1565 /* left button action - spawn a mail reader */
1552 if (ev.xbutton.button == Button1) 1566 if (ev.xbutton.button == Button1)
1553 system (MAIL_SPAWN); 1567 system (MAIL_SPAWN);
1554#else 1568# else
1555 if ( (ev.xbutton.button == Button1) && (mail_spawn != NULL) ) 1569 if ((ev.xbutton.button == Button1) && (mail_spawn != NULL))
1556 system(mail_spawn); 1570 system (mail_spawn);
1557#endif 1571# endif
1558 /* redraw the window */ 1572 /* redraw the window */
1559 Draw_Window (&Clock, 1); 1573 Draw_Window (&Clock, 1);
1560 } 1574 }
1561#endif 1575#endif
1562 break; 1576 break;
1563 } 1577 }
1564 } 1578 }
1565 1579
1566 /* Now wait for time out or new X event */ 1580 /* Now wait for time out or new X event */
1567 FD_ZERO (&in_fdset); 1581 FD_ZERO (&in_fdset);
1568 FD_SET (Xfd, &in_fdset); 1582 FD_SET (Xfd, &in_fdset);
1569 tm.tv_sec = clockUpdate; 1583 tm.tv_sec = clockUpdate;
1572 1586
1573 Draw_Window (&Clock, 0); 1587 Draw_Window (&Clock, 0);
1574#ifdef ICONWIN 1588#ifdef ICONWIN
1575 Draw_Window (&Icon, 0); 1589 Draw_Window (&Icon, 0);
1576#endif 1590#endif
1577 } 1591 }
1578} 1592}
1579 1593
1580/* 1594/*
1581 * Print an error message. 1595 * Print an error message.
1582 */ 1596 */
1583static void 1597static void
1584print_error (const char * fmt, ...) 1598print_error (const char *fmt, ...)
1585{ 1599{
1586 va_list arg_ptr; 1600 va_list arg_ptr;
1587 1601
1588 va_start (arg_ptr, fmt); 1602 va_start (arg_ptr, fmt);
1589 fprintf (stderr, APL_NAME ": "); 1603 fprintf (stderr, APL_NAME ": ");
1590 vfprintf (stderr, fmt, arg_ptr); 1604 vfprintf (stderr, fmt, arg_ptr);
1591 fprintf (stderr,"\n"); 1605 fprintf (stderr, "\n");
1592 va_end (arg_ptr); 1606 va_end (arg_ptr);
1593} 1607}
1608
1594/*----------------------- end-of-file (C source) -----------------------*/ 1609/*----------------------- end-of-file (C source) -----------------------*/

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines