XCB
XCB
|
|
---|---|
Basic data
|
|
developer | Jamey Sharp, Josh Triplett, Bart Massey |
Current version | 1.13 (May 5, 2018) |
operating system | POSIX |
programming language | C. |
category | X-Window core protocol developer library |
License | WITH |
German speaking | No |
xcb.freedesktop.org |
XCB ( XCB inding ) is a program library that makes transactions of the X Window Protocol available in a simple and direct manner via function calls in the C programming language . In doing so, she tries to replace the previous Xlib with a lighter-weight library.
In the meantime, an Xlib is available with Xlib / XCB, the transport layer of which has been replaced by XCB. Due to the interface that is binary compatible with the conventional Xlib , it can be used by existing programs instead of the conventional Xlib.
Overview
XCB was designed as a smaller, modernized replacement for Xlib, formerly the primary C library for communicating with the X Window System, at the same time as a major overhaul of the X implementation that took place in the early 2000s. The main goals of XCB are:
- achieve a reduction in the size and complexity of the library
- to offer direct access to the X11 protocol
The required size reduction is primarily achieved by restricting the scope of XCB to handling the X protocol and omitting Xlib functions, such as the extensive utility library, which, however, were also used less in applications. Secondary goals include making the C interface asynchronous, enabling better multithreading and making extensions (using XML protocol descriptions) easier to implement. The descriptions of the core and extension protocols are in XML , with a program written in Python creating the C bindings .
Another aim is to be able to use the protocol descriptions to create protocol documentation, other language bindings and server-side stubs .
Xlib compatibility
Xlib / XCB offers compatibility with the binary application interface with Xlib and XCB and offers an incremental porting path. Xlib / XCB uses the Xlib protocol layer, 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 mix of libraries developed for one application or another.
aims
XCB aims to:
- smaller and less complex
- direct access to the X11 protocol
- asynchronous to better support concurrent programs
- easy to expand
example
While in Xlib or in Xlib / XCB the event loop is still made in Xlib function calls, here you can see a program section without Xlib calls. The calls are a bit closer to the system than you are used to from Xlib.
/* einfache XCB-Applikation, die ein Rechteck in ein Fenster zeichnet.
Kompilierbar beispielsweise mit: gcc -o xcbtest xcbtest.c -lxcb */
#include <xcb/xcb.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
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 };
/* Verbindung zum X-Server öffnen */
if((c = xcb_connect(NULL,NULL)) == NULL) {
printf("Cannot open display\n");
exit(1);
}
/* get the first screen */
s = xcb_setup_roots_iterator( xcb_get_setup(c) ).data;
/* schwarzen Grafikkontext erzeugen */
g = 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);
/* Fenster erzeugen */
w = 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);
/* Anzeigen (einblenden, "map") des Fensters */
xcb_map_window(c, w);
xcb_flush(c);
/* event loop, Ereignisschleife */
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);
xcb_flush(c);
break;
case XCB_KEY_PRESS: /* beenden, wenn eine Taste gedrückt wird */
done = 1;
break;
}
free(e);
}
/* Verbindung zum X-Server trennen */
xcb_disconnect(c);
return 0;
}
Web links
-
xcb.freedesktop.org Wiki
- XCB API Reference (English)
- Other publications (English)
- Basic Graphics Programming With the XCB Library Tutorial
Individual evidence
- ↑ https://lists.x.org/archives/xorg-announce/2018-March/002851.html
- ↑ Bart Massey, J amey Sharp: XCB: An X Protocol C Binding . (PDF; 53 kB) September 19, 2001 (English)
- ^ The (Re) Architecture of the X Window System. 2003, accessed on May 27, 2019 .
- ^ Xlib / XCB: Xlib with XCB transport. Accessed May 27, 2019 .
- ↑ libx11 with Xlib / XCB now in experimental; please test with your packages. Accessed May 27, 2019 .