Newsgroups: comp.windows.x

In comp.windows.x, judith@mermaid.larc.nasa.gov (Judith Moore) writes:

> Thanks for the attention to my problem. Unfortunately,
> I must be misinterpreting the suggestions. This is what
> I do:
> 	(misc setup)
>    winAttrib.colormap = DefaultColormap(theDisplay, theScreen);
>    mainWindow =	XCreateWindow (theDisplay, ...., &winAttrib);
>    XMapWindow (theDisplay, mainWindow);
>    anImage = XCreateImage (theDisplay, theVisual, 8, ZPixmap, ...); 
>    XPutImage (theDisplay, mainWindow, theGC, anImage, ...);
>    XFlush (theDisplay);
>    sleep (5);
> 
> 	grayMap = XCreateColormap (theDisplay, mainWindow, theVisual, AllocAll);
> 	for (i = 0; i < 255; i++) {
> 		aColor.pixel = i;	
> 		aColor.red = aColor.blue = aColor.green = i << 8;
> 		XStoreColor (theDisplay, grayMap, &aColor);
> 		}
> 	
> 	XSetWindowColormap (theDisplay, mainWindow, grayMap);
> 	XFlush (theDisplay);
> 	sleep (5);
> 
> What happens is, my image appears in the window with the default
> colormap, and just sits there.  The XSetWindowColormap() call
> appears to have no effect whatsoever.  
> 
> If I do the XSetWindowColormap() _before_ XMapWindow(), I get the
> grayscale I expect.  But then I can't change _that_ to anything 
> else.
  
I suspect that your problem is in the Window Manager's colormap focus
policy.  Your application is only empowered to tell the window mgr
which colormap(s) is associated with the window.  It is the window mgr's
responsibility to install the colormap in the 1 or more hardware colormaps
based on the current ColormapFocusPolicy.  The proper behaviour of a
window manager is described in the ICCCM (Inter-Client Communications 
Conventions Manual).  (I hear they have some pretty wild conventions :-)
Beware, window managers don't always live up to these standards.

Try setting your ColormapFocusPolicy resource to pointer in .Xdefaults 
or your equivalent.  The other options are (keyboard and explicit).

Use the xwininfo utility to inspect the current colormap associated 
with your application's window to make sure that a new cmap is being
correctly applied to the window.

The program included below will tell you what the current set
of installed colormaps are.  If your display has a single hardware
colormap this will always be just one colormap at any time. 

--
Howard Stroyan                                         
Hewlett-Packard                                        hstroyan@fc.hp.com
Systems Technology Division                     
----------------------------------------------------------------------
#include <X11/Xlib.h>

#define TRUE 1
#define NULL 0

main()
{
    Display *mydisplay;
    int myscreen;
    Window mywindow;
    GC mygc;
    XEvent myevent;
    KeySym mykey;
    char text[10];
    int count, i;
    Colormap *list, *start;

    mydisplay = XOpenDisplay(getenv("DISPLAY"));
    myscreen = DefaultScreen(mydisplay);

    mywindow = XCreateSimpleWindow(mydisplay,
        RootWindow(mydisplay, myscreen),
        100, 100, 300, 300,
        2,
        BlackPixel(mydisplay, myscreen),
        WhitePixel(mydisplay, myscreen));

    start = list = XListInstalledColormaps(mydisplay, mywindow, &count);

    printf(" %d colormaps installed:\n",count);
    for (i = 0; i < count; i++)
    {
        printf("\t 0x%x \n",*(list++));
    }
    XFree(start);
}
Newsgroups: comp.windows.x,connect.audit