World Library  
Flag as Inappropriate
Email this Article


Original author(s) Bart Massey
Developer(s) Jamey Sharp, Josh Triplett, Bart Massey
Initial release 2001 (2001)
Stable release 1.11.1 / 6 September 2015 (2015-09-06)[1]
Written in C
Operating system POSIX
Type X11 client library
License MIT License
Website .org.freedesktopxcb
X11-clients use XCB to communicate with the X server.
A more complete view of the Linux graphics stack.
Programs often use GTK+ or FLTK or Qt for their GUI widgets.
A more complete view of the components of an operating system for home computers.

XCB (X protocol C-language Binding) is a library implementing the client-side of the X11 display server protocol. XCB is written in the C programming language and distributed under the MIT License. The project was started in 2001 by Bart Massey and aims to replace Xlib.


  • Overview 1
    • Xlib compatibility 1.1
  • Example 2
  • Protocol description 3
  • Logo 4
  • Other language binding 5
  • Notes 6
  • References 7
  • External links 8


XCB was designed as a smaller, modernized replacement for Xlib, previously the primary C library for communicating with the X window system, coinciding with a more complete overhaul of the X implementation that took place during the early 2000s.[2] The main goals of XCB are to

  • Reduce library size and complexity;
  • Provide direct access to the X11 protocol.

The required size reduction is achieved primarily by restricting XCB's scope to handling the X protocol and omitting Xlib functionality such as its extensive utility library, much of which saw little use by applications. This results in a factor thirty reduction of the compiled library size (as of 2004).[3] 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])

Xlib compatibility

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. Xlib/XCB allows an application to open a single connection to the X display server and use both XCB and Xlib, possibly through a mixture of libraries designed for one or the other.[6][7]


/* Simple XCB application drawing a box in a window */
/* to compile it use :
 cc x.c -lxcb

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.

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.



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

Other language binding

  • xpyb - The Python binding to the X Window System using XCB. As of June 2013, it does not support Python 3. Provided by


  1. ^ Schlachter, Uli (2015-09-06). "[Xcb] [ANNOUNCE] libxcb 1.11.1". xcb (Mailing list). Retrieved 2015-09-06. 
  2. ^ Gettys, James; Packard, Keith (2004). The (Re) Architecture of the X Window System (PDF). Proc. Linux Symposium 1. 
  3. ^ Sharp, Jamey (2004). How Xlib is Implemented (And What We're Doing About It) (PDF). Proc. Usenix Annual Techn. Conf., Freenix Track. 
  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. ^ "Xlib/XCB: Xlib with XCB transport". 2008-01-11. Retrieved 2009-09-11. 
  7. ^ 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. 
  8. ^ KittyLogo (


  • Massey, Bart; Sharp, Jamey (2001-09-19). "XCB: An X Protocol C Binding" (PDF). Proceedings of the XFree86 Technical Conference. Oakland, California:  
  • 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:  
  • Sharp, Jamey; Massey, Bart (2002). "XCL: A Compatibility Layer For XCB". Proceedings of the FREENIX Track: 2002 USENIX Annual Technical Conference. Monterey, California:  

External links

  • XCB wiki (
  • XCB API reference - tutorial
  • libxcb tutorial
  • Further publications
  • The X New Developer’s Guide: Xlib and XCB
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from World Library are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.