[Xcb] how to draw a point ?

Vincent Torri torri at cauchy.iecn.u-nancy.fr
Sat Nov 6 08:07:52 PST 2004


hello,

i'm learning xcb (my aim is to port a program to xcb) and i want to draw a
point in a window.

Here is my short program:

#include <stdio.h>
#include <malloc.h>

#include <X11/XCB/xcb.h>
#include <X11/XCB/xcbint.h>

int
main (int argc, char *argv[])
{
  XCBConnection   *c;
  XCBSCREEN       *root;
  XCBDRAWABLE      draw;
  XCBDRAWABLE      p;
  XCBGCONTEXT      black;
  XCBPOINT         point = {100, 100};
  XCBGenericEvent *e;
  CARD32           mask = 0;
  CARD32           values[6];

  c = XCBConnectBasic();
  root = XCBConnSetupSuccessRepRootsIter(c->setup).data;

  mask = XCBCWBackPixel | XCBCWBorderPixel | XCBCWBackingStore |
    XCBCWOverrideRedirect | XCBCWEventMask | XCBCWDontPropagate;
  values[0] = root->white_pixel;
  values[1] = root->black_pixel;
  values[2] = Always;
  values[3] = 0;
  values[4] = ButtonReleaseMask | ExposureMask | StructureNotifyMask
    | EnterWindowMask | LeaveWindowMask;
  values[5] = ButtonPressMask;

  draw.window = XCBWINDOWNew(c);
  XCBCreateWindow(c,
		  0,                    /* depth */
		  draw.window, root->root,
		  20, 200,              /* x, y */
		  150, 150,             /* width, height */
		  10,                   /* border_width */
		  InputOutput,          /* class */
		  root->root_visual,    /* visual */
		  mask, values);
  XCBMapWindow(c, draw.window);

  XCBCreatePixmap(c,
		  0,
		  p.pixmap, draw,
		  150, 150);

  black = XCBGCONTEXTNew(c);
  mask = GCForeground | GCGraphicsExposures;
  values[1] = 0; /* no graphics exposures */
  values[0] = root->black_pixel;
  XCBCreateGC(c, black, draw, mask, values);
  XCBPolyPoint(c,
	       CoordModeOrigin,
	       p,
	       black,
	       1, &point);

  XCBSync(c, 0);

  while (1)
    {
      e = XCBWaitEvent(c);
      switch (e->response_type)
	{
	case XCBButtonRelease:
	  {
	    XCBButtonReleaseEvent *ev = (XCBButtonReleaseEvent *)e;

	    printf ("bouton pressed %d %d\n", ev->event_x, ev->event_y);
	    break;
	  }
	}
      free (e);
    }

  return 1;
}

I see no point at coord (100, 100). Where is (are) my mistake(s) ?
In addition, when i close the window, there's a seg fault. Where does it
come from ?

Thank you very much !

Vincent TORRI



More information about the xcb mailing list