#include <X11/Xlib.h>
#include <X11/Xos.h>
-#if __STDC__
-# define bcopy(from,to,size) memcpy((to),(from),(size))
-# define bzero(addr,size) memset((addr),0,(size))
-extern void screenhack_usleep (unsigned long);
-#else
+extern int get_visual_class ();
extern void screenhack_usleep ();
-#endif
-
#define usleep screenhack_usleep
#define MAX_COLORS 4096
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++)
for (i = 0; i < ncolors; i++)
orig_colors [i].pixel = i;
XQueryColors (dpy, cmap, orig_colors, ncolors);
- bcopy (orig_colors, current_colors, ncolors * sizeof (XColor));
+ memcpy (current_colors, orig_colors, ncolors * sizeof (XColor));
for (i = (out_p ? steps : 0);
(out_p ? i > 0 : i < steps);
int j;
for (j = 0; j < ncolors; j++)
{
- current_colors[j].red = (int)orig_colors[j].red * i / steps;
- current_colors[j].green = (int)orig_colors[j].green * i / steps;
- current_colors[j].blue = (int)orig_colors[j].blue * i / steps;
+ current_colors[j].red = orig_colors[j].red * i / steps;
+ current_colors[j].green = orig_colors[j].green * i / steps;
+ current_colors[j].blue = orig_colors[j].blue * i / steps;
}
XStoreColors (dpy, cmap2, current_colors, ncolors);
XSync (dpy, False);