1
/* $Xorg: AllCmap.c,v 1.4 2001/02/09 02:03:51 xorgcvs Exp $ */
5
Copyright 1989, 1998 The Open Group
7
Permission to use, copy, modify, distribute, and sell this software and its
8
documentation for any purpose is hereby granted without fee, provided that
9
the above copyright notice appear in all copies and that both that
10
copyright notice and this permission notice appear in supporting
13
The above copyright notice and this permission notice shall be included in
14
all copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
20
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23
Except as contained in this notice, the name of The Open Group shall not be
24
used in advertising or otherwise to promote the sale, use or other dealings
25
in this Software without prior written authorization from The Open Group.
28
/* $XFree86: xc/lib/Xmu/AllCmap.c,v 1.8 2001/12/14 19:55:32 dawes Exp $ */
32
#include <X11/Xatom.h>
33
#include <X11/Xutil.h>
34
#include <X11/Xmu/StdCmap.h>
36
static XVisualInfo *getDeepestVisual(int, XVisualInfo*, int);
39
* To create all of the appropriate standard colormaps for every visual of
40
* every screen on a given display, use XmuAllStandardColormaps.
42
* Define and retain as permanent resources all standard colormaps which are
43
* meaningful for the visuals of each screen of the display. Return 0 on
44
* failure, non-zero on success. If the property of any standard colormap
45
* is already defined, redefine it.
47
* This interface is intended to be used by window managers or a client
48
* upon start-up of a session.
50
* The standard colormaps of a screen are defined by properties associated
51
* with the screen's root window. Each screen has exactly one root window.
52
* The property names of standard colormaps are predefined, and each property
53
* name may describe at most one colormap.
55
* The standard colormaps are
63
* Therefore a screen may have at most 6 standard colormap properties defined.
65
* A standard colormap is associated with a particular visual of the screen.
66
* A screen may have multiple visuals defined, including visuals of the same
67
* class at different depths. Note that a visual id might be repeated for
68
* more than one depth, so the visual id and the depth of a visual identify
69
* the visual. The characteristics of the visual will determine which
70
* standard colormaps are meaningful under that visual, and will determine
71
* how the standard colormap is defined. Because a standard colormap is
72
* associated with a specific visual, there must be a method of determining
73
* which visuals take precedence in defining standard colormaps.
75
* The method used here is: for the visual of greatest depth, define all
76
* standard colormaps meaningful to that visual class, according to this
77
* order of (descending) precedence:
80
* 3. TrueColor and GrayScale
81
* 4. StaticColor and StaticGray
83
* Allows partial success by screenful. For example, if a map on screen 1
84
* fails, the maps on screen 0, created earlier, will remain. However,
85
* none on screen 1 will remain. If a map on 0 fails, none will remain.
87
* See the comments under XmuVisualStandardColormaps() for notes on which
88
* standard colormaps are meaningful under these classes of visuals.
92
XmuAllStandardColormaps(Display *dpy)
97
XVisualInfo template, *vinfo, *v1, *v2;
100
/* for each screen, determine all visuals of this server */
101
for (scr=0; scr < ScreenCount(dpy); scr++)
103
template.screen = scr;
104
vinfo_mask = VisualScreenMask;
105
vinfo = XGetVisualInfo(dpy, vinfo_mask, &template, &nvisuals);
106
if (vinfo == NULL) /* unexpected: a screen with no visuals */
109
v1 = getDeepestVisual(DirectColor, vinfo, nvisuals);
110
v2 = getDeepestVisual(PseudoColor, vinfo, nvisuals);
113
(!v1 || (v2->colormap_size >=
114
((v1->red_mask | v1->green_mask | v1->blue_mask) + 1))))
115
status = XmuVisualStandardColormaps(dpy, scr, v2->visualid,
116
(unsigned) v2->depth, 1, 1);
118
status = XmuVisualStandardColormaps(dpy, scr, v1->visualid,
119
(unsigned) v1->depth, 1, 1);
122
if (((v1 = getDeepestVisual(TrueColor, vinfo, nvisuals)) != NULL)
123
|| ((v1 = getDeepestVisual(StaticColor, vinfo, nvisuals)) !=
125
status = XmuVisualStandardColormaps(dpy, scr, v1->visualid,
126
(unsigned) v1->depth, 1, 1);
128
(((v1 = getDeepestVisual(GrayScale, vinfo, nvisuals)) != NULL)
129
|| ((v1 = getDeepestVisual(StaticGray, vinfo, nvisuals)) !=
131
status = XmuVisualStandardColormaps(dpy, scr, v1->visualid,
132
(unsigned) v1->depth, 1, 1);
134
XFree ((char *) vinfo);
141
getDeepestVisual(int visual_class, XVisualInfo *vinfo, int nvisuals)
144
register int maxdepth = 0;
145
XVisualInfo *v = NULL;
147
for (i=0; i < nvisuals; i++, vinfo++)
148
if (vinfo->class == visual_class && vinfo->depth > maxdepth)
150
maxdepth = vinfo->depth;