X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utils%2Ffade.c;h=170cd39e604fad7c6213e957255bc6375e7d46a3;hb=88134d551a9911995c013c5ed06a32c2b1044b85;hp=c6c77a0cfee8e8709de65c78dd07633a7c025004;hpb=0cac953ce8d5139c1a264b417951ee15a3176b51;p=xscreensaver diff --git a/utils/fade.c b/utils/fade.c index c6c77a0c..170cd39e 100644 --- a/utils/fade.c +++ b/utils/fade.c @@ -17,6 +17,7 @@ #include #include +extern int get_visual_class (); extern void screenhack_usleep (); #define usleep screenhack_usleep @@ -31,13 +32,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++)