Re: colormaps and cursors

Steve Lamont (spl@szechuan.ucsd.edu)
Sat, 30 Nov 96 08:58:14 PST

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> I have the following remark ( maybe usefull...)
> May the cause of all these, (color flashes, abnormal change of colors etc)
> was the fact that i have an image as a background (root window) ...

Bingo! Out of Colormap!

> ... It seems that this strange behaviour
> begins when forms have few sells to allocate ... I believe that the root of
> the problem was that i displayed simultanously about 80 colors, but forms
> couldn't allocate more than about 60. Am i wright ?? Is that the cause of
> changing allready allocated colors (even FL_BLACK for example..)?

Yes. XForms will substitute colors once it runs out of free cells.
You should have gotten a warning message. I'm surprised you didn't.

> Finally a request:
> It would be nice if there was a forms function to return the empty color
> sells, so somebody who wants to allocate many colors, to know where to
> stop, before all these happen...

Oddly enough, this is one of those things that's missing not only from
XForms but from X itself. The best you can do is to try to allocate
cells using XAllocColorCells() and keep trying until you win:

Colormap colormap = fl_state[fl_get_vclass()].colormap;
XVisualInfo *xvinfo = fl_state[fl_get_vclass()].xvinfo;
int n_colors = xvinfo->colormap_size;
unsigned long *pixels;

while ( !XAllocColorCells( fl_display(), colormap, False,
NULL, 0, &pixels, n_colors ) && --n_colors )
;

/*
* n_colors, unless zero, will contain the number of free color
* cells.
*/

See your favorite Xlib manual for details on XAllocColorCells().

If you're not going to use the cells directly but just want the number
of available cells, you should do

XFree( pixels );

Of course, if you have multiple applications running and they're all
using the DefaultColormap, then the value for n_colors will change
dynamically and it can't be relied upon 100 percent.

There's a very well written chapter in Volume 1 of the O'Reilly series
on colormappery. Anyone who wishes to understand the X Colormap
concept and its limitations should read it.

spl
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html