http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.14.tar.gz
[xscreensaver] / hacks / halo.c
index 80166335b6235c4d0adf0cfb83840acdc4796f72..fc69ea730af60d27e8f3709fba42ce335a0ababe 100644 (file)
@@ -1,5 +1,5 @@
-/* xscreensaver, Copyright (c) 1993, 1995, 1996, 1997
- *  Jamie Zawinski <jwz@netscape.com>
+/* xscreensaver, Copyright (c) 1993, 1995, 1996, 1997, 1998, 1999, 2003
+ *  Jamie Zawinski <jwz@jwz.org>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
@@ -126,6 +126,11 @@ init_circles (Display *dpy, Window window)
 
   cycle_p = mono_p ? False : get_boolean_resource ("cycle", "Cycle");
 
+  /* If the visual isn't color-indexed, don't bother trying to
+     allocate writable cells. */
+  if (cycle_p && !has_writable_cells (xgwa.screen, xgwa.visual))
+    cycle_p = False;
+
 
   if (mono_p)
     ;
@@ -207,6 +212,8 @@ run_circles (Display *dpy, Window window)
   static Bool first_time_p = True;
   Bool done = False;
   Bool inhibit_sleep = False;
+  static int clear_tick = 0;
+
   XFillRectangle (dpy, pixmap, erase_gc, 0, 0, width, height);
   for (i = 0; i < count; i++)
     {
@@ -250,7 +257,7 @@ run_circles (Display *dpy, Window window)
   if (cycle_p && cmode != seuss_mode)
     {
       struct timeval now;
-      static struct timeval then = { 0, };
+      static struct timeval then = { 0, };
       unsigned long diff;
 #ifdef GETTIMEOFDAY_TWO_ARGS
       struct timezone tzp;
@@ -307,25 +314,15 @@ run_circles (Display *dpy, Window window)
              XSetBackground (dpy, copy_gc, colors [bg_index].pixel);
            }
        }
-#if 1
       /* Sometimes go out from the inside instead of the outside */
-      else if ((random () % 10) == 0)
+      else if (clear_tick == 0 && ((random () % 3) == 0))
        {
-# if 0
-         if (! mono_p)
-           {
-             unsigned long swap = fg_index;
-             fg_index = bg_index;
-             bg_index = swap;
-             XSetForeground (dpy, copy_gc, colors [fg_index].pixel);
-             XSetBackground (dpy, copy_gc, colors [bg_index].pixel);
-           }
-# endif
          iterations = 0; /* ick */
          for (i = 0; i < count; i++)
            circles [i].radius %= circles [i].increment;
+
+          clear_tick = ((random() % 8) + 4) | 1;   /* must be odd */
        }
-#endif
       else
        {
          oiterations = iterations;
@@ -365,7 +362,7 @@ run_circles (Display *dpy, Window window)
                 : (iterations & 1)))
     {
       XCopyPlane (dpy, buffer, window, copy_gc, 0, 0, width, height, 0, 0, 1);
-      XSync (dpy, True);
+      XSync (dpy, False);
       if (anim_p && done)
        XFillRectangle (dpy, buffer, erase_gc, 0, 0, width, height);
     }
@@ -374,7 +371,7 @@ run_circles (Display *dpy, Window window)
   XCopyPlane (dpy, pixmap, window, copy_gc, 0,0,width,height,width,height, 1);
   if (buffer)
     XCopyPlane (dpy, buffer, window, copy_gc, 0,0,width,height,0,height, 1);
-  XSync (dpy, True);
+  XSync (dpy, False);
 #endif
 
   if (done)
@@ -393,23 +390,39 @@ run_circles (Display *dpy, Window window)
          if (! (random() % 10))
            direction = -1;
        }
-      if (done)
-       really_first_p = False;
 
       XSync(dpy, False);
+      screenhack_handle_events (dpy);
 
       if (cycle_p && cycle_delay)
        {
-         int i = 0;
+          i = 0;
          while (i < d)
            {
              rotate_colors (dpy, cmap, colors, ncolors, direction);
              usleep(cycle_delay);
+              screenhack_handle_events (dpy);
              i += cycle_delay;
            }
        }
+      else if (cmode != seuss_mode &&
+               done && !really_first_p && cycle_delay > 0)
+        usleep (cycle_delay * 50);
       else
-       usleep (d);
+        usleep (d);
+
+      if (done)
+       really_first_p = False;
+    }
+
+  if (done && clear_tick > 0)
+    {
+      clear_tick--;
+      if (!clear_tick)
+        {
+          XClearWindow (dpy, window);
+          if (buffer) XFillRectangle (dpy, buffer, erase_gc, 0,0,width,height);
+        }
     }
 }
 
@@ -417,8 +430,8 @@ run_circles (Display *dpy, Window window)
 char *progclass = "Halo";
 
 char *defaults [] = {
-  "*background:                black",
-  "*foreground:                white",
+  ".background:                black",
+  ".foreground:                white",
   "*colorMode:         random",
   "*colors:            100",
   "*cycle:             true",
@@ -446,5 +459,8 @@ screenhack (Display *dpy, Window window)
 {
   init_circles (dpy, window);
   while (1)
-    run_circles (dpy, window);
+    {
+      run_circles (dpy, window);
+      screenhack_handle_events (dpy);
+    }
 }