home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xmu / AllCmap.c next >
Encoding:
C/C++ Source or Header  |  1989-10-08  |  5.7 KB  |  152 lines

  1. /* $XConsortium: AllCmap.c,v 1.6 89/10/08 14:52:32 rws Exp $
  2.  * 
  3.  * Copyright 1989 by the Massachusetts Institute of Technology
  4.  *
  5.  * Permission to use, copy, modify, and distribute this software and its
  6.  * documentation for any purpose and without fee is hereby granted, provided 
  7.  * that the above copyright notice appear in all copies and that both that 
  8.  * copyright notice and this permission notice appear in supporting 
  9.  * documentation, and that the name of M.I.T. not be used in advertising
  10.  * or publicity pertaining to distribution of the software without specific, 
  11.  * written prior permission. M.I.T. makes no representations about the 
  12.  * suitability of this software for any purpose.  It is provided "as is"
  13.  * without express or implied warranty.
  14.  *
  15.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  16.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  17.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  19.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  20.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  *
  22.  * Author:  Donna Converse, MIT X Consortium
  23.  */
  24.  
  25. #include <stdio.h>
  26. #include <X11/Xlib.h>
  27. #include <X11/Xatom.h>
  28. #include <X11/Xutil.h>
  29. #include <X11/Xmu/StdCmap.h>
  30.  
  31. static XVisualInfo *getDeepestVisual();
  32.  
  33. /*
  34.  * To create all of the appropriate standard colormaps for every visual of
  35.  * every screen on a given display, use XmuAllStandardColormaps.
  36.  *
  37.  * Define and retain as permanent resources all standard colormaps which are
  38.  * meaningful for the visuals of each screen of the display.  Return 0 on
  39.  * failure, non-zero on success.  If the property of any standard colormap 
  40.  * is already defined, redefine it.
  41.  *
  42.  * This interface is intended to be used by window managers or a client
  43.  * upon start-up of a session.
  44.  *
  45.  * The standard colormaps of a screen are defined by properties associated
  46.  * with the screen's root window.  Each screen has exactly one root window.
  47.  * The property names of standard colormaps are predefined, and each property
  48.  * name may describe at most one colormap.
  49.  * 
  50.  * The standard colormaps are
  51.  *        RGB_BEST_MAP
  52.  *        RGB_RED_MAP
  53.  *        RGB_GREEN_MAP
  54.  *        RGB_BLUE_MAP
  55.  *        RGB_DEFAULT_MAP
  56.  *        RGB_GRAY_MAP
  57.  *
  58.  * Therefore a screen may have at most 6 standard colormap properties defined.
  59.  *
  60.  * A standard colormap is associated with a particular visual of the screen.
  61.  * A screen may have multiple visuals defined, including visuals of the same
  62.  * class at different depths.  Note that a visual id might be repeated for
  63.  * more than one depth, so the visual id and the depth of a visual identify
  64.  * the visual.  The characteristics of the visual will determine which
  65.  * standard colormaps are meaningful under that visual, and will determine
  66.  * how the standard colormap is defined.  Because a standard colormap is
  67.  * associated with a specific visual, there must be a method of determining
  68.  * which visuals take precedence in defining standard colormaps.
  69.  * 
  70.  * The method used here is: for the visual of greatest depth, define all 
  71.  * standard colormaps meaningful to that visual class, according to this
  72.  * order of (descending) precedence:
  73.  *    1. DirectColor
  74.  *    2. PseudoColor
  75.  *    3. TrueColor and GrayScale
  76.  *    4. StaticColor and StaticGray
  77.  *
  78.  * Allows partial success by screenful.  For example, if a map on screen 1
  79.  * fails, the maps on screen 0, created earlier, will remain.  However,
  80.  * none on screen 1 will remain.  If a map on 0 fails, none will remain.
  81.  *
  82.  * See the comments under XmuVisualStandardColormaps() for notes on which
  83.  * standard colormaps are meaningful under these classes of visuals.
  84.  */
  85.  
  86. Status XmuAllStandardColormaps(dpy)
  87.     Display    *dpy;        /* Specifies the connection to the X server */
  88. {
  89.     int     nvisuals, scr;
  90.     Status    status;
  91.     long    vinfo_mask;
  92.     XVisualInfo    template, *vinfo, *v1, *v2;
  93.     
  94.     /* for each screen, determine all visuals of this server */
  95.     for (scr=0; scr < ScreenCount(dpy); scr++)
  96.     {
  97.     template.screen = scr;
  98.     vinfo_mask = VisualScreenMask;
  99.     vinfo = XGetVisualInfo(dpy, vinfo_mask, &template, &nvisuals);
  100.     if (vinfo == NULL) /* unexpected: a screen with no visuals */
  101.         continue;
  102.  
  103.     v1 = getDeepestVisual(DirectColor, vinfo, nvisuals);
  104.     v2 = getDeepestVisual(PseudoColor, vinfo, nvisuals);
  105.  
  106.     if (v2 &&
  107.         (!v1 || (v2->colormap_size >=
  108.              ((v1->red_mask | v1->green_mask | v1->blue_mask) + 1))))
  109.         status = XmuVisualStandardColormaps(dpy, scr, v2->visualid,
  110.                         (unsigned) v2->depth, 1, 1);
  111.     else if (v1)
  112.         status = XmuVisualStandardColormaps(dpy, scr, v1->visualid,
  113.                         (unsigned) v1->depth, 1, 1);
  114.  
  115.     else {
  116.         if (((v1 = getDeepestVisual(TrueColor, vinfo, nvisuals)) != NULL)
  117.         || ((v1 = getDeepestVisual(StaticColor, vinfo, nvisuals)) !=
  118.         NULL))
  119.         status = XmuVisualStandardColormaps(dpy, scr, v1->visualid,
  120.                            (unsigned) v1->depth, 1, 1);
  121.         if (status && 
  122.            (((v1 = getDeepestVisual(GrayScale, vinfo, nvisuals)) != NULL)
  123.         || ((v1 = getDeepestVisual(StaticGray, vinfo, nvisuals)) != 
  124.             NULL)))
  125.         status = XmuVisualStandardColormaps(dpy, scr, v1->visualid,
  126.                            (unsigned) v1->depth, 1, 1);
  127.     }
  128.     XFree ((char *) vinfo);
  129.     if (!status) break;
  130.     }
  131.     return status;
  132. }
  133.  
  134. static XVisualInfo *getDeepestVisual(visual_class, vinfo, nvisuals)
  135.     int        visual_class;    /* specifies the visual class */
  136.     XVisualInfo    *vinfo;        /* specifies all visuals for a screen */
  137.     int        nvisuals;    /* specifies number of visuals in the list */
  138. {
  139.     register int    i;
  140.     unsigned int    maxdepth = 0;
  141.     XVisualInfo        *v = NULL;
  142.     
  143.     for (i=0; i < nvisuals; i++, vinfo++)
  144.     if (vinfo->class == visual_class && vinfo->depth > maxdepth)
  145.     {
  146.         maxdepth = vinfo->depth;
  147.         v = vinfo;
  148.     }
  149.     return(v);
  150. }
  151.  
  152.