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
8 ** To use, just copy the appropriate file from xlock, add a target
9 ** for it in the Imakefile, and do the following:
11 ** 1) If you include math.h, make sure it is before xlock.h.
12 ** 2) Make sure the first thing you do in initfoo() is to call
13 ** XGetWindowAttributes. This is what actually sets up the
14 ** colormap and whatnot.
15 ** 3) Add an appropriate PROGRAM() line at the end of the .c file.
16 ** The information you need for this comes from xlock's file
19 ** That's about all there is to it.
21 ** As an added bonus, if you put an empty definition of PROGRAM() in
22 ** xlock's xlock.h, you can now use the code with either xlock or
26 ** If you make any improvements to this code, please send them to me!
27 ** It could certainly use some more work.
30 #include "screenhack.h"
35 static unsigned long *pixels = 0, fg_pixel, bg_pixel;
39 static int batchcount;
40 static unsigned int delay;
41 static double saturation;
49 static perscreen Scr[MAXSCREENS];
52 static int screen = 0;
55 My_XGetWindowAttributes (dpy, win, xgwa)
58 XWindowAttributes *xgwa;
60 XGetWindowAttributes (dpy, win, xgwa);
68 cmap = xgwa->colormap;
70 i = get_integer_resource ("ncolors", "Integer");
71 if (i <= 2) i = 2, mono_p = True;
73 pixels = (unsigned long *) calloc (i, sizeof (unsigned long));
74 fg_pixel = get_pixel_resource ("foreground", "Foreground", dpy, cmap);
75 bg_pixel = get_pixel_resource ("background", "Background", dpy, cmap);
77 for (npixels = 0; npixels < i; npixels++) {
78 hsv_to_rgb ((360*npixels)/i, saturation, 1.0, &color.red, &color.green, &color.blue);
79 if (! XAllocColor (dpy, cmap, &color))
81 pixels[npixels] = color.pixel;
84 n = get_integer_resource ("delay", "Usecs");
85 if (n >= 0) delay = n;
86 n = get_integer_resource ("count", "Integer");
87 if (n > 0) batchcount = n;
89 gcv.foreground = fg_pixel;
90 gcv.background = bg_pixel;
91 gc = XCreateGC (dpy, win, GCForeground|GCBackground, &gcv);
93 XClearWindow (dpy, win);
96 Scr[screen].npixels = npixels;
97 Scr[screen].pixels = pixels;
101 #define XGetWindowAttributes(a,b,c) My_XGetWindowAttributes(a,b,c)
104 #define BlackPixel(a,b) bg_pixel
106 #define WhitePixel(a,b) fg_pixel
109 #define seconds() time((time_t*)0)
112 "*background: black",
113 "*foreground: white",
119 XrmOptionDescRec options[] = {
120 {"-count", ".count", XrmoptionSepArg, 0},
121 {"-ncolors", ".ncolors", XrmoptionSepArg, 0},
122 {"-delay", ".delay", XrmoptionSepArg, 0},
124 int options_size = (sizeof (options) / sizeof (options[0]));
126 #define PROGRAM(Y,Z,D,B,S) \
127 char *progclass = Y; \
129 void screenhack (dpy, window) \
143 if (delay) usleep (delay); \