[ Previous | Next | Contents | Glossary | Home | Search ]
Motif 2.1 Widget Writer's Guide


XmeGetDesktopColorCells

return desktop pixel data in XColor[] format

Format

#include <Xm/ColorObjP.h>
Boolean XmeGetDesktopColorCellsScreen
*screenColormap colormapXColor
*colorsint n_colorsint
*n_colors_ret

DESCRIPTION

The Motif library creates and maintains a ColorObject at application initialization time (first VendorShell creation) which holds color information coming from a Color Server running on the desktop (see Color Server protocol). An application that needs to use a private colormap should include in its colormap the desktop pixels returned by the Color Server protocol, plus the pixels used for the desktop icons, so that the rest of the desktop doesn't go "technicolor" when the application colormap is installed (and the desktop default colormap is de-installed). This function calls XmeGetColorObjData(screen...), in order to get the raw pixel information and fill out the XColor[] color array for as many pixels as specified by the colorUse attributes, and then determine the RGB components for these pixel in the desktop colormap.

After it has retrieved the pixels of this screen's color object using XmeGetColorObjData, and added the pixels to the Color calculation cache in Motif (so that widgets created with a colormap set to share pixels get the right pixels for derived colors like shadows) this function calls XQueryColors on the default colormap to get the RGB intensity values for the desktop pixels in the XColor elements. It also sets all the flags to (DoRed|DoGreen|DoBlue) in the XColor array.

For the icon pixels, the function use XParseColor and XAllocColor on the default colormap using the 16 standard desktop icon color names ( "black", "white", "red", "green", "blue", "yellow", "cyan", "magenta", "#dededededede", "#bdbdbdbdbdbd", "#adadadadadad", "#949494949494", "#737373737373", "#636363636363", "#424242424242", "#212121212121") to find out the pixel ids that need to be shared.

XmeGetDesktopColorCells returns most-interesting-pixels first, and guarantees no duplicate pixel entries (which is not the same as duplicate RGB entries)

The order in the XColor array on return is:

  1. Foreground and background for all 8 palettes (primary, secondary, text, active, inactive, front-panel, ws buttons, in that order)

  2. Select color for primary, secondary

  3. The icon pixels (2 for LOW_COLOR and B_W, 16 for HIGH and MEDIUM_COLOR)

  4. Topshadow color for all 8 palettes

  5. Bottomshadow color for all 8 palettes (same order as above)

  6. Rest of select colors

    The idea is that if an application has only, say, 12 pixels to spare in its colormap for the desktop, it should get shared pixels that allow most of the desktop visual to be usable: foreground and background colors first, mainly.

    screen
    X screen passed in.

    colormap
    Colormap for which the pixel are fetched

    colors
    X color structures returned (allocated by called).

    n_colors
    Size available in colors array.

    n_colors_ret
    Number of X colors elements filled by the function

    RETURN VALUE

    False if XmeGetColorObjData returns False, or if colorUse is XmCO_BLACK_WHITE.

    STRUCTURES

    XColor is defined in Xlib.

    ENVIRONMENT

    The information returned by this function depends on the presence of an active Color Server.

    RESOURCES

    This function is affected by the resources set on the Color Server and useColorObj on XmScreen.

    ACTIONS/MESSAGES

    None.

    ERRORS/WARNINGS

    None.

    EXAMPLES

    After calling this function, the application can then add more entries to the XColor[] array (it can do that before in fact) and call XStoreColors with this XColor[] on the new colormap (note that if a program wants to use a private colormap and share the desktop pixels, a ReadWrite colormap must be used, since pixel have to be allocated at specific location, which is not possible with read-only cells.)

    static void
    SetColormap(Widget widget,
                int pixel_for_desktop)
    {
        Colormap my_colormap;
        int ncolors_ret, i, p;
        XColor    colors[256];
     
        if (!XtIsRealized(widget)) return;
     
        /* create a readwrite colormap */
        my_colormap = XCreateColormap(XtDisplay(widget),
                                      XtWindow(widget),
                                      XDefaultVisual(XtDisplay(widget), 0),
                                      AllocAll);
     
        /* we need to keep track of which pixel are used, mark
           them all free before calling XmeGet... */
        for(i=0; i<256; i++) colors[i].pixel = -1;
     
        /* get the desktop pixels in the array */
        XmeGetDesktopColorCells (XtScreen(widget), my_colormap,
                                 colors, pixel_for_desktop,
                                 &ncolors_ret);
     
        /* then fill in the rest of our private colormap */
        for(i=ncolors_ret, p = 0; i<256; i++) {
                    /* get a free pixel id */
                    while (p <= 255 && colors[p].pixel != -1) p
    ++;
                    colors[i].pixel = p;
                    color[i].flags = DoRed|DoGreen|DoBlue;
            color[i].red = color[i].green = color[i].blue = i * 256;
        }
     
        XStoreColors(XtDisplay(widget), my_colormap, colors, 256);
        XtVaSetValues(widget, XmNcolormap, my_colormap, NULL);
    }
     
    main () {
        toplevel = XtAppInitialize(...);
        XtRealizeWidget(toplevel);
     
        SetColormap (toplevel, 40);
        ...
    }

    SEE ALSO

    , , XmeGetColorObjData(3)


  7. [ Previous | Next | Contents | Glossary | Home | Search ]