XCB

XCB (XC Binding) is a program library that the transactions of the X Window protocol with function calls in the C programming available in a simple and direct way. So they tried to replace the current Xlib by a more lightweight library.

Meanwhile, with Xlib / XCB Xlib one available, the transport layer has been replaced by XCB. By using the traditional Xlib binary compatible interface can be used by existing programs instead of traditional Xlib.

Objectives

XCB aims at the following objectives:

  • Smaller and less complex
  • Direct access to the X11 protocol
  • Asynchronously to support concurrent programs better
  • Easy to expand

Example

While in Xlib or in Xlib / XCB the event loop is still made in Xlib function calls, you can see here a program piece without Xlib calls. The calls are something machine-oriented than you would expect from Xlib.

/ * XCB simple application that draws a rectangle in a window.      Compilable example with: gcc -o xcbtest xcbtest.c - lxcb * /     # include   # include   # include     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 ​​;     int done = 0;     xcb_rectangle_t r = { 20, 20, 60, 60};                            Open / * connection to the X server * /     if (( c = xcb_connect (NULL, NULL) ) == NULL) {       printf ( "Can not open display \ n");       exit (1 );     }                          / * Get the first screen * /     s = xcb_setup_roots_iterator ( xcb_get_setup ( c ) ) data. ;                            / * Create black graphics context * /     g = xcb_generate_id (c);     w = s- > root;     mask = XCB_GC_FOREGROUND | XCB_GC_GRAPHICS_EXPOSURES;     values ​​= s- > black_pixel;     values ​​= 0;     xcb_create_gc (c, g, w, mask, values);                            / * Create the window * /     w = xcb_generate_id (c);     mask = XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK;     values ​​= s- > white_pixel;     values ​​= 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);                            / * Display ( Show, "map" ) of the window * /     xcb_map_window ( c, w );       xcb_flush (c);                            / * Event loop, event loop * /     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, f, g, 1, & r );         xcb_flush (c);         break;       case XCB_KEY_PRESS: / * exit if a key is pressed * /         done = 1;         break;       }       free (s);     }                          Disconnect / * connection to the X server * /     xcb_disconnect (c);       return 0;   } Web Links