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.5 by sf-exg, Wed Jul 14 18:50:37 2021 UTC vs.
Revision 1.6 by root, Sat Jul 17 00:10:15 2021 UTC

36 36
37#include <dirent.h> 37#include <dirent.h>
38 38
39#include <X11/Xlib.h> 39#include <X11/Xlib.h>
40#include <X11/Xutil.h> 40#include <X11/Xutil.h>
41
42#include "ecb.h"
41 43
42#define APL_CLASS "Clock" 44#define APL_CLASS "Clock"
43#define APL_NAME "rclock" 45#define APL_NAME "rclock"
44#define MSG_CLASS "Appointment" 46#define MSG_CLASS "Appointment"
45#define MSG_NAME "Appointment" 47#define MSG_NAME "Appointment"
172#if defined (MAIL_BELL) || defined (MAIL_SPAWN) || defined (MAIL_SPOOL) 174#if defined (MAIL_BELL) || defined (MAIL_SPAWN) || defined (MAIL_SPOOL)
173# ifndef MAIL 175# ifndef MAIL
174# define MAIL 176# define MAIL
175# endif 177# endif
176#endif 178#endif
179
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, x2, 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}
177 206
178/*----------------------------------------------------------------------*/ 207/*----------------------------------------------------------------------*/
179 208
180static Display *Xdisplay; /* X display */ 209static Display *Xdisplay; /* X display */
181static int Xfd; /* file descriptor of server connection */ 210static int Xfd; /* file descriptor of server connection */
784 * Provide reminder if needed. 813 * Provide reminder if needed.
785 *----------------------------------------------------------------------*/ 814 *----------------------------------------------------------------------*/
786static void 815static void
787Draw_Window (mywindow_t * W, int full_redraw) 816Draw_Window (mywindow_t * W, int full_redraw)
788{ 817{
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; 818 static int savedDay = -1;
855 819
856 time_t currentTime; 820 time_t currentTime;
857 struct tm *tmval; 821 struct tm *tmval;
858 int ctr_x, ctr_y; 822 int ctr_x, ctr_y;
1013 977
1014 /* 978 /*
1015 * draw clock 979 * draw clock
1016 */ 980 */
1017 981
1018 ctr_x = (W->width / 2); 982 ctr_x = W->width / 2;
1019 ctr_y = (W->height / 2); 983 ctr_y = W->height / 2;
1020 984
1021#define XPOS(i,val) (ctr_x + (W->width * Sin[i%720] * (val) + 100000) / 200000) 985#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) 986#define YPOS(i,val) (ctr_y - (W->height * Sin (i + 180) + 4096) / (819200 / (val)))
1023 /* 987 /*
1024 * how to draw the clock face 988 * how to draw the clock face
1025 */ 989 */
1026 990
1027 /* calculate the positions of the hands */ 991 /* calculate the positions of the hands */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines