[comp.windows.x] Problem with new widget colormap

mike@ai.etl.army.mil (Mike McDonnell) (04/30/89)

How can I change the colormap associated with a widget?  Here are some
code fragments showing attempts, with comments.

Widget w is a core widget inside a form widget. Widget w is used
to display an image.

{
  XSetWindowAttributes swattr;

  disp = XtDisplay(w);
  win = XtWindow(w);
  cmap = make_new_colormap(disp, win);  /* Works just fine. */
  XInstallColormap(disp, cmap);         /* screen flickers briefly */

  /* this works the first time and then royally screws things up!! */
/*  XSetWindowColormap(disp, DefaultRootWindow(disp), cmap); /*  */
    
  swattr.backing_store = Always; /* This works. */
  swattr.colormap = cmap;	/* This does not "take"; server resets? */
  swattr.event_mask |= (ColormapChangeMask | EnterWindowMask);
  XChangeWindowAttributes(disp, win,
			  CWBackingStore | CWColormap | CWEventMask, &swattr);
  XSetWindowColormap(disp, win, cmap);	/* This doesn't do squat. */
}

Running the >>second<< time with the colormap set to the root window gives
the following error (which I find confusing):

X Protocol error:  BadMatch, invalid parameter attributes
  Major opcode of failed request:  1 (X_CreateWindow)
  Minor opcode of failed request:  0
  Resource id in failed request:  0x8006b
  Serial number of failed request:  74
  Current serial number in output stream:  92

This error persists even when I recompile the code with the assignment
of the colormap to the root window commented out, as shown in the
code fragment above.  I have to kill the server to clear the error
condition.

HELP!
-- 
Mike McDonnell at the U.S. Army Engineer Topographic Laboratories, Bldg. 2592
Fort Belvoir, VA 22060-5546   TEL:(202)355-2716   NET: mike@ai.etl.army.mil

converse@EXPO.LCS.MIT.EDU (Donna Converse) (05/02/89)

Window managers take care of installing colormaps for application
programs.  Mechanisms for communication between applications and
window managers concerning installation of colormaps have been
outlined in the ICCCM.   Because the ICCCM is very new, most
clients and window managers do not *yet* observe the conventions.

To have an R3 window manager install a colormap for an application,
	XSetWindowColormap(disp, win, cmap);
Where win is the window of your top level shell widget.