The Full Wiki

XCB: Wikis


Note: Many of our articles have direct quotes from sources you can cite, within the Wikipedia article! This article doesn't yet, but we're working on it! See more info or our list of citable articles.


From Wikipedia, the free encyclopedia

Xcb logo.svg
Developer(s) Jamey Sharp, Josh Triplett, Bart Massey
Stable release 1.3 / 2009-07-15; 5 months ago[1]
Operating system POSIX
Type X Window core protocol development library
License MIT

In computing, XCB (X C 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 distributions nowadays use Xlib/XCB for their libX11, because by opening a single connection to the X server this allows to mix usage of XCB and Xlib in an application and the libraries it uses[2][3].



The main aims of XCB are:

  • reduction in library size and complexity;
  • direct access to the X11 protocol.

Secondary aims include making the C interface asynchronous, facilitating better multithreading and making extensions easier to implement (via XML protocol descriptions).

The core and extension protocol descriptions are in XML, with the C bindings created via a Python script. (Previous versions used XSLT and M4.) A tertiary aim is to repurpose these protocol descriptions for the creation of protocol documentation, further 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])


/* Simple XCB application drawing a box in a window */
#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");
                        /* 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;
  values[0] = s->black_pixel;
  values[1] = 0;
  xcb_create_gc(c, g, w, mask, values);
                       /* create window */
  w = xcb_generate_id(c);
  values[0] = s->white_pixel;
  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);
                        /* 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);
    case XCB_KEY_PRESS:  /* exit on key press */
      done = 1;
                        /* close connection to server */
  return 0;

XCB has a comparable, but slightly lower-level API than Xlib, as can be seen with this example.

The XCB logo was produced by Gearóid Molloy, author of the web comic Neko the Kitty, and donated to the project.[6]


  1. ^ Fontaine, Arnaud (2009-07-15). "[Xcb] [ANNOUNCE] libxcb-1.4". xcb mailing list. Retrieved 2009-09-11.  
  2. ^ "Xlib/XCB: Xlib with XCB transport". 2008-01-11. Retrieved 2009-09-11.  
  3. ^ 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. Retrieved 2009-09-11.  
  4. ^ Massey and Bauer, 2002.
  5. ^ 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."
  6. ^ KittyLogo (


External links



Got something to say? Make a comment.
Your name
Your email address