http://packetstormsecurity.org/UNIX/admin/xscreensaver-4.14.tar.gz
[xscreensaver] / hacks / blitspin.c
index e8ee26537f3b84f687e30bd8a6ee271df32dce2e..1eebcb820f957747ce22215dfa2fda5e1e099b67 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 1992-1997 Jamie Zawinski <jwz@netscape.com>
+/* xscreensaver, Copyright (c) 1992-1997, 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
  */
 
 #include "screenhack.h"
+#include "xpm-pixmap.h"
 #include <stdio.h>
 
-#ifdef HAVE_XPM
-# include <X11/xpm.h>
-# ifndef PIXEL_ALREADY_TYPEDEFED
-#  define PIXEL_ALREADY_TYPEDEFED /* Sigh, Xmu/Drawing.h needs this... */
-# endif
-#endif
-
-#ifdef HAVE_XMU
-# ifndef VMS
-#  include <X11/Xmu/Drawing.h>
-#else  /* VMS */
-#  include <Xmu/Drawing.h>
-# endif /* VMS */
-#endif
-
-#include "default.xbm"
+#include "images/som.xbm"
 
 static Display *dpy;
 static Window window;
@@ -93,93 +79,6 @@ rotate (void)
     }
 }
 
-static void
-read_bitmap (char *bitmap_name, int *widthP, int *heightP)
-{
-#ifdef HAVE_XPM
-  XWindowAttributes xgwa;
-  XpmAttributes xpmattrs;
-  int result;
-  xpmattrs.valuemask = 0;
-  bitmap = 0;
-
-  XGetWindowAttributes (dpy, window, &xgwa);
-
-# ifdef XpmCloseness
-  xpmattrs.valuemask |= XpmCloseness;
-  xpmattrs.closeness = 40000;
-# endif
-# ifdef XpmVisual
-  xpmattrs.valuemask |= XpmVisual;
-  xpmattrs.visual = xgwa.visual;
-# endif
-# ifdef XpmDepth
-  xpmattrs.valuemask |= XpmDepth;
-  xpmattrs.depth = xgwa.depth;
-# endif
-# ifdef XpmColormap
-  xpmattrs.valuemask |= XpmColormap;
-  xpmattrs.colormap = xgwa.colormap;
-# endif
-
-  result = XpmReadFileToPixmap (dpy, window, bitmap_name, &bitmap, 0,
-                               &xpmattrs);
-  switch (result)
-    {
-    case XpmColorError:
-      fprintf (stderr, "%s: warning: xpm color substitution performed\n",
-              progname);
-      /* fall through */
-    case XpmSuccess:
-      *widthP = xpmattrs.width;
-      *heightP = xpmattrs.height;
-      break;
-    case XpmFileInvalid:
-    case XpmOpenFailed:
-      bitmap = 0;
-      break;
-    case XpmColorFailed:
-      fprintf (stderr, "%s: xpm: color allocation failed\n", progname);
-      exit (-1);
-    case XpmNoMemory:
-      fprintf (stderr, "%s: xpm: out of memory\n", progname);
-      exit (-1);
-    default:
-      fprintf (stderr, "%s: xpm: unknown error code %d\n", progname, result);
-      exit (-1);
-    }
-  if (! bitmap)
-#endif
-
-#ifdef HAVE_XMU
-    {
-      int xh, yh;
-      Pixmap b2;
-      bitmap = XmuLocateBitmapFile (DefaultScreenOfDisplay (dpy), bitmap_name,
-                                   0, 0, widthP, heightP, &xh, &yh);
-      if (! bitmap)
-       {
-         fprintf (stderr, "%s: couldn't find bitmap %s\n", progname,
-                  bitmap_name);
-         exit (1);
-       }
-      b2 = XmuCreatePixmapFromBitmap (dpy, window, bitmap, *widthP, *heightP,
-                                     depth, fg, bg);
-      XFreePixmap (dpy, bitmap);
-      bitmap = b2;
-    }
-#else  /* !XMU */
-    {
-      fprintf (stderr,
-              "%s: your vendor doesn't ship the standard Xmu library.\n",
-              progname);
-      fprintf (stderr, "\tWe can't load XBM files without it.\n");
-      exit (1);
-    }
-#endif /* !XMU */
-}
-
-
 static Pixmap
 read_screen (Display *dpy, Window window, int *widthP, int *heightP)
 {
@@ -191,11 +90,11 @@ read_screen (Display *dpy, Window window, int *widthP, int *heightP)
   *widthP = xgwa.width;
   *heightP = xgwa.height;
 
-  grab_screen_image(xgwa.screen, window);
   p = XCreatePixmap(dpy, window, *widthP, *heightP, xgwa.depth);
   gcv.function = GXcopy;
   gc = XCreateGC (dpy, window, GCFunction, &gcv);
-  XCopyArea (dpy, window, p, gc, 0, 0, *widthP, *heightP, 0, 0);
+
+  load_random_image (xgwa.screen, window, p, NULL);
 
   /* Reset the window's background color... */
   XSetWindowBackground (dpy, window,
@@ -249,9 +148,9 @@ init (void)
 
   if (!strcmp (bitmap_name, "(default)"))
     {
-      width = logo_width;
-      height = logo_height;
-      bitmap = XCreatePixmapFromBitmapData (dpy, window, (char *) logo_bits,
+      width = som_width;
+      height = som_height;
+      bitmap = XCreatePixmapFromBitmapData (dpy, window, (char *) som_bits,
                                            width, height, fg, bg, depth);
       scale_up = True; /* definitely. */
     }
@@ -262,7 +161,8 @@ init (void)
     }
   else
     {
-      read_bitmap (bitmap_name, &width, &height);
+      bitmap = xpm_file_to_pixmap (dpy, window, bitmap_name,
+                                   &width, &height, 0);
       scale_up = True; /* probably? */
     }
 
@@ -299,6 +199,7 @@ init (void)
 
   display (self);
   XSync(dpy, False);
+  screenhack_handle_events (dpy);
 }
 
 static void
@@ -313,12 +214,10 @@ display (Pixmap pixmap)
       last_w = xgwa.width;
       last_h = xgwa.height;
     }
-#ifdef HAVE_XPM
   if (depth != 1)
     XCopyArea (dpy, pixmap, window, gc, 0, 0, size, size,
               (xgwa.width-size)>>1, (xgwa.height-size)>>1);
   else
-#endif
     XCopyPlane (dpy, pixmap, window, gc, 0, 0, size, size,
                (xgwa.width-size)>>1, (xgwa.height-size)>>1, 1);
 /*
@@ -326,15 +225,16 @@ display (Pixmap pixmap)
                  ((xgwa.width-size)>>1)-1, ((xgwa.height-size)>>1)-1,
                  size+2, size+2);
 */
-  XSync (dpy, True);
+  XSync (dpy, False);
+  screenhack_handle_events (dpy);
 }
 
 \f
 char *progclass = "BlitSpin";
 
 char *defaults [] = {
-  "BlitSpin.background:        black",         /* to placate SGI */
-  "BlitSpin.foreground:        white",
+  ".background:        black",
+  ".foreground:        white",
   "*delay:     500000",
   "*delay2:    500000",
   "*bitmap:    (default)",
@@ -360,6 +260,7 @@ screenhack (Display *d, Window w)
   while (1)
     {
       rotate ();
+      screenhack_handle_events (d);
       if (delay2) usleep (delay2);
     }
 }