[comp.windows.x] installing a new colormap

clyne@redcloud.scd.ucar.edu (John Clyne) (02/28/91)

Hello, I'm sure this has been discussed before but I don't recall seeing it
and I can't find anything in FAQ. So I apologize in advance. I would like
to install my own colormap created with XCreateColormap. I wouldn't think
this would be too difficult but I haven't had any success. I am aware that
there are some complications brought upon by non-ICCCM compliant window
managers. But I'm running twm which I believe claims to be ICCCM 
compliant. Ideally I want my software to work correctly with both compliant
and non-compliant window managers and if not too much trouble, with no
window manager at all. Could someone please give me step by step instructions
for accomplishing this? I've tried a number of things and they just don't
seem to be working. It appears that I'm successful in installing my
colormap but that the window manager is reinstalling the default colormap.
(I'm typing this posting from home so I can't verify this now). I would like 
my cmap to be installed when i'm in a particular window and uninstalled when i
move the sprite out of that window (the default cmap should be restored
of course). If there are in fact differences between how things need to
be handled with ICCCM compliant and non ICCCM compliant then can one
detect whether the window manager is compliant or not? Could you also
please tell me the distinction between XSetWindowColormap() and 
XInstallColormap()? These two functions don't seem to be behaving as I
would expect from reading the documentation. I'm running R4 of X11 with 
all the latest patches. My application is Xt based. 

Thanks much - jc

	John Clyne 	(clyne@ncar.ucar.edu)
	National Center for Atmospheric Research
	P.O. Box 3000, Boulder, Colorado 80307
	(303) 497-1236

mouse@lightning.mcrcim.mcgill.EDU (03/01/91)

> I would like to install my own colormap created with XCreateColormap.
> I wouldn't think this would be too difficult but I haven't had any
> success.  I am aware that there are some complications brought upon
> by non-ICCCM compliant window managers.  [...]  Ideally I want my
> software to work correctly with both compliant and non-compliant
> window managers and if not too much trouble, with no window manager
> at all.

Without help from the user, this borders on impossible.  The basic
problem is that it's impossible (or at least very difficult) for a
client to tell the difference between no window manager (or a
non-colormap-aware one) and a compliant one that just happens to keep
colormap focus elsewhere for some reason.

If the window manager is colormap-aware, you just set your window's
colormap and let the window manager deal with installing the colormap.
When running without a window manager (does anyone actually do this?!),
or with a non-compliant window manager, you have to do the
XInstallColormap yourself.

If the window manager is at all good at defensive action in the face of
ill-behaved clients, you can probably get away with doing both of the
above and counting on the window manager to take corrective action if
it doesn't want your colormap installed.  I do not recommend this,
though, both because the window manager may *not* be capable of
corrective action and because it typically produces a technicolor flash
that is annoying and, for users who don't understand it, worrisome and
disorienting.

My preferred solution is to assume a compliant window manager is
running by default and provide some way for the user to tell the
program that this is not the case and that it should do its own
colormap installation.  (If, that is, you don't feel you can get away
with ignoring the possibility that no compliant WM is there, a
possibility that's getting fainter and fainter all the time....)

> It appears that I'm successful in installing my colormap but that the
> window manager is reinstalling the default colormap.

Probably.  In this case, you almost certainly are using a compliant
window manager, and its colormap focus policy says that the default
colormap should be installed, so when it sees someone else doing an
install, it just resets it.

> I would like my cmap to be installed when i'm in a particular window
> and uninstalled when i move the sprite out of that window (the
> default cmap should be restored of course).

This is something you will have to work out with your window manager.
Different WMs have different colormap focus policies....

> Could you also please tell me the distinction between
> XSetWindowColormap() and XInstallColormap()?

Every window has a colormap.  Here's what the Xlib document has to say
about this:

	The colormap attribute specifies which colormap best reflects
	the true colors of the InputOutput window.  The colormap must
	have the same visual type as the window, or a BadMatch error
	results.  X servers capable of supporting multiple hardware
	colormaps can use this information, and window managers can use
	it for calls to XInstallColormap.  You can set the colormap
	attribute to a colormap or to CopyFromParent (default).

(It is also possible for a window to have colormap None.  "X does not
define the colors displayed for a window with a colormap of None.")

This attribute is what XSetWindowColormap sets.

XInstallColormap, on the other hand, actually tells the server to use a
colormap.  That is, when a colormap is installed, all windows which
have that colormap as their colormap attribute will be displayed in
their (presumably) correct colors.  (Other windows might be as well,
depending on the visual, the hardware, the server, etc.)  There is a
certain set of colormaps which the server must keep installed.  The
exact algorithm for determining this list is slightly confusing, but
the basic effect is that the N most recently installed colormaps must
be installed, where N is the min-installed-maps value for the screen
(which is typically 1).  Other colormaps might or might not be
installed, depending on the server, the visuals in question, what cells
are allocated, the phase of the moon, etc.

> These two functions don't seem to be behaving as I would expect from
> reading the documentation.

If the above doesn't clear it up, drop me a line with more details and
I'll see if I can see any reason why....

> My application is Xt based.

This *might* be part of the problem.  I don't know what facilities the
toolkit has for managing colormaps, but it seems possible to me that
you're having problems because your use of Xlib-level calls is clashing
with the toolkit's trying to be helpful and doing things for you....

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu