WikiKantila:Introduction
From WikiKantila
#include <X11/XCB/xcb.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
XCBConnection *c;
XCBSCREEN *s;
XCBDRAWABLE w;
XCBGCONTEXT g;
XCBGenericEvent *e;
CARD32 mask;
CARD32 values[2];
int done = 0;
XCBRECTANGLE r = { 20, 20, 60, 60 };
/* open connection with the server */
c = XCBConnect(NULL,NULL);
if (c == NULL) {
printf("Cannot open display\n");
exit(1);
}
/* get the first screen */
s = XCBSetupRootsIter( XCBGetSetup(c) ).data;
/* create black graphics context */
g = XCBGCONTEXTNew(c);
w.window = s->root;
mask = XCBGCForeground | XCBGCGraphicsExposures;
values[0] = s->black_pixel;
values[1] = 0;
XCBCreateGC(c, g, w, mask, values);
/* create window */
w.window = XCBWINDOWNew(c);
mask = XCBCWBackPixel | XCBCWEventMask;
values[0] = s->white_pixel;
values[1] = XCBEventMaskExposure | XCBEventMaskKeyPress;
XCBCreateWindow(c, s->root_depth, w.window, s->root,
10, 10, 100, 100, 1,
XCBWindowClassInputOutput, s->root_visual,
mask, values);
/* map (show) the window */
XCBMapWindow(c, w.window);
XCBFlush(c);
/* event loop */
while (!done && (e = XCBWaitForEvent(c))) {
switch (e->response_type & ~0x80) {
case XCBExpose: /* draw or redraw the window */
XCBPolyFillRectangle(c, w, g, 1, &r);
XCBFlush(c);
break;
case XCBKeyPress: /* exit on key press */
done = 1;
break;
}
free(e);
}
/* close connection to server */
XCBDisconnect(c);
return 0;
}
go back to motif

