Make AddMouseRegion's index unsigned
[dockapps.git] / wmmoonclock / src / wmMoonClock.c
blobdf579e6779676a18b170d477c38083741e0bbf92
1 /*
3 * wmMoonClock-1.26 (C) 1998, 1999 Mike Henderson (mghenderson@lanl.gov)
5 * - Shows Moon Phase....
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program (see the file COPYING); if not, write to the
23 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 * Boston, MA 02110-1301 USA
26 * Things TODO:
27 * - clean up code!
28 * - more detailed documentation.
29 * - reduce size of pixmap! Dont need it in one pixmap.
30 * Aslo, does the hi-color pixmap really need all those colors?
31 * - add rotation of moon so user sees it as they would in reality?
32 * - eclipses. The calcs are quite acurate so this should be easily doable.
33 * (Note the Sun position calcs in CalcEphem are low precision -- high is not
34 * as costly as the Moon calcs.) Sun posiiton is calculated but not used yet...
35 * - Next new moons, next full moons, next quarters, etc...
36 * - Moon names. I.e. Harvest, Blue, etc...
40 * Changes:
41 * Version 1.27 - released June 7, 1999.
42 * fixed a minor bug in computation of azimuth (A in Horizon Coords). Thanks to
43 * Dan Moraru for spotting this one. (There were two SinGlat factors instead of one).
45 * Version 1.26 - released April 22, 1999 (?).
46 * Version 1.25 - released March 22, 1999.
47 * Now auto-detects 8-bit display and forces the LowColor pixmap to
48 * be used. The -low option still works if you need to conserve colors
49 * even on high-color displays.
51 * Added 3 command line options + code to change colors of the data
52 * entries:
54 * -bc <Color> to change background color.
55 * -lc <Color> to change color of labels and headers.
56 * -dc <Color> to change color of data values.
58 * Version 1.24 - released February 9, 1999.
59 * Added low color support via the -low command line option.
61 * Version 1.23 - released February 4, 1999.
62 * cosmetic for AfterStep users. removed spurious black line at RHS edge an mask.
64 * Version 1.22 - released January 8, 1999.
66 * + Changed PI2 to TwoPi in Moon.c -- Linux Pyth. had probs because
67 * PI2 was defined in <math.h>.
69 * Version 1.21 - released January 7, 1999.
71 * + minor bug fixes in Makefile and manpage.
73 * Version 1.2 - released January 3, 1999.
74 * Added:
76 * + Local Time/ Universal Time display.
77 * + Visible: Yes/No to indicate if Moon is up or not.
78 * + Frac (percent through orbit -- this is NOT a simple
79 * conversion of AGE....).
80 * + Horizon Coords. Altitude is measured up from horizon to
81 * Moon in degrees. Azimuth is in degrees from due south.
83 * Also shuffled things around a bit...
87 * Version 1.1 - released December 24, 1998.
88 * Fixed bug in AGE calculation. It now should be highly accurate.
89 * Note that AGE is not the same as Phase*29.530589 ...
90 * I have checked with the Astronomical Almanac and it agrees very
91 * well....
94 * Version 1.0 - released December 16, 1998.
105 * Includes
107 #include <math.h>
108 #include <stdio.h>
109 #include <stdlib.h>
110 #include <string.h>
111 #include <sys/select.h>
112 #include <time.h>
113 #include <X11/X.h>
114 #include <X11/Xlib.h>
115 #include "CalcEphem.h"
116 #include "MoonRise.h"
117 #include "xutils.h"
118 #include "wmMoonClock_master.xpm"
119 #include "wmMoonClock_masterLow.xpm"
120 #include "wmMoonClock_mask.xbm"
125 * Delay between refreshes (in microseconds)
127 #define DELAY 1000000L
129 void ParseCMDLine(int argc, char *argv[]);
130 void pressEvent(XButtonEvent *xev);
131 void print_usage();
134 int ToggleWindow = 0;
135 int nMAX = 1;
136 int Flag = 1;
137 double Glat, Glon, SinGlat, CosGlat, TimeZone;
138 int UseLowColorPixmap = 0;
139 char LabelColor[30] = "#a171ff";
140 char DataColor[30] = "#3dafff";
141 char BackColor[30] = "#010101";
149 * main
151 int main(int argc, char *argv[]) {
157 struct tm *GMTTime, *LocalTime;
158 XEvent event;
159 int i, n, j, ImageNumber, Year, Month, DayOfMonth, digit;
160 long CurrentLocalTime, CurrentGMTTime, date;
161 double UT, val, RA, DEC, UTRise, UTSet, LocalHour, hour24();
162 int D, H, M, S, sgn, A, B, q;
163 CTrans c;
164 struct timeval timeout;
165 fd_set xfdset;
173 * Parse any command line arguments.
175 Glat = Glon = 0.0;
176 ParseCMDLine(argc, argv);
177 c.Glat = Glat, c.Glon = Glon;
178 Glat *= RadPerDeg; SinGlat = sin( Glat ); CosGlat = cos( Glat );
182 initXwindow(argc, argv);
183 if ((DisplayDepth <= 8)||UseLowColorPixmap)
184 openXwindow(argc, argv, wmMoonClock_masterLow, (char *)wmMoonClock_mask_bits, wmMoonClock_mask_width, wmMoonClock_mask_height, BackColor, LabelColor, DataColor);
185 else
186 openXwindow(argc, argv, wmMoonClock_master, (char *)wmMoonClock_mask_bits, wmMoonClock_mask_width, wmMoonClock_mask_height, BackColor, LabelColor, DataColor);
193 * Loop until we die
195 n = 32000;
196 while(1) {
199 if (Flag) {
200 n = 32000;
201 Flag = 0;
208 * The Moon Ephemeris calculations are somewhat costly (the Moon is one of the most
209 * difficult objects to compute position for). So only process every nMAXth cycle of this
210 * loop. We run outer loop it faster to catch expose events, button presses, etc...
213 if (n>nMAX){
215 n = 0;
217 CurrentGMTTime = time(CurrentTime); GMTTime = gmtime(&CurrentGMTTime);
218 UT = GMTTime->tm_hour + GMTTime->tm_min/60.0 + GMTTime->tm_sec/3600.0;
219 Year = GMTTime->tm_year+1900;
220 Month = GMTTime->tm_mon+1;
221 DayOfMonth = GMTTime->tm_mday;
222 date = Year*10000 + Month*100 + DayOfMonth;
223 CurrentLocalTime = CurrentGMTTime; LocalTime = localtime(&CurrentLocalTime);
224 LocalHour = LocalTime->tm_hour + LocalTime->tm_min/60.0 + LocalTime->tm_sec/3600.0;
225 TimeZone = UT - LocalHour;
228 CalcEphem(date, UT, &c);
234 if (ToggleWindow == 0){
237 * Update Moon Image
240 nMAX = 1000;
241 ImageNumber = (int)(c.MoonPhase * 60.0 + 0.5);
242 if (ImageNumber > 59) ImageNumber = 0;
243 if (Glat < 0) ImageNumber = 59 - ImageNumber; /* add southern hemisphere support, closes: #537480 */
244 j = ImageNumber/10;
245 i = ImageNumber%10;
246 copyXPMArea(67+58*i, 2+58*j, 54, 54, 5, 5);
248 } else if (ToggleWindow == 1){
251 * Update Numerical Display
254 /* This requires second precision for LT and UT */
255 nMAX = 0;
259 * Clear plotting area
261 copyXPMArea(4, 69, 56, 56, 4, 4);
266 * Paste up LT and UT.
268 val = LocalHour;
269 H = (int)val; val = (val - H)*60.0;
270 M = (int)val; val = (val - M)*60.0;
271 S = (int)val;
272 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 25, 6);
273 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+5, 6);
274 copyXPMArea(117, 353, 1, 6, 25+10, 6);
275 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 25+12, 6);
276 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+17, 6);
278 val = UT;
279 H = (int)val; val = (val - H)*60.0;
280 M = (int)val; val = (val - M)*60.0;
281 S = (int)val;
282 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 25, 15);
283 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+5, 15);
284 copyXPMArea(117, 353, 1, 6, 25+10, 15);
285 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 25+12, 15);
286 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 25+17, 15);
293 * Paste up AGE.
295 val = c.MoonAge;
296 q = (val < 10.0) ? 5 : 0;
297 A = (int)val;
298 val = (val - A)*100.0;
299 B = (int)val;
300 digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 26-q, 24);
301 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 26+5-q, 24);
302 copyXPMArea(62, 357, 3, 3, 26+11-q, 28);
303 digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 26+15-q, 24);
304 digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 26+20-q, 24);
305 copyXPMArea(143, 354, 3, 3, 26+25-q, 23);
311 * Paste up Phase (Percent Illuminated).
313 val = 0.5*( 1.0 - cos(c.MoonPhase*6.2831853) );
314 val *= 100.0;
315 A = (int)(val+0.5);
316 if (A == 100){
317 copyXPMArea(72, 353, 5, 7, 32+5, 42);
318 copyXPMArea(67, 353, 5, 7, 32+10, 42);
319 copyXPMArea(67, 353, 5, 7, 32+15, 42);
320 copyXPMArea(147, 353, 5, 7, 32+20, 42);
321 } else if (A >= 10){
322 digit = A/10; copyXPMArea(67+digit*5, 353, 5, 7, 32+5, 42);
323 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 32+10, 42);
324 copyXPMArea(147, 353, 5, 7, 32+15, 42);
325 } else {
326 digit = A; copyXPMArea(67+digit*5, 353, 5, 7, 32+5, 42);
327 copyXPMArea(147, 353, 5, 7, 32+10, 42);
334 * Paste up Frac (Percent of way through current lunar cycle).
336 val = c.MoonPhase*100.0;
337 A = (int)(val+0.5);
338 if (A == 100){
339 copyXPMArea(72, 353, 5, 7, 27+5, 33);
340 copyXPMArea(67, 353, 5, 7, 27+10, 33);
341 copyXPMArea(67, 353, 5, 7, 27+15, 33);
342 copyXPMArea(147, 353, 5, 7, 27+20, 33);
343 } else if (A >= 10){
344 digit = A/10; copyXPMArea(67+digit*5, 353, 5, 7, 27+5, 33);
345 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 27+10, 33);
346 copyXPMArea(147, 353, 5, 7, 27+15, 33);
347 } else {
348 digit = A; copyXPMArea(67+digit*5, 353, 5, 7, 27+5, 33);
349 copyXPMArea(147, 353, 5, 7, 27+10, 33);
354 * Paste up Visible Status.
356 if (c.Visible)
357 copyXPMArea(6, 327, 13, 6, 46, 51);
358 else
359 copyXPMArea(26, 327, 9, 6, 46, 51);
364 } else if (ToggleWindow == 2){
367 * Plot up Moon Rise/Set Times
371 nMAX = 60;
374 * Clear plotting area
376 copyXPMArea(4, 134, 56, 56, 4, 4);
380 * Do Yesterday's first
382 MoonRise(Year, Month, DayOfMonth-1, LocalHour, &UTRise, &UTSet);
383 UTTohhmm(UTRise, &H, &M);
384 if (H >= 0){
385 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 19);
386 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 19);
387 copyXPMArea(117, 354, 1, 4, 7+10, 20);
388 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 19);
389 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 19);
390 } else {
391 copyXPMArea(57, 355, 5, 1, 7, 22); copyXPMArea(57, 355, 5, 1, 7+5, 22);
392 copyXPMArea(117, 354, 1, 4, 7+10, 20);
393 copyXPMArea(57, 355, 5, 1, 7+12, 22); copyXPMArea(57, 355, 5, 1, 7+17, 22);
395 UTTohhmm(UTSet, &H, &M);
396 if (H >= 0){
397 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 19);
398 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 19);
399 copyXPMArea(117, 354, 1, 4, 35+10, 20);
400 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 19);
401 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 19);
402 } else {
403 copyXPMArea(57, 355, 5, 1, 35, 22); copyXPMArea(57, 355, 5, 1, 35+5, 22);
404 copyXPMArea(117, 354, 1, 4, 35+10, 20);
405 copyXPMArea(57, 355, 5, 1, 35+12, 22); copyXPMArea(57, 355, 5, 1, 35+17, 22);
410 * Plot up todays Rise/Set times.
412 MoonRise(Year, Month, DayOfMonth, LocalHour, &UTRise, &UTSet);
413 UTTohhmm(UTRise, &H, &M);
414 if (H >= 0){
415 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 29);
416 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 29);
417 copyXPMArea(117, 354, 1, 4, 7+10, 30);
418 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 29);
419 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 29);
420 } else {
421 copyXPMArea(57, 355, 5, 1, 7, 32); copyXPMArea(57, 355, 5, 1, 7+5, 32);
422 copyXPMArea(117, 354, 1, 4, 7+10, 30);
423 copyXPMArea(57, 355, 5, 1, 7+12, 32); copyXPMArea(57, 355, 5, 1, 7+17, 32);
425 UTTohhmm(UTSet, &H, &M);
426 if (H >= 0){
427 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 29);
428 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 29);
429 copyXPMArea(117, 354, 1, 4, 35+10, 30);
430 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 29);
431 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 29);
432 } else {
433 copyXPMArea(57, 355, 5, 1, 35, 32); copyXPMArea(57, 355, 5, 1, 35+5, 32);
434 copyXPMArea(117, 354, 1, 4, 35+10, 30);
435 copyXPMArea(57, 355, 5, 1, 35+12, 32); copyXPMArea(57, 355, 5, 1, 35+17, 32);
441 * Plot up tomorrow's Rise/Set times.
443 MoonRise(Year, Month, DayOfMonth+1, LocalHour, &UTRise, &UTSet);
444 UTTohhmm(UTRise, &H, &M);
445 if (H >= 0){
446 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 7, 39);
447 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+5, 39);
448 copyXPMArea(117, 354, 1, 4, 7+10, 40);
449 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 7+12, 39);
450 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 7+17, 39);
451 } else {
452 copyXPMArea(57, 355, 5, 1, 7, 42); copyXPMArea(57, 355, 5, 1, 7+5, 42);
453 copyXPMArea(117, 354, 1, 4, 7+10, 40);
454 copyXPMArea(57, 355, 5, 1, 7+12, 42); copyXPMArea(57, 355, 5, 1, 7+17, 42);
456 UTTohhmm(UTSet, &H, &M);
457 if (H >= 0){
458 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 35, 39);
459 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+5, 39);
460 copyXPMArea(117, 354, 1, 4, 35+10, 40);
461 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 35+12, 39);
462 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 35+17, 39);
463 } else {
464 copyXPMArea(57, 355, 5, 1, 35, 42); copyXPMArea(57, 355, 5, 1, 35+5, 42);
465 copyXPMArea(117, 354, 1, 4, 35+10, 40);
466 copyXPMArea(57, 355, 5, 1, 35+12, 42); copyXPMArea(57, 355, 5, 1, 35+17, 42);
470 } else if (ToggleWindow == 3){
473 * Plot up Horizon Coords
478 nMAX = 3;
481 * Clear plotting area
483 copyXPMArea(4, 199, 56, 56, 4, 4);
488 * Paste up Azimuth, A
490 val = c.A_moon;
491 sgn = (val < 0.0) ? -1 : 0;
492 val = fabs(val);
493 D = (int)val;
494 val = (val-(double)D)*100.0;
495 M = (int)val;
497 if (sgn < 0) copyXPMArea(120, 357, 2, 1, 19, 27);
499 /* degrees 100's */
500 digit = D/100; copyXPMArea(67+digit*5, 353, 5, 7, 22, 24);
501 D -= digit*100;
503 /* degrees 10's */
504 digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+5, 24);
506 /* degrees 1's */
507 digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+10, 24);
509 /* Decimal */
510 copyXPMArea(62, 357, 3, 3, 22+15, 28);
512 /* Decimal Part */
513 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+19, 24);
515 /* mins 1's */
516 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+24, 24);
518 copyXPMArea(120, 353, 3, 3, 22+29, 23);
525 * Paste up Altitude, h
527 val = c.h_moon;
528 sgn = (val < 0.0) ? -1 : 0;
529 val = fabs(val);
530 D = (int)val;
531 val = (val-(double)D)*100.0;
532 M = (int)val;
534 if (sgn < 0) copyXPMArea(120, 357, 2, 1, 19, 39);
536 /* degrees 10's */
537 digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 22, 36);
539 /* degrees 1's */
540 digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+5, 36);
542 /* Decimal */
543 copyXPMArea(62, 357, 3, 3, 22+10, 40);
545 /* Decimal Part */
546 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 22+14, 36);
548 /* mins 1's */
549 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 22+19, 36);
551 copyXPMArea(120, 353, 3, 3, 22+24, 35);
558 * Paste up Earth-Moon Distance (in units of Earth radii).
560 val = c.EarthMoonDistance;
561 A = (int)val;
562 val = (val - A)*100.0;
563 B = (int)val;
564 digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 30, 47);
565 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+5, 47);
566 copyXPMArea(62, 357, 3, 3, 30+11, 51);
567 digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 30+15, 47);
568 digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+20, 47);
572 } else if (ToggleWindow == 4){
575 * Plot up RA/DEC Coords
580 nMAX = 3;
583 * Clear plotting area
585 copyXPMArea(4, 264, 56, 56, 4, 4);
590 * Paste up Right Ascention
592 RA = c.RA_moon/15.0;
593 H = (int)RA;
594 RA = (RA-(double)H)*60.0;
595 M = (int)RA; RA = (RA-(double)M)*60.0;
596 S = (int)(RA+0.5);
598 /* hours 10's */
599 digit = H/10; copyXPMArea(67+digit*5, 353, 5, 7, 17, 25);
601 /* hours 1's */
602 digit = H%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+5, 25);
604 /* hour symbol */
605 copyXPMArea(138, 354, 3, 3, 17+10, 24);
607 /* mins 10's */
608 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+14, 25);
610 /* mins 1's */
611 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+19, 25);
613 /* min symbol */
614 copyXPMArea(124, 353, 3, 3, 17+23, 24);
616 /* secs 10's */
617 digit = S/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+27, 25);
619 /* secs 1's */
620 digit = S%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+32, 25);
622 /* sec symbol */
623 copyXPMArea(128, 353, 5, 3, 17+36, 24);
629 * Paste up Declination
631 DEC = c.DEC_moon;
632 sgn = (DEC < 0.0) ? -1 : 0;
633 DEC = fabs(DEC);
634 D = (int)DEC;
635 DEC = (DEC-(double)D)*60.0;
636 M = (int)DEC;
637 DEC = (DEC-(double)M)*60.0;
638 S = (int)(DEC+0.5);
640 if (sgn < 0) copyXPMArea(120, 357, 2, 1, 14, 39);
643 /* degrees 10's */
644 digit = D/10; copyXPMArea(67+digit*5, 353, 5, 7, 17, 36);
646 /* degrees 1's */
647 digit = D%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+5, 36);
649 /* degree symbol */
650 copyXPMArea(120, 353, 3, 3, 17+10, 35);
652 /* mins 10's */
653 digit = M/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+14, 36);
655 /* mins 1's */
656 digit = M%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+19, 36);
658 /* min symbol */
659 copyXPMArea(124, 353, 3, 3, 17+23, 35);
661 /* secs 10's */
662 digit = S/10; copyXPMArea(67+digit*5, 353, 5, 7, 17+27, 36);
664 /* secs 1's */
665 digit = S%10; copyXPMArea(67+digit*5, 353, 5, 7, 17+32, 36);
667 /* sec symbol */
668 copyXPMArea(128, 353, 5, 3, 17+36, 35);
674 * Paste up Earth-Moon Distance (in units of Earth radii).
676 val = c.EarthMoonDistance;
677 A = (int)val;
678 val = (val - A)*100.0;
679 B = (int)val;
680 digit = A/10; if (digit != 0) copyXPMArea(67+digit*5, 353, 5, 7, 30, 47);
681 digit = A%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+5, 47);
682 copyXPMArea(62, 357, 3, 3, 30+11, 51);
683 digit = B/10; copyXPMArea(67+digit*5, 353, 5, 7, 30+15, 47);
684 digit = B%10; copyXPMArea(67+digit*5, 353, 5, 7, 30+20, 47);
692 } else {
695 * Update the counter.
697 ++n;
706 * Add X display to file descriptor set for polling.
708 FD_ZERO(&xfdset);
709 FD_SET(ConnectionNumber(display), &xfdset);
714 * Process any pending X events.
716 while(XPending(display)){
717 XNextEvent(display, &event);
718 switch(event.type){
719 case Expose:
720 RedrawWindow();
721 break;
722 case ButtonPress:
723 pressEvent(&event.xbutton);
724 break;
725 case ButtonRelease:
726 break;
736 * Redraw and wait for next update
738 RedrawWindow();
739 timeout.tv_sec = DELAY / 1000000L;
740 timeout.tv_usec = DELAY % 1000000L;
741 select(ConnectionNumber(display) + 1, &xfdset, NULL, NULL, &timeout);
758 * ParseCMDLine()
760 void ParseCMDLine(int argc, char *argv[]) {
762 int i;
763 char *eptr;
765 for (i = 1; i < argc; i++) {
767 if (!strcmp(argv[i], "-display")){
769 ++i;
771 } else if (!strcmp(argv[i], "-bc")){
773 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
774 fprintf(stderr, "wmMoonClock: -bc needs a color argument.\n");
775 print_usage();
776 exit(-1);
778 strcpy(BackColor, argv[++i]);
780 } else if (!strcmp(argv[i], "-lc")){
782 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
783 fprintf(stderr, "wmMoonClock: -lc needs a color argument.\n");
784 print_usage();
785 exit(-1);
787 strcpy(LabelColor, argv[++i]);
789 } else if (!strcmp(argv[i], "-dc")){
791 if ((i+1 >= argc)||(argv[i+1][0] == '-')) {
792 fprintf(stderr, "wmMoonClock: -dc needs a color argument.\n");
793 print_usage();
794 exit(-1);
796 strcpy(DataColor, argv[++i]);
798 } else if (!strcmp(argv[i], "-low")){
800 UseLowColorPixmap = 1;
802 } else if (!strcmp(argv[i], "-lat")){
804 if (i+1 >= argc){
805 fprintf(stderr, "wmMoonClock: -lat needs a value in degrees.\n");
806 print_usage();
807 exit(-1);
808 } else {
809 Glat = strtod(argv[i+1], &eptr);
810 if ((Glat == 0.0)&&(eptr == argv[i+1])){
811 fprintf(stderr, "wmMoonClock: could not convert latitude %s.\n", argv[i+1]);
812 print_usage();
813 exit(-1);
815 ++i;
818 } else if (!strcmp(argv[i], "-lon")){
820 if (i+1 >= argc){
821 fprintf(stderr, "wmMoonClock: -lat needs a value in degrees.\n");
822 print_usage();
823 exit(-1);
824 } else {
825 Glon = strtod(argv[i+1], &eptr);
826 if ((Glon == 0.0)&&(eptr == argv[i+1])){
827 fprintf(stderr, "wmMoonClock: could not convert longitude %s.\n", argv[i+1]);
828 print_usage();
829 exit(-1);
831 ++i;
834 } else {
836 print_usage();
837 exit(1);
844 void print_usage(){
846 printf("\nwmMoonClock version: %s\n", PACKAGE_VERSION);
847 printf("\nusage: wmMoonClock [-display <Display>] [-lat <Latitude>] [-lon <Longitude>] [-h]\n");
848 printf(" [-bc <Color>] [-lc <Color>] [-dc <Color>]\n\n");
849 printf("\t-display <Display>\tUse alternate X display.\n");
850 printf("\t-bc <Color> \t\tBackground color. (e.g. #ffbb00 or orange)\n");
851 printf("\t-lc <Color> \t\tColor for labels.\n");
852 printf("\t-dc <Color> \t\tColor for data entries.\n");
853 printf("\t-low \t\tUse lower color pixmap (for 8-bit displays).\n");
854 printf("\t-lat <Latitude>\t\tObservers Latitude. Positive in northern\n");
855 printf("\t \t\themisphere, negative in southern hemisphere.\n");
856 printf("\t-lon <Longitude>\tObservers Longitude. Greenwich is 0.0, and longitude\n");
857 printf("\t \tincreases positively toward the west. (Alternatively,\n");
858 printf("\t \tnegative numbers can also be used to specify\n");
859 printf("\t \tlongitudes to the east of Greenwich).\n");
860 printf("\t-h\t\t\tDisplay help screen.\n\n");
866 * This routine handles button presses. Clicking in the window
867 * toggles the display.
870 void pressEvent(XButtonEvent *xev){
872 ++ToggleWindow;
873 if (ToggleWindow > 4) ToggleWindow = 0;
874 Flag = 1;
876 return;