[Xcb] how to draw a point ?

Vincent Torri torri at cauchy.iecn.u-nancy.fr
Sun Nov 7 02:43:02 PST 2004


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

well, that's right, i've forgotten to make a new pixmap... Thanks.

i've added such case for the expose event, and drawn my pixmap on the
window with XCBCopyArea when it is exposed. But unfortunately, no pixel on
the window (i've attached the code).

A question: is XCBCopyArea the function that i should use to copy the
pixmap onto the window ?

remark that the Expose event is not called when the window is uncovered,
it is  just called once, when the window is created. I don't know if it's
normal, or if i should use another xcb event.

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

ok, got it, thanks. I've used
while ((e=XCBWaitEvent(c)))
{
  switch over events
  free (e);
}
which works.

Thanks

and btw, glad to see you here, Cobra ;)

best regards

Vincent TORRI
-------------- next part --------------
A non-text attachment was scrubbed...
Name: xpoints.c
Type: text/x-csrc
Size: 2541 bytes
Desc: 
Url : http://freedesktop.org/pipermail/xcb/attachments/20041107/d9a100e8/xpoints.c


More information about the xcb mailing list