[comp.windows.x] X colormap

alien@monkey.ecn.purdue.edu (Yin Chan) (03/08/91)

Hi,

	I have a problem with changing the colormap used by a window.
I need to allocate 256 colors.  How can I create a new colormap and
then force the widget window to display true color defined in the new
colormap?  Also, I would like to know how to restore the default
colormap after executing my program.


Thanks

mouse@lightning.mcrcim.mcgill.EDU (der Mouse) (03/09/91)

> I have a problem with changing the colormap used by a window.  I need
> to allocate 256 colors.  How can I create a new colormap and then
> force the widget window to display true color defined in the new
> colormap?  Also, I would like to know how to restore the default
> colormap after executing my program.

I don't know how to manipulate widgets, so I can't help there, but in
Xlib and protocol terms....

You create a new colormap with XCreateColormap.  But don't do that
blindly; first, make sure a dynamic visual is available and that its
colormaps contain at least 256 entries.  Then, if the default visual is
such a visual, you may want to try allocating out of its colormap; this
reduces technicolor flashing, and if the window won't be up for long or
if the colormap has many more than 256 entries, it is not particularly
unfriendly to other clients.

If you're not using the default visual, you will have to make sure your
window is created using that visual.

Now you have your colormap and have allocated its entries.  If your
entries are read/write, you need to store the colors into them.  (If
you can, use read-only entries, because they can be shared.  One
problem with them, though, is that there is no call to perform many
XAllocColor operations at once.)

Now use XSetWindowColormap (or the colormap attribute at window
creation) to set the colormap of the window in question.

If the window is not a top-level window (well, actually, if the
window's colormap differs from its top-level window's colormap), you
need to set up a WM_COLORMAP_WINDOWS property on your top-level window,
to tell the window manager to watch the window's colormap.

The rest is up to the window manager.  It will install your colormap
when its colormap focus policy says that window should have colormap
focus and will deal with reinstalling the default colormap when
appropriate.  (If you are running a pre-ICCCM window manager, you
should either fix it or switch.  If for some reason you can't do that,
you will have to get your hands dirty with XInstallColormap.)

					der Mouse

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