http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.14.tar.gz
[xscreensaver] / hacks / imsmap.c
index fa861ac0be1f4177c43e762fbf5a7a5cedd58ca7..fad6a8ca4dedf993df6257e681277f1ef84c60c4 100644 (file)
@@ -16,6 +16,7 @@
 
 #include <stdio.h>
 #include <math.h>
+#include <time.h>
 #include <sys/time.h> /* for gettimeofday() */
 
 #include <X11/Xlib.h>
@@ -27,7 +28,7 @@
 #define COUNT (1 << NSTEPS)
 #define CELL(c, r) cell[((unsigned int)(c)) + ((unsigned int) (r)) * xmax]
 
-static enum mode_t { MODE_H, MODE_S, MODE_V, MODE_RANDOM } mode;
+static enum imsmap_mode { MODE_H, MODE_S, MODE_V, MODE_RANDOM } mode;
 
 static GC gc, gc2;
 static XWindowAttributes xgwa;
@@ -55,7 +56,7 @@ init_map (Display *dpy, Window window)
   int fg_h, bg_h;
   double fg_s, fg_v, bg_s, bg_v;
 
-  enum mode_t this_mode;
+  enum imsmap_mode this_mode;
   static Bool rv_p;
     
   XGCValues gcv;
@@ -77,6 +78,7 @@ init_map (Display *dpy, Window window)
 
       if (ncolors <= 2) ncolors = 0;
       if (ncolors == 0) mono_p = True;
+      if (ncolors > 255) ncolors = 255;  /* too many look bad */
 
       fg_pixel = get_pixel_resource ("background", "Background", dpy, cmap);
       bg_pixel = get_pixel_resource ("foreground", "Foreground", dpy, cmap);
@@ -417,7 +419,7 @@ draw_map (Display *dpy, Window window)
              if (cycle_p)
                {
                  struct timeval now;
-                 static struct timeval then = { 0, };
+                 static struct timeval then = { 0, };
                  unsigned long diff;
 #ifdef GETTIMEOFDAY_TWO_ARGS
                  struct timezone tzp;
@@ -439,14 +441,15 @@ draw_map (Display *dpy, Window window)
       xstep = xnextStep;
       ystep = ynextStep;
       if (!mono_p)
-       XSync (dpy, True);
+       XSync (dpy, False);
+      screenhack_handle_events (dpy);
     }
   if (mono_p)
     /* in mono-mode, we do all the drawing at the end */
     floyd_steinberg (dpy, window);
   
   free (cell);
-  XSync (dpy, True);
+  XSync (dpy, False);
 }
 
 
@@ -493,10 +496,14 @@ screenhack (Display *dpy, Window window)
                    rotate_colors (dpy, cmap, colors, ncolors,
                                   cycle_direction);
                    if (cycle_delay) usleep(cycle_delay);
+                    screenhack_handle_events (dpy);
                  }
              }
            else
-             sleep (delay);
+              {
+                screenhack_handle_events (dpy);
+                sleep (delay);
+              }
          }
       }
 }