x11rb_protocol/protocol/
xc_misc.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `XCMisc` X11 extension.
5
6#![allow(clippy::too_many_arguments)]
7// The code generator is simpler if it can always use conversions
8#![allow(clippy::useless_conversion)]
9
10#[allow(unused_imports)]
11use alloc::borrow::Cow;
12#[allow(unused_imports)]
13use core::convert::TryInto;
14use alloc::vec;
15use alloc::vec::Vec;
16use core::convert::TryFrom;
17use crate::errors::ParseError;
18#[allow(unused_imports)]
19use crate::x11_utils::TryIntoUSize;
20use crate::BufWithFds;
21#[allow(unused_imports)]
22use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum};
23#[allow(unused_imports)]
24use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd};
25
26/// The X11 name of the extension for QueryExtension
27pub const X11_EXTENSION_NAME: &str = "XC-MISC";
28
29/// The version number of this extension that this client library supports.
30///
31/// This constant contains the version number of this extension that is supported
32/// by this build of x11rb. For most things, it does not make sense to use this
33/// information. If you need to send a `QueryVersion`, it is recommended to instead
34/// send the maximum version of the extension that you need.
35pub const X11_XML_VERSION: (u32, u32) = (1, 1);
36
37/// Opcode for the GetVersion request
38pub const GET_VERSION_REQUEST: u8 = 0;
39#[derive(Clone, Copy, Default)]
40#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
41#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
42pub struct GetVersionRequest {
43    pub client_major_version: u16,
44    pub client_minor_version: u16,
45}
46impl_debug_if_no_extra_traits!(GetVersionRequest, "GetVersionRequest");
47impl GetVersionRequest {
48    /// Serialize this request into bytes for the provided connection
49    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
50        let length_so_far = 0;
51        let client_major_version_bytes = self.client_major_version.serialize();
52        let client_minor_version_bytes = self.client_minor_version.serialize();
53        let mut request0 = vec![
54            major_opcode,
55            GET_VERSION_REQUEST,
56            0,
57            0,
58            client_major_version_bytes[0],
59            client_major_version_bytes[1],
60            client_minor_version_bytes[0],
61            client_minor_version_bytes[1],
62        ];
63        let length_so_far = length_so_far + request0.len();
64        assert_eq!(length_so_far % 4, 0);
65        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
66        request0[2..4].copy_from_slice(&length.to_ne_bytes());
67        ([request0.into()], vec![])
68    }
69    /// Parse this request given its header, its body, and any fds that go along with it
70    #[cfg(feature = "request-parsing")]
71    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
72        if header.minor_opcode != GET_VERSION_REQUEST {
73            return Err(ParseError::InvalidValue);
74        }
75        let (client_major_version, remaining) = u16::try_parse(value)?;
76        let (client_minor_version, remaining) = u16::try_parse(remaining)?;
77        let _ = remaining;
78        Ok(GetVersionRequest {
79            client_major_version,
80            client_minor_version,
81        })
82    }
83}
84impl Request for GetVersionRequest {
85    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
86
87    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
88        let (bufs, fds) = self.serialize(major_opcode);
89        // Flatten the buffers into a single vector
90        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
91        (buf, fds)
92    }
93}
94impl crate::x11_utils::ReplyRequest for GetVersionRequest {
95    type Reply = GetVersionReply;
96}
97
98#[derive(Clone, Copy, Default)]
99#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
100#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
101pub struct GetVersionReply {
102    pub sequence: u16,
103    pub length: u32,
104    pub server_major_version: u16,
105    pub server_minor_version: u16,
106}
107impl_debug_if_no_extra_traits!(GetVersionReply, "GetVersionReply");
108impl TryParse for GetVersionReply {
109    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
110        let remaining = initial_value;
111        let (response_type, remaining) = u8::try_parse(remaining)?;
112        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
113        let (sequence, remaining) = u16::try_parse(remaining)?;
114        let (length, remaining) = u32::try_parse(remaining)?;
115        let (server_major_version, remaining) = u16::try_parse(remaining)?;
116        let (server_minor_version, remaining) = u16::try_parse(remaining)?;
117        if response_type != 1 {
118            return Err(ParseError::InvalidValue);
119        }
120        let result = GetVersionReply { sequence, length, server_major_version, server_minor_version };
121        let _ = remaining;
122        let remaining = initial_value.get(32 + length as usize * 4..)
123            .ok_or(ParseError::InsufficientData)?;
124        Ok((result, remaining))
125    }
126}
127impl Serialize for GetVersionReply {
128    type Bytes = [u8; 12];
129    fn serialize(&self) -> [u8; 12] {
130        let response_type_bytes = &[1];
131        let sequence_bytes = self.sequence.serialize();
132        let length_bytes = self.length.serialize();
133        let server_major_version_bytes = self.server_major_version.serialize();
134        let server_minor_version_bytes = self.server_minor_version.serialize();
135        [
136            response_type_bytes[0],
137            0,
138            sequence_bytes[0],
139            sequence_bytes[1],
140            length_bytes[0],
141            length_bytes[1],
142            length_bytes[2],
143            length_bytes[3],
144            server_major_version_bytes[0],
145            server_major_version_bytes[1],
146            server_minor_version_bytes[0],
147            server_minor_version_bytes[1],
148        ]
149    }
150    fn serialize_into(&self, bytes: &mut Vec<u8>) {
151        bytes.reserve(12);
152        let response_type_bytes = &[1];
153        bytes.push(response_type_bytes[0]);
154        bytes.extend_from_slice(&[0; 1]);
155        self.sequence.serialize_into(bytes);
156        self.length.serialize_into(bytes);
157        self.server_major_version.serialize_into(bytes);
158        self.server_minor_version.serialize_into(bytes);
159    }
160}
161
162/// Opcode for the GetXIDRange request
163pub const GET_XID_RANGE_REQUEST: u8 = 1;
164#[derive(Clone, Copy, Default)]
165#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
166#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
167pub struct GetXIDRangeRequest;
168impl_debug_if_no_extra_traits!(GetXIDRangeRequest, "GetXIDRangeRequest");
169impl GetXIDRangeRequest {
170    /// Serialize this request into bytes for the provided connection
171    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
172        let length_so_far = 0;
173        let mut request0 = vec![
174            major_opcode,
175            GET_XID_RANGE_REQUEST,
176            0,
177            0,
178        ];
179        let length_so_far = length_so_far + request0.len();
180        assert_eq!(length_so_far % 4, 0);
181        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
182        request0[2..4].copy_from_slice(&length.to_ne_bytes());
183        ([request0.into()], vec![])
184    }
185    /// Parse this request given its header, its body, and any fds that go along with it
186    #[cfg(feature = "request-parsing")]
187    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
188        if header.minor_opcode != GET_XID_RANGE_REQUEST {
189            return Err(ParseError::InvalidValue);
190        }
191        let _ = value;
192        Ok(GetXIDRangeRequest
193        )
194    }
195}
196impl Request for GetXIDRangeRequest {
197    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
198
199    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
200        let (bufs, fds) = self.serialize(major_opcode);
201        // Flatten the buffers into a single vector
202        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
203        (buf, fds)
204    }
205}
206impl crate::x11_utils::ReplyRequest for GetXIDRangeRequest {
207    type Reply = GetXIDRangeReply;
208}
209
210#[derive(Clone, Copy, Default)]
211#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
212#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
213pub struct GetXIDRangeReply {
214    pub sequence: u16,
215    pub length: u32,
216    pub start_id: u32,
217    pub count: u32,
218}
219impl_debug_if_no_extra_traits!(GetXIDRangeReply, "GetXIDRangeReply");
220impl TryParse for GetXIDRangeReply {
221    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
222        let remaining = initial_value;
223        let (response_type, remaining) = u8::try_parse(remaining)?;
224        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
225        let (sequence, remaining) = u16::try_parse(remaining)?;
226        let (length, remaining) = u32::try_parse(remaining)?;
227        let (start_id, remaining) = u32::try_parse(remaining)?;
228        let (count, remaining) = u32::try_parse(remaining)?;
229        if response_type != 1 {
230            return Err(ParseError::InvalidValue);
231        }
232        let result = GetXIDRangeReply { sequence, length, start_id, count };
233        let _ = remaining;
234        let remaining = initial_value.get(32 + length as usize * 4..)
235            .ok_or(ParseError::InsufficientData)?;
236        Ok((result, remaining))
237    }
238}
239impl Serialize for GetXIDRangeReply {
240    type Bytes = [u8; 16];
241    fn serialize(&self) -> [u8; 16] {
242        let response_type_bytes = &[1];
243        let sequence_bytes = self.sequence.serialize();
244        let length_bytes = self.length.serialize();
245        let start_id_bytes = self.start_id.serialize();
246        let count_bytes = self.count.serialize();
247        [
248            response_type_bytes[0],
249            0,
250            sequence_bytes[0],
251            sequence_bytes[1],
252            length_bytes[0],
253            length_bytes[1],
254            length_bytes[2],
255            length_bytes[3],
256            start_id_bytes[0],
257            start_id_bytes[1],
258            start_id_bytes[2],
259            start_id_bytes[3],
260            count_bytes[0],
261            count_bytes[1],
262            count_bytes[2],
263            count_bytes[3],
264        ]
265    }
266    fn serialize_into(&self, bytes: &mut Vec<u8>) {
267        bytes.reserve(16);
268        let response_type_bytes = &[1];
269        bytes.push(response_type_bytes[0]);
270        bytes.extend_from_slice(&[0; 1]);
271        self.sequence.serialize_into(bytes);
272        self.length.serialize_into(bytes);
273        self.start_id.serialize_into(bytes);
274        self.count.serialize_into(bytes);
275    }
276}
277
278/// Opcode for the GetXIDList request
279pub const GET_XID_LIST_REQUEST: u8 = 2;
280#[derive(Clone, Copy, Default)]
281#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
282#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
283pub struct GetXIDListRequest {
284    pub count: u32,
285}
286impl_debug_if_no_extra_traits!(GetXIDListRequest, "GetXIDListRequest");
287impl GetXIDListRequest {
288    /// Serialize this request into bytes for the provided connection
289    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
290        let length_so_far = 0;
291        let count_bytes = self.count.serialize();
292        let mut request0 = vec![
293            major_opcode,
294            GET_XID_LIST_REQUEST,
295            0,
296            0,
297            count_bytes[0],
298            count_bytes[1],
299            count_bytes[2],
300            count_bytes[3],
301        ];
302        let length_so_far = length_so_far + request0.len();
303        assert_eq!(length_so_far % 4, 0);
304        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
305        request0[2..4].copy_from_slice(&length.to_ne_bytes());
306        ([request0.into()], vec![])
307    }
308    /// Parse this request given its header, its body, and any fds that go along with it
309    #[cfg(feature = "request-parsing")]
310    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
311        if header.minor_opcode != GET_XID_LIST_REQUEST {
312            return Err(ParseError::InvalidValue);
313        }
314        let (count, remaining) = u32::try_parse(value)?;
315        let _ = remaining;
316        Ok(GetXIDListRequest {
317            count,
318        })
319    }
320}
321impl Request for GetXIDListRequest {
322    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
323
324    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
325        let (bufs, fds) = self.serialize(major_opcode);
326        // Flatten the buffers into a single vector
327        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
328        (buf, fds)
329    }
330}
331impl crate::x11_utils::ReplyRequest for GetXIDListRequest {
332    type Reply = GetXIDListReply;
333}
334
335#[derive(Clone, Default)]
336#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
337#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
338pub struct GetXIDListReply {
339    pub sequence: u16,
340    pub length: u32,
341    pub ids: Vec<u32>,
342}
343impl_debug_if_no_extra_traits!(GetXIDListReply, "GetXIDListReply");
344impl TryParse for GetXIDListReply {
345    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
346        let remaining = initial_value;
347        let (response_type, remaining) = u8::try_parse(remaining)?;
348        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
349        let (sequence, remaining) = u16::try_parse(remaining)?;
350        let (length, remaining) = u32::try_parse(remaining)?;
351        let (ids_len, remaining) = u32::try_parse(remaining)?;
352        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
353        let (ids, remaining) = crate::x11_utils::parse_list::<u32>(remaining, ids_len.try_to_usize()?)?;
354        if response_type != 1 {
355            return Err(ParseError::InvalidValue);
356        }
357        let result = GetXIDListReply { sequence, length, ids };
358        let _ = remaining;
359        let remaining = initial_value.get(32 + length as usize * 4..)
360            .ok_or(ParseError::InsufficientData)?;
361        Ok((result, remaining))
362    }
363}
364impl Serialize for GetXIDListReply {
365    type Bytes = Vec<u8>;
366    fn serialize(&self) -> Vec<u8> {
367        let mut result = Vec::new();
368        self.serialize_into(&mut result);
369        result
370    }
371    fn serialize_into(&self, bytes: &mut Vec<u8>) {
372        bytes.reserve(32);
373        let response_type_bytes = &[1];
374        bytes.push(response_type_bytes[0]);
375        bytes.extend_from_slice(&[0; 1]);
376        self.sequence.serialize_into(bytes);
377        self.length.serialize_into(bytes);
378        let ids_len = u32::try_from(self.ids.len()).expect("`ids` has too many elements");
379        ids_len.serialize_into(bytes);
380        bytes.extend_from_slice(&[0; 20]);
381        self.ids.serialize_into(bytes);
382    }
383}
384impl GetXIDListReply {
385    /// Get the value of the `ids_len` field.
386    ///
387    /// The `ids_len` field is used as the length field of the `ids` field.
388    /// This function computes the field's value again based on the length of the list.
389    ///
390    /// # Panics
391    ///
392    /// Panics if the value cannot be represented in the target type. This
393    /// cannot happen with values of the struct received from the X11 server.
394    pub fn ids_len(&self) -> u32 {
395        self.ids.len()
396            .try_into().unwrap()
397    }
398}
399