Skip to content

Introduction

This tutorial is based on the Xlib Tutorial written by Guy Keren. The author allowed me to take some parts of his text, mainly the text which deals with the X Windows generality.

This tutorial is intended for people who want to start to program with the XCB library. keep in mind that XCB, like the Xlib library, isn't what most programmers wanting to write X applications are looking for. They should use a much higher level GUI toolkit like Motif, LessTiff, GTK, QT, EWL, ETK, or use Cairo. However, we need to start somewhere. More than this, knowing how things work down below is never a bad idea.

After reading this tutorial, one should be able to write very simple graphical programs, but not programs with decent user interfaces. For such programs, one of the previously mentioned libraries should be used.

But what is XCB? Xlib has been the standard C binding for the X Window System protocol for many years now. It is an excellent piece of work, but there are applications for which it is not ideal, for example:

  • Small platforms: Xlib is a large piece of code, and it's difficult to make it smaller
  • Latency hiding: Xlib requests requiring a reply are effectively synchronous: they block until the reply appears, whether the result is needed immediately or not.
  • Direct access to the protocol: Xlib does quite a bit of caching, layering, and similar optimizations. While this is normally a feature, it makes it difficult to simply emit specified X protocol requests and process specific responses.
  • Threaded applications: While Xlib does attempt to support multithreading, the API makes this difficult and error-prone.
  • New extensions: The Xlib infrastructure provides limited support for the new creation of X extension client side code.

For these reasons, among others, XCB, an X C binding, has been designed to solve the above problems and thus provide a base for

  • Toolkit implementation.
  • Direct protocol-level programming.
  • Lightweight emulation of commonly used portions of the Xlib API.