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