From: stolk@fwi.uva.nl (Bram)
Subject: Creating 8 bit windows on 24 bit display.. How?
Organization: FWI, University of Amsterdam
Lines: 75
Nntp-Posting-Host: carol.fwi.uva.nl

Greetings,


I am using an X server that provides 3 visuals:
PseudoColor 8 bit, Truecolor 24 bit and DirectColor 24 bit.

A problem occurs when I try to create a window with a visual that is different
from the visual of the parent (which uses the default visual which is TC24).

In the Xlib reference guide from 'O reilly one can read in the
section about XCteateWindow, something like:
"In the current implementation of X11: When using a visual other than the
parent's, be sure to create or find a suitable colourmap which is to be used 
in the window attributes when creating, or else a BadMatch occurs."

This warning, strangely enough, is only mentioned in the newer editions
of the X11R5 guides.

However, even if I pass along a suitable colourmap, I still get a BadMatch
when I create a window with a non-default visual.
The code looks like this:

------------------ cut here and you'll destroy your CRT ----------------

Window create_8bit_window_on_truecolour_display(dpy,width,height)
Display *dpy;
int width, height;
{
  Window win;
  XVisualInfo vinfo;
  XSetWindowAttributes attr;

  fprintf(stderr,"Opening 8 bit window...\n");
  if (!XMatchVisualInfo(dpy,DefaultScreen(dpy),8,PseudoColor,&vinfo)) {
    fprintf(stderr,"Your display can't handle 8 bit PseudoColor.\n");
    exit(1);
  }
  fprintf(stderr,"Using visual: %x\n",vinfo.visual->visualid);
  cmap = XCreateColormap(
           dpy,
           DefaultRootWindow(dpy),
           vinfo.visual,
           AllocNone
         );
  XSync(dpy,False);
  XInstallColormap(dpy,cmap);	/* ommision of this line gives same result */
  attr.colormap = cmap;
  win = XCreateWindow(
          dpy,
          DefaultRootWindow(dpy),
          10,10,
          width,height,
          CopyFromParent,       /* border width */
          8,                    /* depth */
          InputOutput,          /* class */
          vinfo.visual,         /* visual */
          CWColormap,
          &attr
        );
  return win;
}

--- cut here and you'll destroy your CRT -----

Executing this piece of code results in a BadMatch error.
Anybody who knows why?
If so, please drop me a line.



	Take care,


		Bram Stolk
		stolk@fwi.uva.nl
