ftp://ftp.krokus.ru/pub/OpenBSD/distfiles/xscreensaver-4.22.tar.gz
[xscreensaver] / hacks / rd-bomb.c
index b420036c92058df73f7bef0b06eca9762cfe336a..dd5253bc259974f74f6cb4dcee38824b12328b5c 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 1992, 1995, 1997, 1998
+/* xscreensaver, Copyright (c) 1992, 1995, 1997, 1998, 1999, 2003
  *  Jamie Zawinski <jwz@jwz.org>
  *
  *  reaction/diffusion textures
@@ -139,10 +139,10 @@ pixack_frame(char *pix_buf)
   if (!(frame%epoch_time)) {
     int s;
     if (0 != frame) {
-      int t = epoch_time / 500;
-      if (t > 15)
-       t = 15;
-      sleep(t);
+      int tt = epoch_time / 500;
+      if (tt > 15)
+       tt = 15;
+      sleep(tt);
     }
          
     for (i = 0; i < npix; i++) {
@@ -198,7 +198,8 @@ pixack_frame(char *pix_buf)
     int ii = i + 1;
     char *q = pix_buf + width * i;
     short *qq = ((short *) pix_buf) + width * i;
-    long  *qqq = ((long *) pix_buf) + width * i;
+/*  long  *qqq = ((long *) pix_buf) + width * i;  -- crashes on Alpha */
+    int   *qqq = ((int  *) pix_buf) + width * i;
     ushort *i1 = r1 + 1 + w2 * ii;
     ushort *i2 = r2 + 1 + w2 * ii;
     ushort *o1 = r1b + 1 + w2 * ii;
@@ -305,7 +306,7 @@ char *defaults [] = {
   "*verbose:   off",
   "*radius:    -1",
   "*speed:     0.0",
-  "*size:      0.66",
+  "*size:      1.0",
   "*delay:     1",
   "*colors:    -1",
 #ifdef HAVE_XSHM_EXTENSION
@@ -379,7 +380,7 @@ screenhack (Display *dpy, Window win)
   double array_x, array_y;
   double array_dx, array_dy;
   int w2;
-  char *p;
+  char *pd;
   int vdepth;
   int npix;
 #ifdef HAVE_XSHM_EXTENSION
@@ -436,6 +437,40 @@ screenhack (Display *dpy, Window win)
            vdepth <= 16 ? 16 :
            32);
 
+  /* Ok, this like, sucks and stuff.  There are some XFree86 systems
+     that have depth-24 visuals, that do not accept depth-32 XImages!
+     Which if you ask me is just absurd, since all it would take is
+     for the server to truncate the bits in that case.  So, this crap
+     here detects the specific case of: we have chosen depth 32;
+     and the server does not support depth 32.  In that case, we
+     try and use depth 16 instead.
+
+     The real fix would be to rewrite this program to deal with
+     depth 24 directly (or even better, arbitrary depths, but that
+     would mean going through the XImage routines instead of messing
+     with the XImage->data directly.)
+
+     jwz, 18-Mar-99: well, the X servers I have access to these days do
+     support 32-deep images on deep visuals, so I no longer have the
+     ability to test this code -- but it was causing problems on the
+     visuals that I do have, and I think that's because I mistakenly
+     wrote `pfv[i].depth' when I meant to write `pfv[i].bits_per_pixel'.
+     The symptom I was seeing was that the grid was 64x64, but the
+     images were being drawn 32x32 -- so there was a black stripe on
+     every other row.  Wow, this code sucks so much.
+   */
+  if (pdepth == 32)
+    {
+      int i, pfvc = 0;
+      Bool ok = False;
+      XPixmapFormatValues *pfv = XListPixmapFormats (dpy, &pfvc);
+      for (i = 0; i < pfvc; i++)
+        if (pfv[i].bits_per_pixel == pdepth)
+          ok = True;
+      if (!ok)
+        pdepth = 16;
+    }
+
   cmap = xgwa.colormap;
   ncolors = get_integer_resource ("colors", "Integer");
 
@@ -463,8 +498,8 @@ screenhack (Display *dpy, Window win)
     }
   }
 
-  p = malloc(npix * (pdepth == 1 ? 1 : (pdepth / 8)));
-  if (!p) {
+  pd = malloc(npix * (pdepth == 1 ? 1 : (pdepth / 8)));
+  if (!pd) {
     fprintf(stderr, "not enough memory for %d pixels.\n", npix);
     exit(1);
   }
@@ -480,8 +515,8 @@ screenhack (Display *dpy, Window win)
        use_shm = False;
       else
        {
-         free(p);
-         p = image->data;
+         free(pd);
+         pd = image->data;
        }
     }
 #endif /* HAVE_XSHM_EXTENSION */
@@ -489,7 +524,7 @@ screenhack (Display *dpy, Window win)
   if (!image)
     {
       image = XCreateImage(dpy, xgwa.visual, vdepth,
-                          ZPixmap, 0, p,
+                          ZPixmap, 0, pd,
                           width, height, 8, 0);
     }
 
@@ -497,7 +532,7 @@ screenhack (Display *dpy, Window win)
     Bool bump = False;
 
     int i, j;
-    pixack_frame(p);
+    pixack_frame(pd);
     for (i = 0; i < array_width; i += width)
       for (j = 0; j < array_height; j += height)
 #ifdef HAVE_XSHM_EXTENSION
@@ -541,6 +576,7 @@ screenhack (Display *dpy, Window win)
     frame++;
 
     XSync(dpy, False);
+    screenhack_handle_events (dpy);
     if (delay > 0)
       usleep(1000 * delay);
   }