xcb/ffi/
base.rs

1use crate::AuthInfo;
2
3use super::ext::*;
4use libc::{c_char, c_int, c_uint, c_void};
5
6/// Current protocol version
7pub const X_PROTOCOL: u32 = 11;
8
9/// Current minor version
10pub const X_PROTOCOL_REVISION: u32 = 0;
11
12/// X_TCP_PORT + display number = server port for TCP transport
13pub const X_TCP_PORT: u32 = 6000;
14
15/// xcb connection errors because of socket, pipe and other stream errors.
16pub const XCB_CONN_ERROR: i32 = 1;
17
18/// xcb connection shutdown because of extension not supported
19pub const XCB_CONN_CLOSED_EXT_NOTSUPPORTED: i32 = 2;
20
21/// malloc(), calloc() and realloc() error upon failure, for eg ENOMEM
22pub const XCB_CONN_CLOSED_MEM_INSUFFICIENT: i32 = 3;
23
24/// Connection closed, exceeding request length that server accepts.
25pub const XCB_CONN_CLOSED_REQ_LEN_EXCEED: i32 = 4;
26
27/// Connection closed, error during parsing display string.
28pub const XCB_CONN_CLOSED_PARSE_ERR: i32 = 5;
29
30/// Connection closed because the server does not have a screen matching the display.
31pub const XCB_CONN_CLOSED_INVALID_SCREEN: i32 = 6;
32
33/// Connection closed because some FD passing operation failed
34pub const XCB_CONN_CLOSED_FDPASSING_FAILED: i32 = 7;
35
36/// XCB Connection structure.
37///
38/// A structure that contain all data that  XCB needs to communicate with an X server.
39pub enum xcb_connection_t {}
40
41pub(crate) enum xcb_special_event_t {}
42
43/// Generic event.
44///
45/// A generic event structure.
46#[derive(Copy, Clone, Debug)]
47#[repr(C)]
48pub struct xcb_generic_event_t {
49    /// Type of the response
50    pub response_type: u8,
51    /// Padding
52    pub pad0: u8,
53    /// Sequence number
54    pub sequence: u16,
55    /// Padding
56    pub pad: [u32; 7],
57    /// full sequence
58    pub full_sequence: u32,
59}
60
61// GE_GENERIC stuff is actually generated in X-proto, but we need it here in FFI form,
62// so it is just copy pasted from xproto.h
63
64/// `response_type` number corresponding to a [xcb_ge_generic_event_t].
65pub const XCB_GE_GENERIC: u8 = 35;
66
67/// FFI type for the Generic Event Extension.
68#[derive(Copy, Clone, Debug)]
69#[repr(C)]
70pub struct xcb_ge_generic_event_t {
71    pub response_type: u8,
72    pub extension: u8,
73    pub sequence: u16,
74    pub length: u32,
75    pub event_type: u16,
76    pub pad0: [u8; 22],
77    pub full_sequence: u32,
78}
79
80/// Generic error
81#[derive(Copy, Clone, Debug)]
82#[repr(C)]
83pub struct xcb_generic_error_t {
84    pub response_type: u8,
85    pub error_code: u8,
86    pub sequence: u16,
87    pub resource_id: u32,
88    pub minor_code: u16,
89    pub major_code: u8,
90    pub pad0: u8,
91    pub pad: [u32; 5],
92    pub full_sequence: u32,
93}
94
95/// FFI type for a void request cookie.
96#[derive(Copy, Clone, Debug)]
97#[repr(C)]
98pub(crate) struct xcb_void_cookie_t {
99    pub(crate) seq: u32,
100}
101
102/// Container for authorization information.
103/// A container for authorization information to be sent to the X server
104#[repr(C)]
105pub(crate) struct xcb_auth_info_t {
106    /// length of the string name (as returned by strlen)
107    pub namelen: c_int,
108    /// String containing the authentication protocol name,
109    /// such as "MIT-MAGIC-COOKIE-1" or "XDM-AUTHORIZATION-1".
110    pub name: *mut c_char,
111    /// length of the data member
112    pub datalen: c_int,
113    /// data interpreted in a protocol specific manner
114    pub data: *mut c_char,
115}
116
117#[link(name = "xcb")]
118extern "C" {
119    pub(crate) fn xcb_flush(c: *mut xcb_connection_t) -> c_int;
120
121    pub(crate) fn xcb_get_maximum_request_length(c: *mut xcb_connection_t) -> u32;
122
123    pub(crate) fn xcb_prefetch_maximum_request_length(c: *mut xcb_connection_t) -> c_void;
124
125    pub(crate) fn xcb_wait_for_event(c: *mut xcb_connection_t) -> *mut xcb_generic_event_t;
126
127    pub(crate) fn xcb_poll_for_event(c: *mut xcb_connection_t) -> *mut xcb_generic_event_t;
128
129    pub(crate) fn xcb_poll_for_queued_event(c: *mut xcb_connection_t) -> *mut xcb_generic_event_t;
130
131    pub(crate) fn xcb_poll_for_special_event(
132        c: *mut xcb_connection_t,
133        se: *mut xcb_special_event_t,
134    ) -> *mut xcb_generic_event_t;
135
136    pub(crate) fn xcb_wait_for_special_event(
137        c: *mut xcb_connection_t,
138        se: *mut xcb_special_event_t,
139    ) -> *mut xcb_generic_event_t;
140
141    pub(crate) fn xcb_register_for_special_xge(
142        c: *mut xcb_connection_t,
143        ext: *mut xcb_extension_t,
144        eid: u32,
145        stamp: *mut u32,
146    ) -> *mut xcb_special_event_t;
147
148    pub(crate) fn xcb_unregister_for_special_event(
149        c: *mut xcb_connection_t,
150        se: *mut xcb_special_event_t,
151    );
152
153    pub(crate) fn xcb_request_check(
154        c: *mut xcb_connection_t,
155        cookie: xcb_void_cookie_t,
156    ) -> *mut xcb_generic_error_t;
157
158    pub(crate) fn xcb_discard_reply(c: *mut xcb_connection_t, sequence: c_uint);
159
160    pub(crate) fn xcb_discard_reply64(c: *mut xcb_connection_t, sequence: u64);
161
162    // We trick the result from `*const xcb_query_extension_reply_t` to `*const u8` to be compatible with
163    // `x::QueryExtensionReply::from_raw`
164    pub(crate) fn xcb_get_extension_data(
165        c: *mut xcb_connection_t,
166        ext: *mut xcb_extension_t,
167    ) -> *const u8;
168
169    pub(crate) fn xcb_prefetch_extension_data(c: *mut xcb_connection_t, ext: *mut xcb_extension_t);
170
171    // We trick the result from `*const xcb_setup_t` to `*const u8` to be compatible with
172    // `x::Setup::from_data`
173    pub(crate) fn xcb_get_setup(c: *mut xcb_connection_t) -> *const u8;
174
175    pub(crate) fn xcb_get_file_descriptor(c: *mut xcb_connection_t) -> c_int;
176
177    pub(crate) fn xcb_connection_has_error(c: *mut xcb_connection_t) -> c_int;
178
179    pub(crate) fn xcb_connect_to_fd(
180        fd: c_int,
181        auth_info: *mut xcb_auth_info_t,
182    ) -> *mut xcb_connection_t;
183
184    pub(crate) fn xcb_disconnect(c: *mut xcb_connection_t);
185
186    pub(crate) fn xcb_parse_display(
187        name: *const c_char,
188        host: *mut *mut c_char,
189        display: *mut c_int,
190        screen: *mut c_int,
191    ) -> c_int;
192
193    pub(crate) fn xcb_connect(
194        displayname: *const c_char,
195        screenp: *mut c_int,
196    ) -> *mut xcb_connection_t;
197
198    pub(crate) fn xcb_connect_to_display_with_auth_info(
199        display: *const c_char,
200        auth: *mut xcb_auth_info_t,
201        screen: *mut c_int,
202    ) -> *mut xcb_connection_t;
203
204    pub(crate) fn xcb_generate_id(c: *mut xcb_connection_t) -> u32;
205
206    pub(crate) fn xcb_total_read(c: *mut xcb_connection_t) -> u64;
207
208    pub(crate) fn xcb_total_written(c: *mut xcb_connection_t) -> u64;
209}