Пример #1
0
void XSetStandardColormap(
    Display *dpy,
    Window w,
    XStandardColormap *cmap,
    Atom property)		/* XA_RGB_BEST_MAP, etc. */
{
    Screen *sp;
    XStandardColormap stdcmap;

    sp = _XScreenOfWindow (dpy, w);
    if (!sp) {
	/* already caught the XGetGeometry error in _XScreenOfWindow */
	return;
    }

    stdcmap.colormap	= cmap->colormap;
    stdcmap.red_max	= cmap->red_max;
    stdcmap.red_mult	= cmap->red_mult;
    stdcmap.green_max	= cmap->green_max;
    stdcmap.green_mult  = cmap->green_mult;
    stdcmap.blue_max	= cmap->blue_max;
    stdcmap.blue_mult	= cmap->blue_mult;
    stdcmap.base_pixel	= cmap->base_pixel;
    stdcmap.visualid	= sp->root_visual->visualid;
    stdcmap.killid	= None;		/* don't know how to kill this one */

#ifdef XCMS
    XSetRGBColormaps (dpy, w, &stdcmap, 1, property);
#endif

    return;
}
Пример #2
0
static Status
lookup(Display *dpy, int screen, VisualID visualid, Atom property,
       XStandardColormap *cnew, Bool replace)
     /*
      * dpy		- specifies display connection
      * screen		- specifies screen number
      * visualid	- specifies visualid for std map
      * property	- specifies colormap property name
      * cnew		- specifies a standard colormap
      * replace		- specifies whether to replace
      */
{
    register int	i;
    int			count;
    XStandardColormap	*stdcmaps, *s;
    Window		win = RootWindow(dpy, screen);

    /* The property does not already exist */

    if (! XGetRGBColormaps(dpy, win, &stdcmaps, &count, property)) {
	if (cnew)
	    XSetRGBColormaps(dpy, win, cnew, 1, property);
	return 0;
    }

    /* The property exists and is not describing the RGB_DEFAULT_MAP */

    if (property != XA_RGB_DEFAULT_MAP) {
	if (replace) {
	    XmuDeleteStandardColormap(dpy, screen, property);
	    if (cnew)
		XSetRGBColormaps(dpy, win, cnew, 1, property);
	}
	XFree((char *)stdcmaps);
	return 1;
    }

    /* The property exists and is RGB_DEFAULT_MAP */

    for (i=0, s=stdcmaps; (i < count) && (s->visualid != visualid); i++, s++)
	;

    /* No RGB_DEFAULT_MAP property matches the given visualid */

    if (i == count) {
	if (cnew) {
	    XStandardColormap	*m, *maps;

	    s = (XStandardColormap *) malloc((unsigned) ((count+1) * sizeof
					      (XStandardColormap)));

	    for (i = 0, m = s, maps = stdcmaps; i < count; i++, m++, maps++) {
		m->colormap   = maps->colormap;
		m->red_max    = maps->red_max;
		m->red_mult   = maps->red_mult;
		m->green_max  = maps->green_max;
		m->green_mult = maps->green_mult;
		m->blue_max   = maps->blue_max;
		m->blue_mult  = maps->blue_mult;
		m->base_pixel = maps->base_pixel;
		m->visualid   = maps->visualid;
		m->killid     = maps->killid;
	    }
	    m->colormap   = cnew->colormap;
	    m->red_max    = cnew->red_max;
	    m->red_mult   = cnew->red_mult;
	    m->green_max  = cnew->green_max;
	    m->green_mult = cnew->green_mult;
	    m->blue_max   = cnew->blue_max;
	    m->blue_mult  = cnew->blue_mult;
	    m->base_pixel = cnew->base_pixel;
	    m->visualid   = cnew->visualid;
	    m->killid     = cnew->killid;

	    XSetRGBColormaps(dpy, win, s, ++count, property);
	    free((char *) s);
	}
	XFree((char *) stdcmaps);
	return 0;
    }

    /* Found an RGB_DEFAULT_MAP property with a matching visualid */

    if (replace) {
	/* Free old resources first - we may need them, particularly in
	 * the default colormap of the screen.  However, because of this,
	 * it is possible that we will destroy the old resource and fail
	 * to create a new one if XmuStandardColormap() fails.
	 */

	if (count == 1) {
	    XmuDeleteStandardColormap(dpy, screen, property);
	    if (cnew)
		XSetRGBColormaps(dpy, win, cnew, 1, property);
	}
	else {
	    XStandardColormap	*map;

	    /* s still points to the matching standard colormap */

	    if (s->killid == ReleaseByFreeingColormap) {
		if ((s->colormap != None) &&
		    (s->colormap != DefaultColormap(dpy, screen)))
		    XFreeColormap(dpy, s->colormap);
	    }
	    else if (s->killid != None)
		XKillClient(dpy, s->killid);

	    map = (cnew) ? cnew : stdcmaps + --count;

	    s->colormap   = map->colormap;
	    s->red_max    = map->red_max;
	    s->red_mult   = map->red_mult;
	    s->green_max  = map->green_max;
	    s->green_mult = map->green_mult;
	    s->blue_max   = map->blue_max;
	    s->blue_mult  = map->blue_mult;
	    s->visualid   = map->visualid;
	    s->killid     = map->killid;

	    XSetRGBColormaps(dpy, win, stdcmaps, count, property);
	}
    }
    XFree((char *) stdcmaps);
    return 1;
}