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

Comparing rxvt-unicode/src/rclock.C (file contents):
Revision 1.3 by root, Mon May 10 00:37:29 2021 UTC vs.
Revision 1.12 by root, Sun Nov 14 18:46:50 2021 UTC

34#include <sys/time.h> 34#include <sys/time.h>
35#include <time.h> 35#include <time.h>
36 36
37#include <dirent.h> 37#include <dirent.h>
38 38
39#include <X11/Intrinsic.h> /* Xlib, Xutil, Xresource, Xfuncproto */ 39#include <X11/Xlib.h>
40#include <X11/Xutil.h>
41
42#include "ecb.h"
43
44#include "version.h"
40 45
41#define APL_CLASS "Clock" 46#define APL_CLASS "Clock"
42#define APL_NAME "rclock" 47#define APL_NAME "rclock"
43#define MSG_CLASS "Appointment" 48#define MSG_CLASS "Appointment"
44#define MSG_NAME "Appointment" 49#define MSG_NAME "Appointment"
46 51
47#ifndef EXIT_SUCCESS /* missed from <stdlib.h> ? */ 52#ifndef EXIT_SUCCESS /* missed from <stdlib.h> ? */
48# define EXIT_SUCCESS 0 53# define EXIT_SUCCESS 0
49# define EXIT_FAILURE 1 54# define EXIT_FAILURE 1
50#endif 55#endif
51
52#define VERSION "TODO: fetch from urxvt somehow"
53 56
54/*--------------------------------*-C-*---------------------------------* 57/*--------------------------------*-C-*---------------------------------*
55 * Compile-time configuration. 58 * Compile-time configuration.
56 *----------------------------------------------------------------------* 59 *----------------------------------------------------------------------*
57 * Copyright (C) 1997 1998 mj olesen <olesen@me.QueensU.CA> 60 * Copyright (C) 1997 1998 mj olesen <olesen@me.QueensU.CA>
134#define MAILUPDATE 60 137#define MAILUPDATE 60
135#define REMINDERS_TIME 10 138#define REMINDERS_TIME 10
136#define DEFER_TIME 3 139#define DEFER_TIME 3
137#define ADJUST_TIME 140#define ADJUST_TIME
138 141
139#define CENTURY 2000 / TODO: verify */ 142#define CENTURY 2000 /* TODO: verify */
140 143
141/*----------------------------------------------------------------------* 144/*----------------------------------------------------------------------*
142 * #define FONT_NAME "7x14" 145 * #define FONT_NAME "7x14"
143 * to define the font to be used for appointment reminders 146 * to define the font to be used for appointment reminders
144 * 147 *
173# define MAIL 176# define MAIL
174# endif 177# endif
175#endif 178#endif
176 179
177/*----------------------------------------------------------------------*/ 180/*----------------------------------------------------------------------*/
181// fourth-order fixed point sine approximation,
182// adapted from https://www.coranac.com/2009/07/sines/
183
184static int32_t
185Sin (int32_t arg)
186{
187 int32_t x = (arg - 360) * 16384 / 360;
188
189 int c, y;
190 static const int qN = 13, qA = 12, B = 19900, C = 3516;
191
192 c = x << (30 - qN); // Semi-circle info into carry.
193 x -= 1 << qN; // sine -> cosine calc
194
195 x = x << (31 - qN); // Mask with PI
196 x = x >> (31 - qN); // Note: SIGNED shift! (to qN)
197 x = x * x >> (2 * qN - 14); // x=x^2 To Q14
198
199 y = B - (x * C >> 14); // B - x^2*C
200 y = (1 << qA) - (x * y >> 16); // A - x^2*(B-x^2*C)
201
202 x = c < 0 ? y : -y;
203
204 return x;
205}
206
207/*----------------------------------------------------------------------*/
178 208
179static Display *Xdisplay; /* X display */ 209static Display *Xdisplay; /* X display */
180static int Xfd; /* file descriptor of server connection */ 210static int Xfd; /* file descriptor of server connection */
181static GC Xgc, Xrvgc; /* normal, reverse video GC */ 211static GC Xgc, Xrvgc; /* normal, reverse video GC */
182 212
195 225
196#define fgColor 0 226#define fgColor 0
197#define bgColor 1 227#define bgColor 1
198static const char *rs_color[2] = { FG_COLOR_NAME, BG_COLOR_NAME }; 228static const char *rs_color[2] = { FG_COLOR_NAME, BG_COLOR_NAME };
199 229
200static Pixel PixColors[2]; 230static unsigned long PixColors[2];
201static const char *rs_geometry = NULL; 231static const char *rs_geometry = NULL;
202 232
203#ifdef ICONWIN 233#ifdef ICONWIN
204static const char *rs_iconGeometry = NULL; 234static const char *rs_iconGeometry = NULL;
205static mywindow_t Icon = { None, 65, 65 }; /* icon window */ 235static mywindow_t Icon = { None, 65, 65 }; /* icon window */
274 0, 0, /* base size */ 304 0, 0, /* base size */
275 NorthWestGravity /* gravity */ 305 NorthWestGravity /* gravity */
276}; 306};
277 307
278/* subroutine declarations */ 308/* subroutine declarations */
279static void geometry2sizehint (mywindow_t * /* win */ , 309static void geometry2sizehint (mywindow_t *win, const char *geom);
280 const char * /* geom */ );
281static void Create_Windows (int /* argc */ , 310static void Create_Windows (int argc, char *argv[]);
282 char * /* argv */ []);
283static void getXevent (void); 311static void getXevent ();
284static void print_error (const char * /* fmt */ , ...); 312static void print_error (const char *fmt, ...);
285 313
286static void Draw_Window (mywindow_t * /* this_win */ , 314static void Draw_Window (mywindow_t *this_win, int full_redraw);
287 int /* full_redraw */ );
288static void Reminder (void); 315static void Reminder ();
289static void Next_Reminder (int /* update_only */ ); 316static void Next_Reminder (int update_only);
290 317
291/* Arguments for Next_Reminder() */ 318/* Arguments for Next_Reminder() */
292#define REPLACE 0 319#define REPLACE 0
293#define UPDATE 1 320#define UPDATE 1
294 321
295/*----------------------------------------------------------------------*/ 322/*----------------------------------------------------------------------*/
296 323
297static void 324static void
298usage (void) 325usage ()
299{ 326{
300 int i; 327 int i;
301 struct 328 struct
302 { 329 {
303 const char *const opt; 330 const char *const opt;
329# endif 356# endif
330#endif 357#endif
331 {"#geom", "icon window geometry"} 358 {"#geom", "icon window geometry"}
332 }; 359 };
333 360
334 fprintf (stderr, "\nUsage v" VERSION ":\n " APL_NAME " [options]\n\n" "where options include:\n"); 361 fprintf (stderr, "\nUsage for urclock version " VERSION "\n\n urclock [options]\n\n" "where options include:\n");
335 362
336 for (i = 0; i < (int)optList_size (); i++) 363 for (i = 0; i < (int)optList_size (); i++)
337 fprintf (stderr, " %-29s%s\n", optList[i].opt, optList[i].desc); 364 fprintf (stderr, " %-29s%s\n", optList[i].opt, optList[i].desc);
338} 365}
339 366
342 * Check out if we are using a maildir drop (qmail) 369 * Check out if we are using a maildir drop (qmail)
343 * Note: this changes mail_dir to hold the "new" diretory 370 * Note: this changes mail_dir to hold the "new" diretory
344 */ 371 */
345#ifdef MAIL 372#ifdef MAIL
346static void 373static void
347CheckMaildir (void) 374CheckMaildir ()
348{ 375{
349 struct stat st; 376 struct stat st;
350 char *buf, *p; 377 char *buf, *p;
351 378
352 if (!*mail_file || stat (mail_file, &st) || !S_ISDIR (st.st_mode)) 379 if (!*mail_file || stat (mail_file, &st) || !S_ISDIR (st.st_mode))
606 633
607/* 634/*
608 * translate geometry string to appropriate sizehint 635 * translate geometry string to appropriate sizehint
609 */ 636 */
610static void 637static void
611geometry2sizehint (mywindow_t * win, const char *geom) 638geometry2sizehint (mywindow_t *win, const char *geom)
612{ 639{
613 int x, y, flags; 640 int x, y, flags;
614 unsigned int width, height; 641 unsigned int width, height;
615 642
616 /* copy in values */ 643 /* copy in values */
740} 767}
741 768
742static time_t 769static time_t
743mk_time (struct tm *tmval) 770mk_time (struct tm *tmval)
744{ 771{
745 return (tmval->tm_min + 60 * (tmval->tm_hour + 24 * (tmval->tm_mday + 31 * ((tmval->tm_mon + 1) + 12 * tmval->tm_year)))); 772 return (tmval->tm_min
773 + 60 * (tmval->tm_hour
774 + 24 * (tmval->tm_mday
775 + 31 * ((tmval->tm_mon + 1)
776 + 12 * tmval->tm_year))));
746} 777}
747
748 778
749#ifdef MAIL 779#ifdef MAIL
750static int 780static int
751MailAvailable () 781MailAvailable ()
752{ 782{
782 * Redraw the whole window after an exposure or size change. 812 * Redraw the whole window after an exposure or size change.
783 * After a timeout, only redraw the hands. 813 * After a timeout, only redraw the hands.
784 * Provide reminder if needed. 814 * Provide reminder if needed.
785 *----------------------------------------------------------------------*/ 815 *----------------------------------------------------------------------*/
786static void 816static void
787Draw_Window (mywindow_t * W, int full_redraw) 817Draw_Window (mywindow_t *W, int full_redraw)
788{ 818{
789 /* pre-computed values for sin() x1000, to avoid using floats */
790 static const short Sin[720] = {
791 0,
792 9, 17, 26, 35, 44, 52, 61, 70, 78, 87, 96, 105,
793 113, 122, 131, 139, 148, 156, 165, 174, 182, 191, 199, 208,
794 216, 225, 233, 242, 250, 259, 267, 276, 284, 292, 301, 309,
795 317, 326, 334, 342, 350, 358, 367, 375, 383, 391, 399, 407,
796 415, 423, 431, 438, 446, 454, 462, 469, 477, 485, 492, 500,
797 508, 515, 522, 530, 537, 545, 552, 559, 566, 574, 581, 588,
798 595, 602, 609, 616, 623, 629, 636, 643, 649, 656, 663, 669,
799 676, 682, 688, 695, 701, 707, 713, 719, 725, 731, 737, 743,
800 749, 755, 760, 766, 772, 777, 783, 788, 793, 799, 804, 809,
801 814, 819, 824, 829, 834, 839, 843, 848, 853, 857, 862, 866,
802 870, 875, 879, 883, 887, 891, 895, 899, 903, 906, 910, 914,
803 917, 921, 924, 927, 930, 934, 937, 940, 943, 946, 948, 951,
804 954, 956, 959, 961, 964, 966, 968, 970, 972, 974, 976, 978,
805 980, 982, 983, 985, 986, 988, 989, 990, 991, 993, 994, 995,
806 995, 996, 997, 998, 998, 999, 999, 999, 1000, 1000, 1000, 1000,
807 1000, 1000, 1000, 999, 999, 999, 998, 998, 997, 996, 995, 995,
808 994, 993, 991, 990, 989, 988, 986, 985, 983, 982, 980, 978,
809 976, 974, 972, 970, 968, 966, 964, 961, 959, 956, 954, 951,
810 948, 946, 943, 940, 937, 934, 930, 927, 924, 921, 917, 914,
811 910, 906, 903, 899, 895, 891, 887, 883, 879, 875, 870, 866,
812 862, 857, 853, 848, 843, 839, 834, 829, 824, 819, 814, 809,
813 804, 799, 793, 788, 783, 777, 772, 766, 760, 755, 749, 743,
814 737, 731, 725, 719, 713, 707, 701, 695, 688, 682, 676, 669,
815 663, 656, 649, 643, 636, 629, 623, 616, 609, 602, 595, 588,
816 581, 574, 566, 559, 552, 545, 537, 530, 523, 515, 508, 500,
817 492, 485, 477, 469, 462, 454, 446, 438, 431, 423, 415, 407,
818 399, 391, 383, 375, 367, 358, 350, 342, 334, 326, 317, 309,
819 301, 292, 284, 276, 267, 259, 250, 242, 233, 225, 216, 208,
820 199, 191, 182, 174, 165, 156, 148, 139, 131, 122, 113, 105,
821 96, 87, 78, 70, 61, 52, 44, 35, 26, 17, 9, 0,
822 -9, -17, -26, -35, -44, -52, -61, -70, -78, -87, -96, -105,
823 -113, -122, -131, -139, -148, -156, -165, -174, -182, -191, -199, -208,
824 -216, -225, -233, -242, -250, -259, -267, -276, -284, -292, -301, -309,
825 -317, -326, -334, -342, -350, -358, -366, -375, -383, -391, -399, -407,
826 -415, -423, -431, -438, -446, -454, -462, -469, -477, -485, -492, -500,
827 -508, -515, -522, -530, -537, -545, -552, -559, -566, -574, -581, -588,
828 -595, -602, -609, -616, -623, -629, -636, -643, -649, -656, -663, -669,
829 -676, -682, -688, -695, -701, -707, -713, -719, -725, -731, -737, -743,
830 -749, -755, -760, -766, -772, -777, -783, -788, -793, -799, -804, -809,
831 -814, -819, -824, -829, -834, -839, -843, -848, -853, -857, -862, -866,
832 -870, -875, -879, -883, -887, -891, -895, -899, -903, -906, -910, -914,
833 -917, -921, -924, -927, -930, -934, -937, -940, -943, -946, -948, -951,
834 -954, -956, -959, -961, -964, -966, -968, -970, -972, -974, -976, -978,
835 -980, -982, -983, -985, -986, -988, -989, -990, -991, -993, -994, -995,
836 -995, -996, -997, -998, -998, -999, -999, -999, -1000, -1000, -1000, -1000,
837 -1000, -1000, -1000, -999, -999, -999, -998, -998, -997, -996, -995, -995,
838 -994, -993, -991, -990, -989, -988, -986, -985, -983, -982, -980, -978,
839 -976, -974, -972, -970, -968, -966, -964, -961, -959, -956, -954, -951,
840 -948, -946, -943, -940, -937, -934, -930, -927, -924, -921, -917, -914,
841 -910, -906, -903, -899, -895, -891, -887, -883, -879, -875, -870, -866,
842 -862, -857, -853, -848, -843, -839, -834, -829, -824, -819, -814, -809,
843 -804, -799, -793, -788, -783, -777, -772, -766, -760, -755, -749, -743,
844 -737, -731, -725, -719, -713, -707, -701, -695, -688, -682, -676, -669,
845 -663, -656, -649, -643, -636, -629, -623, -616, -609, -602, -595, -588,
846 -581, -574, -566, -559, -552, -545, -537, -530, -523, -515, -508, -500,
847 -492, -485, -477, -469, -462, -454, -446, -438, -431, -423, -415, -407,
848 -399, -391, -383, -375, -367, -358, -350, -342, -334, -326, -317, -309,
849 -301, -292, -284, -276, -267, -259, -250, -242, -233, -225, -216, -208,
850 -199, -191, -182, -174, -165, -156, -148, -139, -131, -122, -113, -105,
851 -96, -87, -78, -70, -61, -52, -44, -35, -26, -17, -9,
852 };
853
854 static int savedDay = -1; 819 static int savedDay = -1;
855 820
856 time_t currentTime; 821 time_t currentTime;
857 struct tm *tmval; 822 struct tm *tmval;
858 int ctr_x, ctr_y; 823 int ctr_x, ctr_y;
872#ifdef ICONWIN 837#ifdef ICONWIN
873 static hands_t HandsOld_icon = { -1 }; 838 static hands_t HandsOld_icon = { -1 };
874#endif 839#endif
875#ifdef REMINDERS 840#ifdef REMINDERS
876 static int lastUpdateTime = -10; 841 static int lastUpdateTime = -10;
842#endif
843#ifdef DATE_ON_CLOCK_FACE
844 static char clockdate[10];
877#endif 845#endif
878 846
879#ifdef MAIL 847#ifdef MAIL
880 static time_t mailTime = 0; 848 static time_t mailTime = 0;
881 static int MailUp = 0, MailUp_rvideo = 0; 849 static int MailUp = 0, MailUp_rvideo = 0;
943 911
944 savedDay = tmval->tm_yday; 912 savedDay = tmval->tm_yday;
945 strftime (str, sizeof (str), "%a %h %d", tmval); 913 strftime (str, sizeof (str), "%a %h %d", tmval);
946 XStoreName (Xdisplay, Clock.win, str); 914 XStoreName (Xdisplay, Clock.win, str);
947 XSetIconName (Xdisplay, Clock.win, str); 915 XSetIconName (Xdisplay, Clock.win, str);
948 }
949 916
917#if defined(REMINDERS) && defined(DATE_ON_CLOCK_FACE)
918 if (show_date)
919 {
920 strftime (clockdate, sizeof (clockdate), "%d", tmval);
921 full_redraw = 1;
922 }
923 }
924
925#endif
950 if (full_redraw) 926 if (full_redraw)
951 XClearWindow (Xdisplay, W->win); 927 XClearWindow (Xdisplay, W->win);
952 928
953#ifdef REMINDERS 929#ifdef REMINDERS
954 /* for a message window, just re-draw the message */ 930 /* for a message window, just re-draw the message */
975 Xgc, 951 Xgc,
976 (Msg.width - 952 (Msg.width -
977 XTextWidth (Xfont, beg, (end - beg))) / 2, 10 + Xfont->ascent + FontHeight () * lines, beg, (end - beg)); 953 XTextWidth (Xfont, beg, (end - beg))) / 2, 10 + Xfont->ascent + FontHeight () * lines, beg, (end - beg));
978 } 954 }
979 955
980 XDrawString (Xdisplay, msgButton.Dismiss, Xrvgc, (msgButton.width - XTextWidth (Xfont, "Done", 4)) / 2, Xfont->ascent + 2, "Done", 4); 956 XDrawString (Xdisplay, msgButton.Dismiss, Xrvgc, (msgButton.width - XTextWidth (Xfont, "Done" , 4)) / 2, Xfont->ascent + 2, "Done" , 4);
981 957
982 XDrawString (Xdisplay, msgButton.Defer, Xrvgc, (msgButton.width - XTextWidth (Xfont, "Defer", 5)) / 2, Xfont->ascent + 2, "Defer", 5); 958 XDrawString (Xdisplay, msgButton.Defer , Xrvgc, (msgButton.width - XTextWidth (Xfont, "Defer", 5)) / 2, Xfont->ascent + 2, "Defer", 5);
983 959
984# ifndef NO_REMINDER_EXEC 960# ifndef NO_REMINDER_EXEC
985 XDrawString (Xdisplay, msgButton.Start, Xrvgc, (msgButton.width - XTextWidth (Xfont, "Start", 5)) / 2, Xfont->ascent + 2, "Start", 5); 961 XDrawString (Xdisplay, msgButton.Start , Xrvgc, (msgButton.width - XTextWidth (Xfont, "Start", 5)) / 2, Xfont->ascent + 2, "Start", 5);
986 962
987 if (strlen (execPrgm) > 1) 963 if (strlen (execPrgm) > 1)
988 XMapWindow (Xdisplay, msgButton.Start); 964 XMapWindow (Xdisplay, msgButton.Start);
989 else 965 else
990 XUnmapWindow (Xdisplay, msgButton.Start); 966 XUnmapWindow (Xdisplay, msgButton.Start);
1013 989
1014 /* 990 /*
1015 * draw clock 991 * draw clock
1016 */ 992 */
1017 993
1018 ctr_x = (W->width / 2); 994 ctr_x = W->width / 2;
1019 ctr_y = (W->height / 2); 995 ctr_y = W->height / 2;
1020 996
1021#define XPOS(i,val) (ctr_x + (W->width * Sin[i%720] * (val) + 100000) / 200000) 997#define XPOS(i,val) (ctr_x + (W->width * Sin (i ) + 4096) / (819200 / (val)))
1022#define YPOS(i,val) (ctr_y - (W->height * Sin[(i+180)%720] * (val) + 100000) / 200000) 998#define YPOS(i,val) (ctr_y - (W->height * Sin (i + 180) + 4096) / (819200 / (val)))
1023 /* 999 /*
1024 * how to draw the clock face 1000 * how to draw the clock face
1025 */ 1001 */
1026 1002
1027 /* calculate the positions of the hands */ 1003 /* calculate the positions of the hands */
1066 1042
1067 /* 1043 /*
1068 * Draw the date in the lower half of the clock window. 1044 * Draw the date in the lower half of the clock window.
1069 * The code is enclosed in REMINDERS because it uses the same 1045 * The code is enclosed in REMINDERS because it uses the same
1070 * font as the reminders code. 1046 * font as the reminders code.
1071 * I believe this should be drawn always so it does not get
1072 * "swept away" by the minute hand.
1073 */ 1047 */
1074#if defined(REMINDERS) && defined(DATE_ON_CLOCK_FACE) 1048#if defined(REMINDERS) && defined(DATE_ON_CLOCK_FACE)
1075 if (show_date) 1049 if (show_date)
1076 {
1077 char date[10];
1078
1079 currentTime = time (NULL) + adjustTime; /* get the current time */
1080 tmval = localtime (&currentTime);
1081 strftime (date, sizeof (date), "%d", tmval);
1082 XDrawString (Xdisplay, W->win, X_gc, 1050 XDrawString (Xdisplay, W->win, X_gc,
1083 ctr_x - XTextWidth (Xfont, date, strlen (date)) / 2, 1051 ctr_x - XTextWidth (Xfont, clockdate, strlen (clockdate)) / 2,
1084 ctr_y + FontHeight () + (ctr_y - FontHeight ()) / 2, date, strlen (date)); 1052 ctr_y + FontHeight () + (ctr_y - FontHeight ()) / 2, clockdate, strlen (clockdate));
1085 }
1086#endif 1053#endif
1087 1054
1088 if (full_redraw) 1055 if (full_redraw)
1089 { 1056 {
1090 int mintick; 1057 int mintick;
1403 1370
1404/* 1371/*
1405 * Provide reminder by mapping the message window 1372 * Provide reminder by mapping the message window
1406 */ 1373 */
1407static void 1374static void
1408Reminder (void) 1375Reminder ()
1409{ 1376{
1410 char *beg, *next; 1377 char *beg, *next;
1411 int lines; 1378 int lines;
1412 1379
1413 if (Msg_Mapped) 1380 if (Msg_Mapped)
1476 1443
1477/* 1444/*
1478 * Loops forever, looking for stuff to do. Sleeps 1 minute if nothing to do 1445 * Loops forever, looking for stuff to do. Sleeps 1 minute if nothing to do
1479 */ 1446 */
1480static void 1447static void
1481getXevent (void) 1448getXevent ()
1482{ 1449{
1483 XEvent ev; 1450 XEvent ev;
1484 int num_fds; /* number of file descriptors being used */ 1451 int num_fds; /* number of file descriptors being used */
1485 struct timeval tm; 1452 struct timeval tm;
1486 struct tm *tmval; 1453 struct tm *tmval;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines