void set_colormap(void) {
void set_colormap(int reset) {
void set_colormap(void) {	static int first = 1;	static XColor color[NCOLOR], prev[NCOLOR];	Colormap cmap;	Visual *vis;	int i, ncells, diffs = 0;	if (first) {		screen->colourMap.count = NCOLOR;		screen->serverFormat.trueColour = FALSE;		screen->colourMap.is16 = TRUE;		screen->colourMap.data.shorts = (unsigned short*)			malloc(3*sizeof(short) * NCOLOR);	}	for (i=0; i < NCOLOR; i++) {		prev[i].red   = color[i].red;		prev[i].green = color[i].green;		prev[i].blue  = color[i].blue;	}	X_LOCK;	cmap = DefaultColormap(dpy, scr);	ncells = CellsOfScreen(ScreenOfDisplay(dpy, scr));	vis = default_visual;	if (subwin) {		XWindowAttributes attr;		if (XGetWindowAttributes(dpy, window, &attr)) {			cmap = attr.colormap;			vis = attr.visual;			ncells = vis->map_entries;		}	}	if (first && ncells != NCOLOR) {		if (! quiet) {			fprintf(stderr, "set_colormap: number of cells is %d "			    "instead of %d.\n", ncells, NCOLOR);		}		screen->colourMap.count = ncells;	}	if (flash_cmap && ! first) {		XWindowAttributes attr;		Window r, c;		int rx, ry, wx, wy, tries = 0;		unsigned int m;		c = window;		while (c && tries++ < 16) {			/* XXX XQueryTree somehow? */			XQueryPointer(dpy, c, &r, &c, &rx, &ry, &wx, &wy, &m);			if (c && XGetWindowAttributes(dpy, c, &attr)) {				if (attr.colormap && attr.map_installed) {					cmap = attr.colormap;					vis = attr.visual;					ncells = vis->map_entries;					break;				}			} else {				break;			}		}	}	if (ncells > NCOLOR && ! quiet) {		fprintf(stderr, "set_colormap: big problem: ncells=%d > %d\n",		    ncells, NCOLOR);	}	if (vis->class == TrueColor || vis->class == DirectColor) {		/*		 * Kludge to make 8bpp TrueColor & DirectColor be like		 * the StaticColor map.  The ncells = 8 is "8 per subfield"		 * mentioned in xdpyinfo.  Looks OK... perhaps fortuitously.		 */		if (ncells == 8) {			ncells = NCOLOR;		}	}	for (i=0; i < ncells; i++) {		color[i].pixel = i;		color[i].pad = 0;	}	XQueryColors(dpy, cmap, color, ncells);	X_UNLOCK;	for(i=0; i < ncells; i++) {		screen->colourMap.data.shorts[i*3+0] = color[i].red;		screen->colourMap.data.shorts[i*3+1] = color[i].green;		screen->colourMap.data.shorts[i*3+2] = color[i].blue;		if (prev[i].red   != color[i].red ||		    prev[i].green != color[i].green || 		    prev[i].blue  != color[i].blue ) {			diffs++;		}	}	if (diffs && ! first) {		if (! all_clients_initialized()) {			rfbLog("set_colormap: warning: sending cmap "			    "with uninitialized clients.\n");		}		rfbSetClientColourMaps(screen, 0, ncells);	}	first = 0;}