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.4 by root, Mon May 10 00:40:41 2021 UTC vs.
Revision 1.9 by root, Sun Nov 14 17:26:28 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"
40 43
41#define APL_CLASS "Clock" 44#define APL_CLASS "Clock"
42#define APL_NAME "rclock" 45#define APL_NAME "rclock"
43#define MSG_CLASS "Appointment" 46#define MSG_CLASS "Appointment"
44#define MSG_NAME "Appointment" 47#define MSG_NAME "Appointment"
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 (); 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 (); 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
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 778
748#ifdef MAIL 779#ifdef MAIL
749static int 780static int
750MailAvailable () 781MailAvailable ()
781 * Redraw the whole window after an exposure or size change. 812 * Redraw the whole window after an exposure or size change.
782 * After a timeout, only redraw the hands. 813 * After a timeout, only redraw the hands.
783 * Provide reminder if needed. 814 * Provide reminder if needed.
784 *----------------------------------------------------------------------*/ 815 *----------------------------------------------------------------------*/
785static void 816static void
786Draw_Window (mywindow_t * W, int full_redraw) 817Draw_Window (mywindow_t *W, int full_redraw)
787{ 818{
788 /* pre-computed values for sin() x1000, to avoid using floats */
789 static const short Sin[720] = {
790 0,
791 9, 17, 26, 35, 44, 52, 61, 70, 78, 87, 96, 105,
792 113, 122, 131, 139, 148, 156, 165, 174, 182, 191, 199, 208,
793 216, 225, 233, 242, 250, 259, 267, 276, 284, 292, 301, 309,
794 317, 326, 334, 342, 350, 358, 367, 375, 383, 391, 399, 407,
795 415, 423, 431, 438, 446, 454, 462, 469, 477, 485, 492, 500,
796 508, 515, 522, 530, 537, 545, 552, 559, 566, 574, 581, 588,
797 595, 602, 609, 616, 623, 629, 636, 643, 649, 656, 663, 669,
798 676, 682, 688, 695, 701, 707, 713, 719, 725, 731, 737, 743,
799 749, 755, 760, 766, 772, 777, 783, 788, 793, 799, 804, 809,
800 814, 819, 824, 829, 834, 839, 843, 848, 853, 857, 862, 866,
801 870, 875, 879, 883, 887, 891, 895, 899, 903, 906, 910, 914,
802 917, 921, 924, 927, 930, 934, 937, 940, 943, 946, 948, 951,
803 954, 956, 959, 961, 964, 966, 968, 970, 972, 974, 976, 978,
804 980, 982, 983, 985, 986, 988, 989, 990, 991, 993, 994, 995,
805 995, 996, 997, 998, 998, 999, 999, 999, 1000, 1000, 1000, 1000,
806 1000, 1000, 1000, 999, 999, 999, 998, 998, 997, 996, 995, 995,
807 994, 993, 991, 990, 989, 988, 986, 985, 983, 982, 980, 978,
808 976, 974, 972, 970, 968, 966, 964, 961, 959, 956, 954, 951,
809 948, 946, 943, 940, 937, 934, 930, 927, 924, 921, 917, 914,
810 910, 906, 903, 899, 895, 891, 887, 883, 879, 875, 870, 866,
811 862, 857, 853, 848, 843, 839, 834, 829, 824, 819, 814, 809,
812 804, 799, 793, 788, 783, 777, 772, 766, 760, 755, 749, 743,
813 737, 731, 725, 719, 713, 707, 701, 695, 688, 682, 676, 669,
814 663, 656, 649, 643, 636, 629, 623, 616, 609, 602, 595, 588,
815 581, 574, 566, 559, 552, 545, 537, 530, 523, 515, 508, 500,
816 492, 485, 477, 469, 462, 454, 446, 438, 431, 423, 415, 407,
817 399, 391, 383, 375, 367, 358, 350, 342, 334, 326, 317, 309,
818 301, 292, 284, 276, 267, 259, 250, 242, 233, 225, 216, 208,
819 199, 191, 182, 174, 165, 156, 148, 139, 131, 122, 113, 105,
820 96, 87, 78, 70, 61, 52, 44, 35, 26, 17, 9, 0,
821 -9, -17, -26, -35, -44, -52, -61, -70, -78, -87, -96, -105,
822 -113, -122, -131, -139, -148, -156, -165, -174, -182, -191, -199, -208,
823 -216, -225, -233, -242, -250, -259, -267, -276, -284, -292, -301, -309,
824 -317, -326, -334, -342, -350, -358, -366, -375, -383, -391, -399, -407,
825 -415, -423, -431, -438, -446, -454, -462, -469, -477, -485, -492, -500,
826 -508, -515, -522, -530, -537, -545, -552, -559, -566, -574, -581, -588,
827 -595, -602, -609, -616, -623, -629, -636, -643, -649, -656, -663, -669,
828 -676, -682, -688, -695, -701, -707, -713, -719, -725, -731, -737, -743,
829 -749, -755, -760, -766, -772, -777, -783, -788, -793, -799, -804, -809,
830 -814, -819, -824, -829, -834, -839, -843, -848, -853, -857, -862, -866,
831 -870, -875, -879, -883, -887, -891, -895, -899, -903, -906, -910, -914,
832 -917, -921, -924, -927, -930, -934, -937, -940, -943, -946, -948, -951,
833 -954, -956, -959, -961, -964, -966, -968, -970, -972, -974, -976, -978,
834 -980, -982, -983, -985, -986, -988, -989, -990, -991, -993, -994, -995,
835 -995, -996, -997, -998, -998, -999, -999, -999, -1000, -1000, -1000, -1000,
836 -1000, -1000, -1000, -999, -999, -999, -998, -998, -997, -996, -995, -995,
837 -994, -993, -991, -990, -989, -988, -986, -985, -983, -982, -980, -978,
838 -976, -974, -972, -970, -968, -966, -964, -961, -959, -956, -954, -951,
839 -948, -946, -943, -940, -937, -934, -930, -927, -924, -921, -917, -914,
840 -910, -906, -903, -899, -895, -891, -887, -883, -879, -875, -870, -866,
841 -862, -857, -853, -848, -843, -839, -834, -829, -824, -819, -814, -809,
842 -804, -799, -793, -788, -783, -777, -772, -766, -760, -755, -749, -743,
843 -737, -731, -725, -719, -713, -707, -701, -695, -688, -682, -676, -669,
844 -663, -656, -649, -643, -636, -629, -623, -616, -609, -602, -595, -588,
845 -581, -574, -566, -559, -552, -545, -537, -530, -523, -515, -508, -500,
846 -492, -485, -477, -469, -462, -454, -446, -438, -431, -423, -415, -407,
847 -399, -391, -383, -375, -367, -358, -350, -342, -334, -326, -317, -309,
848 -301, -292, -284, -276, -267, -259, -250, -242, -233, -225, -216, -208,
849 -199, -191, -182, -174, -165, -156, -148, -139, -131, -122, -113, -105,
850 -96, -87, -78, -70, -61, -52, -44, -35, -26, -17, -9,
851 };
852
853 static int savedDay = -1; 819 static int savedDay = -1;
854 820
855 time_t currentTime; 821 time_t currentTime;
856 struct tm *tmval; 822 struct tm *tmval;
857 int ctr_x, ctr_y; 823 int ctr_x, ctr_y;
974 Xgc, 940 Xgc,
975 (Msg.width - 941 (Msg.width -
976 XTextWidth (Xfont, beg, (end - beg))) / 2, 10 + Xfont->ascent + FontHeight () * lines, beg, (end - beg)); 942 XTextWidth (Xfont, beg, (end - beg))) / 2, 10 + Xfont->ascent + FontHeight () * lines, beg, (end - beg));
977 } 943 }
978 944
979 XDrawString (Xdisplay, msgButton.Dismiss, Xrvgc, (msgButton.width - XTextWidth (Xfont, "Done", 4)) / 2, Xfont->ascent + 2, "Done", 4); 945 XDrawString (Xdisplay, msgButton.Dismiss, Xrvgc, (msgButton.width - XTextWidth (Xfont, "Done" , 4)) / 2, Xfont->ascent + 2, "Done", 4);
980 946
981 XDrawString (Xdisplay, msgButton.Defer, Xrvgc, (msgButton.width - XTextWidth (Xfont, "Defer", 5)) / 2, Xfont->ascent + 2, "Defer", 5); 947 XDrawString (Xdisplay, msgButton.Defer , Xrvgc, (msgButton.width - XTextWidth (Xfont, "Defer", 5)) / 2, Xfont->ascent + 2, "Defer", 5);
982 948
983# ifndef NO_REMINDER_EXEC 949# ifndef NO_REMINDER_EXEC
984 XDrawString (Xdisplay, msgButton.Start, Xrvgc, (msgButton.width - XTextWidth (Xfont, "Start", 5)) / 2, Xfont->ascent + 2, "Start", 5); 950 XDrawString (Xdisplay, msgButton.Start , Xrvgc, (msgButton.width - XTextWidth (Xfont, "Start", 5)) / 2, Xfont->ascent + 2, "Start", 5);
985 951
986 if (strlen (execPrgm) > 1) 952 if (strlen (execPrgm) > 1)
987 XMapWindow (Xdisplay, msgButton.Start); 953 XMapWindow (Xdisplay, msgButton.Start);
988 else 954 else
989 XUnmapWindow (Xdisplay, msgButton.Start); 955 XUnmapWindow (Xdisplay, msgButton.Start);
1012 978
1013 /* 979 /*
1014 * draw clock 980 * draw clock
1015 */ 981 */
1016 982
1017 ctr_x = (W->width / 2); 983 ctr_x = W->width / 2;
1018 ctr_y = (W->height / 2); 984 ctr_y = W->height / 2;
1019 985
1020#define XPOS(i,val) (ctr_x + (W->width * Sin[i%720] * (val) + 100000) / 200000) 986#define XPOS(i,val) (ctr_x + (W->width * Sin (i ) + 4096) / (819200 / (val)))
1021#define YPOS(i,val) (ctr_y - (W->height * Sin[(i+180)%720] * (val) + 100000) / 200000) 987#define YPOS(i,val) (ctr_y - (W->height * Sin (i + 180) + 4096) / (819200 / (val)))
1022 /* 988 /*
1023 * how to draw the clock face 989 * how to draw the clock face
1024 */ 990 */
1025 991
1026 /* calculate the positions of the hands */ 992 /* calculate the positions of the hands */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines