XCB

Last updated
Original author(s) Bart Massey
Developer(s) Jamey Sharp, Josh Triplett, Bart Massey
Initial release2001;23 years ago (2001)
Stable release
1.16.1 [1]   OOjs UI icon edit-ltr-progressive.svg / 2 March 2024;20 days ago (2 March 2024)
Repository
Written in C
Operating system POSIX
Type X11 client library
License MIT License
Website xcb.freedesktop.org
X11-clients use XCB to communicate with the X server. X11 display server protocol.svg
X11-clients use XCB to communicate with the X server.
A more complete view of the Linux graphics stack Linux Graphics Stack 2013.svg
A more complete view of the Linux graphics stack
Programs often use GTK or FLTK or Qt for their GUI widgets. Xlib and XCB in the X Window System graphics stack.svg
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. Free and open-source-software display servers and UI toolkits.svg
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.

Contents

Overview

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:

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. [6] 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. [7] [8]

Example

// Simple XCB application for opening a window and drawing a box in it// To compile it using GNU, use:// gcc x.c -lxcb#include<stdio.h>#include<stdlib.h>#include<xcb/xcb.h>intmain(void){xcb_connection_t*c;xcb_screen_t*s;xcb_window_tw;xcb_gcontext_tg;xcb_generic_event_t*e;uint32_tmask;uint32_tvalues[2];intdone=0;xcb_rectangle_tr={20,20,60,60};// open connection to the serverc=xcb_connect(NULL,NULL);if(xcb_connection_has_error(c)){printf("Cannot open display\n");exit(EXIT_FAILURE);}// get the first screens=xcb_setup_roots_iterator(xcb_get_setup(c)).data;// create black graphics contextg=xcb_generate_id(c);w=s->root;mask=XCB_GC_FOREGROUND|XCB_GC_GRAPHICS_EXPOSURES;values[0]=s->black_pixel;values[1]=0;xcb_create_gc(c,g,w,mask,values);// create windoww=xcb_generate_id(c);mask=XCB_CW_BACK_PIXEL|XCB_CW_EVENT_MASK;values[0]=s->white_pixel;values[1]=XCB_EVENT_MASK_EXPOSURE|XCB_EVENT_MASK_KEY_PRESS;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 windowxcb_map_window(c,w);xcb_flush(c);// event loopwhile(!done&&(e=xcb_wait_for_event(c))){switch(e->response_type&~0x80){caseXCB_EXPOSE:// draw or redraw the windowxcb_poly_fill_rectangle(c,w,g,1,&r);xcb_flush(c);break;caseXCB_KEY_PRESS:// exit on key pressdone=1;break;}free(e);}// close connection to serverxcb_disconnect(c);exit(EXIT_SUCCESS);}

The bitwise and operation a->response_type&~0x80 removes a bit that indicates where the event came from. [9]

XCB has a comparable, but slightly lower-level API than Xlib, [10] 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.[ dubious ] libxcb itself is implemented as a code generator and a tiny C stub of utility functions.

An example:

<xcbheader="bigreq"extension-xname="BIG-REQUESTS"extension-name="BigRequests"extension-multiword="true"major-version="0"minor-version="0"><requestname="Enable"opcode="0"><reply><padbytes="1"/><fieldtype="CARD32"name="maximum_request_length"/></reply></request></xcb>

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

Other language bindings

Notes

  1. "libxcb-1.16.1".
  2. Gettys, James; Packard, Keith (2004). The (Re) Architecture of the X Window System (PDF). Proc. Linux Symposium. Vol. 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. Maloney, Ross J. (31 March 2018). Low Level X Window Programming: An Introduction by Examples. Springer. pp. 225–244. ISBN   978-3-319-74250-2 . Retrieved 17 May 2022.
  7. "Xlib/XCB: Xlib with XCB transport". 2008-01-11. Retrieved 2009-09-11.
  8. 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.
  9. "X Window System Protocol". X.Org. Chapter 1. Protocol Formats. Retrieved 22 March 2024. Every event contains an 8-bit type code. The most significant bit in this code is set if the event was generated from a SendEvent request.{{cite web}}: CS1 maint: location (link)
  10. Jamey Sharp; Bart Massey (2002), XCL : An Xlib Compatibility Layer For XCB, USENIX 2002 Annual Technical Conference, Freenix Track
  11. KittyLogo (xcb.freedesktop.org)

Related Research Articles

<span class="mw-page-title-main">X Window System</span> Windowing system for bitmap displays on UNIX-like systems

The X Window System is a windowing system for bitmap displays, common on Unix-like operating systems.

<span class="mw-page-title-main">Windowing system</span> Software that manages separately different parts of display screens

In computing, a windowing system is a software suite that manages separately different parts of display screens. It is a type of graphical user interface (GUI) which implements the WIMP paradigm for a user interface.

In computing, on the X Window System, X11 color names are represented in a simple text file, which maps certain strings to RGB color values. It was traditionally shipped with every X11 installation, hence the name, and is usually located in <X11root>/lib/X11/rgb.txt. The web colors list is descended from it but differs for certain color names.

freedesktop.org (fd.o), formerly X Desktop Group (XDG), is a project to work on interoperability and shared base technology for free-software desktop environments for the X Window System (X11) and Wayland on Linux and other Unix-like operating systems. Although freedesktop.org produces specifications for interoperability, it is not a formal standards body.

<span class="mw-page-title-main">X.Org Foundation</span> Nonprofit organization

The X.Org Foundation is a non-profit corporation chartered to research, develop, support, organize, administrate, standardize, promote, and defend a free and open accelerated graphics stack. This includes, but is not limited to, the following projects: DRM, Mesa 3D, Wayland, and the X Window System and its primary implementation, the X.Org Server.

X.Org Server is the free and open-source implementation of the X Window System (X11) display server stewarded by the X.Org Foundation.

In computing, the X Window System is a network-transparent windowing system for bitmap displays. This article details the protocols and technical structure of X11.

<span class="mw-page-title-main">X Toolkit Intrinsics</span>

X Toolkit Intrinsics is a library that implements an API to facilitate the development of programs with a graphical user interface (GUI) for the X Window System. It can be used in the C language. Design took place late 1980s to early 1990s.

<span class="mw-page-title-main">Xgl</span> Display server implementation

Xgl is an obsolete display server implementation supporting the X Window System protocol designed to take advantage of modern graphics cards via their OpenGL drivers, layered on top of OpenGL. It supports hardware acceleration of all X, OpenGL and XVideo applications and graphical effects by a compositing window manager such as Compiz or Beryl. The project was started by David Reveman of Novell and first released on January 2, 2006. It was removed from the X.org server in favor of AIGLX on June 12, 2008.

<span class="mw-page-title-main">Xlib</span> Client library for the X Window System

Xlib is an X Window System protocol client library written in the C programming language. It contains functions for interacting with an X server. These functions allow programmers to write programs without knowing the details of the X protocol.

In computing, XFixes is an X Window System extension which makes useful additions to the X11 protocol. It was started in 2003 by Keith Packard. It first appeared in the KDrive X server and later in X.Org Server version 6.8.0.

<span class="mw-page-title-main">X Rendering Extension</span>

The X Rendering Extension is an extension to the X11 core protocol to implement image compositing in the X server, to allow an efficient display of transparent images.

<span class="mw-page-title-main">X Window selection</span>

Selections, cut buffers, and drag-and-drop are the mechanisms used in the X Window System to allow a user to transfer data from one window to another. Selections and cut buffer are typically used when a user selects text or some other data in a window and pastes in another one. Drag-and-drop is used when a user selects something in a window, then clicks on the selection and drags it into another window.

The X Window System core protocol is the base protocol of the X Window System, which is a networked windowing system for bitmap displays used to build graphical user interfaces on Unix, Unix-like, and other operating systems. The X Window System is based on a client–server model: a single server controls the input/output hardware, such as the screen, the keyboard, and the mouse; all application programs act as clients, interacting with the user and with the other clients via the server. This interaction is regulated by the X Window System core protocol. Other protocols related to the X Window System exist, both built at the top of the X Window System core protocol or as separate protocols.

In human–computer interfaces, the X keyboard extension or XKB is a part of the X Window System that extends the ability to control the keyboard over what is offered by the X Window System core protocol, and allows to use multiple keyboard layouts.

The MIT Shared Memory Extension or MIT-SHM or XShm is an X Window System extension for exchange of image data between client and server using shared memory. The mechanism only works when both pieces are on the same computer.

<span class="mw-page-title-main">Xephyr</span>

Xephyr is display server software implementing the X11 display server protocol based on KDrive which targets a window on a host X Server as its framebuffer. It is written by Matthew Allum. Xephyr is an X-on-X implementation and runs on X.Org Server and can work with Glamor. Future versions could make use of libinput. Replacing Xephyr with the xf86-video-dummy and xf86-video-nested drivers in the normal X.Org server is being considered as part of X11R7.8.

<span class="mw-page-title-main">Wayland (protocol)</span> Display system intended to replace X11

Wayland is a communication protocol that specifies the communication between a display server and its clients, as well as a C library implementation of that protocol. A display server using the Wayland protocol is called a Wayland compositor, because it additionally performs the task of a compositing window manager.

awesome (window manager) Window manager for X Window System

awesome is a dynamic window manager for the X Window System developed in the C and Lua programming languages. Lua is also used for configuring and extending the window manager. Its development began as a fork of dwm, though has differed considerably since. It aims to be extremely small and fast, yet extensively customizable. It makes it possible for the user to manage windows with the use of keyboard.

References