* for licensing information.
*/
-#include <X11/XCB/xcb.h>
-#include <X11/XCB/xcb_aux.h>
+#include <xcb/xcb.h>
+#include <xcb/xcb_aux.h>
#include "reply_formats.h"
#include <math.h>
#include <stdlib.h> /* for free(3) */
#define PI 3.14159265
-static XCBConnection *c;
-static XCBSCREEN *root;
-static XCBGCONTEXT white, black;
+static xcb_connection_t *c;
+static xcb_screen_t *root;
+static xcb_gcontext_t white, black;
static int depth;
#define WINS 8
static struct {
- XCBDRAWABLE w;
- XCBDRAWABLE p;
- CARD16 width;
- CARD16 height;
+ xcb_drawable_t w;
+ xcb_drawable_t p;
+ uint16_t width;
+ uint16_t height;
float angv;
} windows[WINS];
static void get_depth()
{
- XCBDRAWABLE drawable = { root->root };
- XCBGetGeometryRep *geom;
- geom = XCBGetGeometryReply(c, XCBGetGeometry(c, drawable), 0);
+ xcb_drawable_t drawable = { root->root };
+ xcb_get_geometry_reply_t *geom;
+ geom = xcb_get_geometry_reply(c, xcb_get_geometry(c, drawable), 0);
if(!geom)
{
perror("GetGeometry(root) failed");
depth = geom->depth;
fprintf(stderr, "Root 0x%x: %dx%dx%d\n",
- root->root.xid, geom->width, geom->height, geom->depth);
+ root->root, geom->width, geom->height, geom->depth);
free(geom);
}
pthread_t thr;
int i;
- CARD32 mask = XCBGCForeground | XCBGCGraphicsExposures;
- CARD32 values[2];
- XCBDRAWABLE rootwin;
+ uint32_t mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;
+ uint32_t values[2];
+ xcb_drawable_t rootwin;
int screen_num;
- c = XCBConnect(0, &screen_num);
- root = XCBAuxGetScreen(c, screen_num);
+ c = xcb_connect(0, &screen_num);
+ root = xcb_aux_get_screen(c, screen_num);
get_depth();
- rootwin.window = root->root;
- white = XCBGCONTEXTNew(c);
- black = XCBGCONTEXTNew(c);
+ rootwin = root->root;
+ white = xcb_generate_id(c);
+ black = xcb_generate_id(c);
pthread_create(&thr, 0, event_thread, 0);
values[1] = 0; /* no graphics exposures */
values[0] = root->white_pixel;
- XCBCreateGC(c, white, rootwin, mask, values);
+ xcb_create_gc(c, white, rootwin, mask, values);
values[0] = root->black_pixel;
- XCBCreateGC(c, black, rootwin, mask, values);
+ xcb_create_gc(c, black, rootwin, mask, values);
for(i = 1; i < WINS; ++i)
pthread_create(&thr, 0, run, (void*)i);
void paint(int idx)
{
- XCBCopyArea(c, windows[idx].p, windows[idx].w, white, 0, 0, 0, 0,
+ xcb_copy_area(c, windows[idx].p, windows[idx].w, white, 0, 0, 0, 0,
windows[idx].width, windows[idx].height);
- if(!XCBSync(c, 0))
+ /* FIXME: better error detection for broken pipe
+ if(!xcb_sync(c, 0))
{
- perror("XCBSync failed");
+ perror("xcb_sync_t failed");
abort();
}
+ */
+ xcb_aux_sync(c);
}
void *run(void *param)
int xo, yo;
double r, theta = 0;
- XCBPOINT line[2];
+ xcb_point_t line[2];
- windows[idx].w.window = XCBWINDOWNew(c);
- windows[idx].p.pixmap = XCBPIXMAPNew(c);
+ windows[idx].w = xcb_generate_id(c);
+ windows[idx].p = xcb_generate_id(c);
windows[idx].width = 300;
line[0].x = xo = windows[idx].width / 2;
windows[idx].height = 300;
}
{
- CARD32 mask = XCBCWBackPixel | XCBCWEventMask | XCBCWDontPropagate;
- CARD32 values[3];
- XCBRECTANGLE rect = { 0, 0, windows[idx].width, windows[idx].height };
+ uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_DONT_PROPAGATE;
+ uint32_t values[3];
+ xcb_rectangle_t rect = { 0, 0, windows[idx].width, windows[idx].height };
values[0] = root->white_pixel;
- values[1] = XCBEventMaskButtonRelease | XCBEventMaskExposure;
- values[2] = XCBEventMaskButtonPress;
+ values[1] = XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_EXPOSURE;
+ values[2] = XCB_EVENT_MASK_BUTTON_PRESS;
- XCBCreateWindow(c, depth, windows[idx].w.window, root->root,
+ xcb_create_window(c, depth, windows[idx].w, root->root,
/* x */ 0, /* y */ 0,
windows[idx].width, windows[idx].height,
- /* border */ 0, XCBWindowClassInputOutput,
+ /* border */ 0, XCB_WINDOW_CLASS_INPUT_OUTPUT,
/* visual */ root->root_visual,
mask, values);
- XCBMapWindow(c, windows[idx].w.window);
+ xcb_map_window(c, windows[idx].w);
- XCBCreatePixmap(c, depth,
- windows[idx].p.pixmap, windows[idx].w,
+ xcb_create_pixmap(c, depth,
+ windows[idx].p, windows[idx].w,
windows[idx].width, windows[idx].height);
- XCBPolyFillRectangle(c, windows[idx].p, white, 1, &rect);
+ xcb_poly_fill_rectangle(c, windows[idx].p, white, 1, &rect);
}
- XCBSync(c, 0);
+ xcb_flush(c);
while(1)
{
line[1].x = xo + r * cos(theta);
line[1].y = yo + r * sin(theta);
- XCBPolyLine(c, XCBCoordModeOrigin, windows[idx].p, black,
+ xcb_poly_line(c, XCB_COORD_MODE_ORIGIN, windows[idx].p, black,
2, line);
line[1].x = xo + r * cos(theta + LAG);
line[1].y = yo + r * sin(theta + LAG);
- XCBPolyLine(c, XCBCoordModeOrigin, windows[idx].p, white,
+ xcb_poly_line(c, XCB_COORD_MODE_ORIGIN, windows[idx].p, white,
2, line);
paint(idx);
usleep(1000000 / FRAME_RATE);
}
+
+ return 0;
}
-int lookup_window(XCBWINDOW w)
+int lookup_window(xcb_window_t w)
{
int i;
for(i = 0; i < WINS; ++i)
- if(windows[i].w.window.xid == w.xid)
+ if(windows[i].w == w)
return i;
return -1;
}
void *event_thread(void *param)
{
- XCBGenericEvent *e;
+ xcb_generic_event_t *e;
int idx;
while(1)
{
- e = XCBWaitForEvent(c);
+ e = xcb_wait_for_event(c);
if(!formatEvent(e))
return 0;
- if(e->response_type == XCBExpose)
+ if(e->response_type == XCB_EXPOSE)
{
- XCBExposeEvent *ee = (XCBExposeEvent *) e;
+ xcb_expose_event_t *ee = (xcb_expose_event_t *) e;
idx = lookup_window(ee->window);
if(idx == -1)
fprintf(stderr, "Expose on unknown window!\n");
else
{
- XCBCopyArea(c, windows[idx].p, windows[idx].w,
+ xcb_copy_area(c, windows[idx].p, windows[idx].w,
white, ee->x, ee->y, ee->x, ee->y,
ee->width, ee->height);
if(ee->count == 0)
- XCBFlush(c);
+ xcb_flush(c);
}
}
- else if(e->response_type == XCBButtonRelease)
+ else if(e->response_type == XCB_BUTTON_RELEASE)
{
- XCBButtonReleaseEvent *bre = (XCBButtonReleaseEvent *) e;
+ xcb_button_release_event_t *bre = (xcb_button_release_event_t *) e;
idx = lookup_window(bre->event);
if(idx == -1)
fprintf(stderr, "ButtonRelease on unknown window!\n");
else
{
- if(bre->detail.id == XCBButton1)
+ if(bre->detail == XCB_BUTTON_INDEX_1)
windows[idx].angv = -windows[idx].angv;
- else if(bre->detail.id == XCBButton4)
+ else if(bre->detail == XCB_BUTTON_INDEX_4)
windows[idx].angv += 0.001;
- else if(bre->detail.id == XCBButton5)
+ else if(bre->detail == XCB_BUTTON_INDEX_5)
windows[idx].angv -= 0.001;
}
}