XCB
X protocol C language binding library

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.
01Overview
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. 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). 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. (Xlib has long been known to contain errors.)
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.

02Example
The bitwise and operation a->response_type & ~0x80 removes a bit that indicates where the event came from.
XCB has a comparable, but slightly lower-level API than Xlib, as can be seen with this example.

03Protocol 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.
An 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>
04Logo
The XCB logo was produced by Gearóid Molloy, author of the web comic Neko the Kitty, and donated to the project.

05Other language bindings
- XCB.pm - Perl module implementing bindings to XCB.
- xpyb - The Python binding to the X Window System using XCB. As of June 2013, it does not support Python 3. Provided by freedesktop.org.
- xcffib - Another Python binding which supports Python 2 & 3 as well as several more X extensions than xpyb.
- guile-xcb - Guile module implementing a language to treat the xcb definition as source code.
Sources and credits
This article is adapted from the Wikipedia article “XCB”, written by its contributors and licensed under CC BY-SA 4.0. Fathomly has changed the layout, removed citation markers, navigation and maintenance notices, and adjusted punctuation. This adapted version is shared under the same license. For references, see the original article.
Images, from Wikimedia Commons:
- Xcb logo.svg by Gearóid Molloy, Phillipp Heise This file was made by User:Sven Translation If this image contains text, it can be translated easily into your language. If you need help, contact me Flexible licenses If you want to use this picture with another license than stated below, contact me Contact the author If you need a really fast answer, mail me. If you need only a fast answer, write me here., GPL
- X11 display server protocol.svg by ScotXW, CC BY-SA 3.0
- Linux Graphics Stack 2013.svg by ScotXW, CC BY-SA 3.0
- Xlib and XCB in the X Window System graphics stack.svg by No machine-readable author provided. Echinacin35 wc assumed (based on copyright claims)., Public domain
- Free and open-source-software display servers and UI toolkits.svg by ScotXW, CC BY-SA 3.0
Fathomly is not affiliated with or endorsed by the Wikimedia Foundation. Spotted a problem? Tell us.