xcb_dl/lib.rs
1//! This crate contains bindings for libxcb, libxcb-xinput, etc.
2//! Symbols are loaded dynamically at runtime; linking at compile time is not supported.
3//!
4//! # Features
5//!
6//! Only bindings for libxcb are available by default.
7//! Enable the appropriately named features to enable bindings for libxcb-xinput etc.
8//!
9//! # Handling Missing Symbols
10//!
11//! Symbols are loaded lazily when they are accessed.
12//! If this fails, we panic.
13//! Enable the `has_symbol` feature to handle missing symbols more gracefully.
14//! This enables methods of the form `has_X` that return whether a symbol can be loaded.
15//!
16//! ```
17//! # unsafe {
18//! let lib = xcb_dl::Xcb::load().unwrap();
19//! if !lib.has_xcb_total_written() {
20//! eprintln!("Cannot monitor total number of bytes written.");
21//! }
22//! # }
23//! ```
24//!
25//! # Constructing Structs
26//!
27//! Future versions of this crate might add new fields to structs or remove padding fields.
28//! This is not considered a breaking change.
29//! Construct objects using `Default::default()` to ensure that your code remains valid:
30//!
31//! ```
32//! let format = xcb_dl::ffi::xcb_format_t {
33//! depth: 0,
34//! bits_per_pixel: 0,
35//! scanline_pad: 0,
36//! ..Default::default()
37//! };
38//! ```
39//!
40//! # Semantic Documentation
41//!
42//! This crate contains almost no semantic documentation.
43//! Documentation of the X core protocol and extensions is available at [freedesktop] and [x.org].
44//! Documentation of the libxcb functions that are not auto-generated from the protocols is available
45//! in the [libxcb] repository. Check `src/xcb.h` and `src/xcbext.h`.
46//!
47//! [freedesktop]: https://gitlab.freedesktop.org/xorg/proto/xorgproto
48//! [x.org]: https://www.x.org/releases/X11R7.7/doc/
49//! [libxcb]: https://gitlab.freedesktop.org/xorg/lib/libxcb
50//!
51//! # libxcb Architecture
52//!
53//! This sections provides a brief overview of the auto-generated functions in libxcb.
54//! Consult the [libxcb][libxcb2] documentation for more details.
55//!
56//! [libxcb2]: https://xcb.freedesktop.org/
57//!
58//! The terminology in this section is not the official libxcb terminology.
59//!
60//! libxcb sends **requests** to and receives **messages** from the X server.
61//! There are three types of messages:
62//!
63//! - **value replies**: A success message sent in response to a request.
64//! - **error replies**: An error sent in response to a request.
65//! - **events**: An event such as a key press.
66//!
67//! The code that sends a request can specify that replies should automatically be discarded by calling
68//! `xcb_discard_reply`.
69//!
70//! libxcb maintains two queues for incoming messages:
71//!
72//! - the **event queue**: Contains messages that can be retrieved via `xcb_poll_for_event` etc.
73//! - the **reply queue**: Contains messages that can only be retrieved by the code that sent the request.
74//!
75//! Events are always placed in the event queue.
76//!
77//! Value replies are placed in the reply queue unless they are being discarded.
78//!
79//! Each request has two variants:
80//!
81//! - **checked**: Error replies are placed in the reply queue unless they are being discarded.
82//! - **unchecked**: Error replies are placed in the event queue unless they are being discarded.
83//!
84//! There are two types of requests:
85//!
86//! - **void requests**: These do not generate value replies but can generate error replies.
87//! - **value requests**: These can generate either value replies or error replies.
88//!
89//! The default variant of void requests is unchecked.
90//! For each such request libxcb provides a function with the suffix `_checked` that uses the checked variant.
91//!
92//! The default variant of value requests is checked.
93//! For each such request libxcb provides a function with the suffix `_unchecked` that uses the unchecked variant.
94//!
95//! Messages placed in the reply queue must be retrieved by the user.
96//! Otherwise they will never be discarded.
97//!
98//! For void requests, error replies can be retrieved by calling `xcb_request_check`.
99//!
100//! For every value request libxcb provides a function with the suffix `_reply` that can
101//! be used to retrieve the value or error reply.
102//!
103//! ## Memory Management
104//!
105//! libxcb never takes ownership of memory passed to it.
106//!
107//! The functions that return messages pass ownership of the message to the caller.
108//! These messages can be freed with `libc::free`.
109//!
110//! ## Non-homogeneous Requests
111//!
112//! Some requests contain variably sized data and possibly non-homogeneous arrays.
113//! To simplify creating such requests, libxcb provides auxiliary functions with the suffix `_aux`.
114//! These functions take fixed-sized arguments and internally create a serialized request.
115//!
116//! ## Non-homogeneous Replies
117//!
118//! Some replies contain variably sized data and possibly non-homogeneous arrays.
119//!
120//! The data structures of libxcb do not contain fields for this data.
121//! Instead, libxcb provides accessor functions to retrieve pointers to these fields.
122//!
123//! If the fields are non-homogeneous arrays, these accessor functions return iterators.
124//! The pointer in these iterators can be advanced by calling an appropriately named `_next` function.
125//!
126//! If the fields are homogeneous arrays, libxcb provides `_length` functions that return the number
127//! of elements in the array.
128//!
129//! In some cases these accessor functions return `*mut c_void`.
130//! In these cases libxcb usually provides an `_unpack` function that deserializes the data into
131//! a struct.
132#![allow(
133 non_camel_case_types,
134 non_snake_case,
135 clippy::missing_safety_doc,
136 clippy::type_complexity,
137 clippy::too_many_arguments
138)]
139
140pub use libs::*;
141
142#[macro_use]
143mod macros;
144mod headers;
145mod lazy;
146mod libs;
147
148pub mod ffi {
149 pub use crate::headers::*;
150 use std::fmt::{Debug, Formatter};
151
152 impl Debug for xcb_client_message_data_t {
153 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
154 unsafe {
155 f.debug_struct("xcb_client_message_data_t")
156 .field("data8", &self.data8)
157 .finish()
158 }
159 }
160 }
161
162 #[cfg(feature = "xcb_xinput_types")]
163 impl Debug for xcb_input_event_for_send_t {
164 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
165 unsafe {
166 f.debug_struct("xcb_input_event_for_send_t")
167 .field("response_type", &self.event_header.response_type)
168 .finish_non_exhaustive()
169 }
170 }
171 }
172
173 #[cfg(feature = "xcb_xkb_types")]
174 impl Debug for xcb_xkb_action_t {
175 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
176 unsafe {
177 f.debug_struct("xcb_xkb_action_t")
178 .field("type", &self.type_)
179 .finish_non_exhaustive()
180 }
181 }
182 }
183
184 #[cfg(feature = "xcb_xkb_types")]
185 impl Debug for xcb_xkb_behavior_t {
186 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
187 unsafe {
188 f.debug_struct("xcb_xkb_behavior_t")
189 .field("type", &self.type_)
190 .finish_non_exhaustive()
191 }
192 }
193 }
194
195 #[cfg(feature = "xcb_randr_types")]
196 impl Debug for xcb_randr_notify_data_t {
197 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
198 f.debug_struct("xcb_randr_notify_data_t")
199 .finish_non_exhaustive()
200 }
201 }
202}