[Xcb] how to draw a point ?
Kevin Brosius
cobra at compuserve.com
Sat Nov 6 17:02:08 PST 2004
Jamey Sharp wrote:
>
>
> On Sat, Nov 06, 2004 at 05:07:52PM +0100, Vincent Torri wrote:
> > i'm learning xcb (my aim is to port a program to xcb) and i want to draw a
> > point in a window.
>
> Cool!
>
> > Here is my short program:
> >
> > ...
> >
> > I see no point at coord (100, 100). Where is (are) my mistake(s) ?
>
> I see a couple of problems off-hand.
>
> You haven't assigned a value returned from XCBPIXMAPNew to p.pixmap, so
> you might have gotten an error that you didn't see. (We have some ideas
> about how to make that easier, but for now you probably want to check
> for X errors returned by XCBWaitEvent.) So make sure to assign to
> p.pixmap before calling XCBCreatePixmap on it.
>
> Also, you haven't copied the contents of your pixmap to your window,
> which you should make sure you only do after you've received an Expose
> event. I think. (I'm not actually an X expert.)
Yes, that's correct. Vincent, in X, you generally respond to Expose
events by copying your window contents from the pixmap you draw them on,
to the exposed area. X doesn't manage your displayed image for you
(like a canvas library like evas would) so you need to handle re-drawing
the contents anytime the window is shown, or a portion of it is
uncovered from behind another app (an expose event.)
You can add a case like:
case XCBExpose:
printf(" expose\n");
break;
to your event loop to see when exposes are generated. The most
efficient method is to check the expose event dimensions (it returns
coords and width,height, if I recall, for the exposed area) and just
copy the region that the expose event says was shown.
>
> > In addition, when i close the window, there's a seg fault. Where does it
> > come from ?
>
> When you close this window, your window manager is calling XKillClient,
> which causes the X server to close the socket connection to your
> program. When the connection closes, XCBWaitEvent returns null, which
> you're dereferencing in the condition of your switch statement.
>
something like:
e = XCBWaitEvent(c);
if (e)
{
.... event loop ....
}
/* otherwise, we've lost the X connection, let's terminate */
else
break;
works ok here...
> > Thank you very much !
>
> Sure!
> --
> Jamey Sharp <jamey at minilop.net> - http://minilop.net/
>
--
Kevin
More information about the xcb
mailing list