http://ftp.x.org/contrib/applications/xscreensaver-2.16.tar.gz
[xscreensaver] / hacks / xlock.h
index a53a99a9444273dd64f9dd5962ea9c78ab1c117a..d509f563c37103b0d19aa0cfb5d4cd69ee21da40 100644 (file)
@@ -4,6 +4,14 @@
 **
 **  for xlock 2.3 and xscreensaver 1.2, 28AUG92
 **
+**  Modified for xlockmore 3.0 by Anthony Thyssen <anthony@cit.gu.edu.au>
+**  on August 1995.
+**
+**  Tweaked by jwz to work with both ANSI and K&R compilers, 10-May-97.
+**
+**    Note: this file no longer works as of (at least) xlockmore 4.03a10:
+**    see jwz's new xlockmore.h file for a similar hack that works with
+**    code written for that version.
 **
 **  To use, just copy the appropriate file from xlock, add a target
 **  for it in the Imakefile, and do the following:
@@ -38,8 +46,13 @@ static Colormap cmap;
 
 static int batchcount;
 static unsigned int delay;
+static unsigned int cycles;
 static double saturation;
 
+#ifndef min
+#define min(a,b) ((a)<(b)?(a):(b))
+#endif
+
 typedef struct {
   GC gc;
   int npixels;
@@ -52,10 +65,14 @@ static Display *dsp;
 static int screen = 0;
 
 static void
+#ifdef __STDC__
+My_XGetWindowAttributes (Display *dpy, Window win, XWindowAttributes *xgwa)
+#else /* !__STDC__ */
 My_XGetWindowAttributes (dpy, win, xgwa)
   Display *dpy;
   Window win;
   XWindowAttributes *xgwa;
+#endif /* !__STDC__ */
 {
   XGetWindowAttributes (dpy, win, xgwa);
 
@@ -75,7 +92,8 @@ My_XGetWindowAttributes (dpy, win, xgwa)
     bg_pixel = get_pixel_resource ("background", "Background", dpy, cmap);
     if (! mono_p) {
       for (npixels = 0; npixels < i; npixels++) {
-        hsv_to_rgb ((360*npixels)/i, saturation, 1.0, &color.red, &color.green, &color.blue);
+        hsv_to_rgb ((360*npixels)/i, saturation, 1.0,
+                   &color.red, &color.green, &color.blue);
         if (! XAllocColor (dpy, cmap, &color))
           break;
         pixels[npixels] = color.pixel;
@@ -86,6 +104,9 @@ My_XGetWindowAttributes (dpy, win, xgwa)
     n = get_integer_resource ("count", "Integer");
     if (n > 0) batchcount = n;
 
+    n = get_integer_resource ("cycles", "Integer");
+    if (n >= 0) cycles = n;
+
     gcv.foreground = fg_pixel;
     gcv.background = bg_pixel;
     gc = XCreateGC (dpy, win, GCForeground|GCBackground, &gcv);
@@ -113,6 +134,8 @@ char *defaults[] = {
   "*foreground:        white",
   "*ncolors:   64",
   "*delay:     -1",
+  "*count:     -1",
+  "*cycles:    -1",
   0
 };
 
@@ -120,27 +143,50 @@ XrmOptionDescRec options[] = {
   {"-count",   ".count",       XrmoptionSepArg, 0},
   {"-ncolors", ".ncolors",     XrmoptionSepArg, 0},
   {"-delay",   ".delay",       XrmoptionSepArg, 0},
+  {"-cycles",   ".cycles",      XrmoptionSepArg, 0},
+  { 0, 0, 0, 0 }
 };
-int options_size = (sizeof (options) / sizeof (options[0]));
 
-#define PROGRAM(Y,Z,D,B,S) \
-char *progclass = Y;                   \
+#if defined(__STDC__) || defined(__ANSI_CPP__)
+# define XLOCK_INIT(Z) init##Z
+# define XLOCK_DRAW(Z) draw##Z
+#else  /* K&R CPP */
+# define XLOCK_INIT(Z) init/**/Z
+# define XLOCK_DRAW(Z) draw/**/Z
+#endif /* K&R CPP */
+
+#ifdef __STDC__
+# define XLOCK_SCREENHACK_PROTOTYPE()  \
+  screenhack(Display *dpy, Window window)
+# define XLOCK_PROTOS(Z) /* */
+#else  /* K&R C */
+# define XLOCK_SCREENHACK_PROTOTYPE()  \
+  screenhack(dpy, window)              \
+       Display *dpy;                   \
+       Window window;
+# define XLOCK_PROTOS(Z)               \
+  void init##Z(Window);                        \
+  void draw##Z(Window);                        \
+
+#endif /* K&R C */
+
+#define PROGRAM(Y,Z,D,B,C,S)           \
+  char *progclass = Y;                 \
+  XLOCK_PROTOS(Z)                      \
                                        \
-void screenhack (dpy, window)          \
-  Display *dpy;                                \
-  Window window;                       \
-{                                      \
-  batchcount = B;                      \
-  delay = D;                           \
-  saturation = S;                      \
-  dsp = dpy;                           \
+  void XLOCK_SCREENHACK_PROTOTYPE()    \
+  {                                    \
+    batchcount = B;                    \
+    delay = D;                         \
+    cycles = C;                                \
+    saturation = S;                    \
+    dsp = dpy;                         \
                                        \
-  while (1) {                          \
-    init##Z (window);                  \
-    for (;;) {                         \
-      draw##Z (window);                        \
-      XSync (dpy, True);               \
-      if (delay) usleep (delay);       \
-    }                                  \
-  }                                    \
-}
+    XLOCK_INIT(Z) (window);            \
+    while (1)                          \
+      {                                        \
+       XLOCK_DRAW(Z) (window);         \
+       XSync (dpy, True);              \
+       if (delay) usleep (delay);      \
+      }                                        \
+  }