ftp://ftp.uni-heidelberg.de/pub/X11/contrib/applications/xscreensaver-1.25.tar.Z
[xscreensaver] / utils / fade.c
index c6c77a0cfee8e8709de65c78dd07633a7c025004..16f815ce066488b3d18dd477a193b29842e3df43 100644 (file)
@@ -1,4 +1,4 @@
-/* xscreensaver, Copyright (c) 1992 Jamie Zawinski <jwz@lucid.com>
+/* xscreensaver, Copyright (c) 1992 Jamie Zawinski <jwz@mcom.com>
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
  * documentation for any purpose is hereby granted without fee, provided that
 #include <X11/Xlib.h>
 #include <X11/Xos.h>
 
-extern void screenhack_usleep ();
+#if __STDC__
+# define P(x)x
+#else
+# define P(x)()
+#endif
+
+extern int get_visual_class P((Display *, Visual *));
+extern void screenhack_usleep P((int));
 #define usleep screenhack_usleep
 
 #define MAX_COLORS 4096
@@ -31,13 +38,23 @@ copy_colormap (dpy, cmap, into_cmap)
      Colormap cmap, into_cmap;
 {
   int i;
-  ncolors = CellsOfScreen (DefaultScreenOfDisplay (dpy));
+  Screen *screen = DefaultScreenOfDisplay (dpy);
+  Visual *visual = DefaultVisualOfScreen (screen);
+  Window window = RootWindowOfScreen (screen);
+  int vclass = get_visual_class (dpy, visual);
+
+  ncolors = CellsOfScreen (screen);
+
+  /* If this is a colormap on a mono visual, or one with insanely many
+     color cells, bug out. */
   if (ncolors <= 2 || ncolors > MAX_COLORS)
     return 0;
+  /* If this is a non-writable visual, bug out. */
+  if (vclass == StaticGray || vclass == StaticColor || vclass == TrueColor)
+    return 0;
+
   if (! into_cmap)
-    into_cmap = XCreateColormap (dpy, RootWindow (dpy, DefaultScreen (dpy)),
-                                DefaultVisual (dpy, DefaultScreen (dpy)),
-                                AllocAll);
+    into_cmap = XCreateColormap (dpy, window, visual, AllocAll);
   if (! cmap)
     cmap = DefaultColormap (dpy, DefaultScreen (dpy));
   for (i = 0; i < ncolors; i++)