Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

XCB

From Wikipedia, the free encyclopedia
X protocol C language binding library
This articlerelies excessively onreferences toprimary sources. Please improve this article by addingsecondary or tertiary sources.
Find sources: "XCB" – news ·newspapers ·books ·scholar ·JSTOR
(November 2009) (Learn how and when to remove this message)
Original author(s)Bart Massey
Developer(s)Jamey Sharp, Josh Triplett, Bart Massey
Initial release2001; 24 years ago (2001)
Stable release
1.17.0[1] Edit this on Wikidata / 15 April 2024; 11 months ago (15 April 2024)
Repository
Written inC
Operating systemPOSIX
TypeX11 client library
LicenseMIT License
Websitexcb.freedesktop.org
X11-clients use XCB to communicate with theX server.
A more complete view of theLinux graphics stack
Programs often useGTK orFLTK orQt for theirGUI widgets.
A more complete view of the components of an operating system for home computers.

XCB (X protocol C-language Binding) is alibrary implementing the client-side of theX11 display server protocol. XCB is written in theC programming language and distributed under theMIT License. The project was started in 2001 by Bart Massey and aims to replaceXlib.

Overview

[edit]

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:

  • reduce library size and complexity
  • provide direct access to theX11 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).[3]Secondary goals include making the C interfaceasynchronous, facilitating bettermultithreading and making it easier to implement extensions (viaXML protocol descriptions).

The core and extension protocol descriptions are inXML, with a program written inPython creating the C bindings. (Previous versions usedXSLT andM4.)

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 XCBformally correct usingZ notation.[4] (Xlib has long been known to contain errors.[5])

Xlib compatibility

[edit]

Xlib/XCB providesapplication 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 Xdisplay server and use both XCB and Xlib, possibly through a mixture of libraries designed for one or the other.[7][8]

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<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);}

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

XCB has a comparable, but slightly lower-level API thanXlib,[10] as can be seen with this example.

Protocol description

[edit]

Creators of XCB have invented a specializedinterface description language to model X11 protocol in language-neutral way and facilitate generation of bindings to other programming languages.[dubiousdiscuss] 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>

Logo

[edit]

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

Other language bindings

[edit]
  • 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 byfreedesktop.org.
  • xcffib - Another Python binding which supports Python 2 & 3 as well as several more X extensions than xpyb.

Notes

[edit]
  1. ^"libxcb-1.17.0".
  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. Retrieved17 May 2022.
  7. ^"Xlib/XCB: Xlib with XCB transport". 2008-01-11. Retrieved2009-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). Retrieved2009-09-11.
  9. ^"X Window System Protocol".X.Org. Chapter 1. Protocol Formats. Retrieved22 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)

References

[edit]

External links

[edit]
OS components
Sound
Graphics
Other
Libraries
Frameworks
Meetings
Architecture
Extensions
Components
and notable
implementations
Display servers
Client libraries
Display managers
Session managers
Window managers
(comparison)
Compositing
Stacking
Tiling
Standards
Applications
Low-level platform-specific
OnAmigaOS
OnClassic Mac OS,macOS
OnWindows
OnUnix,
underX11
OnBeOS,Haiku
OnAndroid
CLI
Low Level Cross-platform
CLI
C
Java
High-level, platform-specific
OnAmigaOS
OnClassic Mac OS,macOS
Object Pascal
Objective-C,Swift
C++
CLI
OnWindows
CLI
C++
Object Pascal
OnUnix,
underX11
OnAndroid
High-level, cross-platform
C
C++
Objective-C
CLI
Adobe Flash
Go
Haskell
Java
JavaScript
Common Lisp
Lua
Pascal
Object Pascal
Perl
PHP
Python
Ruby
Tcl
XML
shell
Dart
Retrieved from "https://en.wikipedia.org/w/index.php?title=XCB&oldid=1231543598"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2025 Movatter.jp