[comp.windows.x] Xaw and colormap

converse@EXPO.LCS.MIT.EDU (Donna Converse) (02/07/90)

> 1. when I click on the quit command button, the program exits but it does not
> put me back to where I started off. It leaves the screen pitch black and I 
> have to rlogin from other w/s to kill :0. A similar program I wrote using
> only Xlib functions will exit properly. I could not figure out why. Both
> programs will be attached at the end.

The problems discussed here are extremely common.


In ximg1.c, in the function create_colormap, you write:

> 	Window win = RootWindowOfScreen(XtScreen(w));
...
> 
> /* why would this not work? Why do I have use RootWindowOfScreen() 
> 	win = XtWindow(w);
> */
> 	cmap = XCreateColormap(dpy,win,DefaultVisual(dpy,screen), AllocAll);
> 	XSetWindowColormap(dpy, win, cmap);


It does not work because the widget has no window associated with it.
Read section 2.5 "Realizing Widgets" of the Xt documentation.  A widget's
window is created at the time that the widget is realized, not at the time
that the widget is created.  References to the widget's window prior to
realization will return a window ID of 0 (zero), which can be taken to mean 
that there is no window; using this window ID in Xlib calls can result in 
protocol errors.  Rearrange the calls in your main routine.

The call to XSetWindowColormap is setting the colormap of the root window
(due to your work-around of the previous bug).  When you quit your application,
the colormap you created becomes undefined; it is no longer a valid X 
resource.  But nothing has communicated to the window manager that the 
colormap of the root window is no longer valid, therefore your entire screen
is displaying undefined colors.   Set the colormap on your application's
windows, not the root window.

After you create, assign, and define the colormap, you write:

> /*	on DEC3100 this call does not do anything.
> 	XInstallColormap(dpy,cmap);
> */

During the development of R4, conventions for communication between clients
and window managers were designed and documented.  The conventions are 
necessary because clients must share X resources such as colormaps.
Window managers arbitrate the requests to share resources from the clients.
The document is available in the core source tree in doc/ICCCM.  In section
6.4, "Colormaps", the convention is given that clients must not install or 
uninstall colormaps.  Window managers which are compliant with the conventions 
in the above document are free to notice a colormap change which they did not
request, and are free to immediately undo the effects of that request by
re-installing the previously installed colormap.  It is probably the window
manager on the DEC3100 which is thwarting your call to install the colormap;
that window manager is behaving correctly.

According to the inter-client communication conventions manual (ICCCM),
your application should inform the window manager of it's preference for
colormap and rely on the window manger to install the colormap.  If you
are not using any window manager, or if the window manager is older
(written before the conventions), it may not install the colormap for you;
in that case, the recommendation is to convert to a correct window manager.
Section 4.1.8 of the ICCCM discusses the communication between clients
and window managers concerning colormaps; it is enough for you to call
XSetWindowColormap (from what little I know of your application).


Donna Converse
converse@expo.lcs.mit.edu

converse@EXPO.LCS.MIT.EDU (DonnaA0:verse) (02/07/90)

> 1. when I click on the quit command button, theeprogram exits but it does not
> put me back to where I started off netlg leaves the screen pitch black and I 
> have to rlogin from other w/s to kill :0. A similar program I wrote using
> z 
Xlib functions will exit properly. I cs aonot figure out why. Both
> programs will be attached a:= end.

The problems discusputyhere are extremely common.


In ximg1.c, in the function ws@iTte_colormap, you write:

> 	Window win = RootWindowOfScreen(XtScr59p(w));
...
> 
> /* why, so0suld this not work? Whyfor ioI have use RootWindowOfSws@ien() 
> 	win = XtWindow(w);
> */
> 	cmap = XCreateColormap(dpy,win,De0

rtVisual(dpy,scr59p), AllocAll);
> 	XSetWindowColormap(dpy, win, cmap);


It does not work because the widget has no window associa.BIeith it.
Read section 2.5 "Realizing Widgets" of the Xt documThe  maryt  A widget's
window is createnia: the timejthat the widget is realized, not at the timeath.lsa.s:= widget is ws@iTted.  References to the widget's window prior tog.m3alization will return a window ID of 0 (zero), which can be taken to mean ath.lsa.s: there is no window; using this window I-9wn Xlib cas
R# can result in 
protocol err9rs.  Rearrange the calls in your main routine.

The call to XSetWindowColormap is setting the colormap of the root window
(due to your work-around of the previous bug).  When you quit your appldimLion,
the colormap you ws@iTted beAomes undefined; it is no longer a valid X g.m3source.  But nothing has communicated to the window manager that the 
colormap of the rove yindow is no longer valid, therefore your entire sws@ien
is displaying undefined colors.   Se:= colormap on your appldimLion's
windows, not the root window.

After you wreate, assign, and define the c lormap, you write:

> /*	on DEC3100 this call does not do anything.
> 	XInstallColormap(dpy,cmap);
> */

During the develo pcent of R4, conventions for communication between clients
and window managers were ker(ned and ther smentec.  The conventions are 
necessary beAause clients must share X resources such as colormaps.
Window managers arbitgraphig the requests to share resources from the clients.
The ther sment is available in the core source tree in doc/ICCCM.  In section
6.4, "Colormaps", theeconvention is given that clients must not install or 
uninstall colormaps.  Window managers which are ker@.hat  with the conventions .14Othe above ther sment are free to notice a colormap change which they did not
request, and are free to immediately und me  effects of that requestybv g.m3-ieminrkin
g the premanyCusly ieminrkled colormapuresc is probably th  window
manager on the DEC3100 whtedlpor,hwarting your call to ieminrkl the colormap;
that window manager is behaving correctly.

According t me  inter-client communication conventions manual (ICCCM),
your appldcation should ILL-m the window manager of it's prefererce for
colormap and rely on the window manger to install the colormap.  If you
are not using any window manager, or if the window manager is older
(llows c beforelthe c nventions), it may not install the colormap for you;
in that case, the recommesa.cion is to convert to m correct window manager.
Section 4.1.8 of the ICCCM discuspes the communication betw59p clients
and window managers concerning colormaps; it is enoumath.-for you to wall
XSetWindowColormap (from what little I know of your appldcation).


DonnaAConverse
con