http://ftp.x.org/contrib/applications/xscreensaver-3.06.tar.gz
[xscreensaver] / hacks / pedal.c
index 8cde8d53666bd617bf224b809a5a682016174faa..7f8e5bd6c8470d52a08e8da3b6010cd5afea989b 100644 (file)
@@ -9,7 +9,7 @@
  *  Dale Moore  <Dale.Moore@cs.cmu.edu>
  *  24-Jun-1994
  *
- *  Copyright \(co 1994, by Carnegie Mellon University.  Permission to use,
+ *  Copyright (c) 1994, by Carnegie Mellon University.  Permission to use,
  *  copy, modify, distribute, and sell this software and its documentation
  *  for any purpose is hereby granted without fee, provided fnord that the
  *  above copyright notice appear in all copies and that both that copyright
@@ -72,12 +72,8 @@ static Bool fade_p;
 #define rand_range(a, b) (a + random() % (b - a))
 
 
-static int gcd (m, n)
-    int m;
-    int n;
-/* 
- * Greatest Common Divisor (also Greates common factor).
- */
+static int
+gcd(int m, int n) /* Greatest Common Divisor (also Greates common factor). */
 {
     int r;
 
@@ -89,10 +85,7 @@ static int gcd (m, n)
     }
 }
 
-static int numlines (a, b, d)
-    int a;
-    int b;
-    int d;
+static int numlines (int a, int b, int d)
 /*
  * Description:
  *
@@ -123,9 +116,7 @@ static int numlines (a, b, d)
 }
 
 static int
-compute_pedal(points, maxpoints)
-XPoint *points;
-int maxpoints;
+compute_pedal(XPoint *points, int maxpoints)
 /*
  * Description:
  *
@@ -199,9 +190,7 @@ int maxpoints;
 }
 
 static void
-init_pedal (dpy, window)
-     Display *dpy;
-     Window window;
+init_pedal (Display *dpy, Window window)
 {
   XGCValues gcv;
   XWindowAttributes xgwa;
@@ -230,14 +219,9 @@ init_pedal (dpy, window)
   cmap = xgwa.colormap;
 
   gcv.function = GXcopy;
-  gcv.subwindow_mode = IncludeInferiors;
   gcv.foreground = get_pixel_resource ("foreground", "Foreground", dpy, cmap);
   gcv.background = get_pixel_resource ("background", "Background", dpy, cmap);
-  gc = XCreateGC (
-       dpy,
-       window,
-       GCForeground | GCBackground |GCFunction | GCSubwindowMode ,
-       &gcv);
+  gc = XCreateGC (dpy, window, GCForeground | GCBackground |GCFunction, &gcv);
 
   if (fade_p)
   {
@@ -272,12 +256,8 @@ init_pedal (dpy, window)
 }
 
 static void
-fade_foreground (dpy, cmap, from, to, steps)
-    Display *dpy;
-    Colormap cmap;
-    XColor from;
-    XColor to;
-    int steps;
+fade_foreground (Display *dpy, Colormap cmap,
+                XColor from, XColor to, int steps)
 /*
  * This routine assumes that we have a writeable colormap.
  * That means that the default colormap is not full, and that
@@ -296,15 +276,14 @@ fade_foreground (dpy, cmap, from, to, steps)
       inbetween.blue  = from.blue  + (to.blue  - from.blue)  * i / steps ;
       XStoreColor (dpy, cmap, &inbetween);
       /* If we don't sync, these can bunch up */
-      XSync(dpy, 0);
+      XSync(dpy, False);
+      screenhack_handle_events (dpy);
       usleep(udelay);
     }
 }
 
 static void
-pedal (dpy, window)
-     Display *dpy;
-     Window window;
+pedal (Display *dpy, Window window)
 /*
  *    Since the XFillPolygon doesn't require that the last
  *    point == first point, the number of points is the same
@@ -339,13 +318,14 @@ pedal (dpy, window)
        XColor color;
        hsv_to_rgb (random()%360, 1.0, 1.0,
                   &color.red, &color.green, &color.blue);
-       XSync(dpy, 0);
+       XSync(dpy, False);
        if (fade_p)
         {
           foreground.red = color.red;
           foreground.green = color.green;
           foreground.blue = color.blue;
-          XStoreColor (dpy, cmap, &foreground);
+          /* don't do this here -- let fade_foreground() bring it up! */
+          /* XStoreColor (dpy, cmap, &foreground); */
         }
        else if (XAllocColor (dpy, cmap, &color))
         {
@@ -356,7 +336,7 @@ pedal (dpy, window)
           foreground.blue = color.blue;
           foreground.pixel = color.pixel;
         }
-       XSync(dpy, 0);
+       XSync(dpy, False);
      }
 
     /* Fade in by bringing the foreground back from background */
@@ -372,8 +352,8 @@ char *progclass = "Pedal";
  * should be dark.
  */
 char *defaults [] = {
-  "Pedal.background:           black",         /* to placate SGI */
-  "Pedal.foreground:           white",
+  ".background:                        black",
+  ".foreground:                        white",
   "*delay:                     5",
   "*fadedelay:                 200000",
   "*maxlines:                  1000",
@@ -386,19 +366,17 @@ XrmOptionDescRec options [] = {
   { "-maxlines",       ".maxlines",            XrmoptionSepArg, 0 },
   { "-foreground",      ".foreground",          XrmoptionSepArg, 0 },
   { "-background",      ".background",          XrmoptionSepArg, 0 },
+  { 0, 0, 0, 0 }
 };
 
-int options_size = (sizeof (options) / sizeof (options[0]));
-
 void
-screenhack (dpy, window)
-     Display *dpy;
-     Window window;
+screenhack (Display *dpy, Window window)
 {
     init_pedal (dpy, window);
     for (;;) {
        pedal (dpy, window);
-       XSync(dpy, 0);
+       XSync(dpy, False);
+        screenhack_handle_events (dpy);
        if (delay) sleep (delay);
     }
 }