Re: canvas colormaps

Steve Lamont (spl@szechuan.ucsd.edu)
Wed, 15 Jan 97 22:01:15 PST

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

> Accorind to xwininfo, both the main form and the canvas are using the
> same colormap. When I don't install my own that is.

Sorry. I conflated the gl_canvas and plain canvas. The plain canvas
does not give you a new colormap but uses the default for the visual.

> Yes, I think this is where my problem lies. xwininfo says my canvas is using
> the colormap I created, but it isn't installed. Putting the mouse inside the
> canvas doesn't install it, but it should. This is on fvwm, twm and 4Dwm. I
> know that the gl demo does cause a colormap switch on the canvas window, so it
> is possible, xforms just doesn't do it for me.

I agree. This is very strange. I just spent longer than I care to
admit messing with this and have lost on all fronts. I have no idea
why this should be happening. The XA_WM_COLORMAP_WINDOWS property
seems to be properly set but nothing happens. I get a ColormapNotify
event if I select for it when the colormap is set in the Window
attributes but nothing happens when the Canvas gets focus.

I'm totally out of clues at this point. Why this should act in this
manner is completely beyond me.

I'm running X11R6.1 on a Sun SPARC 5 with SunOS 4.1.4. My window
manager is tvtwm and XForms is 0.84 Fix 2. TC?

A test program and .fd file are attached.

spl

- - -

#include <stdio.h>
#include "forms.h"
#include "try.h"

int handle( FL_OBJECT *obj, Window win, int win_width, int win_height,
XEvent *xev, void *user_data )

{

if ( xev->type == ColormapNotify ) {

XColormapEvent *cev = ( XColormapEvent *) xev;

fprintf( stderr, "%08lx %s %s\n",
cev->colormap, cev->new ? "True" : "False",
cev->state == ColormapInstalled ?
"Installed" : "Not installed" );

} else if ( xev->type == EnterNotify ) {

Window *windows;
int n;
int i;

XGetWMColormapWindows( fl_get_display(),
obj->form->window,
&windows, &n );

fprintf( stderr, "windows with custom colormaps = %d\n", n );
for ( i = 0; i < n; i++ )
fprintf( stderr, "%2d %08lx\n", i, windows[i] );
XFree( windows );

}

}

int init( FL_OBJECT *canvas )

{

Visual *visual;
Window canvas_window;
int n;
XSetWindowAttributes attrs;
unsigned long pixels[256];
Colormap colormap;

visual = DefaultVisual( fl_get_display(),
DefaultScreen( fl_get_display() ) );
colormap =
XCreateColormap( fl_get_display(),
DefaultRootWindow( fl_get_display() ),
visual, AllocNone );
if ( !XAllocColorCells( fl_get_display(),
colormap, True,
NULL, 0, pixels, 256 ) )
fprintf( stderr, "alloc cells lossage!\n" );
fprintf( stderr, "colormap = %08lx\n", colormap );
for ( n = 0; n < 256; n++ ) {

XColor c;

c.flags = 0x07;
c.red =
c.green =
c.blue = n << 8;
c.pixel = pixels[n];

XStoreColor( fl_get_display(), colormap, &c );

}
fl_set_canvas_visual( canvas, visual );
fl_set_canvas_colormap( canvas, colormap );

canvas_window = FL_ObjWin( canvas );


}

int activate( FL_OBJECT *canvas )

{

Window canvas_window;
XSetWindowAttributes attrs;

canvas_window = FL_ObjWin( canvas );
attrs.background_pixel = 100;
XChangeWindowAttributes( fl_get_display(),
canvas_window,
CWBackPixel,
&attrs );
XClearWindow( fl_get_display(), FL_ObjWin( canvas ) );

fprintf( stderr, "activate done -- %08lx\n", FL_ObjWin( canvas ) );

}

int main(int argc, char *argv[])

{

FD_try *fd_try;

fl_initialize(&argc, argv, 0, 0, 0);
fd_try = create_form_try();

fl_modify_canvas_prop( fd_try->canvas, init, activate, NULL );

fl_add_canvas_handler( fd_try->canvas, EnterNotify, handle, NULL );
fl_add_canvas_handler( fd_try->canvas, ColormapNotify, handle, NULL );

fl_show_form(fd_try->try,FL_PLACE_CENTER,FL_FULLBORDER,"try");

fl_do_forms();

return 0;

}

- - -
Magic: 13000

Internal Form Definition File
(do not change)

Number of forms: 1
Unit of measure: FL_COORD_PIXEL

=============== FORM ===============
Name: try
Width: 510
Height: 390
Number of Objects: 3

--------------------
class: FL_BOX
type: UP_BOX
box: 0 0 510 390
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_DEFAULT_SIZE
lcol: FL_BLACK
label:
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name:
callback:
argument:

--------------------
class: FL_BUTTON
type: NORMAL_BUTTON
box: 210 10 80 40
boxtype: FL_UP_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_DEFAULT_SIZE
lcol: FL_BLACK
label: Button
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name:
callback:
argument:

--------------------
class: FL_CANVAS
type: NORMAL_CANVAS
box: 10 60 490 320
boxtype: FL_DOWN_BOX
colors: FL_COL1 FL_COL1
alignment: FL_ALIGN_CENTER
style: FL_NORMAL_STYLE
size: FL_DEFAULT_SIZE
lcol: FL_BLACK
label:
shortcut:
resize: FL_RESIZE_ALL
gravity: FL_NoGravity FL_NoGravity
name: canvas
callback:
argument:

==============================
create_the_forms
- - -