XCB
| This article relies on references to primary sources or sources affiliated with the subject, rather than references from independent authors and third-party publications. Please add citations from reliable sources. (November 2009) |
| Developer(s) | Jamey Sharp, Josh Triplett, Bart Massey |
|---|---|
| Stable release | 1.7 / August 13, 2010[1] |
| Operating system | POSIX |
| Type | X Window core protocol development library |
| License | MIT |
| Website | xcb.freedesktop.org |
In computing, XCB (X protocol C-language Binding) is a C language binding for the X Window System. It is implemented as free software and aims to replace Xlib. The project was started in 2001 by Bart Massey.
Xlib/XCB provides application binary interface compatibility with both Xlib and XCB, providing an incremental porting path. Xlib/XCB uses the protocol layer of Xlib, but replaces the Xlib transport layer with XCB, and provides access to the underlying XCB connection for direct use of XCB. Most operating systems use Xlib/XCB for their libX11[citation needed], because it allows an application to open a single connection to the X server and use both XCB and Xlib, possibly through a mixture of libraries designed for one or the other.[2][3]
Contents |
[edit] Goals
The main goals of XCB are to
- reduce library size and complexity;
- provide direct access to the X11 protocol.
Secondary goals include making the C interface asynchronous, facilitating better multithreading and making it easier to implement extensions (via XML protocol descriptions).
The core and extension protocol descriptions are in XML, with a program written in Python creating the C bindings. (Previous versions used XSLT and M4.)
A further goal is to be able to use these protocol descriptions to create protocol documentation, more language bindings, and server-side stubs.
Massey and others have worked to prove key portions of XCB formally correct using Z notation.[4] (Xlib has long been known to contain errors.[5])
[edit] Example
/* Simple XCB application drawing a box in a window */ /* to compile it use : gcc -Wall x.c -lxcb */ #include <xcb/xcb.h> #include <stdio.h> #include <stdlib.h> int main(void) { xcb_connection_t *c; xcb_screen_t *s; xcb_window_t w; xcb_gcontext_t g; xcb_generic_event_t *e; uint32_t mask; uint32_t values[2]; int done = 0; xcb_rectangle_t r = { 20, 20, 60, 60 }; /* open connection with the server */ c = xcb_connect(NULL,NULL); if (xcb_connection_has_error(c)) { printf("Cannot open display\n"); exit(1); } /* get the first screen */ s = xcb_setup_roots_iterator( xcb_get_setup(c) ).data; /* create black graphics context */ g = xcb_generate_id(c); w = s->root; mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES; values[0] = s->black_pixel; values[1] = 0; xcb_create_gc(c, g, w, mask, values); /* create window */ w = xcb_generate_id(c); mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK; 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, mask, values); /* map (show) the window */ xcb_map_window(c, w); xcb_flush(c); /* event loop */ while (!done && (e = xcb_wait_for_event(c))) { switch (e->response_type & ~0x80) { case XCB_EXPOSE: /* draw or redraw the window */ xcb_poly_fill_rectangle(c, w, g, 1, &r); xcb_flush(c); break; case XCB_KEY_PRESS: /* exit on key press */ done = 1; break; } free(e); } /* close connection to server */ xcb_disconnect(c); return 0; }
XCB has a comparable, but slightly lower-level API than Xlib, as can be seen with this example.
[edit] Protocol description
Creators of XCB have invented a specialized Interface description language to model X11 protocol in language-neutral way and facilitate generation of bindings to other programming languages. libxcb itself is implemented as a code generator and a tiny C stub of utility functions.
Example:
<xcb header="bigreq" extension-xname="BIG-REQUESTS" extension-name="BigRequests" extension-multiword="true" major-version="0" minor-version="0"> <request name="Enable" opcode="0"> <reply> <pad bytes="1" /> <field type="CARD32" name="maximum_request_length" /> </reply> </request> </xcb>
[edit] Logo
The XCB logo was produced by Gearóid Molloy, author of the web comic Neko the Kitty, and donated to the project.[6]
[edit] Notes
- ^ Danjou, Julien (2010-08-13). "[Xcb] [ANNOUNCE] libxcb 1.7". xcb mailing list. http://lists.freedesktop.org/archives/xcb/2010-August/006352.html. Retrieved 2010-08-30.
- ^ "Xlib/XCB: Xlib with XCB transport". 2008-01-11. http://xcb.freedesktop.org/XlibXcb/. Retrieved 2009-09-11.
- ^ Jamey Sharp and Josh Triplett (2006-11-26). "libx11 with Xlib/XCB now in experimental; please test with your packages". debian-devel-announce mailing list. http://lists.debian.org/debian-devel-announce/2006/11/msg00010.html. Retrieved 2009-09-11.
- ^ Massey and Bauer, 2002.
- ^ Sharp and Massey, 2002, §2.4. "While Xlib was designed to support threaded applications, and while that support is not unusable, there are known race conditions that cannot be eliminated without changing the Xlib interface."
- ^ KittyLogo (xcb.freedesktop.org)
[edit] References
- Massey, Bart; Sharp, Jamey (2001-09-19). "XCB: An X Protocol C Binding" (PDF). Proceedings of the XFree86 Technical Conference. Oakland, California: USENIX. http://www.linuxshowcase.org/2001/full_papers/massey/massey.pdf. Retrieved 2008-11-07.
- Massey, Bart; Bauer, Robert (2002). "X Meets Z: Verifying Correctness In The Presence Of POSIX Threads". Proceedings of the FREENIX Track: 2002 USENIX Annual Technical Conference. Monterey, California: USENIX. pp. 221–234. http://www.usenix.org/events/usenix02/tech/freenix/full_papers/massey/massey_html/index.html. Retrieved 2008-11-07.
- Sharp, Jamey; Massey, Bart (2002). "XCL: A Compatibility Layer For XCB". Proceedings of the FREENIX Track: 2002 USENIX Annual Technical Conference. Monterey, California: USENIX. pp. 71–83. http://www.usenix.org/events/usenix02/tech/freenix/full_papers/sharp/sharp_html/index.html. Retrieved 2008-11-07.
[edit] External links
|
||||||||||||||||