xcb_dl/headers/
xcbext.rs

1#![allow(unused_macros)]
2
3use crate::ffi::*;
4use crate::lazy::*;
5use crate::*;
6use std::os::raw::*;
7
8/// The libxcb identifier of an extension.
9#[derive(Copy, Clone, Debug)]
10#[repr(C)]
11pub struct xcb_extension_t {
12    pub name: *const c_char,
13    pub global_id: c_int,
14}
15
16/// A libxcb request.
17#[derive(Copy, Clone, Debug)]
18#[repr(C)]
19pub struct xcb_protocol_request_t {
20    pub count: usize,
21    pub ext: *mut xcb_extension_t,
22    pub opcode: u8,
23    pub isvoid: u8,
24}
25
26/// The `xcb_send_request_flags_t` enum.
27pub type xcb_send_request_flags_t = c_int;
28/// The `XCB_REQUEST_CHECKED` variant of `xcb_send_request_flags_t`.
29pub const XCB_REQUEST_CHECKED: xcb_send_request_flags_t = 0x01;
30/// The `XCB_REQUEST_RAW` variant of `xcb_send_request_flags_t`.
31pub const XCB_REQUEST_RAW: xcb_send_request_flags_t = 0x02;
32/// The `XCB_REQUEST_DISCARD_REPLY` variant of `xcb_send_request_flags_t`.
33pub const XCB_REQUEST_DISCARD_REPLY: xcb_send_request_flags_t = 0x04;
34/// The `XCB_REQUEST_REPLY_FDS` variant of `xcb_send_request_flags_t`.
35pub const XCB_REQUEST_REPLY_FDS: xcb_send_request_flags_t = 0x08;
36
37pub(crate) struct XcbXcbext {
38    xcb_send_request: LazySymbol<
39        unsafe fn(
40            c: *mut xcb_connection_t,
41            flags: c_int,
42            vector: *mut libc::iovec,
43            request: *const xcb_protocol_request_t,
44        ) -> c_uint,
45    >,
46    xcb_send_request_with_fds: LazySymbol<
47        unsafe fn(
48            c: *mut xcb_connection_t,
49            flags: c_int,
50            vector: *mut libc::iovec,
51            request: *const xcb_protocol_request_t,
52            num_fds: c_uint,
53            fds: *mut c_int,
54        ) -> c_uint,
55    >,
56    xcb_send_request64: LazySymbol<
57        unsafe fn(
58            c: *mut xcb_connection_t,
59            flags: c_int,
60            vector: *mut libc::iovec,
61            request: *const xcb_protocol_request_t,
62        ) -> u64,
63    >,
64    xcb_send_request_with_fds64: LazySymbol<
65        unsafe fn(
66            c: *mut xcb_connection_t,
67            flags: c_int,
68            vector: *mut libc::iovec,
69            request: *const xcb_protocol_request_t,
70            num_fds: c_uint,
71            fds: *mut c_int,
72        ) -> u64,
73    >,
74    xcb_send_fd: LazySymbol<unsafe fn(c: *mut xcb_connection_t, fd: c_int)>,
75    xcb_take_socket: LazySymbol<
76        unsafe fn(
77            c: *mut xcb_connection_t,
78            return_socket: extern "C" fn(closure: *mut c_void),
79            closure: *mut c_void,
80            flags: c_int,
81            sent: *mut u64,
82        ) -> c_int,
83    >,
84    xcb_writev: LazySymbol<
85        unsafe fn(
86            c: *mut xcb_connection_t,
87            vector: *mut libc::iovec,
88            count: c_int,
89            requests: u64,
90        ) -> c_int,
91    >,
92    xcb_wait_for_reply: LazySymbol<
93        unsafe fn(
94            c: *mut xcb_connection_t,
95            request: c_uint,
96            e: *mut *mut xcb_generic_error_t,
97        ) -> *mut c_void,
98    >,
99    xcb_wait_for_reply64: LazySymbol<
100        unsafe fn(
101            c: *mut xcb_connection_t,
102            request: u64,
103            e: *mut *mut xcb_generic_error_t,
104        ) -> *mut c_void,
105    >,
106    xcb_poll_for_reply: LazySymbol<
107        unsafe fn(
108            c: *mut xcb_connection_t,
109            request: c_uint,
110            reply: *mut *mut c_void,
111            error: *mut *mut xcb_generic_error_t,
112        ) -> c_int,
113    >,
114    xcb_poll_for_reply64: LazySymbol<
115        unsafe fn(
116            c: *mut xcb_connection_t,
117            request: u64,
118            reply: *mut *mut c_void,
119            error: *mut *mut xcb_generic_error_t,
120        ) -> c_int,
121    >,
122    xcb_popcount: LazySymbol<unsafe fn(mask: u32) -> c_int>,
123    xcb_sumof: LazySymbol<unsafe fn(list: *mut u8, len: c_int) -> c_int>,
124}
125
126macro_rules! sym {
127    ($self:expr, $f:ident) => {
128        $self
129            .xcbext
130            .$f
131            .get(&$self.lib, concat!(stringify!($f), "\0"))
132    };
133}
134
135macro_rules! has_sym {
136    ($self:expr, $f:ident) => {
137        unsafe {
138            $self
139                .xcbext
140                .$f
141                .exists(&$self.lib, concat!(stringify!($f), "\0"))
142        }
143    };
144}
145
146impl Xcb {
147    /// Sends a request.
148    #[inline]
149    pub unsafe fn xcb_send_request(
150        &self,
151        c: *mut xcb_connection_t,
152        flags: c_int,
153        vector: *mut libc::iovec,
154        request: *const xcb_protocol_request_t,
155    ) -> c_uint {
156        sym!(self, xcb_send_request)(c, flags, vector, request)
157    }
158
159    /// Returns `true` iff the symbol `xcb_send_request` could be loaded.
160    #[cfg(feature = "has_symbol")]
161    pub fn has_xcb_send_request(&self) -> bool {
162        has_sym!(self, xcb_send_request)
163    }
164
165    /// Sends a request with file descriptors.
166    #[inline]
167    pub unsafe fn xcb_send_request_with_fds(
168        &self,
169        c: *mut xcb_connection_t,
170        flags: c_int,
171        vector: *mut libc::iovec,
172        request: *const xcb_protocol_request_t,
173        num_fds: c_uint,
174        fds: *mut c_int,
175    ) -> c_uint {
176        sym!(self, xcb_send_request_with_fds)(c, flags, vector, request, num_fds, fds)
177    }
178
179    /// Returns `true` iff the symbol `xcb_send_request_with_fds` could be loaded.
180    #[cfg(feature = "has_symbol")]
181    pub fn has_xcb_send_request_with_fds(&self) -> bool {
182        has_sym!(self, xcb_send_request_with_fds)
183    }
184
185    /// Sends a request with 64-bit sequence numbers.
186    #[inline]
187    pub unsafe fn xcb_send_request64(
188        &self,
189        c: *mut xcb_connection_t,
190        flags: c_int,
191        vector: *mut libc::iovec,
192        request: *const xcb_protocol_request_t,
193    ) -> u64 {
194        sym!(self, xcb_send_request64)(c, flags, vector, request)
195    }
196
197    /// Returns `true` iff the symbol `xcb_send_request` could be loaded.
198    #[cfg(feature = "has_symbol")]
199    pub fn has_xcb_send_request64(&self) -> bool {
200        has_sym!(self, xcb_send_request64)
201    }
202
203    /// Sends a request with file descriptors with 64-bit sequence numbers.
204    #[inline]
205    pub unsafe fn xcb_send_request_with_fds64(
206        &self,
207        c: *mut xcb_connection_t,
208        flags: c_int,
209        vector: *mut libc::iovec,
210        request: *const xcb_protocol_request_t,
211        num_fds: c_uint,
212        fds: *mut c_int,
213    ) -> u64 {
214        sym!(self, xcb_send_request_with_fds64)(c, flags, vector, request, num_fds, fds)
215    }
216
217    /// Returns `true` iff the symbol `xcb_send_request_with_fds64` could be loaded.
218    #[cfg(feature = "has_symbol")]
219    pub fn has_xcb_send_request_with_fds64(&self) -> bool {
220        has_sym!(self, xcb_send_request_with_fds64)
221    }
222
223    /// Send a file descriptor to the server in the next call to `xcb_send_request`.
224    #[deprecated]
225    #[inline]
226    pub unsafe fn xcb_send_fd(&self, c: *mut xcb_connection_t, fd: c_int) {
227        sym!(self, xcb_send_fd)(c, fd)
228    }
229
230    /// Returns `true` iff the symbol `xcb_send_fd` could be loaded.
231    #[cfg(feature = "has_symbol")]
232    pub fn has_xcb_send_fd(&self) -> bool {
233        has_sym!(self, xcb_send_fd)
234    }
235
236    /// Take over the write side of the socket.
237    #[inline]
238    pub unsafe fn xcb_take_socket(
239        &self,
240        c: *mut xcb_connection_t,
241        return_socket: extern "C" fn(closure: *mut c_void),
242        closure: *mut c_void,
243        flags: c_int,
244        sent: *mut u64,
245    ) -> c_int {
246        sym!(self, xcb_take_socket)(c, return_socket, closure, flags, sent)
247    }
248
249    /// Returns `true` iff the symbol `xcb_take_socket` could be loaded.
250    #[cfg(feature = "has_symbol")]
251    pub fn has_xcb_take_socket(&self) -> bool {
252        has_sym!(self, xcb_take_socket)
253    }
254
255    /// Send raw data to the X server.
256    #[inline]
257    pub unsafe fn xcb_writev(
258        &self,
259        c: *mut xcb_connection_t,
260        vector: *mut libc::iovec,
261        count: c_int,
262        requests: u64,
263    ) -> c_int {
264        sym!(self, xcb_writev)(c, vector, count, requests)
265    }
266
267    /// Returns `true` iff the symbol `xcb_writev` could be loaded.
268    #[cfg(feature = "has_symbol")]
269    pub fn has_xcb_writev(&self) -> bool {
270        has_sym!(self, xcb_writev)
271    }
272
273    /// Wait for the reply of a given request.
274    #[inline]
275    pub unsafe fn xcb_wait_for_reply(
276        &self,
277        c: *mut xcb_connection_t,
278        request: c_uint,
279        e: *mut *mut xcb_generic_error_t,
280    ) -> *mut c_void {
281        sym!(self, xcb_wait_for_reply)(c, request, e)
282    }
283
284    /// Returns `true` iff the symbol `xcb_wait_for_reply` could be loaded.
285    #[cfg(feature = "has_symbol")]
286    pub fn has_xcb_wait_for_reply(&self) -> bool {
287        has_sym!(self, xcb_wait_for_reply)
288    }
289
290    /// Wait for the reply of a given request, with 64-bit sequence number.
291    #[inline]
292    pub unsafe fn xcb_wait_for_reply64(
293        &self,
294        c: *mut xcb_connection_t,
295        request: u64,
296        e: *mut *mut xcb_generic_error_t,
297    ) -> *mut c_void {
298        sym!(self, xcb_wait_for_reply64)(c, request, e)
299    }
300
301    /// Returns `true` iff the symbol `xcb_wait_for_reply64` could be loaded.
302    #[cfg(feature = "has_symbol")]
303    pub fn has_xcb_wait_for_reply64(&self) -> bool {
304        has_sym!(self, xcb_wait_for_reply64)
305    }
306
307    /// Poll for the reply of a given request.
308    #[inline]
309    pub unsafe fn xcb_poll_for_reply(
310        &self,
311        c: *mut xcb_connection_t,
312        request: c_uint,
313        reply: *mut *mut c_void,
314        e: *mut *mut xcb_generic_error_t,
315    ) -> c_int {
316        sym!(self, xcb_poll_for_reply)(c, request, reply, e)
317    }
318
319    /// Returns `true` iff the symbol `xcb_poll_for_reply` could be loaded.
320    #[cfg(feature = "has_symbol")]
321    pub fn has_xcb_poll_for_reply(&self) -> bool {
322        has_sym!(self, xcb_poll_for_reply)
323    }
324
325    /// Poll for the reply of a given request, with 64-bit sequence number.
326    #[inline]
327    pub unsafe fn xcb_poll_for_reply64(
328        &self,
329        c: *mut xcb_connection_t,
330        request: u64,
331        reply: *mut *mut c_void,
332        e: *mut *mut xcb_generic_error_t,
333    ) -> c_int {
334        sym!(self, xcb_poll_for_reply64)(c, request, reply, e)
335    }
336
337    /// Returns `true` iff the symbol `xcb_poll_for_reply64` could be loaded.
338    #[cfg(feature = "has_symbol")]
339    pub fn has_xcb_poll_for_reply64(&self) -> bool {
340        has_sym!(self, xcb_poll_for_reply64)
341    }
342
343    #[inline]
344    pub unsafe fn xcb_popcount(&self, mask: u32) -> c_int {
345        sym!(self, xcb_popcount)(mask)
346    }
347
348    /// Returns `true` iff the symbol `xcb_popcount` could be loaded.
349    #[cfg(feature = "has_symbol")]
350    pub fn has_xcb_popcount(&self) -> bool {
351        has_sym!(self, xcb_popcount)
352    }
353
354    #[inline]
355    pub unsafe fn xcb_sumof(&self, list: *mut u8, len: c_int) -> c_int {
356        sym!(self, xcb_sumof)(list, len)
357    }
358
359    /// Returns `true` iff the symbol `xcb_sumof` could be loaded.
360    #[cfg(feature = "has_symbol")]
361    pub fn has_xcb_sumof(&self) -> bool {
362        has_sym!(self, xcb_sumof)
363    }
364}
365
366#[cfg(all(test, feature = "has_symbol"))]
367mod test {
368    #[test]
369    fn has_all() {
370        let lib = unsafe { crate::Xcb::load().unwrap() };
371        assert!(lib.has_xcb_send_request());
372        assert!(lib.has_xcb_send_request_with_fds());
373        assert!(lib.has_xcb_send_request64());
374        assert!(lib.has_xcb_send_request_with_fds64());
375        assert!(lib.has_xcb_send_fd());
376        assert!(lib.has_xcb_take_socket());
377        assert!(lib.has_xcb_writev());
378        assert!(lib.has_xcb_wait_for_reply());
379        assert!(lib.has_xcb_wait_for_reply64());
380        assert!(lib.has_xcb_poll_for_reply());
381        assert!(lib.has_xcb_poll_for_reply64());
382        assert!(lib.has_xcb_popcount());
383        assert!(lib.has_xcb_sumof());
384    }
385}