[comp.windows.x] Xt and Colormaps - timing paradox

csvsj@garnet.berkeley.edu (Steve Jacobson) (11/08/89)

Our multiwindowed application creates a window with a custom colormap. We
use twm, modified to separate colormap focus from keyboard focus.

We've experienced random failures by twm to install the custom colormap.
The probability of failure is higher when the client is run on a computer
much faster than the computer running the server.

I've made some changes to twm that eliminates the problem (so far), but
I'm concerned about the timing issues involved.

Our application does not call XInstallColormap(). It calls XSetWindowColormap() 
and lets the window manager do the install. XSetWindowColormap() requires
a window id argument, so we call XtPopup() on the window we're creating, and
then call XSetWindowColormap(), using XtWindow() on the realized widget to
get the window id argument.

When twm fails, this is what happens:

1. twm gets a MapRequest event
2. twm calls its AddWindow routine
3. early in AddWindow(), twm calls XGetWindowAttributes(). When problems
   occur, the colormap attribute is not the custom colormap. In other words,
   the attribute query has happened before the server has processed the
   application's XSetWindowColormap() call.
4. later, twm installs the new window's colormap, which may be stale.


I "fixed" the problem by redoing the XGetWindowAttributes() call right before
all XInstallColormap() calls in twm's event.c file. This reduces the
chance of installing a stale colormap.

I have two questions/comments:

1. The problem occurs because I can't specify the custom colormap before I
   realize the widget. Is this correct? If so, the toolkit should allow me
   to set the colormap BEFORE the widget is realized, so there is no
   chance of a timing related colormap installation error.

2. We've benefited somewhat from the toolkit; it's freed us from becoming X
   protocol experts. So I don't understand a little bit about the event
   sequence involved here. The toolkit realize leads to the maprequest event,
   but how come the subsequent XSetWindowColormap() call doesn't lead to
   a colormap notify event? Is it a timing thing, with the server not
   generating a colormap notify because the window hasn't been mapped yet?
   If a colormap notify would occur, twm would notice it, and install the
   right colormap.

Steve