AllCmap.c

Go to the documentation of this file.
00001 /* $Xorg: AllCmap.c,v 1.4 2001/02/09 02:03:51 xorgcvs Exp $ */
00002 
00003 /* 
00004  
00005 Copyright 1989, 1998  The Open Group
00006 
00007 Permission to use, copy, modify, distribute, and sell this software and its
00008 documentation for any purpose is hereby granted without fee, provided that
00009 the above copyright notice appear in all copies and that both that
00010 copyright notice and this permission notice appear in supporting
00011 documentation.
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of The Open Group shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from The Open Group.
00026 
00027 */
00028 /* $XFree86: xc/lib/Xmu/AllCmap.c,v 1.7 2001/01/17 19:42:53 dawes Exp $ */
00029 
00030 #include <stdio.h>
00031 #include <X11/Xlib.h>
00032 #include <X11/Xatom.h>
00033 #include <X11/Xutil.h>
00034 #include <X11/Xmu/StdCmap.h>
00035  
00036 static XVisualInfo *getDeepestVisual(int, XVisualInfo*, int);
00037 
00038 /*
00039  * To create all of the appropriate standard colormaps for every visual of
00040  * every screen on a given display, use XmuAllStandardColormaps.
00041  *
00042  * Define and retain as permanent resources all standard colormaps which are
00043  * meaningful for the visuals of each screen of the display.  Return 0 on
00044  * failure, non-zero on success.  If the property of any standard colormap 
00045  * is already defined, redefine it.
00046  *
00047  * This interface is intended to be used by window managers or a client
00048  * upon start-up of a session.
00049  *
00050  * The standard colormaps of a screen are defined by properties associated
00051  * with the screen's root window.  Each screen has exactly one root window.
00052  * The property names of standard colormaps are predefined, and each property
00053  * name may describe at most one colormap.
00054  * 
00055  * The standard colormaps are
00056  *              RGB_BEST_MAP
00057  *              RGB_RED_MAP
00058  *              RGB_GREEN_MAP
00059  *              RGB_BLUE_MAP
00060  *              RGB_DEFAULT_MAP
00061  *              RGB_GRAY_MAP
00062  *
00063  * Therefore a screen may have at most 6 standard colormap properties defined.
00064  *
00065  * A standard colormap is associated with a particular visual of the screen.
00066  * A screen may have multiple visuals defined, including visuals of the same
00067  * class at different depths.  Note that a visual id might be repeated for
00068  * more than one depth, so the visual id and the depth of a visual identify
00069  * the visual.  The characteristics of the visual will determine which
00070  * standard colormaps are meaningful under that visual, and will determine
00071  * how the standard colormap is defined.  Because a standard colormap is
00072  * associated with a specific visual, there must be a method of determining
00073  * which visuals take precedence in defining standard colormaps.
00074  * 
00075  * The method used here is: for the visual of greatest depth, define all 
00076  * standard colormaps meaningful to that visual class, according to this
00077  * order of (descending) precedence:
00078  *      1. DirectColor
00079  *      2. PseudoColor
00080  *      3. TrueColor and GrayScale
00081  *      4. StaticColor and StaticGray
00082  *
00083  * Allows partial success by screenful.  For example, if a map on screen 1
00084  * fails, the maps on screen 0, created earlier, will remain.  However,
00085  * none on screen 1 will remain.  If a map on 0 fails, none will remain.
00086  *
00087  * See the comments under XmuVisualStandardColormaps() for notes on which
00088  * standard colormaps are meaningful under these classes of visuals.
00089  */
00090 
00091 Status
00092 XmuAllStandardColormaps(Display *dpy)
00093 {
00094     int         nvisuals, scr;
00095     Status      status;
00096     long        vinfo_mask;
00097     XVisualInfo template, *vinfo, *v1, *v2;
00098 
00099     status = 0;
00100     /* for each screen, determine all visuals of this server */
00101     for (scr=0; scr < ScreenCount(dpy); scr++)
00102     {
00103         template.screen = scr;
00104         vinfo_mask = VisualScreenMask;
00105         vinfo = XGetVisualInfo(dpy, vinfo_mask, &template, &nvisuals);
00106         if (vinfo == NULL) /* unexpected: a screen with no visuals */
00107             continue;
00108 
00109         v1 = getDeepestVisual(DirectColor, vinfo, nvisuals);
00110         v2 = getDeepestVisual(PseudoColor, vinfo, nvisuals);
00111 
00112         if (v2 &&
00113             (!v1 || (v2->colormap_size >=
00114                      ((v1->red_mask | v1->green_mask | v1->blue_mask) + 1))))
00115             status = XmuVisualStandardColormaps(dpy, scr, v2->visualid,
00116                                                 (unsigned) v2->depth, 1, 1);
00117         else if (v1)
00118             status = XmuVisualStandardColormaps(dpy, scr, v1->visualid,
00119                                                 (unsigned) v1->depth, 1, 1);
00120 
00121         else {
00122             if (((v1 = getDeepestVisual(TrueColor, vinfo, nvisuals)) != NULL)
00123                 || ((v1 = getDeepestVisual(StaticColor, vinfo, nvisuals)) !=
00124                 NULL))
00125                 status = XmuVisualStandardColormaps(dpy, scr, v1->visualid,
00126                                                    (unsigned) v1->depth, 1, 1);
00127             if (status && 
00128                (((v1 = getDeepestVisual(GrayScale, vinfo, nvisuals)) != NULL)
00129                 || ((v1 = getDeepestVisual(StaticGray, vinfo, nvisuals)) != 
00130                     NULL)))
00131                 status = XmuVisualStandardColormaps(dpy, scr, v1->visualid,
00132                                                    (unsigned) v1->depth, 1, 1);
00133         }
00134         XFree ((char *) vinfo);
00135         if (!status) break;
00136     }
00137     return status;
00138 }
00139 
00140 static XVisualInfo *
00141 getDeepestVisual(int visual_class, XVisualInfo *vinfo, int nvisuals)
00142 {
00143     register int        i;
00144     register int        maxdepth = 0;
00145     XVisualInfo         *v = NULL;
00146     
00147     for (i=0; i < nvisuals; i++, vinfo++)
00148         if (vinfo->class == visual_class && vinfo->depth > maxdepth)
00149         {
00150             maxdepth = vinfo->depth;
00151             v = vinfo;
00152         }
00153     return(v);
00154 }
00155 

Generated on Sun Mar 4 15:03:56 2007 for Scilab [trunk] by  doxygen 1.5.1