This file aims to describe the way that breadx is structured. This should, hopefully, act as a catalogue of potential starting points for new contributors.
This document assumes some knowledge of the core X11 protocol. Consider reading this document for more information.
Optional dependencies are italic, and public dependencies are bold.
advanceis an "unsafe-quarantine microcrate" that I created that essentially reimplementsIoSlice::advance()in a way that is safe for use in non-Nightly environments. It consists of about four lines of code that maneuvers around lifetimes requirements.ahashis used to provide a fast, hardware optimized collision resistant hash function for the extension map.async-iois the async-I/O OS driver backing theasync-stdandsmolruntimes. It is optionally imported when theasync-std-supportfeature is enabled so thatasync_io::Async::<impl CanBeAsyncDisplay>can implementAsyncDisplay.blockingis the blocking-tasks thread pool used by the
async-stdandsmolruntimes. It is optionally imported when theasync-std-supportfeature is enabled, in order to isolate the loading of.Xauthorityonto the thread pool.bytemuckis a public dependency, since theNoUninittrait is used as a bound for theVoidtrait. It is exclusively used in theVoidtrait and could likely be removed in the future.cfg_ifis used to branch between features at various points in an idiomatic way. This could be removed in the future.concurrent-queueis used to create a list of wakers that is used to handle asynchronous access to theMutexinSyncDisplay. It is only enabled when thesync_displayfeature is.- [
fionread] is an unsafe-quarantine microcrate that I created that wraps around theFIONREADioctl call. For the Windows target, it is used to tell when thenon_blocking_*family of functions should continue on with the read or exit early. This dependency could likely be removed in the future if a better way of preforming non-blocking reads on Windows is implemented. futures-utilis imported when theasyncfeature is enabled, and is primarily used to provide convenience functions on theFuturetrait and import the [Stream] trait.gethostnameis imported when thestdfeature is enabled, and is used to get the hostname of the current computer for use in the authorization protocol.hashbrownis used to provide the hash map used in the extension map. Note that this is the only place inbreadxwhere hash maps are used.nixis used to implement certain functionality for connections on Unix targets. Namely, it is used for sending ancillary file descriptors along the wire for named connections. It is only imported when thestdfeature is enabled, and is an empty crate on non-Unix targets.parking_lotis used to replace the mutexes normally used inSyncDisplaywhen theplfeature is enabled. Note that the standard library now uses a "futex" implementation that is supposedly faster thanparking_lot's locking mechanisms, so this feature may be removed in the future.socket2is used to initialize abstract sockets for the Unix target, initialize sockets in a non-blocking manner forasync, and provide a generic shutdown implementation forStdConnection. It is only used when thestdfeature is enabled.tokiois used so thatAsyncDisplaycan be implemented forAsyncFd::<impl CanBeAsyncDisplay>. Only thenetandrtfeatures are enabled.netis necessary for theAsyncFdtype, andrtis used to providespawn_blockingso that file loading work can be offset onto a blocking thread. This crate is only imported when thetokio-supportfeature is enabled.tracingis used to provide logging support. As an aside, performance could probably be increased by restricting certain log emissions to debug mode.x11rb-protocolis used to provide the X11 protocol. Various modules ofx11rb-protocolare re-exported, including theprotocolandx11_utilsmodules. In order to prevent breaking changes from occurring (asx11rb-protocolis an unstable crate), it is pinned to a patch version.
This is the overall structure of the breadx repository, from the
repository root.
This contains the actual breadx crate that is published on crates.io.
This generator is used to create the automatically_generated.rs file,
which contains helper functions for sending requests to the X server.
It uses the xcbproto submodule (also in the repository root) as a
source of information to generate from.
This library is a parser for the XML-XCB format used in xcbproto. It
is used by breadx-generator to parse the xcbproto submodule.
The connection module defines the Connection trait, which is
used to represent the "byte stream" that is used to communicate with
the X server. It can be seen as a no_std-compatible version of
Read and Write, with extra extensions to support file
descriptor passing and non-blocking reading. BasicDisplay uses
this type as a transport.
In addition to the Connection trait, there are three other important
types that are defined here:
BufConnection, which acts as a wrapper over anotherConnectiontype, but adds buffering to both ends of the stream. It is analogous to [BufReader] and [BufWriter].StdConnectionwraps around aRead+Writetype to create aConnectiontype. Note that, for the extra features, the type also needs to beAsRawFdon Unix systems andAsRawSocketon Windows ones.SendmsgConnectionwraps around aUnixStreamand provides a variant of it that can pass file descriptors.
The user should be using NameConnection most of the time and
shouldn't need to worry about this module.
The display module contains all of the inner workings of the
connections to the X11 server. This contains the most complex code
by far.
The root module provides four primary traits:
DisplayBaseprovides common functionality between all types of connections, like being able to poll for replies/events as well as theSetup. Note that theSetupis in anArcin order to allow it to be kept outside of a mutex for things likeSyncDisplay.Displayis a blocking connection.CanBeAsyncDisplayis something that could be a non-blocking connection, if it were given an I/O driver.AsyncDisplayis a non-blocking connection complete with an attached I/O driver.
This module contains the implementation of the BasicDisplay, which
is the canonical implementation of the Display trait.
TODO: finish this