x11rb_protocol/protocol/
xf86dri.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `XF86Dri` 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 = "XFree86-DRI";
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) = (4, 1);
36
37#[derive(Clone, Copy, Default)]
38#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
39#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
40pub struct DrmClipRect {
41    pub x1: i16,
42    pub y1: i16,
43    pub x2: i16,
44    pub x3: i16,
45}
46impl_debug_if_no_extra_traits!(DrmClipRect, "DrmClipRect");
47impl TryParse for DrmClipRect {
48    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
49        let (x1, remaining) = i16::try_parse(remaining)?;
50        let (y1, remaining) = i16::try_parse(remaining)?;
51        let (x2, remaining) = i16::try_parse(remaining)?;
52        let (x3, remaining) = i16::try_parse(remaining)?;
53        let result = DrmClipRect { x1, y1, x2, x3 };
54        Ok((result, remaining))
55    }
56}
57impl Serialize for DrmClipRect {
58    type Bytes = [u8; 8];
59    fn serialize(&self) -> [u8; 8] {
60        let x1_bytes = self.x1.serialize();
61        let y1_bytes = self.y1.serialize();
62        let x2_bytes = self.x2.serialize();
63        let x3_bytes = self.x3.serialize();
64        [
65            x1_bytes[0],
66            x1_bytes[1],
67            y1_bytes[0],
68            y1_bytes[1],
69            x2_bytes[0],
70            x2_bytes[1],
71            x3_bytes[0],
72            x3_bytes[1],
73        ]
74    }
75    fn serialize_into(&self, bytes: &mut Vec<u8>) {
76        bytes.reserve(8);
77        self.x1.serialize_into(bytes);
78        self.y1.serialize_into(bytes);
79        self.x2.serialize_into(bytes);
80        self.x3.serialize_into(bytes);
81    }
82}
83
84/// Opcode for the QueryVersion request
85pub const QUERY_VERSION_REQUEST: u8 = 0;
86#[derive(Clone, Copy, Default)]
87#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
88#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
89pub struct QueryVersionRequest;
90impl_debug_if_no_extra_traits!(QueryVersionRequest, "QueryVersionRequest");
91impl QueryVersionRequest {
92    /// Serialize this request into bytes for the provided connection
93    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
94        let length_so_far = 0;
95        let mut request0 = vec![
96            major_opcode,
97            QUERY_VERSION_REQUEST,
98            0,
99            0,
100        ];
101        let length_so_far = length_so_far + request0.len();
102        assert_eq!(length_so_far % 4, 0);
103        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
104        request0[2..4].copy_from_slice(&length.to_ne_bytes());
105        ([request0.into()], vec![])
106    }
107    /// Parse this request given its header, its body, and any fds that go along with it
108    #[cfg(feature = "request-parsing")]
109    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
110        if header.minor_opcode != QUERY_VERSION_REQUEST {
111            return Err(ParseError::InvalidValue);
112        }
113        let _ = value;
114        Ok(QueryVersionRequest
115        )
116    }
117}
118impl Request for QueryVersionRequest {
119    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
120
121    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
122        let (bufs, fds) = self.serialize(major_opcode);
123        // Flatten the buffers into a single vector
124        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
125        (buf, fds)
126    }
127}
128impl crate::x11_utils::ReplyRequest for QueryVersionRequest {
129    type Reply = QueryVersionReply;
130}
131
132#[derive(Clone, Copy, Default)]
133#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
134#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
135pub struct QueryVersionReply {
136    pub sequence: u16,
137    pub length: u32,
138    pub dri_major_version: u16,
139    pub dri_minor_version: u16,
140    pub dri_minor_patch: u32,
141}
142impl_debug_if_no_extra_traits!(QueryVersionReply, "QueryVersionReply");
143impl TryParse for QueryVersionReply {
144    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
145        let remaining = initial_value;
146        let (response_type, remaining) = u8::try_parse(remaining)?;
147        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
148        let (sequence, remaining) = u16::try_parse(remaining)?;
149        let (length, remaining) = u32::try_parse(remaining)?;
150        let (dri_major_version, remaining) = u16::try_parse(remaining)?;
151        let (dri_minor_version, remaining) = u16::try_parse(remaining)?;
152        let (dri_minor_patch, remaining) = u32::try_parse(remaining)?;
153        if response_type != 1 {
154            return Err(ParseError::InvalidValue);
155        }
156        let result = QueryVersionReply { sequence, length, dri_major_version, dri_minor_version, dri_minor_patch };
157        let _ = remaining;
158        let remaining = initial_value.get(32 + length as usize * 4..)
159            .ok_or(ParseError::InsufficientData)?;
160        Ok((result, remaining))
161    }
162}
163impl Serialize for QueryVersionReply {
164    type Bytes = [u8; 16];
165    fn serialize(&self) -> [u8; 16] {
166        let response_type_bytes = &[1];
167        let sequence_bytes = self.sequence.serialize();
168        let length_bytes = self.length.serialize();
169        let dri_major_version_bytes = self.dri_major_version.serialize();
170        let dri_minor_version_bytes = self.dri_minor_version.serialize();
171        let dri_minor_patch_bytes = self.dri_minor_patch.serialize();
172        [
173            response_type_bytes[0],
174            0,
175            sequence_bytes[0],
176            sequence_bytes[1],
177            length_bytes[0],
178            length_bytes[1],
179            length_bytes[2],
180            length_bytes[3],
181            dri_major_version_bytes[0],
182            dri_major_version_bytes[1],
183            dri_minor_version_bytes[0],
184            dri_minor_version_bytes[1],
185            dri_minor_patch_bytes[0],
186            dri_minor_patch_bytes[1],
187            dri_minor_patch_bytes[2],
188            dri_minor_patch_bytes[3],
189        ]
190    }
191    fn serialize_into(&self, bytes: &mut Vec<u8>) {
192        bytes.reserve(16);
193        let response_type_bytes = &[1];
194        bytes.push(response_type_bytes[0]);
195        bytes.extend_from_slice(&[0; 1]);
196        self.sequence.serialize_into(bytes);
197        self.length.serialize_into(bytes);
198        self.dri_major_version.serialize_into(bytes);
199        self.dri_minor_version.serialize_into(bytes);
200        self.dri_minor_patch.serialize_into(bytes);
201    }
202}
203
204/// Opcode for the QueryDirectRenderingCapable request
205pub const QUERY_DIRECT_RENDERING_CAPABLE_REQUEST: u8 = 1;
206#[derive(Clone, Copy, Default)]
207#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
208#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
209pub struct QueryDirectRenderingCapableRequest {
210    pub screen: u32,
211}
212impl_debug_if_no_extra_traits!(QueryDirectRenderingCapableRequest, "QueryDirectRenderingCapableRequest");
213impl QueryDirectRenderingCapableRequest {
214    /// Serialize this request into bytes for the provided connection
215    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
216        let length_so_far = 0;
217        let screen_bytes = self.screen.serialize();
218        let mut request0 = vec![
219            major_opcode,
220            QUERY_DIRECT_RENDERING_CAPABLE_REQUEST,
221            0,
222            0,
223            screen_bytes[0],
224            screen_bytes[1],
225            screen_bytes[2],
226            screen_bytes[3],
227        ];
228        let length_so_far = length_so_far + request0.len();
229        assert_eq!(length_so_far % 4, 0);
230        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
231        request0[2..4].copy_from_slice(&length.to_ne_bytes());
232        ([request0.into()], vec![])
233    }
234    /// Parse this request given its header, its body, and any fds that go along with it
235    #[cfg(feature = "request-parsing")]
236    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
237        if header.minor_opcode != QUERY_DIRECT_RENDERING_CAPABLE_REQUEST {
238            return Err(ParseError::InvalidValue);
239        }
240        let (screen, remaining) = u32::try_parse(value)?;
241        let _ = remaining;
242        Ok(QueryDirectRenderingCapableRequest {
243            screen,
244        })
245    }
246}
247impl Request for QueryDirectRenderingCapableRequest {
248    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
249
250    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
251        let (bufs, fds) = self.serialize(major_opcode);
252        // Flatten the buffers into a single vector
253        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
254        (buf, fds)
255    }
256}
257impl crate::x11_utils::ReplyRequest for QueryDirectRenderingCapableRequest {
258    type Reply = QueryDirectRenderingCapableReply;
259}
260
261#[derive(Clone, Copy, Default)]
262#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
263#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
264pub struct QueryDirectRenderingCapableReply {
265    pub sequence: u16,
266    pub length: u32,
267    pub is_capable: bool,
268}
269impl_debug_if_no_extra_traits!(QueryDirectRenderingCapableReply, "QueryDirectRenderingCapableReply");
270impl TryParse for QueryDirectRenderingCapableReply {
271    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
272        let remaining = initial_value;
273        let (response_type, remaining) = u8::try_parse(remaining)?;
274        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
275        let (sequence, remaining) = u16::try_parse(remaining)?;
276        let (length, remaining) = u32::try_parse(remaining)?;
277        let (is_capable, remaining) = bool::try_parse(remaining)?;
278        if response_type != 1 {
279            return Err(ParseError::InvalidValue);
280        }
281        let result = QueryDirectRenderingCapableReply { sequence, length, is_capable };
282        let _ = remaining;
283        let remaining = initial_value.get(32 + length as usize * 4..)
284            .ok_or(ParseError::InsufficientData)?;
285        Ok((result, remaining))
286    }
287}
288impl Serialize for QueryDirectRenderingCapableReply {
289    type Bytes = [u8; 9];
290    fn serialize(&self) -> [u8; 9] {
291        let response_type_bytes = &[1];
292        let sequence_bytes = self.sequence.serialize();
293        let length_bytes = self.length.serialize();
294        let is_capable_bytes = self.is_capable.serialize();
295        [
296            response_type_bytes[0],
297            0,
298            sequence_bytes[0],
299            sequence_bytes[1],
300            length_bytes[0],
301            length_bytes[1],
302            length_bytes[2],
303            length_bytes[3],
304            is_capable_bytes[0],
305        ]
306    }
307    fn serialize_into(&self, bytes: &mut Vec<u8>) {
308        bytes.reserve(9);
309        let response_type_bytes = &[1];
310        bytes.push(response_type_bytes[0]);
311        bytes.extend_from_slice(&[0; 1]);
312        self.sequence.serialize_into(bytes);
313        self.length.serialize_into(bytes);
314        self.is_capable.serialize_into(bytes);
315    }
316}
317
318/// Opcode for the OpenConnection request
319pub const OPEN_CONNECTION_REQUEST: u8 = 2;
320#[derive(Clone, Copy, Default)]
321#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
322#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
323pub struct OpenConnectionRequest {
324    pub screen: u32,
325}
326impl_debug_if_no_extra_traits!(OpenConnectionRequest, "OpenConnectionRequest");
327impl OpenConnectionRequest {
328    /// Serialize this request into bytes for the provided connection
329    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
330        let length_so_far = 0;
331        let screen_bytes = self.screen.serialize();
332        let mut request0 = vec![
333            major_opcode,
334            OPEN_CONNECTION_REQUEST,
335            0,
336            0,
337            screen_bytes[0],
338            screen_bytes[1],
339            screen_bytes[2],
340            screen_bytes[3],
341        ];
342        let length_so_far = length_so_far + request0.len();
343        assert_eq!(length_so_far % 4, 0);
344        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
345        request0[2..4].copy_from_slice(&length.to_ne_bytes());
346        ([request0.into()], vec![])
347    }
348    /// Parse this request given its header, its body, and any fds that go along with it
349    #[cfg(feature = "request-parsing")]
350    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
351        if header.minor_opcode != OPEN_CONNECTION_REQUEST {
352            return Err(ParseError::InvalidValue);
353        }
354        let (screen, remaining) = u32::try_parse(value)?;
355        let _ = remaining;
356        Ok(OpenConnectionRequest {
357            screen,
358        })
359    }
360}
361impl Request for OpenConnectionRequest {
362    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
363
364    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
365        let (bufs, fds) = self.serialize(major_opcode);
366        // Flatten the buffers into a single vector
367        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
368        (buf, fds)
369    }
370}
371impl crate::x11_utils::ReplyRequest for OpenConnectionRequest {
372    type Reply = OpenConnectionReply;
373}
374
375#[derive(Clone, Default)]
376#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
377#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
378pub struct OpenConnectionReply {
379    pub sequence: u16,
380    pub length: u32,
381    pub sarea_handle_low: u32,
382    pub sarea_handle_high: u32,
383    pub bus_id: Vec<u8>,
384}
385impl_debug_if_no_extra_traits!(OpenConnectionReply, "OpenConnectionReply");
386impl TryParse for OpenConnectionReply {
387    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
388        let remaining = initial_value;
389        let (response_type, remaining) = u8::try_parse(remaining)?;
390        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
391        let (sequence, remaining) = u16::try_parse(remaining)?;
392        let (length, remaining) = u32::try_parse(remaining)?;
393        let (sarea_handle_low, remaining) = u32::try_parse(remaining)?;
394        let (sarea_handle_high, remaining) = u32::try_parse(remaining)?;
395        let (bus_id_len, remaining) = u32::try_parse(remaining)?;
396        let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
397        let (bus_id, remaining) = crate::x11_utils::parse_u8_list(remaining, bus_id_len.try_to_usize()?)?;
398        let bus_id = bus_id.to_vec();
399        if response_type != 1 {
400            return Err(ParseError::InvalidValue);
401        }
402        let result = OpenConnectionReply { sequence, length, sarea_handle_low, sarea_handle_high, bus_id };
403        let _ = remaining;
404        let remaining = initial_value.get(32 + length as usize * 4..)
405            .ok_or(ParseError::InsufficientData)?;
406        Ok((result, remaining))
407    }
408}
409impl Serialize for OpenConnectionReply {
410    type Bytes = Vec<u8>;
411    fn serialize(&self) -> Vec<u8> {
412        let mut result = Vec::new();
413        self.serialize_into(&mut result);
414        result
415    }
416    fn serialize_into(&self, bytes: &mut Vec<u8>) {
417        bytes.reserve(32);
418        let response_type_bytes = &[1];
419        bytes.push(response_type_bytes[0]);
420        bytes.extend_from_slice(&[0; 1]);
421        self.sequence.serialize_into(bytes);
422        self.length.serialize_into(bytes);
423        self.sarea_handle_low.serialize_into(bytes);
424        self.sarea_handle_high.serialize_into(bytes);
425        let bus_id_len = u32::try_from(self.bus_id.len()).expect("`bus_id` has too many elements");
426        bus_id_len.serialize_into(bytes);
427        bytes.extend_from_slice(&[0; 12]);
428        bytes.extend_from_slice(&self.bus_id);
429    }
430}
431impl OpenConnectionReply {
432    /// Get the value of the `bus_id_len` field.
433    ///
434    /// The `bus_id_len` field is used as the length field of the `bus_id` field.
435    /// This function computes the field's value again based on the length of the list.
436    ///
437    /// # Panics
438    ///
439    /// Panics if the value cannot be represented in the target type. This
440    /// cannot happen with values of the struct received from the X11 server.
441    pub fn bus_id_len(&self) -> u32 {
442        self.bus_id.len()
443            .try_into().unwrap()
444    }
445}
446
447/// Opcode for the CloseConnection request
448pub const CLOSE_CONNECTION_REQUEST: u8 = 3;
449#[derive(Clone, Copy, Default)]
450#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
451#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
452pub struct CloseConnectionRequest {
453    pub screen: u32,
454}
455impl_debug_if_no_extra_traits!(CloseConnectionRequest, "CloseConnectionRequest");
456impl CloseConnectionRequest {
457    /// Serialize this request into bytes for the provided connection
458    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
459        let length_so_far = 0;
460        let screen_bytes = self.screen.serialize();
461        let mut request0 = vec![
462            major_opcode,
463            CLOSE_CONNECTION_REQUEST,
464            0,
465            0,
466            screen_bytes[0],
467            screen_bytes[1],
468            screen_bytes[2],
469            screen_bytes[3],
470        ];
471        let length_so_far = length_so_far + request0.len();
472        assert_eq!(length_so_far % 4, 0);
473        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
474        request0[2..4].copy_from_slice(&length.to_ne_bytes());
475        ([request0.into()], vec![])
476    }
477    /// Parse this request given its header, its body, and any fds that go along with it
478    #[cfg(feature = "request-parsing")]
479    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
480        if header.minor_opcode != CLOSE_CONNECTION_REQUEST {
481            return Err(ParseError::InvalidValue);
482        }
483        let (screen, remaining) = u32::try_parse(value)?;
484        let _ = remaining;
485        Ok(CloseConnectionRequest {
486            screen,
487        })
488    }
489}
490impl Request for CloseConnectionRequest {
491    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
492
493    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
494        let (bufs, fds) = self.serialize(major_opcode);
495        // Flatten the buffers into a single vector
496        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
497        (buf, fds)
498    }
499}
500impl crate::x11_utils::VoidRequest for CloseConnectionRequest {
501}
502
503/// Opcode for the GetClientDriverName request
504pub const GET_CLIENT_DRIVER_NAME_REQUEST: u8 = 4;
505#[derive(Clone, Copy, Default)]
506#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
507#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
508pub struct GetClientDriverNameRequest {
509    pub screen: u32,
510}
511impl_debug_if_no_extra_traits!(GetClientDriverNameRequest, "GetClientDriverNameRequest");
512impl GetClientDriverNameRequest {
513    /// Serialize this request into bytes for the provided connection
514    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
515        let length_so_far = 0;
516        let screen_bytes = self.screen.serialize();
517        let mut request0 = vec![
518            major_opcode,
519            GET_CLIENT_DRIVER_NAME_REQUEST,
520            0,
521            0,
522            screen_bytes[0],
523            screen_bytes[1],
524            screen_bytes[2],
525            screen_bytes[3],
526        ];
527        let length_so_far = length_so_far + request0.len();
528        assert_eq!(length_so_far % 4, 0);
529        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
530        request0[2..4].copy_from_slice(&length.to_ne_bytes());
531        ([request0.into()], vec![])
532    }
533    /// Parse this request given its header, its body, and any fds that go along with it
534    #[cfg(feature = "request-parsing")]
535    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
536        if header.minor_opcode != GET_CLIENT_DRIVER_NAME_REQUEST {
537            return Err(ParseError::InvalidValue);
538        }
539        let (screen, remaining) = u32::try_parse(value)?;
540        let _ = remaining;
541        Ok(GetClientDriverNameRequest {
542            screen,
543        })
544    }
545}
546impl Request for GetClientDriverNameRequest {
547    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
548
549    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
550        let (bufs, fds) = self.serialize(major_opcode);
551        // Flatten the buffers into a single vector
552        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
553        (buf, fds)
554    }
555}
556impl crate::x11_utils::ReplyRequest for GetClientDriverNameRequest {
557    type Reply = GetClientDriverNameReply;
558}
559
560#[derive(Clone, Default)]
561#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
562#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
563pub struct GetClientDriverNameReply {
564    pub sequence: u16,
565    pub length: u32,
566    pub client_driver_major_version: u32,
567    pub client_driver_minor_version: u32,
568    pub client_driver_patch_version: u32,
569    pub client_driver_name: Vec<u8>,
570}
571impl_debug_if_no_extra_traits!(GetClientDriverNameReply, "GetClientDriverNameReply");
572impl TryParse for GetClientDriverNameReply {
573    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
574        let remaining = initial_value;
575        let (response_type, remaining) = u8::try_parse(remaining)?;
576        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
577        let (sequence, remaining) = u16::try_parse(remaining)?;
578        let (length, remaining) = u32::try_parse(remaining)?;
579        let (client_driver_major_version, remaining) = u32::try_parse(remaining)?;
580        let (client_driver_minor_version, remaining) = u32::try_parse(remaining)?;
581        let (client_driver_patch_version, remaining) = u32::try_parse(remaining)?;
582        let (client_driver_name_len, remaining) = u32::try_parse(remaining)?;
583        let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?;
584        let (client_driver_name, remaining) = crate::x11_utils::parse_u8_list(remaining, client_driver_name_len.try_to_usize()?)?;
585        let client_driver_name = client_driver_name.to_vec();
586        if response_type != 1 {
587            return Err(ParseError::InvalidValue);
588        }
589        let result = GetClientDriverNameReply { sequence, length, client_driver_major_version, client_driver_minor_version, client_driver_patch_version, client_driver_name };
590        let _ = remaining;
591        let remaining = initial_value.get(32 + length as usize * 4..)
592            .ok_or(ParseError::InsufficientData)?;
593        Ok((result, remaining))
594    }
595}
596impl Serialize for GetClientDriverNameReply {
597    type Bytes = Vec<u8>;
598    fn serialize(&self) -> Vec<u8> {
599        let mut result = Vec::new();
600        self.serialize_into(&mut result);
601        result
602    }
603    fn serialize_into(&self, bytes: &mut Vec<u8>) {
604        bytes.reserve(32);
605        let response_type_bytes = &[1];
606        bytes.push(response_type_bytes[0]);
607        bytes.extend_from_slice(&[0; 1]);
608        self.sequence.serialize_into(bytes);
609        self.length.serialize_into(bytes);
610        self.client_driver_major_version.serialize_into(bytes);
611        self.client_driver_minor_version.serialize_into(bytes);
612        self.client_driver_patch_version.serialize_into(bytes);
613        let client_driver_name_len = u32::try_from(self.client_driver_name.len()).expect("`client_driver_name` has too many elements");
614        client_driver_name_len.serialize_into(bytes);
615        bytes.extend_from_slice(&[0; 8]);
616        bytes.extend_from_slice(&self.client_driver_name);
617    }
618}
619impl GetClientDriverNameReply {
620    /// Get the value of the `client_driver_name_len` field.
621    ///
622    /// The `client_driver_name_len` field is used as the length field of the `client_driver_name` field.
623    /// This function computes the field's value again based on the length of the list.
624    ///
625    /// # Panics
626    ///
627    /// Panics if the value cannot be represented in the target type. This
628    /// cannot happen with values of the struct received from the X11 server.
629    pub fn client_driver_name_len(&self) -> u32 {
630        self.client_driver_name.len()
631            .try_into().unwrap()
632    }
633}
634
635/// Opcode for the CreateContext request
636pub const CREATE_CONTEXT_REQUEST: u8 = 5;
637#[derive(Clone, Copy, Default)]
638#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
639#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
640pub struct CreateContextRequest {
641    pub screen: u32,
642    pub visual: u32,
643    pub context: u32,
644}
645impl_debug_if_no_extra_traits!(CreateContextRequest, "CreateContextRequest");
646impl CreateContextRequest {
647    /// Serialize this request into bytes for the provided connection
648    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
649        let length_so_far = 0;
650        let screen_bytes = self.screen.serialize();
651        let visual_bytes = self.visual.serialize();
652        let context_bytes = self.context.serialize();
653        let mut request0 = vec![
654            major_opcode,
655            CREATE_CONTEXT_REQUEST,
656            0,
657            0,
658            screen_bytes[0],
659            screen_bytes[1],
660            screen_bytes[2],
661            screen_bytes[3],
662            visual_bytes[0],
663            visual_bytes[1],
664            visual_bytes[2],
665            visual_bytes[3],
666            context_bytes[0],
667            context_bytes[1],
668            context_bytes[2],
669            context_bytes[3],
670        ];
671        let length_so_far = length_so_far + request0.len();
672        assert_eq!(length_so_far % 4, 0);
673        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
674        request0[2..4].copy_from_slice(&length.to_ne_bytes());
675        ([request0.into()], vec![])
676    }
677    /// Parse this request given its header, its body, and any fds that go along with it
678    #[cfg(feature = "request-parsing")]
679    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
680        if header.minor_opcode != CREATE_CONTEXT_REQUEST {
681            return Err(ParseError::InvalidValue);
682        }
683        let (screen, remaining) = u32::try_parse(value)?;
684        let (visual, remaining) = u32::try_parse(remaining)?;
685        let (context, remaining) = u32::try_parse(remaining)?;
686        let _ = remaining;
687        Ok(CreateContextRequest {
688            screen,
689            visual,
690            context,
691        })
692    }
693}
694impl Request for CreateContextRequest {
695    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
696
697    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
698        let (bufs, fds) = self.serialize(major_opcode);
699        // Flatten the buffers into a single vector
700        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
701        (buf, fds)
702    }
703}
704impl crate::x11_utils::ReplyRequest for CreateContextRequest {
705    type Reply = CreateContextReply;
706}
707
708#[derive(Clone, Copy, Default)]
709#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
710#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
711pub struct CreateContextReply {
712    pub sequence: u16,
713    pub length: u32,
714    pub hw_context: u32,
715}
716impl_debug_if_no_extra_traits!(CreateContextReply, "CreateContextReply");
717impl TryParse for CreateContextReply {
718    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
719        let remaining = initial_value;
720        let (response_type, remaining) = u8::try_parse(remaining)?;
721        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
722        let (sequence, remaining) = u16::try_parse(remaining)?;
723        let (length, remaining) = u32::try_parse(remaining)?;
724        let (hw_context, remaining) = u32::try_parse(remaining)?;
725        if response_type != 1 {
726            return Err(ParseError::InvalidValue);
727        }
728        let result = CreateContextReply { sequence, length, hw_context };
729        let _ = remaining;
730        let remaining = initial_value.get(32 + length as usize * 4..)
731            .ok_or(ParseError::InsufficientData)?;
732        Ok((result, remaining))
733    }
734}
735impl Serialize for CreateContextReply {
736    type Bytes = [u8; 12];
737    fn serialize(&self) -> [u8; 12] {
738        let response_type_bytes = &[1];
739        let sequence_bytes = self.sequence.serialize();
740        let length_bytes = self.length.serialize();
741        let hw_context_bytes = self.hw_context.serialize();
742        [
743            response_type_bytes[0],
744            0,
745            sequence_bytes[0],
746            sequence_bytes[1],
747            length_bytes[0],
748            length_bytes[1],
749            length_bytes[2],
750            length_bytes[3],
751            hw_context_bytes[0],
752            hw_context_bytes[1],
753            hw_context_bytes[2],
754            hw_context_bytes[3],
755        ]
756    }
757    fn serialize_into(&self, bytes: &mut Vec<u8>) {
758        bytes.reserve(12);
759        let response_type_bytes = &[1];
760        bytes.push(response_type_bytes[0]);
761        bytes.extend_from_slice(&[0; 1]);
762        self.sequence.serialize_into(bytes);
763        self.length.serialize_into(bytes);
764        self.hw_context.serialize_into(bytes);
765    }
766}
767
768/// Opcode for the DestroyContext request
769pub const DESTROY_CONTEXT_REQUEST: u8 = 6;
770#[derive(Clone, Copy, Default)]
771#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
772#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
773pub struct DestroyContextRequest {
774    pub screen: u32,
775    pub context: u32,
776}
777impl_debug_if_no_extra_traits!(DestroyContextRequest, "DestroyContextRequest");
778impl DestroyContextRequest {
779    /// Serialize this request into bytes for the provided connection
780    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
781        let length_so_far = 0;
782        let screen_bytes = self.screen.serialize();
783        let context_bytes = self.context.serialize();
784        let mut request0 = vec![
785            major_opcode,
786            DESTROY_CONTEXT_REQUEST,
787            0,
788            0,
789            screen_bytes[0],
790            screen_bytes[1],
791            screen_bytes[2],
792            screen_bytes[3],
793            context_bytes[0],
794            context_bytes[1],
795            context_bytes[2],
796            context_bytes[3],
797        ];
798        let length_so_far = length_so_far + request0.len();
799        assert_eq!(length_so_far % 4, 0);
800        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
801        request0[2..4].copy_from_slice(&length.to_ne_bytes());
802        ([request0.into()], vec![])
803    }
804    /// Parse this request given its header, its body, and any fds that go along with it
805    #[cfg(feature = "request-parsing")]
806    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
807        if header.minor_opcode != DESTROY_CONTEXT_REQUEST {
808            return Err(ParseError::InvalidValue);
809        }
810        let (screen, remaining) = u32::try_parse(value)?;
811        let (context, remaining) = u32::try_parse(remaining)?;
812        let _ = remaining;
813        Ok(DestroyContextRequest {
814            screen,
815            context,
816        })
817    }
818}
819impl Request for DestroyContextRequest {
820    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
821
822    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
823        let (bufs, fds) = self.serialize(major_opcode);
824        // Flatten the buffers into a single vector
825        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
826        (buf, fds)
827    }
828}
829impl crate::x11_utils::VoidRequest for DestroyContextRequest {
830}
831
832/// Opcode for the CreateDrawable request
833pub const CREATE_DRAWABLE_REQUEST: u8 = 7;
834#[derive(Clone, Copy, Default)]
835#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
836#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
837pub struct CreateDrawableRequest {
838    pub screen: u32,
839    pub drawable: u32,
840}
841impl_debug_if_no_extra_traits!(CreateDrawableRequest, "CreateDrawableRequest");
842impl CreateDrawableRequest {
843    /// Serialize this request into bytes for the provided connection
844    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
845        let length_so_far = 0;
846        let screen_bytes = self.screen.serialize();
847        let drawable_bytes = self.drawable.serialize();
848        let mut request0 = vec![
849            major_opcode,
850            CREATE_DRAWABLE_REQUEST,
851            0,
852            0,
853            screen_bytes[0],
854            screen_bytes[1],
855            screen_bytes[2],
856            screen_bytes[3],
857            drawable_bytes[0],
858            drawable_bytes[1],
859            drawable_bytes[2],
860            drawable_bytes[3],
861        ];
862        let length_so_far = length_so_far + request0.len();
863        assert_eq!(length_so_far % 4, 0);
864        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
865        request0[2..4].copy_from_slice(&length.to_ne_bytes());
866        ([request0.into()], vec![])
867    }
868    /// Parse this request given its header, its body, and any fds that go along with it
869    #[cfg(feature = "request-parsing")]
870    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
871        if header.minor_opcode != CREATE_DRAWABLE_REQUEST {
872            return Err(ParseError::InvalidValue);
873        }
874        let (screen, remaining) = u32::try_parse(value)?;
875        let (drawable, remaining) = u32::try_parse(remaining)?;
876        let _ = remaining;
877        Ok(CreateDrawableRequest {
878            screen,
879            drawable,
880        })
881    }
882}
883impl Request for CreateDrawableRequest {
884    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
885
886    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
887        let (bufs, fds) = self.serialize(major_opcode);
888        // Flatten the buffers into a single vector
889        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
890        (buf, fds)
891    }
892}
893impl crate::x11_utils::ReplyRequest for CreateDrawableRequest {
894    type Reply = CreateDrawableReply;
895}
896
897#[derive(Clone, Copy, Default)]
898#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
899#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
900pub struct CreateDrawableReply {
901    pub sequence: u16,
902    pub length: u32,
903    pub hw_drawable_handle: u32,
904}
905impl_debug_if_no_extra_traits!(CreateDrawableReply, "CreateDrawableReply");
906impl TryParse for CreateDrawableReply {
907    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
908        let remaining = initial_value;
909        let (response_type, remaining) = u8::try_parse(remaining)?;
910        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
911        let (sequence, remaining) = u16::try_parse(remaining)?;
912        let (length, remaining) = u32::try_parse(remaining)?;
913        let (hw_drawable_handle, remaining) = u32::try_parse(remaining)?;
914        if response_type != 1 {
915            return Err(ParseError::InvalidValue);
916        }
917        let result = CreateDrawableReply { sequence, length, hw_drawable_handle };
918        let _ = remaining;
919        let remaining = initial_value.get(32 + length as usize * 4..)
920            .ok_or(ParseError::InsufficientData)?;
921        Ok((result, remaining))
922    }
923}
924impl Serialize for CreateDrawableReply {
925    type Bytes = [u8; 12];
926    fn serialize(&self) -> [u8; 12] {
927        let response_type_bytes = &[1];
928        let sequence_bytes = self.sequence.serialize();
929        let length_bytes = self.length.serialize();
930        let hw_drawable_handle_bytes = self.hw_drawable_handle.serialize();
931        [
932            response_type_bytes[0],
933            0,
934            sequence_bytes[0],
935            sequence_bytes[1],
936            length_bytes[0],
937            length_bytes[1],
938            length_bytes[2],
939            length_bytes[3],
940            hw_drawable_handle_bytes[0],
941            hw_drawable_handle_bytes[1],
942            hw_drawable_handle_bytes[2],
943            hw_drawable_handle_bytes[3],
944        ]
945    }
946    fn serialize_into(&self, bytes: &mut Vec<u8>) {
947        bytes.reserve(12);
948        let response_type_bytes = &[1];
949        bytes.push(response_type_bytes[0]);
950        bytes.extend_from_slice(&[0; 1]);
951        self.sequence.serialize_into(bytes);
952        self.length.serialize_into(bytes);
953        self.hw_drawable_handle.serialize_into(bytes);
954    }
955}
956
957/// Opcode for the DestroyDrawable request
958pub const DESTROY_DRAWABLE_REQUEST: u8 = 8;
959#[derive(Clone, Copy, Default)]
960#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
961#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
962pub struct DestroyDrawableRequest {
963    pub screen: u32,
964    pub drawable: u32,
965}
966impl_debug_if_no_extra_traits!(DestroyDrawableRequest, "DestroyDrawableRequest");
967impl DestroyDrawableRequest {
968    /// Serialize this request into bytes for the provided connection
969    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
970        let length_so_far = 0;
971        let screen_bytes = self.screen.serialize();
972        let drawable_bytes = self.drawable.serialize();
973        let mut request0 = vec![
974            major_opcode,
975            DESTROY_DRAWABLE_REQUEST,
976            0,
977            0,
978            screen_bytes[0],
979            screen_bytes[1],
980            screen_bytes[2],
981            screen_bytes[3],
982            drawable_bytes[0],
983            drawable_bytes[1],
984            drawable_bytes[2],
985            drawable_bytes[3],
986        ];
987        let length_so_far = length_so_far + request0.len();
988        assert_eq!(length_so_far % 4, 0);
989        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
990        request0[2..4].copy_from_slice(&length.to_ne_bytes());
991        ([request0.into()], vec![])
992    }
993    /// Parse this request given its header, its body, and any fds that go along with it
994    #[cfg(feature = "request-parsing")]
995    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
996        if header.minor_opcode != DESTROY_DRAWABLE_REQUEST {
997            return Err(ParseError::InvalidValue);
998        }
999        let (screen, remaining) = u32::try_parse(value)?;
1000        let (drawable, remaining) = u32::try_parse(remaining)?;
1001        let _ = remaining;
1002        Ok(DestroyDrawableRequest {
1003            screen,
1004            drawable,
1005        })
1006    }
1007}
1008impl Request for DestroyDrawableRequest {
1009    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1010
1011    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1012        let (bufs, fds) = self.serialize(major_opcode);
1013        // Flatten the buffers into a single vector
1014        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1015        (buf, fds)
1016    }
1017}
1018impl crate::x11_utils::VoidRequest for DestroyDrawableRequest {
1019}
1020
1021/// Opcode for the GetDrawableInfo request
1022pub const GET_DRAWABLE_INFO_REQUEST: u8 = 9;
1023#[derive(Clone, Copy, Default)]
1024#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1025#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1026pub struct GetDrawableInfoRequest {
1027    pub screen: u32,
1028    pub drawable: u32,
1029}
1030impl_debug_if_no_extra_traits!(GetDrawableInfoRequest, "GetDrawableInfoRequest");
1031impl GetDrawableInfoRequest {
1032    /// Serialize this request into bytes for the provided connection
1033    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1034        let length_so_far = 0;
1035        let screen_bytes = self.screen.serialize();
1036        let drawable_bytes = self.drawable.serialize();
1037        let mut request0 = vec![
1038            major_opcode,
1039            GET_DRAWABLE_INFO_REQUEST,
1040            0,
1041            0,
1042            screen_bytes[0],
1043            screen_bytes[1],
1044            screen_bytes[2],
1045            screen_bytes[3],
1046            drawable_bytes[0],
1047            drawable_bytes[1],
1048            drawable_bytes[2],
1049            drawable_bytes[3],
1050        ];
1051        let length_so_far = length_so_far + request0.len();
1052        assert_eq!(length_so_far % 4, 0);
1053        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1054        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1055        ([request0.into()], vec![])
1056    }
1057    /// Parse this request given its header, its body, and any fds that go along with it
1058    #[cfg(feature = "request-parsing")]
1059    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1060        if header.minor_opcode != GET_DRAWABLE_INFO_REQUEST {
1061            return Err(ParseError::InvalidValue);
1062        }
1063        let (screen, remaining) = u32::try_parse(value)?;
1064        let (drawable, remaining) = u32::try_parse(remaining)?;
1065        let _ = remaining;
1066        Ok(GetDrawableInfoRequest {
1067            screen,
1068            drawable,
1069        })
1070    }
1071}
1072impl Request for GetDrawableInfoRequest {
1073    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1074
1075    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1076        let (bufs, fds) = self.serialize(major_opcode);
1077        // Flatten the buffers into a single vector
1078        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1079        (buf, fds)
1080    }
1081}
1082impl crate::x11_utils::ReplyRequest for GetDrawableInfoRequest {
1083    type Reply = GetDrawableInfoReply;
1084}
1085
1086#[derive(Clone, Default)]
1087#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1088#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1089pub struct GetDrawableInfoReply {
1090    pub sequence: u16,
1091    pub length: u32,
1092    pub drawable_table_index: u32,
1093    pub drawable_table_stamp: u32,
1094    pub drawable_origin_x: i16,
1095    pub drawable_origin_y: i16,
1096    pub drawable_size_w: i16,
1097    pub drawable_size_h: i16,
1098    pub back_x: i16,
1099    pub back_y: i16,
1100    pub clip_rects: Vec<DrmClipRect>,
1101    pub back_clip_rects: Vec<DrmClipRect>,
1102}
1103impl_debug_if_no_extra_traits!(GetDrawableInfoReply, "GetDrawableInfoReply");
1104impl TryParse for GetDrawableInfoReply {
1105    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1106        let remaining = initial_value;
1107        let (response_type, remaining) = u8::try_parse(remaining)?;
1108        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1109        let (sequence, remaining) = u16::try_parse(remaining)?;
1110        let (length, remaining) = u32::try_parse(remaining)?;
1111        let (drawable_table_index, remaining) = u32::try_parse(remaining)?;
1112        let (drawable_table_stamp, remaining) = u32::try_parse(remaining)?;
1113        let (drawable_origin_x, remaining) = i16::try_parse(remaining)?;
1114        let (drawable_origin_y, remaining) = i16::try_parse(remaining)?;
1115        let (drawable_size_w, remaining) = i16::try_parse(remaining)?;
1116        let (drawable_size_h, remaining) = i16::try_parse(remaining)?;
1117        let (num_clip_rects, remaining) = u32::try_parse(remaining)?;
1118        let (back_x, remaining) = i16::try_parse(remaining)?;
1119        let (back_y, remaining) = i16::try_parse(remaining)?;
1120        let (num_back_clip_rects, remaining) = u32::try_parse(remaining)?;
1121        let (clip_rects, remaining) = crate::x11_utils::parse_list::<DrmClipRect>(remaining, num_clip_rects.try_to_usize()?)?;
1122        let (back_clip_rects, remaining) = crate::x11_utils::parse_list::<DrmClipRect>(remaining, num_back_clip_rects.try_to_usize()?)?;
1123        if response_type != 1 {
1124            return Err(ParseError::InvalidValue);
1125        }
1126        let result = GetDrawableInfoReply { sequence, length, drawable_table_index, drawable_table_stamp, drawable_origin_x, drawable_origin_y, drawable_size_w, drawable_size_h, back_x, back_y, clip_rects, back_clip_rects };
1127        let _ = remaining;
1128        let remaining = initial_value.get(32 + length as usize * 4..)
1129            .ok_or(ParseError::InsufficientData)?;
1130        Ok((result, remaining))
1131    }
1132}
1133impl Serialize for GetDrawableInfoReply {
1134    type Bytes = Vec<u8>;
1135    fn serialize(&self) -> Vec<u8> {
1136        let mut result = Vec::new();
1137        self.serialize_into(&mut result);
1138        result
1139    }
1140    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1141        bytes.reserve(36);
1142        let response_type_bytes = &[1];
1143        bytes.push(response_type_bytes[0]);
1144        bytes.extend_from_slice(&[0; 1]);
1145        self.sequence.serialize_into(bytes);
1146        self.length.serialize_into(bytes);
1147        self.drawable_table_index.serialize_into(bytes);
1148        self.drawable_table_stamp.serialize_into(bytes);
1149        self.drawable_origin_x.serialize_into(bytes);
1150        self.drawable_origin_y.serialize_into(bytes);
1151        self.drawable_size_w.serialize_into(bytes);
1152        self.drawable_size_h.serialize_into(bytes);
1153        let num_clip_rects = u32::try_from(self.clip_rects.len()).expect("`clip_rects` has too many elements");
1154        num_clip_rects.serialize_into(bytes);
1155        self.back_x.serialize_into(bytes);
1156        self.back_y.serialize_into(bytes);
1157        let num_back_clip_rects = u32::try_from(self.back_clip_rects.len()).expect("`back_clip_rects` has too many elements");
1158        num_back_clip_rects.serialize_into(bytes);
1159        self.clip_rects.serialize_into(bytes);
1160        self.back_clip_rects.serialize_into(bytes);
1161    }
1162}
1163impl GetDrawableInfoReply {
1164    /// Get the value of the `num_clip_rects` field.
1165    ///
1166    /// The `num_clip_rects` field is used as the length field of the `clip_rects` field.
1167    /// This function computes the field's value again based on the length of the list.
1168    ///
1169    /// # Panics
1170    ///
1171    /// Panics if the value cannot be represented in the target type. This
1172    /// cannot happen with values of the struct received from the X11 server.
1173    pub fn num_clip_rects(&self) -> u32 {
1174        self.clip_rects.len()
1175            .try_into().unwrap()
1176    }
1177    /// Get the value of the `num_back_clip_rects` field.
1178    ///
1179    /// The `num_back_clip_rects` field is used as the length field of the `back_clip_rects` field.
1180    /// This function computes the field's value again based on the length of the list.
1181    ///
1182    /// # Panics
1183    ///
1184    /// Panics if the value cannot be represented in the target type. This
1185    /// cannot happen with values of the struct received from the X11 server.
1186    pub fn num_back_clip_rects(&self) -> u32 {
1187        self.back_clip_rects.len()
1188            .try_into().unwrap()
1189    }
1190}
1191
1192/// Opcode for the GetDeviceInfo request
1193pub const GET_DEVICE_INFO_REQUEST: u8 = 10;
1194#[derive(Clone, Copy, Default)]
1195#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1196#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1197pub struct GetDeviceInfoRequest {
1198    pub screen: u32,
1199}
1200impl_debug_if_no_extra_traits!(GetDeviceInfoRequest, "GetDeviceInfoRequest");
1201impl GetDeviceInfoRequest {
1202    /// Serialize this request into bytes for the provided connection
1203    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1204        let length_so_far = 0;
1205        let screen_bytes = self.screen.serialize();
1206        let mut request0 = vec![
1207            major_opcode,
1208            GET_DEVICE_INFO_REQUEST,
1209            0,
1210            0,
1211            screen_bytes[0],
1212            screen_bytes[1],
1213            screen_bytes[2],
1214            screen_bytes[3],
1215        ];
1216        let length_so_far = length_so_far + request0.len();
1217        assert_eq!(length_so_far % 4, 0);
1218        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1219        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1220        ([request0.into()], vec![])
1221    }
1222    /// Parse this request given its header, its body, and any fds that go along with it
1223    #[cfg(feature = "request-parsing")]
1224    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1225        if header.minor_opcode != GET_DEVICE_INFO_REQUEST {
1226            return Err(ParseError::InvalidValue);
1227        }
1228        let (screen, remaining) = u32::try_parse(value)?;
1229        let _ = remaining;
1230        Ok(GetDeviceInfoRequest {
1231            screen,
1232        })
1233    }
1234}
1235impl Request for GetDeviceInfoRequest {
1236    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1237
1238    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1239        let (bufs, fds) = self.serialize(major_opcode);
1240        // Flatten the buffers into a single vector
1241        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1242        (buf, fds)
1243    }
1244}
1245impl crate::x11_utils::ReplyRequest for GetDeviceInfoRequest {
1246    type Reply = GetDeviceInfoReply;
1247}
1248
1249#[derive(Clone, Default)]
1250#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1251#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1252pub struct GetDeviceInfoReply {
1253    pub sequence: u16,
1254    pub length: u32,
1255    pub framebuffer_handle_low: u32,
1256    pub framebuffer_handle_high: u32,
1257    pub framebuffer_origin_offset: u32,
1258    pub framebuffer_size: u32,
1259    pub framebuffer_stride: u32,
1260    pub device_private: Vec<u32>,
1261}
1262impl_debug_if_no_extra_traits!(GetDeviceInfoReply, "GetDeviceInfoReply");
1263impl TryParse for GetDeviceInfoReply {
1264    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1265        let remaining = initial_value;
1266        let (response_type, remaining) = u8::try_parse(remaining)?;
1267        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1268        let (sequence, remaining) = u16::try_parse(remaining)?;
1269        let (length, remaining) = u32::try_parse(remaining)?;
1270        let (framebuffer_handle_low, remaining) = u32::try_parse(remaining)?;
1271        let (framebuffer_handle_high, remaining) = u32::try_parse(remaining)?;
1272        let (framebuffer_origin_offset, remaining) = u32::try_parse(remaining)?;
1273        let (framebuffer_size, remaining) = u32::try_parse(remaining)?;
1274        let (framebuffer_stride, remaining) = u32::try_parse(remaining)?;
1275        let (device_private_size, remaining) = u32::try_parse(remaining)?;
1276        let (device_private, remaining) = crate::x11_utils::parse_list::<u32>(remaining, device_private_size.try_to_usize()?)?;
1277        if response_type != 1 {
1278            return Err(ParseError::InvalidValue);
1279        }
1280        let result = GetDeviceInfoReply { sequence, length, framebuffer_handle_low, framebuffer_handle_high, framebuffer_origin_offset, framebuffer_size, framebuffer_stride, device_private };
1281        let _ = remaining;
1282        let remaining = initial_value.get(32 + length as usize * 4..)
1283            .ok_or(ParseError::InsufficientData)?;
1284        Ok((result, remaining))
1285    }
1286}
1287impl Serialize for GetDeviceInfoReply {
1288    type Bytes = Vec<u8>;
1289    fn serialize(&self) -> Vec<u8> {
1290        let mut result = Vec::new();
1291        self.serialize_into(&mut result);
1292        result
1293    }
1294    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1295        bytes.reserve(32);
1296        let response_type_bytes = &[1];
1297        bytes.push(response_type_bytes[0]);
1298        bytes.extend_from_slice(&[0; 1]);
1299        self.sequence.serialize_into(bytes);
1300        self.length.serialize_into(bytes);
1301        self.framebuffer_handle_low.serialize_into(bytes);
1302        self.framebuffer_handle_high.serialize_into(bytes);
1303        self.framebuffer_origin_offset.serialize_into(bytes);
1304        self.framebuffer_size.serialize_into(bytes);
1305        self.framebuffer_stride.serialize_into(bytes);
1306        let device_private_size = u32::try_from(self.device_private.len()).expect("`device_private` has too many elements");
1307        device_private_size.serialize_into(bytes);
1308        self.device_private.serialize_into(bytes);
1309    }
1310}
1311impl GetDeviceInfoReply {
1312    /// Get the value of the `device_private_size` field.
1313    ///
1314    /// The `device_private_size` field is used as the length field of the `device_private` field.
1315    /// This function computes the field's value again based on the length of the list.
1316    ///
1317    /// # Panics
1318    ///
1319    /// Panics if the value cannot be represented in the target type. This
1320    /// cannot happen with values of the struct received from the X11 server.
1321    pub fn device_private_size(&self) -> u32 {
1322        self.device_private.len()
1323            .try_into().unwrap()
1324    }
1325}
1326
1327/// Opcode for the AuthConnection request
1328pub const AUTH_CONNECTION_REQUEST: u8 = 11;
1329#[derive(Clone, Copy, Default)]
1330#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1331#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1332pub struct AuthConnectionRequest {
1333    pub screen: u32,
1334    pub magic: u32,
1335}
1336impl_debug_if_no_extra_traits!(AuthConnectionRequest, "AuthConnectionRequest");
1337impl AuthConnectionRequest {
1338    /// Serialize this request into bytes for the provided connection
1339    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1340        let length_so_far = 0;
1341        let screen_bytes = self.screen.serialize();
1342        let magic_bytes = self.magic.serialize();
1343        let mut request0 = vec![
1344            major_opcode,
1345            AUTH_CONNECTION_REQUEST,
1346            0,
1347            0,
1348            screen_bytes[0],
1349            screen_bytes[1],
1350            screen_bytes[2],
1351            screen_bytes[3],
1352            magic_bytes[0],
1353            magic_bytes[1],
1354            magic_bytes[2],
1355            magic_bytes[3],
1356        ];
1357        let length_so_far = length_so_far + request0.len();
1358        assert_eq!(length_so_far % 4, 0);
1359        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1360        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1361        ([request0.into()], vec![])
1362    }
1363    /// Parse this request given its header, its body, and any fds that go along with it
1364    #[cfg(feature = "request-parsing")]
1365    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1366        if header.minor_opcode != AUTH_CONNECTION_REQUEST {
1367            return Err(ParseError::InvalidValue);
1368        }
1369        let (screen, remaining) = u32::try_parse(value)?;
1370        let (magic, remaining) = u32::try_parse(remaining)?;
1371        let _ = remaining;
1372        Ok(AuthConnectionRequest {
1373            screen,
1374            magic,
1375        })
1376    }
1377}
1378impl Request for AuthConnectionRequest {
1379    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1380
1381    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1382        let (bufs, fds) = self.serialize(major_opcode);
1383        // Flatten the buffers into a single vector
1384        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1385        (buf, fds)
1386    }
1387}
1388impl crate::x11_utils::ReplyRequest for AuthConnectionRequest {
1389    type Reply = AuthConnectionReply;
1390}
1391
1392#[derive(Clone, Copy, Default)]
1393#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1394#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1395pub struct AuthConnectionReply {
1396    pub sequence: u16,
1397    pub length: u32,
1398    pub authenticated: u32,
1399}
1400impl_debug_if_no_extra_traits!(AuthConnectionReply, "AuthConnectionReply");
1401impl TryParse for AuthConnectionReply {
1402    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1403        let remaining = initial_value;
1404        let (response_type, remaining) = u8::try_parse(remaining)?;
1405        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1406        let (sequence, remaining) = u16::try_parse(remaining)?;
1407        let (length, remaining) = u32::try_parse(remaining)?;
1408        let (authenticated, remaining) = u32::try_parse(remaining)?;
1409        if response_type != 1 {
1410            return Err(ParseError::InvalidValue);
1411        }
1412        let result = AuthConnectionReply { sequence, length, authenticated };
1413        let _ = remaining;
1414        let remaining = initial_value.get(32 + length as usize * 4..)
1415            .ok_or(ParseError::InsufficientData)?;
1416        Ok((result, remaining))
1417    }
1418}
1419impl Serialize for AuthConnectionReply {
1420    type Bytes = [u8; 12];
1421    fn serialize(&self) -> [u8; 12] {
1422        let response_type_bytes = &[1];
1423        let sequence_bytes = self.sequence.serialize();
1424        let length_bytes = self.length.serialize();
1425        let authenticated_bytes = self.authenticated.serialize();
1426        [
1427            response_type_bytes[0],
1428            0,
1429            sequence_bytes[0],
1430            sequence_bytes[1],
1431            length_bytes[0],
1432            length_bytes[1],
1433            length_bytes[2],
1434            length_bytes[3],
1435            authenticated_bytes[0],
1436            authenticated_bytes[1],
1437            authenticated_bytes[2],
1438            authenticated_bytes[3],
1439        ]
1440    }
1441    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1442        bytes.reserve(12);
1443        let response_type_bytes = &[1];
1444        bytes.push(response_type_bytes[0]);
1445        bytes.extend_from_slice(&[0; 1]);
1446        self.sequence.serialize_into(bytes);
1447        self.length.serialize_into(bytes);
1448        self.authenticated.serialize_into(bytes);
1449    }
1450}
1451