2 ** Helpful definitions for porting xlock modes to xscreensaver.
3 ** by Charles Hannum, mycroft@ai.mit.edu
5 ** for xlock 2.3 and xscreensaver 1.2, 28AUG92
7 ** Modified for xlockmore 3.0 by Anthony Thyssen <anthony@cit.gu.edu.au>
10 ** Tweaked by jwz to work with both ANSI and K&R compilers, 10-May-97.
12 ** Note: this file no longer works as of (at least) xlockmore 4.03a10:
13 ** see jwz's new xlockmore.h file for a similar hack that works with
14 ** code written for that version.
16 ** To use, just copy the appropriate file from xlock, add a target
17 ** for it in the Imakefile, and do the following:
19 ** 1) If you include math.h, make sure it is before xlock.h.
20 ** 2) Make sure the first thing you do in initfoo() is to call
21 ** XGetWindowAttributes. This is what actually sets up the
22 ** colormap and whatnot.
23 ** 3) Add an appropriate PROGRAM() line at the end of the .c file.
24 ** The information you need for this comes from xlock's file
27 ** That's about all there is to it.
29 ** As an added bonus, if you put an empty definition of PROGRAM() in
30 ** xlock's xlock.h, you can now use the code with either xlock or
34 ** If you make any improvements to this code, please send them to me!
35 ** It could certainly use some more work.
38 #include "screenhack.h"
43 static unsigned long *pixels = 0, fg_pixel, bg_pixel;
47 static int batchcount;
48 static unsigned int delay;
49 static unsigned int cycles;
50 static double saturation;
53 #define min(a,b) ((a)<(b)?(a):(b))
62 static perscreen Scr[MAXSCREENS];
65 static int screen = 0;
69 My_XGetWindowAttributes (Display *dpy, Window win, XWindowAttributes *xgwa)
71 My_XGetWindowAttributes (dpy, win, xgwa)
74 XWindowAttributes *xgwa;
75 #endif /* !__STDC__ */
77 XGetWindowAttributes (dpy, win, xgwa);
85 cmap = xgwa->colormap;
87 i = get_integer_resource ("ncolors", "Integer");
88 if (i <= 2) i = 2, mono_p = True;
90 pixels = (unsigned long *) calloc (i, sizeof (unsigned long));
91 fg_pixel = get_pixel_resource ("foreground", "Foreground", dpy, cmap);
92 bg_pixel = get_pixel_resource ("background", "Background", dpy, cmap);
94 for (npixels = 0; npixels < i; npixels++) {
95 hsv_to_rgb ((360*npixels)/i, saturation, 1.0,
96 &color.red, &color.green, &color.blue);
97 if (! XAllocColor (dpy, cmap, &color))
99 pixels[npixels] = color.pixel;
102 n = get_integer_resource ("delay", "Usecs");
103 if (n >= 0) delay = n;
104 n = get_integer_resource ("count", "Integer");
105 if (n > 0) batchcount = n;
107 n = get_integer_resource ("cycles", "Integer");
108 if (n >= 0) cycles = n;
110 gcv.foreground = fg_pixel;
111 gcv.background = bg_pixel;
112 gc = XCreateGC (dpy, win, GCForeground|GCBackground, &gcv);
114 XClearWindow (dpy, win);
117 Scr[screen].npixels = npixels;
118 Scr[screen].pixels = pixels;
122 #define XGetWindowAttributes(a,b,c) My_XGetWindowAttributes(a,b,c)
125 #define BlackPixel(a,b) bg_pixel
127 #define WhitePixel(a,b) fg_pixel
130 #define seconds() time((time_t*)0)
133 "*background: black",
134 "*foreground: white",
142 XrmOptionDescRec options[] = {
143 {"-count", ".count", XrmoptionSepArg, 0},
144 {"-ncolors", ".ncolors", XrmoptionSepArg, 0},
145 {"-delay", ".delay", XrmoptionSepArg, 0},
146 {"-cycles", ".cycles", XrmoptionSepArg, 0},
150 #if defined(__STDC__) || defined(__ANSI_CPP__)
151 # define XLOCK_INIT(Z) init##Z
152 # define XLOCK_DRAW(Z) draw##Z
154 # define XLOCK_INIT(Z) init/**/Z
155 # define XLOCK_DRAW(Z) draw/**/Z
159 # define XLOCK_SCREENHACK_PROTOTYPE() \
160 screenhack(Display *dpy, Window window)
161 # define XLOCK_PROTOS(Z) /* */
163 # define XLOCK_SCREENHACK_PROTOTYPE() \
164 screenhack(dpy, window) \
167 # define XLOCK_PROTOS(Z) \
168 void init##Z(Window); \
169 void draw##Z(Window); \
173 #define PROGRAM(Y,Z,D,B,C,S) \
174 char *progclass = Y; \
177 void XLOCK_SCREENHACK_PROTOTYPE() \
185 XLOCK_INIT(Z) (window); \
188 XLOCK_DRAW(Z) (window); \
190 if (delay) usleep (delay); \