fbpx
Wikipedia

XCB

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.

XCB
Original author(s)Bart Massey
Developer(s)Jamey Sharp, Josh Triplett, Bart Massey
Initial release2001; 22 years ago (2001)
Stable release
1.14 / February 2020; 2 years ago (2020-02)
Repository
  • gitlab.freedesktop.org/xorg/lib/libxcb
Written inC
Operating systemPOSIX
TypeX11 client library
LicenseMIT License
Websitexcb.freedesktop.org
X11-clients use XCB to communicate with the X server.
A more complete view of the Linux graphics stack
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.

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.[1] The main goals of XCB are to:

  • reduce library size and complexity
  • provide direct access to the X11 protocol

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).[2] 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.[3] (Xlib has long been known to contain errors.[4])

Xlib compatibility

Xlib/XCB provides application binary interface compatibility with both Xlib and XCB, providing an incremental porting path.[5] 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.[6][7]

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> int main(void) {  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 };  // open connection to the server  c = xcb_connect(NULL,NULL);  if (xcb_connection_has_error(c)) {  printf("Cannot open display\n");  exit(EXIT_FAILURE);  }  // 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[0] = s->black_pixel;  values[1] = 0;  xcb_create_gc(c, g, w, mask, values);  // create window  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);  // map (show) the window  xcb_map_window(c, w);  xcb_flush(c);  // 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, w, g, 1, &r);  xcb_flush(c);  break;  case XCB_KEY_PRESS: // exit on key press  done = 1;  break;  }  free(e);  }  // close connection to server  xcb_disconnect(c);  exit(EXIT_SUCCESS); } 

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

An example:

<xcb header="bigreq" extension-xname="BIG-REQUESTS" extension-name="BigRequests" extension-multiword="true" major-version="0" minor-version="0"> <request name="Enable" opcode="0"> <reply> <pad bytes="1" /> <field type="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.[9]

Other language bindings

  • XCB.pm - Perl module implementing bindings to XCB.
  • xpyb - The Python binding to the X Window System using XCB. As of June 2013, it does not support Python 3. Provided by freedesktop.org.
  • xcffib - Another Python binding which supports Python 2 & 3 as well as several more X extensions than xpyb.

Notes

  1. ^ Gettys, James; Packard, Keith (2004). The (Re) Architecture of the X Window System (PDF). Proc. Linux Symposium. Vol. 1.
  2. ^ Sharp, Jamey (2004). How Xlib is Implemented (And What We're Doing About It) (PDF). Proc. Usenix Annual Techn. Conf., Freenix Track.
  3. ^ Massey and Bauer, 2002.
  4. ^ 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."
  5. ^ 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.
  6. ^ "Xlib/XCB: Xlib with XCB transport". 2008-01-11. Retrieved 2009-09-11.
  7. ^ 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.
  8. ^ Jamey Sharp; Bart Massey (2002), XCL : An Xlib Compatibility Layer For XCB, USENIX 2002 Annual Technical Conference, Freenix Track
  9. ^ KittyLogo (xcb.freedesktop.org)

References

  • Massey, Bart; Sharp, Jamey (2001-09-19). "XCB: An X Protocol C Binding" (PDF). Proceedings of the XFree86 Technical Conference. Oakland, California: USENIX. Retrieved 2012-03-12.
  • Massey, Bart; Bauer, Robert (2002). "X Meets Z: Verifying Correctness In The Presence Of POSIX Threads". Proceedings of the FREENIX Track: 2002 USENIX Annual Technical Conference. Monterey, California: USENIX. pp. 221–234. Retrieved 2008-11-07.
  • Sharp, Jamey; Massey, Bart (2002). "XCL: A Compatibility Layer For XCB". Proceedings of the FREENIX Track: 2002 USENIX Annual Technical Conference. Monterey, California: USENIX. pp. 71–83. Retrieved 2008-11-07.

External links

  • XCB wiki (freedesktop.org)
  • XCB API reference, tutorial
  • libxcb tutorial
  • Further publications
  • The X New Developer’s Guide: Xlib and XCB

this, article, relies, excessively, references, primary, sources, please, improve, this, article, adding, secondary, tertiary, sources, find, sources, news, newspapers, books, scholar, jstor, november, 2009, learn, when, remove, this, template, message, protoc. This article relies excessively on references to primary sources Please improve this article by adding secondary or tertiary sources Find sources XCB news newspapers books scholar JSTOR November 2009 Learn how and when to remove this template message 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 XCBOriginal author s Bart MasseyDeveloper s Jamey Sharp Josh Triplett Bart MasseyInitial release2001 22 years ago 2001 Stable release1 14 February 2020 2 years ago 2020 02 Repositorygitlab wbr freedesktop wbr org wbr xorg wbr lib wbr libxcbWritten inCOperating systemPOSIXTypeX11 client libraryLicenseMIT LicenseWebsitexcb wbr freedesktop wbr orgX11 clients use XCB to communicate with the X server A more complete view of the Linux graphics stack 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 Contents 1 Overview 1 1 Xlib compatibility 2 Example 3 Protocol description 4 Logo 5 Other language bindings 6 Notes 7 References 8 External linksOverview EditXCB 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 1 The main goals of XCB are to reduce library size and complexity provide direct access to the X11 protocolThe 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 2 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 3 Xlib has long been known to contain errors 4 Xlib compatibility Edit Xlib XCB provides application binary interface compatibility with both Xlib and XCB providing an incremental porting path 5 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 6 7 Example Edit Simple XCB application for opening a window and drawing a box in it To compile it using GNU use gcc x c lxcb include lt stdio h gt include lt stdlib h gt include lt xcb xcb h gt int main void 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 open connection to the server c xcb connect NULL NULL if xcb connection has error c printf Cannot open display n exit EXIT FAILURE 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 gt root mask XCB GC FOREGROUND XCB GC GRAPHICS EXPOSURES values 0 s gt black pixel values 1 0 xcb create gc c g w mask values create window w xcb generate id c mask XCB CW BACK PIXEL XCB CW EVENT MASK values 0 s gt white pixel values 1 XCB EVENT MASK EXPOSURE XCB EVENT MASK KEY PRESS xcb create window c s gt root depth w s gt root 10 10 100 100 1 XCB WINDOW CLASS INPUT OUTPUT s gt root visual mask values map show the window xcb map window c w xcb flush c event loop while done amp amp e xcb wait for event c switch e gt response type amp 0x80 case XCB EXPOSE draw or redraw the window xcb poly fill rectangle c w g 1 amp r xcb flush c break case XCB KEY PRESS exit on key press done 1 break free e close connection to server xcb disconnect c exit EXIT SUCCESS XCB has a comparable but slightly lower level API than Xlib 8 as can be seen with this example Protocol description EditCreators 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 libxcb itself is implemented as a code generator and a tiny C stub of utility functions An example lt xcb header bigreq extension xname BIG REQUESTS extension name BigRequests extension multiword true major version 0 minor version 0 gt lt request name Enable opcode 0 gt lt reply gt lt pad bytes 1 gt lt field type CARD32 name maximum request length gt lt reply gt lt request gt lt xcb gt Logo EditThe XCB logo was produced by Gearoid Molloy author of the web comic Neko the Kitty and donated to the project 9 Other language bindings EditXCB pm Perl module implementing bindings to XCB xpyb The Python binding to the X Window System using XCB As of June 2013 it does not support Python 3 Provided by freedesktop org xcffib Another Python binding which supports Python 2 amp 3 as well as several more X extensions than xpyb Notes Edit Gettys James Packard Keith 2004 The Re Architecture of the X Window System PDF Proc Linux Symposium Vol 1 Sharp Jamey 2004 How Xlib is Implemented And What We re Doing About It PDF Proc Usenix Annual Techn Conf Freenix Track Massey and Bauer 2002 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 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 Xlib XCB Xlib with XCB transport 2008 01 11 Retrieved 2009 09 11 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 Jamey Sharp Bart Massey 2002 XCL An Xlib Compatibility Layer For XCB USENIX 2002 Annual Technical Conference Freenix Track KittyLogo xcb freedesktop org References EditMassey Bart Sharp Jamey 2001 09 19 XCB An X Protocol C Binding PDF Proceedings of the XFree86 Technical Conference Oakland California USENIX Retrieved 2012 03 12 Massey Bart Bauer Robert 2002 X Meets Z Verifying Correctness In The Presence Of POSIX Threads Proceedings of the FREENIX Track 2002 USENIX Annual Technical Conference Monterey California USENIX pp 221 234 Retrieved 2008 11 07 Sharp Jamey Massey Bart 2002 XCL A Compatibility Layer For XCB Proceedings of the FREENIX Track 2002 USENIX Annual Technical Conference Monterey California USENIX pp 71 83 Retrieved 2008 11 07 External links Edit Free Software portalXCB wiki freedesktop org XCB API reference tutorial libxcb tutorial Further publications The X New Developer s Guide Xlib and XCB Retrieved from https en wikipedia org w index php title XCB amp oldid 1104189857, wikipedia, wiki, book, books, library,

article

, read, download, free, free download, mp3, video, mp4, 3gp, jpg, jpeg, gif, png, picture, music, song, movie, book, game, games.