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 ** Modified for xlockmore 3.0 by Anthony Thyssen <anthony@cit.gu.edu.au>
11 ** To use, just copy the appropriate file from xlock, add a target
12 ** for it in the Imakefile, and do the following:
14 ** 1) If you include math.h, make sure it is before xlock.h.
15 ** 2) Make sure the first thing you do in initfoo() is to call
16 ** XGetWindowAttributes. This is what actually sets up the
17 ** colormap and whatnot.
18 ** 3) Add an appropriate PROGRAM() line at the end of the .c file.
19 ** The information you need for this comes from xlock's file
22 ** That's about all there is to it.
24 ** As an added bonus, if you put an empty definition of PROGRAM() in
25 ** xlock's xlock.h, you can now use the code with either xlock or
29 ** If you make any improvements to this code, please send them to me!
30 ** It could certainly use some more work.
33 #include "screenhack.h"
38 static unsigned long *pixels = 0, fg_pixel, bg_pixel;
42 static int batchcount;
43 static unsigned int delay;
44 static unsigned int cycles;
45 static double saturation;
48 #define min(a,b) ((a)<(b)?(a):(b))
57 static perscreen Scr[MAXSCREENS];
60 static int screen = 0;
63 My_XGetWindowAttributes (dpy, win, xgwa)
66 XWindowAttributes *xgwa;
68 XGetWindowAttributes (dpy, win, xgwa);
76 cmap = xgwa->colormap;
78 i = get_integer_resource ("ncolors", "Integer");
79 if (i <= 2) i = 2, mono_p = True;
81 pixels = (unsigned long *) calloc (i, sizeof (unsigned long));
82 fg_pixel = get_pixel_resource ("foreground", "Foreground", dpy, cmap);
83 bg_pixel = get_pixel_resource ("background", "Background", dpy, cmap);
85 for (npixels = 0; npixels < i; npixels++) {
86 hsv_to_rgb ((360*npixels)/i, saturation, 1.0,
87 &color.red, &color.green, &color.blue);
88 if (! XAllocColor (dpy, cmap, &color))
90 pixels[npixels] = color.pixel;
93 n = get_integer_resource ("delay", "Usecs");
94 if (n >= 0) delay = n;
95 n = get_integer_resource ("count", "Integer");
96 if (n > 0) batchcount = n;
98 n = get_integer_resource ("cycles", "Integer");
99 if (n >= 0) cycles = n;
101 gcv.foreground = fg_pixel;
102 gcv.background = bg_pixel;
103 gc = XCreateGC (dpy, win, GCForeground|GCBackground, &gcv);
105 XClearWindow (dpy, win);
108 Scr[screen].npixels = npixels;
109 Scr[screen].pixels = pixels;
113 #define XGetWindowAttributes(a,b,c) My_XGetWindowAttributes(a,b,c)
116 #define BlackPixel(a,b) bg_pixel
118 #define WhitePixel(a,b) fg_pixel
121 #define seconds() time((time_t*)0)
124 "*background: black",
125 "*foreground: white",
133 XrmOptionDescRec options[] = {
134 {"-count", ".count", XrmoptionSepArg, 0},
135 {"-ncolors", ".ncolors", XrmoptionSepArg, 0},
136 {"-delay", ".delay", XrmoptionSepArg, 0},
137 {"-cycles", ".cycles", XrmoptionSepArg, 0},
139 int options_size = (sizeof (options) / sizeof (options[0]));
141 #define PROGRAM(Y,Z,D,B,C,S) \
142 char *progclass = Y; \
144 void screenhack (dpy, window) \
158 if (delay) usleep (delay); \