[comp.windows.x] Help with WM_COLORMAP_WINDOWS

jdp@polstra.UUCP (John Polstra) (03/02/90)

I am trying to use one of the Standard Colormaps (to be concrete, let's say
RGB_GREEN_MAP) in a window, but I can't seem to get twm to switch to the
proper colormap when the cursor enters the window.  Can somebody help me?

This is with a Sun 3/180, SunOS 4.0.1, X11R4, twm window manager, no
patches installed.  Here's what my program does:

1.  Creates a top-level application shell ("toplevel") with XtAppInitialize().
2.  Creates a widget ("canvas") with XtVaCreateManagedWidget().  This is
    a widget that I built myself, but it is very similar to the "window"
    widget example in chapter 7 of the Athena Widget Set documentation.
    I.e., it is a plain window that can be drawn into, and it provides
    callbacks for expose and resize events.
3.  Registers callbacks using XtAddCallback().
4.  Calls XtRealizeWidget(toplevel).
5.  Calls XGetStandardColormap(..., &sc, ...) to get the XStandardColormap info.
6.  Calls XSetWindowColormap(dpy, XtWindow(canvas), sc.colormap).
7.  Calls XtSetWMColormapWindows(toplevel, &canvas, 1).
8.  Calls XtAppMainLoop().

When I first start up the X server, I run "xstdcmap -all" to create all of
the standard colormaps.

When I run my program, my expose callback gets called.  It draws its
image, which looks OK except that the colors are all wrong.

A call to XGetWindowAttributes() within the expose callback confirms
that the window colormap is the correct one for RGB_GREEN_MAP.  The
visual ID looks OK too (PseudoColor).  Using XQueryColors() shows that
the RGB values in the colormap are appropriate for RGB_GREEN_MAP.

If I use xprop to print out the window properties, it says
"WM_COLORMAP_WINDOWS(WINDOW): window id #  0x800002", and that is indeed
the correct window ID for my canvas widget.

I have found that I can get the desired behavior by replacing step 6 with an
XSetWindowColormap on my toplevel window, and eliminating step 7 entirely.
But I don't really *want* my toplevel window to use the RGB_GREEN_MAP.

Am I doing something wrong, or have I found a bug?
-- 

-  John Polstra               jdp@polstra.UUCP
   Polstra & Co., Inc.        ...{uunet,sun,pyramid}!practic!polstra!jdp
   Seattle, WA                (206) 932-6482

stroyan@hpfcso.HP.COM (Mike Stroyan) (03/04/90)

> 7.  Calls XtSetWMColormapWindows(toplevel, &canvas, 1).
> 8.  Calls XtAppMainLoop().

> If I use xprop to print out the window properties, it says
> "WM_COLORMAP_WINDOWS(WINDOW): window id #  0x800002", and that is indeed
> the correct window ID for my canvas widget.
> 
> I have found that I can get the desired behavior by replacing step 6 with an
> XSetWindowColormap on my toplevel window, and eliminating step 7 entirely.
> But I don't really *want* my toplevel window to use the RGB_GREEN_MAP.

According to the ICCCM the top level window's colormap will be given
priority over the windows in the WM_COLORMAP_WINDOWS property unless
the top level window also appears in the property.  Use something like
the following code to list your canvas window ahead of the toplevel window.

{
	Widget list[2];
	list[0] = canvas;
	list[1] = toplevel;
	XtSetWMColormapWindows(toplevel, list, 2);
}

Unless the server can actually support multiple simultaneous colormaps,
this will make the server always use RGB_GREEN_MAP when colormap focus
is on your application window.  You might want to consider swapping the
order of the WM_COLORMAP_WINDOWS list based on Enter and Leave events
on the canvas widget.

Mike Stroyan, stroyan@hpfcla.hp.com