Lines 1-18
Link Here
|
1 |
--- Dclock.c.orig Sat Dec 17 23:46:28 2005 |
1 |
--- Dclock.c.orig 2008-07-08 13:00:35.000000000 +0900 |
2 |
+++ Dclock.c Sat Dec 17 23:47:28 2005 |
2 |
+++ Dclock.c 2012-10-08 00:49:08.000000000 +0900 |
3 |
@@ -9,9 +9,9 @@ |
3 |
@@ -8,10 +8,10 @@ |
4 |
#include <stdio.h> |
4 |
#include <stdlib.h> |
5 |
#include <unistd.h> |
5 |
#include <unistd.h> |
6 |
#include <string.h> |
6 |
#include <string.h> |
7 |
-#include <values.h> |
7 |
-#include <values.h> |
8 |
+#include <limits.h> |
8 |
+#include <limits.h> |
|
|
9 |
#include <math.h> |
9 |
#include <time.h> |
10 |
#include <time.h> |
10 |
-#include <wait.h> |
11 |
-#include <wait.h> |
11 |
+#include <sys/wait.h> |
12 |
+#include <sys/wait.h> |
12 |
#include <errno.h> |
13 |
#include <errno.h> |
13 |
#include <X11/IntrinsicP.h> |
14 |
#include <X11/IntrinsicP.h> |
14 |
#include <X11/Xos.h> |
15 |
#include <X11/Xos.h> |
15 |
@@ -171,7 +171,7 @@ |
16 |
@@ -66,7 +66,7 @@ |
|
|
17 |
static int old_digs[4]; |
18 |
static struct tm before; |
19 |
static char *saved_date; |
20 |
-static cur_position; /* outline current digit for setting alarm */ |
21 |
+static int cur_position; /* outline current digit for setting alarm */ |
22 |
static struct { int hrs, mins; } Alarm; |
23 |
static int TopOffset = 0; |
24 |
|
25 |
@@ -165,7 +165,7 @@ |
26 |
XtOffset(DclockWidget,dclock.font), XtRString, "fixed"}, |
27 |
#ifdef XFT_SUPPORT |
28 |
{ XftNfontName, "fontName", XtRString, sizeof(String), |
29 |
- XtOffset(DclockWidget,dclock.xftfontname), XtRString, "charter"}, |
30 |
+ XtOffset(DclockWidget,dclock.xftfontname), XtRString, NULL}, |
31 |
#endif |
32 |
{ XtNangle, "Slope", XtRFloat, sizeof(float), |
33 |
XtOffset(DclockWidget,dclock.angle), XtRFloat, (caddr_t)&sslope}, |
34 |
@@ -182,7 +182,7 @@ |
16 |
{ XtNbellFile, "bellFile", XtRString, sizeof(String), |
35 |
{ XtNbellFile, "bellFile", XtRString, sizeof(String), |
17 |
XtOffset(DclockWidget,dclock.bellfile), XtRString, (String)NULL}, |
36 |
XtOffset(DclockWidget,dclock.bellfile), XtRString, (String)NULL}, |
18 |
{ XtNaudioPlay, "audioPlay", XtRString, sizeof(String), |
37 |
{ XtNaudioPlay, "audioPlay", XtRString, sizeof(String), |
Lines 21-23
Link Here
|
21 |
}; |
40 |
}; |
22 |
|
41 |
|
23 |
/* Define the Dclock widget */ |
42 |
/* Define the Dclock widget */ |
|
|
43 |
@@ -235,7 +235,7 @@ |
44 |
* These stipples give different densities for the |
45 |
* different stages of fading. |
46 |
*/ |
47 |
-static unsigned char stpl_1_8th[] = |
48 |
+static char stpl_1_8th[] = |
49 |
{ |
50 |
0x80, 0x80, 0x08, 0x08, 0x80, 0x80, 0x08, 0x08, |
51 |
0x80, 0x80, 0x08, 0x08, 0x80, 0x80, 0x08, 0x08, |
52 |
@@ -243,7 +243,7 @@ |
53 |
0x80, 0x80, 0x08, 0x08, 0x80, 0x80, 0x08, 0x08 |
54 |
}; |
55 |
|
56 |
-static unsigned char stpl_1_4th[] = |
57 |
+static char stpl_1_4th[] = |
58 |
{ |
59 |
0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22, |
60 |
0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22, |
61 |
@@ -251,7 +251,7 @@ |
62 |
0x88, 0x88, 0x22, 0x22, 0x88, 0x88, 0x22, 0x22 |
63 |
}; |
64 |
|
65 |
-static unsigned char stpl_3_8ths[] = |
66 |
+static char stpl_3_8ths[] = |
67 |
{ |
68 |
0xA2, 0xA2, 0x15, 0x15, 0xA8, 0xA8, 0x45, 0x45, |
69 |
0x2A, 0x2A, 0x51, 0x51, 0x8A, 0x8A, 0x54, 0x54, |
70 |
@@ -259,7 +259,7 @@ |
71 |
0x2A, 0x2A, 0x51, 0x51, 0x8A, 0x8A, 0x54, 0x54 |
72 |
}; |
73 |
|
74 |
-static unsigned char stpl_one_half[] = |
75 |
+static char stpl_one_half[] = |
76 |
{ |
77 |
0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, |
78 |
0x55, 0x55, 0xAA, 0xAA, 0x55, 0x55, 0xAA, 0xAA, |
79 |
@@ -344,6 +344,12 @@ |
80 |
segment_pts tiny_segment_pts; |
81 |
segment_pts norm_segment_pts; |
82 |
|
83 |
+#ifdef XFT_SUPPORT |
84 |
+#define XFT_COND(dclock) ((dclock).xftfontname) |
85 |
+#else |
86 |
+#define XFT_COND(dclock) (0) |
87 |
+#endif |
88 |
+ |
89 |
/* ARGSUSED */ |
90 |
static void |
91 |
Initialize (request, new) |
92 |
@@ -386,11 +392,13 @@ |
93 |
if (new->dclock.sec_gap < 0.0) new->dclock.sec_gap = 0.0; |
94 |
|
95 |
#ifdef XFT_SUPPORT |
96 |
- new->dclock.xftfont = XftFontOpen(dpy, DefaultScreen(dpy), |
97 |
+ if (XFT_COND(new->dclock)) { |
98 |
+ new->dclock.xftfont = XftFontOpen(dpy, DefaultScreen(dpy), |
99 |
XFT_FAMILY, XftTypeString, new->dclock.xftfontname, |
100 |
XFT_SIZE, XftTypeDouble, ((float)new->core.height / 6.0) - 4.0, |
101 |
NULL); |
102 |
- new->dclock.xftdraw = NULL; |
103 |
+ new->dclock.xftdraw = NULL; |
104 |
+ } |
105 |
#endif |
106 |
|
107 |
GetGC(new); |
108 |
@@ -447,11 +455,11 @@ |
109 |
if (new->dclock.date_fmt && !*new->dclock.date_fmt) |
110 |
new->dclock.date_fmt = NULL; |
111 |
if (new->dclock.dateup && new->dclock.date_fmt) |
112 |
-#ifdef XFT_SUPPORT |
113 |
+ if (XFT_COND(new->dclock)) { |
114 |
TopOffset = new->core.height / 6; |
115 |
-#else |
116 |
+ } else { |
117 |
TopOffset = new->dclock.font->ascent + new->dclock.font->descent; |
118 |
-#endif |
119 |
+ } |
120 |
|
121 |
else |
122 |
TopOffset = 0; |
123 |
@@ -493,7 +501,7 @@ |
124 |
|
125 |
static void |
126 |
invert_bitmap(bm, h, w) |
127 |
-unsigned char *bm; |
128 |
+char *bm; |
129 |
int h, w; |
130 |
{ |
131 |
int i, *wp; |
132 |
@@ -519,7 +527,7 @@ |
133 |
XtCreateWindow(w, InputOutput, (Visual *)CopyFromParent, *valueMask, attrs); |
134 |
|
135 |
#ifdef XFT_SUPPORT |
136 |
- if (dw->dclock.xftdraw == NULL) { |
137 |
+ if (XFT_COND(dw->dclock) && dw->dclock.xftdraw == NULL) { |
138 |
XColor color; |
139 |
Colormap cm = DefaultColormap(dp, sc); |
140 |
|
141 |
@@ -574,7 +582,8 @@ |
142 |
XDestroyRegion(clip_colon); |
143 |
|
144 |
#ifdef XFT_SUPPORT |
145 |
- XftFontClose(XtDisplay(w), w->dclock.xftfont); |
146 |
+ if (XFT_COND(w->dclock)) |
147 |
+ XftFontClose(XtDisplay(w), w->dclock.xftfont); |
148 |
#endif |
149 |
} |
150 |
|
151 |
@@ -596,11 +605,13 @@ |
152 |
winheight = w->core.height; |
153 |
|
154 |
#ifdef XFT_SUPPORT |
155 |
- XftFontClose(dpy, w->dclock.xftfont); |
156 |
- w->dclock.xftfont = XftFontOpen(dpy, DefaultScreen(dpy), |
157 |
+ if(XFT_COND(w->dclock)) { |
158 |
+ XftFontClose(dpy, w->dclock.xftfont); |
159 |
+ w->dclock.xftfont = XftFontOpen(dpy, DefaultScreen(dpy), |
160 |
XFT_FAMILY, XftTypeString, w->dclock.xftfontname, |
161 |
XFT_SIZE, XftTypeDouble, ((float)winheight / 6.0) - 4.0, |
162 |
NULL); |
163 |
+ } |
164 |
#endif |
165 |
|
166 |
y_ratio = (float)winheight / CLOCK_HEIGHT; |
167 |
@@ -608,11 +619,13 @@ |
168 |
if (w->dclock.date_fmt || !w->dclock.display_time || w->dclock.alarm || |
169 |
w->dclock.bell) |
170 |
/* make win temporarily shorter so digits will fit on top of date */ |
171 |
-#ifdef XFT_SUPPORT |
172 |
- winheight -= w->core.height / 6; |
173 |
-#else |
174 |
- winheight -= w->dclock.font->ascent + w->dclock.font->descent; |
175 |
-#endif |
176 |
+ { |
177 |
+ if(XFT_COND(w->dclock)) { |
178 |
+ winheight -= w->core.height / 6; |
179 |
+ } else { |
180 |
+ winheight -= w->dclock.font->ascent + w->dclock.font->descent; |
181 |
+ } |
182 |
+ } |
183 |
|
184 |
/* |
185 |
* if the width of all segments are equal, then the width in x is the |
186 |
@@ -1351,7 +1364,7 @@ |
187 |
XtAppContext app; |
188 |
Boolean save_scroll = w->dclock.scroll; |
189 |
Boolean save_fade = w->dclock.fade; |
190 |
- long t; |
191 |
+ time_t t; |
192 |
|
193 |
if (!XtIsRealized((Widget)w)) |
194 |
return; |
195 |
@@ -1421,7 +1434,7 @@ |
196 |
{ |
197 |
char buf[11]; |
198 |
Boolean alarm_went_off = False; |
199 |
- long t = time(0); |
200 |
+ time_t t = time(0); |
201 |
register struct tm *l_time = localtime(&t); |
202 |
float digit_w = w->dclock.digit_w; |
203 |
float digit_h = w->dclock.digit_h; |
204 |
@@ -1522,7 +1535,7 @@ |
205 |
Pixmap new_pix[4]; |
206 |
int new_digs[4], digitxpos, digitypos; |
207 |
int cur_sec = 0; |
208 |
- long t; |
209 |
+ time_t t; |
210 |
register struct tm *now; |
211 |
|
212 |
/* definitions for the window x and y positions of each of the large digits. */ |
213 |
@@ -1585,7 +1598,7 @@ |
214 |
unsigned long fade_rate = w->dclock.fade_rate * 1000; |
215 |
|
216 |
for (i = 0; i < 4; i++) /* if pixmaps don't match, fade it */ |
217 |
- if (chgd[i] = (new_pix[i] != old_pix[i])) |
218 |
+ if ((chgd[i] = (new_pix[i] != old_pix[i]))) |
219 |
{ |
220 |
tmp_pix[i] = XCreatePixmap(dpy, win, (int)(digit_w + slope_add), |
221 |
(int)digit_h, DefaultDepthOfScreen(XtScreen(w))); |
222 |
@@ -1669,51 +1682,60 @@ |
223 |
char datestr[128]; |
224 |
register char *p; |
225 |
int x, datep; |
226 |
+ int tsize; |
227 |
#ifdef XFT_SUPPORT |
228 |
- int tsize = w->core.height / 6; |
229 |
XGlyphInfo xftextents; |
230 |
-#else |
231 |
- int tsize = w->dclock.font->ascent + w->dclock.font->descent; |
232 |
#endif |
233 |
|
234 |
+ if (XFT_COND(w->dclock)) { |
235 |
+ tsize = w->core.height / 6; |
236 |
+ } else { |
237 |
+ tsize = w->dclock.font->ascent + w->dclock.font->descent; |
238 |
+ } |
239 |
+ |
240 |
if (!w->dclock.display_time) |
241 |
datep = strlen(strcpy(datestr, "Push HERE to Set/Unset Alarm")); |
242 |
else |
243 |
datep = strftime(datestr, 128, w->dclock.date_fmt, now); |
244 |
|
245 |
+ if (XFT_COND(w->dclock)) { |
246 |
#ifdef XFT_SUPPORT |
247 |
- XftTextExtents8(dpy, w->dclock.xftfont, datestr, datep, &xftextents); |
248 |
- x = (w->core.width - xftextents.width) / 2; |
249 |
-#else |
250 |
- x = (w->core.width - XTextWidth(w->dclock.font, datestr, datep)) / 2; |
251 |
+ XftTextExtents8(dpy, w->dclock.xftfont, (FcChar8*)datestr, datep, &xftextents); |
252 |
+ x = (w->core.width - xftextents.width) / 2; |
253 |
#endif |
254 |
+ } else { |
255 |
+ x = (w->core.width - XTextWidth(w->dclock.font, datestr, datep)) / 2; |
256 |
+ } |
257 |
+ |
258 |
if (x < 2) |
259 |
x = 2; |
260 |
if (TopOffset) { |
261 |
- |
262 |
+ if (XFT_COND(w->dclock)) { |
263 |
#ifdef XFT_SUPPORT |
264 |
- XftDrawRect(w->dclock.xftdraw, &w->dclock.xftbg, 0, 0, winwidth, tsize); |
265 |
- XftDrawString8(w->dclock.xftdraw, &w->dclock.xftfg, w->dclock.xftfont, x, |
266 |
- (BORDER/2) + tsize - 2, datestr, datep); |
267 |
-#else |
268 |
- XFillRectangle(dpy, win, w->dclock.backGC, |
269 |
- 0, 0, winwidth, tsize); |
270 |
- XDrawString(dpy, win, w->dclock.foreGC, |
271 |
- x, ((BORDER/2)+w->dclock.xftfont->height), datestr, datep); |
272 |
+ XftDrawRect(w->dclock.xftdraw, &w->dclock.xftbg, 0, 0, winwidth, tsize); |
273 |
+ XftDrawString8(w->dclock.xftdraw, &w->dclock.xftfg, w->dclock.xftfont, x, |
274 |
+ (BORDER/2) + tsize - 2, (FcChar8*)datestr, datep); |
275 |
#endif |
276 |
+ } else { |
277 |
+ XFillRectangle(dpy, win, w->dclock.backGC, |
278 |
+ 0, 0, winwidth, tsize); |
279 |
+ XDrawString(dpy, win, w->dclock.foreGC, |
280 |
+ x, ((BORDER/2)+tsize), datestr, datep); |
281 |
+ } |
282 |
} else { |
283 |
- |
284 |
+ if (XFT_COND(w->dclock)) { |
285 |
#ifdef XFT_SUPPORT |
286 |
- XftDrawRect(w->dclock.xftdraw, &w->dclock.xftbg, 0, winheight - tsize, |
287 |
+ XftDrawRect(w->dclock.xftdraw, &w->dclock.xftbg, 0, winheight - tsize, |
288 |
winwidth, tsize); |
289 |
- XftDrawString8(w->dclock.xftdraw, &w->dclock.xftfg, w->dclock.xftfont, x, |
290 |
- winheight - BORDER - 2, datestr, datep); |
291 |
-#else |
292 |
- XFillRectangle(dpy, win, w->dclock.backGC, |
293 |
- 0, winheight - tsize, winwidth, tsize); |
294 |
- XDrawString(dpy, win, w->dclock.foreGC, |
295 |
- x, winheight - BORDER, datestr, datep); |
296 |
+ XftDrawString8(w->dclock.xftdraw, &w->dclock.xftfg, w->dclock.xftfont, x, |
297 |
+ winheight - BORDER - 2, (FcChar8*)datestr, datep); |
298 |
#endif |
299 |
+ } else { |
300 |
+ XFillRectangle(dpy, win, w->dclock.backGC, |
301 |
+ 0, winheight - tsize, winwidth, tsize); |
302 |
+ XDrawString(dpy, win, w->dclock.foreGC, |
303 |
+ x, winheight - BORDER, datestr, datep); |
304 |
+ } |
305 |
} |
306 |
} |
307 |
|
308 |
@@ -1992,13 +2014,13 @@ |
309 |
w->dclock.date_fmt = saved_date; |
310 |
saved_date = tmp; |
311 |
|
312 |
- if (w->dclock.dateup && w->dclock.date_fmt) |
313 |
-#ifdef XFT_SUPPORT |
314 |
- TopOffset = w->core.height / 6; |
315 |
-#else |
316 |
- TopOffset = w->dclock.font->ascent + w->dclock.font->descent; |
317 |
-#endif |
318 |
- else |
319 |
+ if (w->dclock.dateup && w->dclock.date_fmt) { |
320 |
+ if (XFT_COND(w->dclock)) { |
321 |
+ TopOffset = w->core.height / 6; |
322 |
+ } else { |
323 |
+ TopOffset = w->dclock.font->ascent + w->dclock.font->descent; |
324 |
+ } |
325 |
+ } else |
326 |
TopOffset = 0; |
327 |
|
328 |
before.tm_wday = -1; |
329 |
@@ -2021,13 +2043,13 @@ |
330 |
XtSetArg(arg, XtNdateUp, !w->dclock.dateup); |
331 |
XtSetValues((Widget)w, &arg, 1); |
332 |
|
333 |
- if (w->dclock.dateup && w->dclock.date_fmt) |
334 |
-#ifdef XFT_SUPPORT |
335 |
- TopOffset = w->core.height / 6; |
336 |
-#else |
337 |
- TopOffset = w->dclock.font->ascent + w->dclock.font->descent; |
338 |
-#endif |
339 |
- else |
340 |
+ if (w->dclock.dateup && w->dclock.date_fmt) { |
341 |
+ if (XFT_COND(w->dclock)) { |
342 |
+ TopOffset = w->core.height / 6; |
343 |
+ } else { |
344 |
+ TopOffset = w->dclock.font->ascent + w->dclock.font->descent; |
345 |
+ } |
346 |
+ } else |
347 |
TopOffset = 0; |
348 |
|
349 |
ResizeNow(w); |
350 |
@@ -2038,7 +2060,7 @@ |
351 |
toggle_bell(w) |
352 |
DclockWidget w; |
353 |
{ |
354 |
- if (w->dclock.bell = !w->dclock.bell) { |
355 |
+ if ((w->dclock.bell = !w->dclock.bell)) { |
356 |
playbell(w, 1); |
357 |
} |
358 |
ResizeNow(w); |
359 |
@@ -2159,7 +2181,7 @@ |
360 |
DclockWidget w; |
361 |
XButtonEvent *event; |
362 |
{ |
363 |
- static saved_secs, saved_miltime, saved_fade, saved_blink; |
364 |
+ static int saved_secs, saved_miltime, saved_fade, saved_blink; |
365 |
|
366 |
if (event->button == 3) { |
367 |
if (!(w->dclock.display_time = !w->dclock.display_time)) { |
368 |
@@ -2184,20 +2206,20 @@ |
369 |
*/ |
370 |
int i, x, y = (int)((BORDER/2)*y_ratio) + TopOffset; |
371 |
/* first check to see if user toggles the alarm */ |
372 |
-#ifdef XFT_SUPPORT |
373 |
- if (TopOffset) |
374 |
+ if (XFT_COND(w->dclock)) { |
375 |
+ if (TopOffset) |
376 |
i = (BORDER + (w->core.height / 6)) |
377 |
- event->y; |
378 |
- else |
379 |
+ else |
380 |
i = event->y - (winheight - (w->core.height / 6)); |
381 |
-#else |
382 |
- if (TopOffset) |
383 |
+ } else { |
384 |
+ if (TopOffset) |
385 |
i = (BORDER + (w->dclock.font->ascent + w->dclock.font->descent)) |
386 |
- event->y; |
387 |
- else |
388 |
+ else |
389 |
i = event->y - (winheight - (w->dclock.font->ascent |
390 |
+ w->dclock.font->descent)); |
391 |
-#endif |
392 |
+ } |
393 |
if (i >= 0) |
394 |
toggle_alarm(w); |
395 |
else for (i = 0; i < 4; i++) { |