Libxcb

From LQWiki
Jump to navigation Jump to search

libxcb or just XCB is a low level library to interact with a X server. The library (or, more accurately, libraries) is a attempt to replace the old Xlib library set that was and still remains (as of 2007) the primary way to interact with X in C. XCB aims to be relatively low latency (compared to Xlib), better thread support, and low footprint.

As of 2007, XCB is fairly complete, but possibly not mature/API stable. There is also a severe lack of documentation, most of the documentation is DoxyGen generated with no descriptions for 99% of the things documented. luckily, since the XCB API's are fairly self descriptive, and exists at the same level as Xlib, a combination of a Xlib reference manual and some exploration, one can figure out the API fairly easily.

XCB Particularities

XCB differs from Xlib in two major ways: First, low latency is achieved by having functions be non blocking, each request to the X server returns a cookie, you use the cookie later to request the X servers reply, the idea being that multiple requests can be made before requiring a reply. This tends to mean that operations in XCB have two steps, sending the request, then asking for the reply when needed. If a error occurs, its only accessible from the reply, and only if you supply a error data type to fill.

Secondly, data types tend to have associated iterators and iterator functions. These iterators can be used to go over a list of possible values. Various functions in XCB return a iterator when dealing with lists, rather then having the programmer construct these iterators themselves. This also means its not possible to simply index such a list.

Lastly, tho not important enough to mention with a number, XCB doesn't have convince macros like Xlib does. A good example is getting a Screen, you have to go thru a iterator, you cant simply ask for the default screen as you could in Xlib.

External Links