Talk:XCB
From Wikipedia, the free encyclopedia
[edit] Peer review of a related article
I submitted X Window core protocol for peer review, as I intend to candidate it for featured status. I would appreciate comments (Peer review page). - Liberatore(T) 18:07, 21 February 2006 (UTC)
[edit] Question
In the example, I see a function XCBWaitForEvent. As far as I understand, this function actually waits for events on the network, and this is different than the corresponding Xlib function (which looks a local queue). If this is correct, it may be a good idea to mention, as it looks like a big differnce. - Liberatore(T) 11:51, 4 May 2006 (UTC)
- No, there is also an internal event queue in XCB. Both XCB and Xlib will block if the queue is empty. --IanOsgood 19:33, 24 August 2006 (UTC)
-
- Thanks. This could be added to the article, now or in the future (Liberatore, 2006). 20:52, 24 August 2006 (UTC)
[edit] Improved version of XCB example code
This is a matter of opinion, but here is a version that is shorter and takes advantage of C99 features. I think it elucidates the task at hand much more clearly than the existing code. If there are no comments, I will change the article to include this code.
#include <xcb/xcb.h> #include <stdio.h> #include <stdlib.h> #include <errno.h> int main(int argc, char **argv) { /* open connection with the server */ xcb_connection_t *c = xcb_connect(NULL,NULL); if (xcb_connection_has_error(c)) { errno = ENOTCONN; perror(*argv); return EXIT_FAILURE; } /* get the first screen */ xcb_screen_t *s = xcb_setup_roots_iterator( xcb_get_setup(c) ).data; xcb_gcontext_t g = xcb_generate_id(c); uint32_t values[2]= {s->black_pixel, 0}; xcb_create_gc(c, g, s->root, XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES , values); /* create window */ xcb_window_t w = xcb_generate_id(c); values[0] = s->white_pixel; values[1] = XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_KEY_PRESS; xcb_create_window( c, s->root_depth, w, s->root, 10, 10, 100, 100, 1, XCB_WINDOW_CLASS_INPUT_OUTPUT, s->root_visual, XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK, values ); /* map (show) the window */ xcb_map_window(c, w); xcb_flush(c); /* event loop */ xcb_generic_event_t *e; for( xcb_rectangle_t r = {20,20,60,60}; ( e = xcb_wait_for_event(c) ) && XCB_KEY_PRESS != ( e->response_type & ~0x80 ); free(e) ) if(XCB_EXPOSE == (e->response_type & ~0x80)) { /* draw or redraw the window */ xcb_poly_fill_rectangle(c, w, g, 1, &r); xcb_flush(c); } free(e); // catch the missed free() that occurs when the for-loop exits /* close connection to server */ xcb_disconnect(c); return EXIT_SUCCESS; }
—The preceding unsigned comment was added by 216.115.29.1 (talk • contribs) 20:10, 5 April 2007 (UTC)