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.
advance
is 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.ahash
is used to provide a fast, hardware optimized collision resistant hash function for the extension map.async-io
is the async-I/O OS driver backing theasync-std
andsmol
runtimes. It is optionally imported when theasync-std-support
feature is enabled so thatasync_io::Async::<impl CanBeAsyncDisplay>
can implementAsyncDisplay
.blocking
is the blocking-tasks thread pool used by the
async-std
andsmol
runtimes. It is optionally imported when theasync-std-support
feature is enabled, in order to isolate the loading of.Xauthority
onto the thread pool.bytemuck
is a public dependency, since theNoUninit
trait is used as a bound for theVoid
trait. It is exclusively used in theVoid
trait and could likely be removed in the future.cfg_if
is used to branch between features at various points in an idiomatic way. This could be removed in the future.concurrent-queue
is used to create a list of wakers that is used to handle asynchronous access to theMutex
inSyncDisplay
. It is only enabled when thesync_display
feature is.- [
fionread
] is an unsafe-quarantine microcrate that I created that wraps around theFIONREAD
ioctl 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-util
is imported when theasync
feature is enabled, and is primarily used to provide convenience functions on theFuture
trait and import the [Stream
] trait.gethostname
is imported when thestd
feature is enabled, and is used to get the hostname of the current computer for use in the authorization protocol.hashbrown
is used to provide the hash map used in the extension map. Note that this is the only place inbreadx
where hash maps are used.nix
is 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 thestd
feature is enabled, and is an empty crate on non-Unix targets.parking_lot
is used to replace the mutexes normally used inSyncDisplay
when thepl
feature 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.socket2
is 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 thestd
feature is enabled.tokio
is used so thatAsyncDisplay
can be implemented forAsyncFd::<impl CanBeAsyncDisplay>
. Only thenet
andrt
features are enabled.net
is necessary for theAsyncFd
type, andrt
is used to providespawn_blocking
so that file loading work can be offset onto a blocking thread. This crate is only imported when thetokio-support
feature is enabled.tracing
is used to provide logging support. As an aside, performance could probably be increased by restricting certain log emissions to debug mode.x11rb-protocol
is used to provide the X11 protocol. Various modules ofx11rb-protocol
are re-exported, including theprotocol
andx11_utils
modules. In order to prevent breaking changes from occurring (asx11rb-protocol
is 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 anotherConnection
type, but adds buffering to both ends of the stream. It is analogous to [BufReader
] and [BufWriter
].StdConnection
wraps around aRead
+Write
type to create aConnection
type. Note that, for the extra features, the type also needs to beAsRawFd
on Unix systems andAsRawSocket
on Windows ones.SendmsgConnection
wraps around aUnixStream
and 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:
DisplayBase
provides common functionality between all types of connections, like being able to poll for replies/events as well as theSetup
. Note that theSetup
is in anArc
in order to allow it to be kept outside of a mutex for things likeSyncDisplay
.Display
is a blocking connection.CanBeAsyncDisplay
is something that could be a non-blocking connection, if it were given an I/O driver.AsyncDisplay
is 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