Newsgroups: comp.windows.x
Path: cantaloupe.srv.cs.cmu.edu!crabapple.srv.cs.cmu.edu!fs7.ece.cmu.edu!europa.eng.gtefsd.com!gatech!enterpoop.mit.edu!thunder.mcrcim.mcgill.edu!mouse
From: mouse@thunder.mcrcim.mcgill.edu (der Mouse)
Subject: Re: Creating 8 bit windows on 24 bit display.. How?
Message-ID: <1993Apr17.143934.29594@thunder.mcrcim.mcgill.edu>
Organization: McGill Research Centre for Intelligent Machines
References: <1993Apr16.093209.25719@fwi.uva.nl>
Date: Sat, 17 Apr 93 14:39:34 GMT
Lines: 59

In article <1993Apr16.093209.25719@fwi.uva.nl>, stolk@fwi.uva.nl (Bram) writes:

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

Lucky dog... :-)

> 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.

It applies with equal force to earlier versions.  Presumably only
recently did the author(s) decide it was important enough to mention.
The necessity it refers to has always been there, but it's been
implicit in the way CreateWindow requests default some attributes of
the new window.

> However, even if I pass along a suitable colourmap, I still get a
> BadMatch when I create a window with a non-default visual.

>   attr.colormap = cmap;
>   win = XCreateWindow(
[...]
>           CopyFromParent,       /* border width */
>           8,                    /* depth */
>           InputOutput,          /* class */
>           vinfo.visual,         /* visual */
>           CWColormap,
>           &attr
>         );

This is because the warning you read is incomplete.  You have to
provide not only a colormap but also a border.  The default border is
CopyFromParent, which is not valid when the window's depth doesn't
match its parent's.  Specify a border-pixmap of the correct depth, or a
border-pixel, and the problem should go away.

There is another problem: I can't find anything to indicate that
CopyFromParent makes any sense as the border_width parameter to
XCreateWindow.  Your Xlib implementation probably defines
CopyFromParent as zero, to simplify the conversion to wire format, so
you are unwittingly asking for a border width of zero, due to the Xlib
implementation not providing stricter type-checking.  (To be fair, I'm
not entirely certain it's possible for Xlib to catch this.)

					der Mouse

				mouse@mcrcim.mcgill.edu
