[Xcb] some questions

Jamey Sharp jamey at minilop.net
Sun Nov 14 10:28:02 PST 2004

On Fri, Nov 12, 2004 at 10:32:04AM +0100, Vincent Torri wrote:
> I use a XCBDRAWABLE for creating a window. Could I use the pixmap field of
> this drawable for writing a colored rectangle (for example) in it, or is
> this pixmap field for other purposes ? I ask this because in hypnomoire.c,
> there's a struct with 2 drawables, the window and the pixmap, but for the
> window, only its window field is used, and for the pixmap, only the pixmap
> field is used. So it seems that for those 2 xcbdrawables, only one of the
> 2 fields are used. It seems strange to me.

On Fri, Nov 12, 2004 at 10:23:23PM -0500, Jeremy A. Kolb wrote:
> One question, drawables have window and pixmap 
> members... so why in the demos do people use one drawable for the pixmap 
> and another for the window?

XCBDRAWABLE is a union, not a structure.

Some operations, like CreatePixmap, only work when applied to PIXMAPs.
Others like CreateWindow only work on WINDOWs. But many operations can
operate on either, such as the various drawing operations. These take a
DRAWABLE, which is the X protocol name given to "a thing that's either a

In Xlib, this detail isn't obvious, because Window, Pixmap, and Drawable
objects are all typedef'd from XID, which is just an unsigned 32-bit
integer. Because of the way C's type system works, a Pixmap may be
passed where a Window is expected and vice versa, leading to obscure
bugs. This is why in XCB we use the C type system to enforce stricter

As a result, users of XCB can quickly discover that they have to
understand the difference between WINDOW, PIXMAP, and DRAWABLE, while
users of Xlib might have gotten lucky for a while before being confused
by weird errors.

There have to be two separate objects for the window and the pixmap in
the demos, because there are two separate XCB...New calls. I stored the
results into DRAWABLEs so I wouldn't have to construct DRAWABLEs from
WINDOWs or PIXMAPs later. In light of the type-safety requirements that
led to this design, I wonder if that was a bad idea, since someone might
think they could put a WINDOW into the DRAWABLE and get a PIXMAP out.
(No, you can't do that.)

Vincent, if you look at PolyFillRectangle, you'll see that it doesn't
take a PIXMAP - it takes a DRAWABLE. So no, you can't use the pixmap
field, but you can use the drawable itself.

Hope that helps.
Jamey Sharp <jamey at minilop.net> - http://minilop.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://freedesktop.org/pipermail/xcb/attachments/20041114/f3d39294/attachment.pgp

More information about the xcb mailing list