diff options
author | Ian Osgood <iano@quirkster.com> | 2006-09-24 14:24:23 -0700 |
---|---|---|
committer | Ian Osgood <iano@quirkster.com> | 2006-09-24 14:24:23 -0700 |
commit | 84892289c90cd76232592238517d80928a53a701 (patch) | |
tree | 2b9b42446a43bc10aaadcf8d75ad4741bcb169e3 /hypnomoire.c | |
parent | a388fd327ae42213aa5dfb7fddd19b9fc2541ca0 (diff) |
All XCB demos compile and work after the Great Renaming.
Diffstat (limited to 'hypnomoire.c')
-rw-r--r-- | hypnomoire.c | 104 |
1 files changed, 53 insertions, 51 deletions
diff --git a/hypnomoire.c b/hypnomoire.c index 46e2999..0f98b23 100644 --- a/hypnomoire.c +++ b/hypnomoire.c @@ -21,17 +21,17 @@ #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]; @@ -40,9 +40,9 @@ void *event_thread(void *param); 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"); @@ -60,28 +60,28 @@ int main() 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); + white = xcb_gcontext_new(c); + black = xcb_gcontext_new(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); @@ -93,14 +93,16 @@ int main() 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); - /* TODO: better error detection for broken pipe */ - 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) @@ -110,10 +112,10 @@ 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.window = xcb_window_new(c); + windows[idx].p.pixmap = xcb_pixmap_new(c); windows[idx].width = 300; line[0].x = xo = windows[idx].width / 2; windows[idx].height = 300; @@ -127,41 +129,41 @@ void *run(void *param) } { - 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.window, 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.window); - XCBCreatePixmap(c, depth, + xcb_create_pixmap(c, depth, windows[idx].p.pixmap, 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); } - XCBFlush(c); + 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); @@ -177,7 +179,7 @@ void *run(void *param) return 0; } -int lookup_window(XCBWINDOW w) +int lookup_window(xcb_window_t w) { int i; for(i = 0; i < WINS; ++i) @@ -188,42 +190,42 @@ int lookup_window(XCBWINDOW w) 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.id == XCB_BUTTON_INDEX_1) windows[idx].angv = -windows[idx].angv; - else if(bre->detail.id == XCBButton4) + else if(bre->detail.id == XCB_BUTTON_INDEX_4) windows[idx].angv += 0.001; - else if(bre->detail.id == XCBButton5) + else if(bre->detail.id == XCB_BUTTON_INDEX_5) windows[idx].angv -= 0.001; } } |