x11rb_protocol/protocol/
randr.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `RandR` 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#[allow(unused_imports)]
26use super::render;
27#[allow(unused_imports)]
28use super::xproto;
29
30/// The X11 name of the extension for QueryExtension
31pub const X11_EXTENSION_NAME: &str = "RANDR";
32
33/// The version number of this extension that this client library supports.
34///
35/// This constant contains the version number of this extension that is supported
36/// by this build of x11rb. For most things, it does not make sense to use this
37/// information. If you need to send a `QueryVersion`, it is recommended to instead
38/// send the maximum version of the extension that you need.
39pub const X11_XML_VERSION: (u32, u32) = (1, 6);
40
41pub type Mode = u32;
42
43pub type Crtc = u32;
44
45pub type Output = u32;
46
47pub type Provider = u32;
48
49pub type Lease = u32;
50
51/// Opcode for the BadOutput error
52pub const BAD_OUTPUT_ERROR: u8 = 0;
53
54/// Opcode for the BadCrtc error
55pub const BAD_CRTC_ERROR: u8 = 1;
56
57/// Opcode for the BadMode error
58pub const BAD_MODE_ERROR: u8 = 2;
59
60/// Opcode for the BadProvider error
61pub const BAD_PROVIDER_ERROR: u8 = 3;
62
63#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
64#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
65pub struct Rotation(u16);
66impl Rotation {
67    pub const ROTATE0: Self = Self(1 << 0);
68    pub const ROTATE90: Self = Self(1 << 1);
69    pub const ROTATE180: Self = Self(1 << 2);
70    pub const ROTATE270: Self = Self(1 << 3);
71    pub const REFLECT_X: Self = Self(1 << 4);
72    pub const REFLECT_Y: Self = Self(1 << 5);
73}
74impl From<Rotation> for u16 {
75    #[inline]
76    fn from(input: Rotation) -> Self {
77        input.0
78    }
79}
80impl From<Rotation> for Option<u16> {
81    #[inline]
82    fn from(input: Rotation) -> Self {
83        Some(input.0)
84    }
85}
86impl From<Rotation> for u32 {
87    #[inline]
88    fn from(input: Rotation) -> Self {
89        u32::from(input.0)
90    }
91}
92impl From<Rotation> for Option<u32> {
93    #[inline]
94    fn from(input: Rotation) -> Self {
95        Some(u32::from(input.0))
96    }
97}
98impl From<u8> for Rotation {
99    #[inline]
100    fn from(value: u8) -> Self {
101        Self(value.into())
102    }
103}
104impl From<u16> for Rotation {
105    #[inline]
106    fn from(value: u16) -> Self {
107        Self(value)
108    }
109}
110impl core::fmt::Debug for Rotation  {
111    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
112        let variants = [
113            (Self::ROTATE0.0.into(), "ROTATE0", "Rotate0"),
114            (Self::ROTATE90.0.into(), "ROTATE90", "Rotate90"),
115            (Self::ROTATE180.0.into(), "ROTATE180", "Rotate180"),
116            (Self::ROTATE270.0.into(), "ROTATE270", "Rotate270"),
117            (Self::REFLECT_X.0.into(), "REFLECT_X", "ReflectX"),
118            (Self::REFLECT_Y.0.into(), "REFLECT_Y", "ReflectY"),
119        ];
120        pretty_print_bitmask(fmt, self.0.into(), &variants)
121    }
122}
123bitmask_binop!(Rotation, u16);
124
125#[derive(Clone, Copy, Default)]
126#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
127#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
128pub struct ScreenSize {
129    pub width: u16,
130    pub height: u16,
131    pub mwidth: u16,
132    pub mheight: u16,
133}
134impl_debug_if_no_extra_traits!(ScreenSize, "ScreenSize");
135impl TryParse for ScreenSize {
136    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
137        let (width, remaining) = u16::try_parse(remaining)?;
138        let (height, remaining) = u16::try_parse(remaining)?;
139        let (mwidth, remaining) = u16::try_parse(remaining)?;
140        let (mheight, remaining) = u16::try_parse(remaining)?;
141        let result = ScreenSize { width, height, mwidth, mheight };
142        Ok((result, remaining))
143    }
144}
145impl Serialize for ScreenSize {
146    type Bytes = [u8; 8];
147    fn serialize(&self) -> [u8; 8] {
148        let width_bytes = self.width.serialize();
149        let height_bytes = self.height.serialize();
150        let mwidth_bytes = self.mwidth.serialize();
151        let mheight_bytes = self.mheight.serialize();
152        [
153            width_bytes[0],
154            width_bytes[1],
155            height_bytes[0],
156            height_bytes[1],
157            mwidth_bytes[0],
158            mwidth_bytes[1],
159            mheight_bytes[0],
160            mheight_bytes[1],
161        ]
162    }
163    fn serialize_into(&self, bytes: &mut Vec<u8>) {
164        bytes.reserve(8);
165        self.width.serialize_into(bytes);
166        self.height.serialize_into(bytes);
167        self.mwidth.serialize_into(bytes);
168        self.mheight.serialize_into(bytes);
169    }
170}
171
172#[derive(Clone, Default)]
173#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
174#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
175pub struct RefreshRates {
176    pub rates: Vec<u16>,
177}
178impl_debug_if_no_extra_traits!(RefreshRates, "RefreshRates");
179impl TryParse for RefreshRates {
180    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
181        let (n_rates, remaining) = u16::try_parse(remaining)?;
182        let (rates, remaining) = crate::x11_utils::parse_list::<u16>(remaining, n_rates.try_to_usize()?)?;
183        let result = RefreshRates { rates };
184        Ok((result, remaining))
185    }
186}
187impl Serialize for RefreshRates {
188    type Bytes = Vec<u8>;
189    fn serialize(&self) -> Vec<u8> {
190        let mut result = Vec::new();
191        self.serialize_into(&mut result);
192        result
193    }
194    fn serialize_into(&self, bytes: &mut Vec<u8>) {
195        let n_rates = u16::try_from(self.rates.len()).expect("`rates` has too many elements");
196        n_rates.serialize_into(bytes);
197        self.rates.serialize_into(bytes);
198    }
199}
200impl RefreshRates {
201    /// Get the value of the `nRates` field.
202    ///
203    /// The `nRates` field is used as the length field of the `rates` field.
204    /// This function computes the field's value again based on the length of the list.
205    ///
206    /// # Panics
207    ///
208    /// Panics if the value cannot be represented in the target type. This
209    /// cannot happen with values of the struct received from the X11 server.
210    pub fn n_rates(&self) -> u16 {
211        self.rates.len()
212            .try_into().unwrap()
213    }
214}
215
216/// Opcode for the QueryVersion request
217pub const QUERY_VERSION_REQUEST: u8 = 0;
218#[derive(Clone, Copy, Default)]
219#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
220#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
221pub struct QueryVersionRequest {
222    pub major_version: u32,
223    pub minor_version: u32,
224}
225impl_debug_if_no_extra_traits!(QueryVersionRequest, "QueryVersionRequest");
226impl QueryVersionRequest {
227    /// Serialize this request into bytes for the provided connection
228    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
229        let length_so_far = 0;
230        let major_version_bytes = self.major_version.serialize();
231        let minor_version_bytes = self.minor_version.serialize();
232        let mut request0 = vec![
233            major_opcode,
234            QUERY_VERSION_REQUEST,
235            0,
236            0,
237            major_version_bytes[0],
238            major_version_bytes[1],
239            major_version_bytes[2],
240            major_version_bytes[3],
241            minor_version_bytes[0],
242            minor_version_bytes[1],
243            minor_version_bytes[2],
244            minor_version_bytes[3],
245        ];
246        let length_so_far = length_so_far + request0.len();
247        assert_eq!(length_so_far % 4, 0);
248        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
249        request0[2..4].copy_from_slice(&length.to_ne_bytes());
250        ([request0.into()], vec![])
251    }
252    /// Parse this request given its header, its body, and any fds that go along with it
253    #[cfg(feature = "request-parsing")]
254    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
255        if header.minor_opcode != QUERY_VERSION_REQUEST {
256            return Err(ParseError::InvalidValue);
257        }
258        let (major_version, remaining) = u32::try_parse(value)?;
259        let (minor_version, remaining) = u32::try_parse(remaining)?;
260        let _ = remaining;
261        Ok(QueryVersionRequest {
262            major_version,
263            minor_version,
264        })
265    }
266}
267impl Request for QueryVersionRequest {
268    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
269
270    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
271        let (bufs, fds) = self.serialize(major_opcode);
272        // Flatten the buffers into a single vector
273        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
274        (buf, fds)
275    }
276}
277impl crate::x11_utils::ReplyRequest for QueryVersionRequest {
278    type Reply = QueryVersionReply;
279}
280
281#[derive(Clone, Copy, Default)]
282#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
283#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
284pub struct QueryVersionReply {
285    pub sequence: u16,
286    pub length: u32,
287    pub major_version: u32,
288    pub minor_version: u32,
289}
290impl_debug_if_no_extra_traits!(QueryVersionReply, "QueryVersionReply");
291impl TryParse for QueryVersionReply {
292    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
293        let remaining = initial_value;
294        let (response_type, remaining) = u8::try_parse(remaining)?;
295        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
296        let (sequence, remaining) = u16::try_parse(remaining)?;
297        let (length, remaining) = u32::try_parse(remaining)?;
298        let (major_version, remaining) = u32::try_parse(remaining)?;
299        let (minor_version, remaining) = u32::try_parse(remaining)?;
300        let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
301        if response_type != 1 {
302            return Err(ParseError::InvalidValue);
303        }
304        let result = QueryVersionReply { sequence, length, major_version, minor_version };
305        let _ = remaining;
306        let remaining = initial_value.get(32 + length as usize * 4..)
307            .ok_or(ParseError::InsufficientData)?;
308        Ok((result, remaining))
309    }
310}
311impl Serialize for QueryVersionReply {
312    type Bytes = [u8; 32];
313    fn serialize(&self) -> [u8; 32] {
314        let response_type_bytes = &[1];
315        let sequence_bytes = self.sequence.serialize();
316        let length_bytes = self.length.serialize();
317        let major_version_bytes = self.major_version.serialize();
318        let minor_version_bytes = self.minor_version.serialize();
319        [
320            response_type_bytes[0],
321            0,
322            sequence_bytes[0],
323            sequence_bytes[1],
324            length_bytes[0],
325            length_bytes[1],
326            length_bytes[2],
327            length_bytes[3],
328            major_version_bytes[0],
329            major_version_bytes[1],
330            major_version_bytes[2],
331            major_version_bytes[3],
332            minor_version_bytes[0],
333            minor_version_bytes[1],
334            minor_version_bytes[2],
335            minor_version_bytes[3],
336            0,
337            0,
338            0,
339            0,
340            0,
341            0,
342            0,
343            0,
344            0,
345            0,
346            0,
347            0,
348            0,
349            0,
350            0,
351            0,
352        ]
353    }
354    fn serialize_into(&self, bytes: &mut Vec<u8>) {
355        bytes.reserve(32);
356        let response_type_bytes = &[1];
357        bytes.push(response_type_bytes[0]);
358        bytes.extend_from_slice(&[0; 1]);
359        self.sequence.serialize_into(bytes);
360        self.length.serialize_into(bytes);
361        self.major_version.serialize_into(bytes);
362        self.minor_version.serialize_into(bytes);
363        bytes.extend_from_slice(&[0; 16]);
364    }
365}
366
367#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
368#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
369pub struct SetConfig(u8);
370impl SetConfig {
371    pub const SUCCESS: Self = Self(0);
372    pub const INVALID_CONFIG_TIME: Self = Self(1);
373    pub const INVALID_TIME: Self = Self(2);
374    pub const FAILED: Self = Self(3);
375}
376impl From<SetConfig> for u8 {
377    #[inline]
378    fn from(input: SetConfig) -> Self {
379        input.0
380    }
381}
382impl From<SetConfig> for Option<u8> {
383    #[inline]
384    fn from(input: SetConfig) -> Self {
385        Some(input.0)
386    }
387}
388impl From<SetConfig> for u16 {
389    #[inline]
390    fn from(input: SetConfig) -> Self {
391        u16::from(input.0)
392    }
393}
394impl From<SetConfig> for Option<u16> {
395    #[inline]
396    fn from(input: SetConfig) -> Self {
397        Some(u16::from(input.0))
398    }
399}
400impl From<SetConfig> for u32 {
401    #[inline]
402    fn from(input: SetConfig) -> Self {
403        u32::from(input.0)
404    }
405}
406impl From<SetConfig> for Option<u32> {
407    #[inline]
408    fn from(input: SetConfig) -> Self {
409        Some(u32::from(input.0))
410    }
411}
412impl From<u8> for SetConfig {
413    #[inline]
414    fn from(value: u8) -> Self {
415        Self(value)
416    }
417}
418impl core::fmt::Debug for SetConfig  {
419    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
420        let variants = [
421            (Self::SUCCESS.0.into(), "SUCCESS", "Success"),
422            (Self::INVALID_CONFIG_TIME.0.into(), "INVALID_CONFIG_TIME", "InvalidConfigTime"),
423            (Self::INVALID_TIME.0.into(), "INVALID_TIME", "InvalidTime"),
424            (Self::FAILED.0.into(), "FAILED", "Failed"),
425        ];
426        pretty_print_enum(fmt, self.0.into(), &variants)
427    }
428}
429
430/// Opcode for the SetScreenConfig request
431pub const SET_SCREEN_CONFIG_REQUEST: u8 = 2;
432#[derive(Clone, Copy, Default)]
433#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
434#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
435pub struct SetScreenConfigRequest {
436    pub window: xproto::Window,
437    pub timestamp: xproto::Timestamp,
438    pub config_timestamp: xproto::Timestamp,
439    pub size_id: u16,
440    pub rotation: Rotation,
441    pub rate: u16,
442}
443impl_debug_if_no_extra_traits!(SetScreenConfigRequest, "SetScreenConfigRequest");
444impl SetScreenConfigRequest {
445    /// Serialize this request into bytes for the provided connection
446    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
447        let length_so_far = 0;
448        let window_bytes = self.window.serialize();
449        let timestamp_bytes = self.timestamp.serialize();
450        let config_timestamp_bytes = self.config_timestamp.serialize();
451        let size_id_bytes = self.size_id.serialize();
452        let rotation_bytes = u16::from(self.rotation).serialize();
453        let rate_bytes = self.rate.serialize();
454        let mut request0 = vec![
455            major_opcode,
456            SET_SCREEN_CONFIG_REQUEST,
457            0,
458            0,
459            window_bytes[0],
460            window_bytes[1],
461            window_bytes[2],
462            window_bytes[3],
463            timestamp_bytes[0],
464            timestamp_bytes[1],
465            timestamp_bytes[2],
466            timestamp_bytes[3],
467            config_timestamp_bytes[0],
468            config_timestamp_bytes[1],
469            config_timestamp_bytes[2],
470            config_timestamp_bytes[3],
471            size_id_bytes[0],
472            size_id_bytes[1],
473            rotation_bytes[0],
474            rotation_bytes[1],
475            rate_bytes[0],
476            rate_bytes[1],
477            0,
478            0,
479        ];
480        let length_so_far = length_so_far + request0.len();
481        assert_eq!(length_so_far % 4, 0);
482        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
483        request0[2..4].copy_from_slice(&length.to_ne_bytes());
484        ([request0.into()], vec![])
485    }
486    /// Parse this request given its header, its body, and any fds that go along with it
487    #[cfg(feature = "request-parsing")]
488    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
489        if header.minor_opcode != SET_SCREEN_CONFIG_REQUEST {
490            return Err(ParseError::InvalidValue);
491        }
492        let (window, remaining) = xproto::Window::try_parse(value)?;
493        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
494        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
495        let (size_id, remaining) = u16::try_parse(remaining)?;
496        let (rotation, remaining) = u16::try_parse(remaining)?;
497        let rotation = rotation.into();
498        let (rate, remaining) = u16::try_parse(remaining)?;
499        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
500        let _ = remaining;
501        Ok(SetScreenConfigRequest {
502            window,
503            timestamp,
504            config_timestamp,
505            size_id,
506            rotation,
507            rate,
508        })
509    }
510}
511impl Request for SetScreenConfigRequest {
512    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
513
514    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
515        let (bufs, fds) = self.serialize(major_opcode);
516        // Flatten the buffers into a single vector
517        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
518        (buf, fds)
519    }
520}
521impl crate::x11_utils::ReplyRequest for SetScreenConfigRequest {
522    type Reply = SetScreenConfigReply;
523}
524
525#[derive(Clone, Copy, Default)]
526#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
527#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
528pub struct SetScreenConfigReply {
529    pub status: SetConfig,
530    pub sequence: u16,
531    pub length: u32,
532    pub new_timestamp: xproto::Timestamp,
533    pub config_timestamp: xproto::Timestamp,
534    pub root: xproto::Window,
535    pub subpixel_order: render::SubPixel,
536}
537impl_debug_if_no_extra_traits!(SetScreenConfigReply, "SetScreenConfigReply");
538impl TryParse for SetScreenConfigReply {
539    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
540        let remaining = initial_value;
541        let (response_type, remaining) = u8::try_parse(remaining)?;
542        let (status, remaining) = u8::try_parse(remaining)?;
543        let (sequence, remaining) = u16::try_parse(remaining)?;
544        let (length, remaining) = u32::try_parse(remaining)?;
545        let (new_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
546        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
547        let (root, remaining) = xproto::Window::try_parse(remaining)?;
548        let (subpixel_order, remaining) = u16::try_parse(remaining)?;
549        let remaining = remaining.get(10..).ok_or(ParseError::InsufficientData)?;
550        if response_type != 1 {
551            return Err(ParseError::InvalidValue);
552        }
553        let status = status.into();
554        let subpixel_order = subpixel_order.into();
555        let result = SetScreenConfigReply { status, sequence, length, new_timestamp, config_timestamp, root, subpixel_order };
556        let _ = remaining;
557        let remaining = initial_value.get(32 + length as usize * 4..)
558            .ok_or(ParseError::InsufficientData)?;
559        Ok((result, remaining))
560    }
561}
562impl Serialize for SetScreenConfigReply {
563    type Bytes = [u8; 32];
564    fn serialize(&self) -> [u8; 32] {
565        let response_type_bytes = &[1];
566        let status_bytes = u8::from(self.status).serialize();
567        let sequence_bytes = self.sequence.serialize();
568        let length_bytes = self.length.serialize();
569        let new_timestamp_bytes = self.new_timestamp.serialize();
570        let config_timestamp_bytes = self.config_timestamp.serialize();
571        let root_bytes = self.root.serialize();
572        let subpixel_order_bytes = (u32::from(self.subpixel_order) as u16).serialize();
573        [
574            response_type_bytes[0],
575            status_bytes[0],
576            sequence_bytes[0],
577            sequence_bytes[1],
578            length_bytes[0],
579            length_bytes[1],
580            length_bytes[2],
581            length_bytes[3],
582            new_timestamp_bytes[0],
583            new_timestamp_bytes[1],
584            new_timestamp_bytes[2],
585            new_timestamp_bytes[3],
586            config_timestamp_bytes[0],
587            config_timestamp_bytes[1],
588            config_timestamp_bytes[2],
589            config_timestamp_bytes[3],
590            root_bytes[0],
591            root_bytes[1],
592            root_bytes[2],
593            root_bytes[3],
594            subpixel_order_bytes[0],
595            subpixel_order_bytes[1],
596            0,
597            0,
598            0,
599            0,
600            0,
601            0,
602            0,
603            0,
604            0,
605            0,
606        ]
607    }
608    fn serialize_into(&self, bytes: &mut Vec<u8>) {
609        bytes.reserve(32);
610        let response_type_bytes = &[1];
611        bytes.push(response_type_bytes[0]);
612        u8::from(self.status).serialize_into(bytes);
613        self.sequence.serialize_into(bytes);
614        self.length.serialize_into(bytes);
615        self.new_timestamp.serialize_into(bytes);
616        self.config_timestamp.serialize_into(bytes);
617        self.root.serialize_into(bytes);
618        (u32::from(self.subpixel_order) as u16).serialize_into(bytes);
619        bytes.extend_from_slice(&[0; 10]);
620    }
621}
622
623#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
624#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
625pub struct NotifyMask(u16);
626impl NotifyMask {
627    pub const SCREEN_CHANGE: Self = Self(1 << 0);
628    pub const CRTC_CHANGE: Self = Self(1 << 1);
629    pub const OUTPUT_CHANGE: Self = Self(1 << 2);
630    pub const OUTPUT_PROPERTY: Self = Self(1 << 3);
631    pub const PROVIDER_CHANGE: Self = Self(1 << 4);
632    pub const PROVIDER_PROPERTY: Self = Self(1 << 5);
633    pub const RESOURCE_CHANGE: Self = Self(1 << 6);
634    pub const LEASE: Self = Self(1 << 7);
635}
636impl From<NotifyMask> for u16 {
637    #[inline]
638    fn from(input: NotifyMask) -> Self {
639        input.0
640    }
641}
642impl From<NotifyMask> for Option<u16> {
643    #[inline]
644    fn from(input: NotifyMask) -> Self {
645        Some(input.0)
646    }
647}
648impl From<NotifyMask> for u32 {
649    #[inline]
650    fn from(input: NotifyMask) -> Self {
651        u32::from(input.0)
652    }
653}
654impl From<NotifyMask> for Option<u32> {
655    #[inline]
656    fn from(input: NotifyMask) -> Self {
657        Some(u32::from(input.0))
658    }
659}
660impl From<u8> for NotifyMask {
661    #[inline]
662    fn from(value: u8) -> Self {
663        Self(value.into())
664    }
665}
666impl From<u16> for NotifyMask {
667    #[inline]
668    fn from(value: u16) -> Self {
669        Self(value)
670    }
671}
672impl core::fmt::Debug for NotifyMask  {
673    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
674        let variants = [
675            (Self::SCREEN_CHANGE.0.into(), "SCREEN_CHANGE", "ScreenChange"),
676            (Self::CRTC_CHANGE.0.into(), "CRTC_CHANGE", "CrtcChange"),
677            (Self::OUTPUT_CHANGE.0.into(), "OUTPUT_CHANGE", "OutputChange"),
678            (Self::OUTPUT_PROPERTY.0.into(), "OUTPUT_PROPERTY", "OutputProperty"),
679            (Self::PROVIDER_CHANGE.0.into(), "PROVIDER_CHANGE", "ProviderChange"),
680            (Self::PROVIDER_PROPERTY.0.into(), "PROVIDER_PROPERTY", "ProviderProperty"),
681            (Self::RESOURCE_CHANGE.0.into(), "RESOURCE_CHANGE", "ResourceChange"),
682            (Self::LEASE.0.into(), "LEASE", "Lease"),
683        ];
684        pretty_print_bitmask(fmt, self.0.into(), &variants)
685    }
686}
687bitmask_binop!(NotifyMask, u16);
688
689/// Opcode for the SelectInput request
690pub const SELECT_INPUT_REQUEST: u8 = 4;
691#[derive(Clone, Copy, Default)]
692#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
693#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
694pub struct SelectInputRequest {
695    pub window: xproto::Window,
696    pub enable: NotifyMask,
697}
698impl_debug_if_no_extra_traits!(SelectInputRequest, "SelectInputRequest");
699impl SelectInputRequest {
700    /// Serialize this request into bytes for the provided connection
701    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
702        let length_so_far = 0;
703        let window_bytes = self.window.serialize();
704        let enable_bytes = u16::from(self.enable).serialize();
705        let mut request0 = vec![
706            major_opcode,
707            SELECT_INPUT_REQUEST,
708            0,
709            0,
710            window_bytes[0],
711            window_bytes[1],
712            window_bytes[2],
713            window_bytes[3],
714            enable_bytes[0],
715            enable_bytes[1],
716            0,
717            0,
718        ];
719        let length_so_far = length_so_far + request0.len();
720        assert_eq!(length_so_far % 4, 0);
721        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
722        request0[2..4].copy_from_slice(&length.to_ne_bytes());
723        ([request0.into()], vec![])
724    }
725    /// Parse this request given its header, its body, and any fds that go along with it
726    #[cfg(feature = "request-parsing")]
727    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
728        if header.minor_opcode != SELECT_INPUT_REQUEST {
729            return Err(ParseError::InvalidValue);
730        }
731        let (window, remaining) = xproto::Window::try_parse(value)?;
732        let (enable, remaining) = u16::try_parse(remaining)?;
733        let enable = enable.into();
734        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
735        let _ = remaining;
736        Ok(SelectInputRequest {
737            window,
738            enable,
739        })
740    }
741}
742impl Request for SelectInputRequest {
743    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
744
745    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
746        let (bufs, fds) = self.serialize(major_opcode);
747        // Flatten the buffers into a single vector
748        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
749        (buf, fds)
750    }
751}
752impl crate::x11_utils::VoidRequest for SelectInputRequest {
753}
754
755/// Opcode for the GetScreenInfo request
756pub const GET_SCREEN_INFO_REQUEST: u8 = 5;
757#[derive(Clone, Copy, Default)]
758#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
759#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
760pub struct GetScreenInfoRequest {
761    pub window: xproto::Window,
762}
763impl_debug_if_no_extra_traits!(GetScreenInfoRequest, "GetScreenInfoRequest");
764impl GetScreenInfoRequest {
765    /// Serialize this request into bytes for the provided connection
766    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
767        let length_so_far = 0;
768        let window_bytes = self.window.serialize();
769        let mut request0 = vec![
770            major_opcode,
771            GET_SCREEN_INFO_REQUEST,
772            0,
773            0,
774            window_bytes[0],
775            window_bytes[1],
776            window_bytes[2],
777            window_bytes[3],
778        ];
779        let length_so_far = length_so_far + request0.len();
780        assert_eq!(length_so_far % 4, 0);
781        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
782        request0[2..4].copy_from_slice(&length.to_ne_bytes());
783        ([request0.into()], vec![])
784    }
785    /// Parse this request given its header, its body, and any fds that go along with it
786    #[cfg(feature = "request-parsing")]
787    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
788        if header.minor_opcode != GET_SCREEN_INFO_REQUEST {
789            return Err(ParseError::InvalidValue);
790        }
791        let (window, remaining) = xproto::Window::try_parse(value)?;
792        let _ = remaining;
793        Ok(GetScreenInfoRequest {
794            window,
795        })
796    }
797}
798impl Request for GetScreenInfoRequest {
799    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
800
801    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
802        let (bufs, fds) = self.serialize(major_opcode);
803        // Flatten the buffers into a single vector
804        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
805        (buf, fds)
806    }
807}
808impl crate::x11_utils::ReplyRequest for GetScreenInfoRequest {
809    type Reply = GetScreenInfoReply;
810}
811
812#[derive(Clone, Default)]
813#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
814#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
815pub struct GetScreenInfoReply {
816    pub rotations: Rotation,
817    pub sequence: u16,
818    pub length: u32,
819    pub root: xproto::Window,
820    pub timestamp: xproto::Timestamp,
821    pub config_timestamp: xproto::Timestamp,
822    pub size_id: u16,
823    pub rotation: Rotation,
824    pub rate: u16,
825    pub n_info: u16,
826    pub sizes: Vec<ScreenSize>,
827    pub rates: Vec<RefreshRates>,
828}
829impl_debug_if_no_extra_traits!(GetScreenInfoReply, "GetScreenInfoReply");
830impl TryParse for GetScreenInfoReply {
831    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
832        let remaining = initial_value;
833        let (response_type, remaining) = u8::try_parse(remaining)?;
834        let (rotations, remaining) = u8::try_parse(remaining)?;
835        let (sequence, remaining) = u16::try_parse(remaining)?;
836        let (length, remaining) = u32::try_parse(remaining)?;
837        let (root, remaining) = xproto::Window::try_parse(remaining)?;
838        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
839        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
840        let (n_sizes, remaining) = u16::try_parse(remaining)?;
841        let (size_id, remaining) = u16::try_parse(remaining)?;
842        let (rotation, remaining) = u16::try_parse(remaining)?;
843        let (rate, remaining) = u16::try_parse(remaining)?;
844        let (n_info, remaining) = u16::try_parse(remaining)?;
845        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
846        let (sizes, remaining) = crate::x11_utils::parse_list::<ScreenSize>(remaining, n_sizes.try_to_usize()?)?;
847        let (rates, remaining) = crate::x11_utils::parse_list::<RefreshRates>(remaining, u32::from(n_info).checked_sub(u32::from(n_sizes)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?;
848        if response_type != 1 {
849            return Err(ParseError::InvalidValue);
850        }
851        let rotations = rotations.into();
852        let rotation = rotation.into();
853        let result = GetScreenInfoReply { rotations, sequence, length, root, timestamp, config_timestamp, size_id, rotation, rate, n_info, sizes, rates };
854        let _ = remaining;
855        let remaining = initial_value.get(32 + length as usize * 4..)
856            .ok_or(ParseError::InsufficientData)?;
857        Ok((result, remaining))
858    }
859}
860impl Serialize for GetScreenInfoReply {
861    type Bytes = Vec<u8>;
862    fn serialize(&self) -> Vec<u8> {
863        let mut result = Vec::new();
864        self.serialize_into(&mut result);
865        result
866    }
867    fn serialize_into(&self, bytes: &mut Vec<u8>) {
868        bytes.reserve(32);
869        let response_type_bytes = &[1];
870        bytes.push(response_type_bytes[0]);
871        (u16::from(self.rotations) as u8).serialize_into(bytes);
872        self.sequence.serialize_into(bytes);
873        self.length.serialize_into(bytes);
874        self.root.serialize_into(bytes);
875        self.timestamp.serialize_into(bytes);
876        self.config_timestamp.serialize_into(bytes);
877        let n_sizes = u16::try_from(self.sizes.len()).expect("`sizes` has too many elements");
878        n_sizes.serialize_into(bytes);
879        self.size_id.serialize_into(bytes);
880        u16::from(self.rotation).serialize_into(bytes);
881        self.rate.serialize_into(bytes);
882        self.n_info.serialize_into(bytes);
883        bytes.extend_from_slice(&[0; 2]);
884        self.sizes.serialize_into(bytes);
885        assert_eq!(self.rates.len(), usize::try_from(u32::from(self.n_info).checked_sub(u32::from(n_sizes)).unwrap()).unwrap(), "`rates` has an incorrect length");
886        self.rates.serialize_into(bytes);
887    }
888}
889impl GetScreenInfoReply {
890    /// Get the value of the `nSizes` field.
891    ///
892    /// The `nSizes` field is used as the length field of the `sizes` field.
893    /// This function computes the field's value again based on the length of the list.
894    ///
895    /// # Panics
896    ///
897    /// Panics if the value cannot be represented in the target type. This
898    /// cannot happen with values of the struct received from the X11 server.
899    pub fn n_sizes(&self) -> u16 {
900        self.sizes.len()
901            .try_into().unwrap()
902    }
903}
904
905/// Opcode for the GetScreenSizeRange request
906pub const GET_SCREEN_SIZE_RANGE_REQUEST: u8 = 6;
907#[derive(Clone, Copy, Default)]
908#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
909#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
910pub struct GetScreenSizeRangeRequest {
911    pub window: xproto::Window,
912}
913impl_debug_if_no_extra_traits!(GetScreenSizeRangeRequest, "GetScreenSizeRangeRequest");
914impl GetScreenSizeRangeRequest {
915    /// Serialize this request into bytes for the provided connection
916    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
917        let length_so_far = 0;
918        let window_bytes = self.window.serialize();
919        let mut request0 = vec![
920            major_opcode,
921            GET_SCREEN_SIZE_RANGE_REQUEST,
922            0,
923            0,
924            window_bytes[0],
925            window_bytes[1],
926            window_bytes[2],
927            window_bytes[3],
928        ];
929        let length_so_far = length_so_far + request0.len();
930        assert_eq!(length_so_far % 4, 0);
931        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
932        request0[2..4].copy_from_slice(&length.to_ne_bytes());
933        ([request0.into()], vec![])
934    }
935    /// Parse this request given its header, its body, and any fds that go along with it
936    #[cfg(feature = "request-parsing")]
937    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
938        if header.minor_opcode != GET_SCREEN_SIZE_RANGE_REQUEST {
939            return Err(ParseError::InvalidValue);
940        }
941        let (window, remaining) = xproto::Window::try_parse(value)?;
942        let _ = remaining;
943        Ok(GetScreenSizeRangeRequest {
944            window,
945        })
946    }
947}
948impl Request for GetScreenSizeRangeRequest {
949    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
950
951    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
952        let (bufs, fds) = self.serialize(major_opcode);
953        // Flatten the buffers into a single vector
954        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
955        (buf, fds)
956    }
957}
958impl crate::x11_utils::ReplyRequest for GetScreenSizeRangeRequest {
959    type Reply = GetScreenSizeRangeReply;
960}
961
962#[derive(Clone, Copy, Default)]
963#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
964#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
965pub struct GetScreenSizeRangeReply {
966    pub sequence: u16,
967    pub length: u32,
968    pub min_width: u16,
969    pub min_height: u16,
970    pub max_width: u16,
971    pub max_height: u16,
972}
973impl_debug_if_no_extra_traits!(GetScreenSizeRangeReply, "GetScreenSizeRangeReply");
974impl TryParse for GetScreenSizeRangeReply {
975    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
976        let remaining = initial_value;
977        let (response_type, remaining) = u8::try_parse(remaining)?;
978        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
979        let (sequence, remaining) = u16::try_parse(remaining)?;
980        let (length, remaining) = u32::try_parse(remaining)?;
981        let (min_width, remaining) = u16::try_parse(remaining)?;
982        let (min_height, remaining) = u16::try_parse(remaining)?;
983        let (max_width, remaining) = u16::try_parse(remaining)?;
984        let (max_height, remaining) = u16::try_parse(remaining)?;
985        let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
986        if response_type != 1 {
987            return Err(ParseError::InvalidValue);
988        }
989        let result = GetScreenSizeRangeReply { sequence, length, min_width, min_height, max_width, max_height };
990        let _ = remaining;
991        let remaining = initial_value.get(32 + length as usize * 4..)
992            .ok_or(ParseError::InsufficientData)?;
993        Ok((result, remaining))
994    }
995}
996impl Serialize for GetScreenSizeRangeReply {
997    type Bytes = [u8; 32];
998    fn serialize(&self) -> [u8; 32] {
999        let response_type_bytes = &[1];
1000        let sequence_bytes = self.sequence.serialize();
1001        let length_bytes = self.length.serialize();
1002        let min_width_bytes = self.min_width.serialize();
1003        let min_height_bytes = self.min_height.serialize();
1004        let max_width_bytes = self.max_width.serialize();
1005        let max_height_bytes = self.max_height.serialize();
1006        [
1007            response_type_bytes[0],
1008            0,
1009            sequence_bytes[0],
1010            sequence_bytes[1],
1011            length_bytes[0],
1012            length_bytes[1],
1013            length_bytes[2],
1014            length_bytes[3],
1015            min_width_bytes[0],
1016            min_width_bytes[1],
1017            min_height_bytes[0],
1018            min_height_bytes[1],
1019            max_width_bytes[0],
1020            max_width_bytes[1],
1021            max_height_bytes[0],
1022            max_height_bytes[1],
1023            0,
1024            0,
1025            0,
1026            0,
1027            0,
1028            0,
1029            0,
1030            0,
1031            0,
1032            0,
1033            0,
1034            0,
1035            0,
1036            0,
1037            0,
1038            0,
1039        ]
1040    }
1041    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1042        bytes.reserve(32);
1043        let response_type_bytes = &[1];
1044        bytes.push(response_type_bytes[0]);
1045        bytes.extend_from_slice(&[0; 1]);
1046        self.sequence.serialize_into(bytes);
1047        self.length.serialize_into(bytes);
1048        self.min_width.serialize_into(bytes);
1049        self.min_height.serialize_into(bytes);
1050        self.max_width.serialize_into(bytes);
1051        self.max_height.serialize_into(bytes);
1052        bytes.extend_from_slice(&[0; 16]);
1053    }
1054}
1055
1056/// Opcode for the SetScreenSize request
1057pub const SET_SCREEN_SIZE_REQUEST: u8 = 7;
1058#[derive(Clone, Copy, Default)]
1059#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1060#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1061pub struct SetScreenSizeRequest {
1062    pub window: xproto::Window,
1063    pub width: u16,
1064    pub height: u16,
1065    pub mm_width: u32,
1066    pub mm_height: u32,
1067}
1068impl_debug_if_no_extra_traits!(SetScreenSizeRequest, "SetScreenSizeRequest");
1069impl SetScreenSizeRequest {
1070    /// Serialize this request into bytes for the provided connection
1071    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1072        let length_so_far = 0;
1073        let window_bytes = self.window.serialize();
1074        let width_bytes = self.width.serialize();
1075        let height_bytes = self.height.serialize();
1076        let mm_width_bytes = self.mm_width.serialize();
1077        let mm_height_bytes = self.mm_height.serialize();
1078        let mut request0 = vec![
1079            major_opcode,
1080            SET_SCREEN_SIZE_REQUEST,
1081            0,
1082            0,
1083            window_bytes[0],
1084            window_bytes[1],
1085            window_bytes[2],
1086            window_bytes[3],
1087            width_bytes[0],
1088            width_bytes[1],
1089            height_bytes[0],
1090            height_bytes[1],
1091            mm_width_bytes[0],
1092            mm_width_bytes[1],
1093            mm_width_bytes[2],
1094            mm_width_bytes[3],
1095            mm_height_bytes[0],
1096            mm_height_bytes[1],
1097            mm_height_bytes[2],
1098            mm_height_bytes[3],
1099        ];
1100        let length_so_far = length_so_far + request0.len();
1101        assert_eq!(length_so_far % 4, 0);
1102        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1103        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1104        ([request0.into()], vec![])
1105    }
1106    /// Parse this request given its header, its body, and any fds that go along with it
1107    #[cfg(feature = "request-parsing")]
1108    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1109        if header.minor_opcode != SET_SCREEN_SIZE_REQUEST {
1110            return Err(ParseError::InvalidValue);
1111        }
1112        let (window, remaining) = xproto::Window::try_parse(value)?;
1113        let (width, remaining) = u16::try_parse(remaining)?;
1114        let (height, remaining) = u16::try_parse(remaining)?;
1115        let (mm_width, remaining) = u32::try_parse(remaining)?;
1116        let (mm_height, remaining) = u32::try_parse(remaining)?;
1117        let _ = remaining;
1118        Ok(SetScreenSizeRequest {
1119            window,
1120            width,
1121            height,
1122            mm_width,
1123            mm_height,
1124        })
1125    }
1126}
1127impl Request for SetScreenSizeRequest {
1128    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1129
1130    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1131        let (bufs, fds) = self.serialize(major_opcode);
1132        // Flatten the buffers into a single vector
1133        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1134        (buf, fds)
1135    }
1136}
1137impl crate::x11_utils::VoidRequest for SetScreenSizeRequest {
1138}
1139
1140#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
1141#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1142pub struct ModeFlag(u32);
1143impl ModeFlag {
1144    pub const HSYNC_POSITIVE: Self = Self(1 << 0);
1145    pub const HSYNC_NEGATIVE: Self = Self(1 << 1);
1146    pub const VSYNC_POSITIVE: Self = Self(1 << 2);
1147    pub const VSYNC_NEGATIVE: Self = Self(1 << 3);
1148    pub const INTERLACE: Self = Self(1 << 4);
1149    pub const DOUBLE_SCAN: Self = Self(1 << 5);
1150    pub const CSYNC: Self = Self(1 << 6);
1151    pub const CSYNC_POSITIVE: Self = Self(1 << 7);
1152    pub const CSYNC_NEGATIVE: Self = Self(1 << 8);
1153    pub const HSKEW_PRESENT: Self = Self(1 << 9);
1154    pub const BCAST: Self = Self(1 << 10);
1155    pub const PIXEL_MULTIPLEX: Self = Self(1 << 11);
1156    pub const DOUBLE_CLOCK: Self = Self(1 << 12);
1157    pub const HALVE_CLOCK: Self = Self(1 << 13);
1158}
1159impl From<ModeFlag> for u32 {
1160    #[inline]
1161    fn from(input: ModeFlag) -> Self {
1162        input.0
1163    }
1164}
1165impl From<ModeFlag> for Option<u32> {
1166    #[inline]
1167    fn from(input: ModeFlag) -> Self {
1168        Some(input.0)
1169    }
1170}
1171impl From<u8> for ModeFlag {
1172    #[inline]
1173    fn from(value: u8) -> Self {
1174        Self(value.into())
1175    }
1176}
1177impl From<u16> for ModeFlag {
1178    #[inline]
1179    fn from(value: u16) -> Self {
1180        Self(value.into())
1181    }
1182}
1183impl From<u32> for ModeFlag {
1184    #[inline]
1185    fn from(value: u32) -> Self {
1186        Self(value)
1187    }
1188}
1189impl core::fmt::Debug for ModeFlag  {
1190    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1191        let variants = [
1192            (Self::HSYNC_POSITIVE.0, "HSYNC_POSITIVE", "HsyncPositive"),
1193            (Self::HSYNC_NEGATIVE.0, "HSYNC_NEGATIVE", "HsyncNegative"),
1194            (Self::VSYNC_POSITIVE.0, "VSYNC_POSITIVE", "VsyncPositive"),
1195            (Self::VSYNC_NEGATIVE.0, "VSYNC_NEGATIVE", "VsyncNegative"),
1196            (Self::INTERLACE.0, "INTERLACE", "Interlace"),
1197            (Self::DOUBLE_SCAN.0, "DOUBLE_SCAN", "DoubleScan"),
1198            (Self::CSYNC.0, "CSYNC", "Csync"),
1199            (Self::CSYNC_POSITIVE.0, "CSYNC_POSITIVE", "CsyncPositive"),
1200            (Self::CSYNC_NEGATIVE.0, "CSYNC_NEGATIVE", "CsyncNegative"),
1201            (Self::HSKEW_PRESENT.0, "HSKEW_PRESENT", "HskewPresent"),
1202            (Self::BCAST.0, "BCAST", "Bcast"),
1203            (Self::PIXEL_MULTIPLEX.0, "PIXEL_MULTIPLEX", "PixelMultiplex"),
1204            (Self::DOUBLE_CLOCK.0, "DOUBLE_CLOCK", "DoubleClock"),
1205            (Self::HALVE_CLOCK.0, "HALVE_CLOCK", "HalveClock"),
1206        ];
1207        pretty_print_bitmask(fmt, self.0, &variants)
1208    }
1209}
1210bitmask_binop!(ModeFlag, u32);
1211
1212#[derive(Clone, Copy, Default)]
1213#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1214#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1215pub struct ModeInfo {
1216    pub id: u32,
1217    pub width: u16,
1218    pub height: u16,
1219    pub dot_clock: u32,
1220    pub hsync_start: u16,
1221    pub hsync_end: u16,
1222    pub htotal: u16,
1223    pub hskew: u16,
1224    pub vsync_start: u16,
1225    pub vsync_end: u16,
1226    pub vtotal: u16,
1227    pub name_len: u16,
1228    pub mode_flags: ModeFlag,
1229}
1230impl_debug_if_no_extra_traits!(ModeInfo, "ModeInfo");
1231impl TryParse for ModeInfo {
1232    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1233        let (id, remaining) = u32::try_parse(remaining)?;
1234        let (width, remaining) = u16::try_parse(remaining)?;
1235        let (height, remaining) = u16::try_parse(remaining)?;
1236        let (dot_clock, remaining) = u32::try_parse(remaining)?;
1237        let (hsync_start, remaining) = u16::try_parse(remaining)?;
1238        let (hsync_end, remaining) = u16::try_parse(remaining)?;
1239        let (htotal, remaining) = u16::try_parse(remaining)?;
1240        let (hskew, remaining) = u16::try_parse(remaining)?;
1241        let (vsync_start, remaining) = u16::try_parse(remaining)?;
1242        let (vsync_end, remaining) = u16::try_parse(remaining)?;
1243        let (vtotal, remaining) = u16::try_parse(remaining)?;
1244        let (name_len, remaining) = u16::try_parse(remaining)?;
1245        let (mode_flags, remaining) = u32::try_parse(remaining)?;
1246        let mode_flags = mode_flags.into();
1247        let result = ModeInfo { id, width, height, dot_clock, hsync_start, hsync_end, htotal, hskew, vsync_start, vsync_end, vtotal, name_len, mode_flags };
1248        Ok((result, remaining))
1249    }
1250}
1251impl Serialize for ModeInfo {
1252    type Bytes = [u8; 32];
1253    fn serialize(&self) -> [u8; 32] {
1254        let id_bytes = self.id.serialize();
1255        let width_bytes = self.width.serialize();
1256        let height_bytes = self.height.serialize();
1257        let dot_clock_bytes = self.dot_clock.serialize();
1258        let hsync_start_bytes = self.hsync_start.serialize();
1259        let hsync_end_bytes = self.hsync_end.serialize();
1260        let htotal_bytes = self.htotal.serialize();
1261        let hskew_bytes = self.hskew.serialize();
1262        let vsync_start_bytes = self.vsync_start.serialize();
1263        let vsync_end_bytes = self.vsync_end.serialize();
1264        let vtotal_bytes = self.vtotal.serialize();
1265        let name_len_bytes = self.name_len.serialize();
1266        let mode_flags_bytes = u32::from(self.mode_flags).serialize();
1267        [
1268            id_bytes[0],
1269            id_bytes[1],
1270            id_bytes[2],
1271            id_bytes[3],
1272            width_bytes[0],
1273            width_bytes[1],
1274            height_bytes[0],
1275            height_bytes[1],
1276            dot_clock_bytes[0],
1277            dot_clock_bytes[1],
1278            dot_clock_bytes[2],
1279            dot_clock_bytes[3],
1280            hsync_start_bytes[0],
1281            hsync_start_bytes[1],
1282            hsync_end_bytes[0],
1283            hsync_end_bytes[1],
1284            htotal_bytes[0],
1285            htotal_bytes[1],
1286            hskew_bytes[0],
1287            hskew_bytes[1],
1288            vsync_start_bytes[0],
1289            vsync_start_bytes[1],
1290            vsync_end_bytes[0],
1291            vsync_end_bytes[1],
1292            vtotal_bytes[0],
1293            vtotal_bytes[1],
1294            name_len_bytes[0],
1295            name_len_bytes[1],
1296            mode_flags_bytes[0],
1297            mode_flags_bytes[1],
1298            mode_flags_bytes[2],
1299            mode_flags_bytes[3],
1300        ]
1301    }
1302    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1303        bytes.reserve(32);
1304        self.id.serialize_into(bytes);
1305        self.width.serialize_into(bytes);
1306        self.height.serialize_into(bytes);
1307        self.dot_clock.serialize_into(bytes);
1308        self.hsync_start.serialize_into(bytes);
1309        self.hsync_end.serialize_into(bytes);
1310        self.htotal.serialize_into(bytes);
1311        self.hskew.serialize_into(bytes);
1312        self.vsync_start.serialize_into(bytes);
1313        self.vsync_end.serialize_into(bytes);
1314        self.vtotal.serialize_into(bytes);
1315        self.name_len.serialize_into(bytes);
1316        u32::from(self.mode_flags).serialize_into(bytes);
1317    }
1318}
1319
1320/// Opcode for the GetScreenResources request
1321pub const GET_SCREEN_RESOURCES_REQUEST: u8 = 8;
1322#[derive(Clone, Copy, Default)]
1323#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1324#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1325pub struct GetScreenResourcesRequest {
1326    pub window: xproto::Window,
1327}
1328impl_debug_if_no_extra_traits!(GetScreenResourcesRequest, "GetScreenResourcesRequest");
1329impl GetScreenResourcesRequest {
1330    /// Serialize this request into bytes for the provided connection
1331    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1332        let length_so_far = 0;
1333        let window_bytes = self.window.serialize();
1334        let mut request0 = vec![
1335            major_opcode,
1336            GET_SCREEN_RESOURCES_REQUEST,
1337            0,
1338            0,
1339            window_bytes[0],
1340            window_bytes[1],
1341            window_bytes[2],
1342            window_bytes[3],
1343        ];
1344        let length_so_far = length_so_far + request0.len();
1345        assert_eq!(length_so_far % 4, 0);
1346        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1347        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1348        ([request0.into()], vec![])
1349    }
1350    /// Parse this request given its header, its body, and any fds that go along with it
1351    #[cfg(feature = "request-parsing")]
1352    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1353        if header.minor_opcode != GET_SCREEN_RESOURCES_REQUEST {
1354            return Err(ParseError::InvalidValue);
1355        }
1356        let (window, remaining) = xproto::Window::try_parse(value)?;
1357        let _ = remaining;
1358        Ok(GetScreenResourcesRequest {
1359            window,
1360        })
1361    }
1362}
1363impl Request for GetScreenResourcesRequest {
1364    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1365
1366    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1367        let (bufs, fds) = self.serialize(major_opcode);
1368        // Flatten the buffers into a single vector
1369        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1370        (buf, fds)
1371    }
1372}
1373impl crate::x11_utils::ReplyRequest for GetScreenResourcesRequest {
1374    type Reply = GetScreenResourcesReply;
1375}
1376
1377#[derive(Clone, Default)]
1378#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1379#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1380pub struct GetScreenResourcesReply {
1381    pub sequence: u16,
1382    pub length: u32,
1383    pub timestamp: xproto::Timestamp,
1384    pub config_timestamp: xproto::Timestamp,
1385    pub crtcs: Vec<Crtc>,
1386    pub outputs: Vec<Output>,
1387    pub modes: Vec<ModeInfo>,
1388    pub names: Vec<u8>,
1389}
1390impl_debug_if_no_extra_traits!(GetScreenResourcesReply, "GetScreenResourcesReply");
1391impl TryParse for GetScreenResourcesReply {
1392    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1393        let remaining = initial_value;
1394        let (response_type, remaining) = u8::try_parse(remaining)?;
1395        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1396        let (sequence, remaining) = u16::try_parse(remaining)?;
1397        let (length, remaining) = u32::try_parse(remaining)?;
1398        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
1399        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
1400        let (num_crtcs, remaining) = u16::try_parse(remaining)?;
1401        let (num_outputs, remaining) = u16::try_parse(remaining)?;
1402        let (num_modes, remaining) = u16::try_parse(remaining)?;
1403        let (names_len, remaining) = u16::try_parse(remaining)?;
1404        let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?;
1405        let (crtcs, remaining) = crate::x11_utils::parse_list::<Crtc>(remaining, num_crtcs.try_to_usize()?)?;
1406        let (outputs, remaining) = crate::x11_utils::parse_list::<Output>(remaining, num_outputs.try_to_usize()?)?;
1407        let (modes, remaining) = crate::x11_utils::parse_list::<ModeInfo>(remaining, num_modes.try_to_usize()?)?;
1408        let (names, remaining) = crate::x11_utils::parse_u8_list(remaining, names_len.try_to_usize()?)?;
1409        let names = names.to_vec();
1410        if response_type != 1 {
1411            return Err(ParseError::InvalidValue);
1412        }
1413        let result = GetScreenResourcesReply { sequence, length, timestamp, config_timestamp, crtcs, outputs, modes, names };
1414        let _ = remaining;
1415        let remaining = initial_value.get(32 + length as usize * 4..)
1416            .ok_or(ParseError::InsufficientData)?;
1417        Ok((result, remaining))
1418    }
1419}
1420impl Serialize for GetScreenResourcesReply {
1421    type Bytes = Vec<u8>;
1422    fn serialize(&self) -> Vec<u8> {
1423        let mut result = Vec::new();
1424        self.serialize_into(&mut result);
1425        result
1426    }
1427    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1428        bytes.reserve(32);
1429        let response_type_bytes = &[1];
1430        bytes.push(response_type_bytes[0]);
1431        bytes.extend_from_slice(&[0; 1]);
1432        self.sequence.serialize_into(bytes);
1433        self.length.serialize_into(bytes);
1434        self.timestamp.serialize_into(bytes);
1435        self.config_timestamp.serialize_into(bytes);
1436        let num_crtcs = u16::try_from(self.crtcs.len()).expect("`crtcs` has too many elements");
1437        num_crtcs.serialize_into(bytes);
1438        let num_outputs = u16::try_from(self.outputs.len()).expect("`outputs` has too many elements");
1439        num_outputs.serialize_into(bytes);
1440        let num_modes = u16::try_from(self.modes.len()).expect("`modes` has too many elements");
1441        num_modes.serialize_into(bytes);
1442        let names_len = u16::try_from(self.names.len()).expect("`names` has too many elements");
1443        names_len.serialize_into(bytes);
1444        bytes.extend_from_slice(&[0; 8]);
1445        self.crtcs.serialize_into(bytes);
1446        self.outputs.serialize_into(bytes);
1447        self.modes.serialize_into(bytes);
1448        bytes.extend_from_slice(&self.names);
1449    }
1450}
1451impl GetScreenResourcesReply {
1452    /// Get the value of the `num_crtcs` field.
1453    ///
1454    /// The `num_crtcs` field is used as the length field of the `crtcs` field.
1455    /// This function computes the field's value again based on the length of the list.
1456    ///
1457    /// # Panics
1458    ///
1459    /// Panics if the value cannot be represented in the target type. This
1460    /// cannot happen with values of the struct received from the X11 server.
1461    pub fn num_crtcs(&self) -> u16 {
1462        self.crtcs.len()
1463            .try_into().unwrap()
1464    }
1465    /// Get the value of the `num_outputs` field.
1466    ///
1467    /// The `num_outputs` field is used as the length field of the `outputs` field.
1468    /// This function computes the field's value again based on the length of the list.
1469    ///
1470    /// # Panics
1471    ///
1472    /// Panics if the value cannot be represented in the target type. This
1473    /// cannot happen with values of the struct received from the X11 server.
1474    pub fn num_outputs(&self) -> u16 {
1475        self.outputs.len()
1476            .try_into().unwrap()
1477    }
1478    /// Get the value of the `num_modes` field.
1479    ///
1480    /// The `num_modes` field is used as the length field of the `modes` field.
1481    /// This function computes the field's value again based on the length of the list.
1482    ///
1483    /// # Panics
1484    ///
1485    /// Panics if the value cannot be represented in the target type. This
1486    /// cannot happen with values of the struct received from the X11 server.
1487    pub fn num_modes(&self) -> u16 {
1488        self.modes.len()
1489            .try_into().unwrap()
1490    }
1491    /// Get the value of the `names_len` field.
1492    ///
1493    /// The `names_len` field is used as the length field of the `names` field.
1494    /// This function computes the field's value again based on the length of the list.
1495    ///
1496    /// # Panics
1497    ///
1498    /// Panics if the value cannot be represented in the target type. This
1499    /// cannot happen with values of the struct received from the X11 server.
1500    pub fn names_len(&self) -> u16 {
1501        self.names.len()
1502            .try_into().unwrap()
1503    }
1504}
1505
1506#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
1507#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1508pub struct Connection(u8);
1509impl Connection {
1510    pub const CONNECTED: Self = Self(0);
1511    pub const DISCONNECTED: Self = Self(1);
1512    pub const UNKNOWN: Self = Self(2);
1513}
1514impl From<Connection> for u8 {
1515    #[inline]
1516    fn from(input: Connection) -> Self {
1517        input.0
1518    }
1519}
1520impl From<Connection> for Option<u8> {
1521    #[inline]
1522    fn from(input: Connection) -> Self {
1523        Some(input.0)
1524    }
1525}
1526impl From<Connection> for u16 {
1527    #[inline]
1528    fn from(input: Connection) -> Self {
1529        u16::from(input.0)
1530    }
1531}
1532impl From<Connection> for Option<u16> {
1533    #[inline]
1534    fn from(input: Connection) -> Self {
1535        Some(u16::from(input.0))
1536    }
1537}
1538impl From<Connection> for u32 {
1539    #[inline]
1540    fn from(input: Connection) -> Self {
1541        u32::from(input.0)
1542    }
1543}
1544impl From<Connection> for Option<u32> {
1545    #[inline]
1546    fn from(input: Connection) -> Self {
1547        Some(u32::from(input.0))
1548    }
1549}
1550impl From<u8> for Connection {
1551    #[inline]
1552    fn from(value: u8) -> Self {
1553        Self(value)
1554    }
1555}
1556impl core::fmt::Debug for Connection  {
1557    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1558        let variants = [
1559            (Self::CONNECTED.0.into(), "CONNECTED", "Connected"),
1560            (Self::DISCONNECTED.0.into(), "DISCONNECTED", "Disconnected"),
1561            (Self::UNKNOWN.0.into(), "UNKNOWN", "Unknown"),
1562        ];
1563        pretty_print_enum(fmt, self.0.into(), &variants)
1564    }
1565}
1566
1567/// Opcode for the GetOutputInfo request
1568pub const GET_OUTPUT_INFO_REQUEST: u8 = 9;
1569#[derive(Clone, Copy, Default)]
1570#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1571#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1572pub struct GetOutputInfoRequest {
1573    pub output: Output,
1574    pub config_timestamp: xproto::Timestamp,
1575}
1576impl_debug_if_no_extra_traits!(GetOutputInfoRequest, "GetOutputInfoRequest");
1577impl GetOutputInfoRequest {
1578    /// Serialize this request into bytes for the provided connection
1579    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1580        let length_so_far = 0;
1581        let output_bytes = self.output.serialize();
1582        let config_timestamp_bytes = self.config_timestamp.serialize();
1583        let mut request0 = vec![
1584            major_opcode,
1585            GET_OUTPUT_INFO_REQUEST,
1586            0,
1587            0,
1588            output_bytes[0],
1589            output_bytes[1],
1590            output_bytes[2],
1591            output_bytes[3],
1592            config_timestamp_bytes[0],
1593            config_timestamp_bytes[1],
1594            config_timestamp_bytes[2],
1595            config_timestamp_bytes[3],
1596        ];
1597        let length_so_far = length_so_far + request0.len();
1598        assert_eq!(length_so_far % 4, 0);
1599        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1600        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1601        ([request0.into()], vec![])
1602    }
1603    /// Parse this request given its header, its body, and any fds that go along with it
1604    #[cfg(feature = "request-parsing")]
1605    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1606        if header.minor_opcode != GET_OUTPUT_INFO_REQUEST {
1607            return Err(ParseError::InvalidValue);
1608        }
1609        let (output, remaining) = Output::try_parse(value)?;
1610        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
1611        let _ = remaining;
1612        Ok(GetOutputInfoRequest {
1613            output,
1614            config_timestamp,
1615        })
1616    }
1617}
1618impl Request for GetOutputInfoRequest {
1619    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1620
1621    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1622        let (bufs, fds) = self.serialize(major_opcode);
1623        // Flatten the buffers into a single vector
1624        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1625        (buf, fds)
1626    }
1627}
1628impl crate::x11_utils::ReplyRequest for GetOutputInfoRequest {
1629    type Reply = GetOutputInfoReply;
1630}
1631
1632#[derive(Clone, Default)]
1633#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1634#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1635pub struct GetOutputInfoReply {
1636    pub status: SetConfig,
1637    pub sequence: u16,
1638    pub length: u32,
1639    pub timestamp: xproto::Timestamp,
1640    pub crtc: Crtc,
1641    pub mm_width: u32,
1642    pub mm_height: u32,
1643    pub connection: Connection,
1644    pub subpixel_order: render::SubPixel,
1645    pub num_preferred: u16,
1646    pub crtcs: Vec<Crtc>,
1647    pub modes: Vec<Mode>,
1648    pub clones: Vec<Output>,
1649    pub name: Vec<u8>,
1650}
1651impl_debug_if_no_extra_traits!(GetOutputInfoReply, "GetOutputInfoReply");
1652impl TryParse for GetOutputInfoReply {
1653    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1654        let remaining = initial_value;
1655        let (response_type, remaining) = u8::try_parse(remaining)?;
1656        let (status, remaining) = u8::try_parse(remaining)?;
1657        let (sequence, remaining) = u16::try_parse(remaining)?;
1658        let (length, remaining) = u32::try_parse(remaining)?;
1659        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
1660        let (crtc, remaining) = Crtc::try_parse(remaining)?;
1661        let (mm_width, remaining) = u32::try_parse(remaining)?;
1662        let (mm_height, remaining) = u32::try_parse(remaining)?;
1663        let (connection, remaining) = u8::try_parse(remaining)?;
1664        let (subpixel_order, remaining) = u8::try_parse(remaining)?;
1665        let (num_crtcs, remaining) = u16::try_parse(remaining)?;
1666        let (num_modes, remaining) = u16::try_parse(remaining)?;
1667        let (num_preferred, remaining) = u16::try_parse(remaining)?;
1668        let (num_clones, remaining) = u16::try_parse(remaining)?;
1669        let (name_len, remaining) = u16::try_parse(remaining)?;
1670        let (crtcs, remaining) = crate::x11_utils::parse_list::<Crtc>(remaining, num_crtcs.try_to_usize()?)?;
1671        let (modes, remaining) = crate::x11_utils::parse_list::<Mode>(remaining, num_modes.try_to_usize()?)?;
1672        let (clones, remaining) = crate::x11_utils::parse_list::<Output>(remaining, num_clones.try_to_usize()?)?;
1673        let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?;
1674        let name = name.to_vec();
1675        if response_type != 1 {
1676            return Err(ParseError::InvalidValue);
1677        }
1678        let status = status.into();
1679        let connection = connection.into();
1680        let subpixel_order = subpixel_order.into();
1681        let result = GetOutputInfoReply { status, sequence, length, timestamp, crtc, mm_width, mm_height, connection, subpixel_order, num_preferred, crtcs, modes, clones, name };
1682        let _ = remaining;
1683        let remaining = initial_value.get(32 + length as usize * 4..)
1684            .ok_or(ParseError::InsufficientData)?;
1685        Ok((result, remaining))
1686    }
1687}
1688impl Serialize for GetOutputInfoReply {
1689    type Bytes = Vec<u8>;
1690    fn serialize(&self) -> Vec<u8> {
1691        let mut result = Vec::new();
1692        self.serialize_into(&mut result);
1693        result
1694    }
1695    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1696        bytes.reserve(36);
1697        let response_type_bytes = &[1];
1698        bytes.push(response_type_bytes[0]);
1699        u8::from(self.status).serialize_into(bytes);
1700        self.sequence.serialize_into(bytes);
1701        self.length.serialize_into(bytes);
1702        self.timestamp.serialize_into(bytes);
1703        self.crtc.serialize_into(bytes);
1704        self.mm_width.serialize_into(bytes);
1705        self.mm_height.serialize_into(bytes);
1706        u8::from(self.connection).serialize_into(bytes);
1707        (u32::from(self.subpixel_order) as u8).serialize_into(bytes);
1708        let num_crtcs = u16::try_from(self.crtcs.len()).expect("`crtcs` has too many elements");
1709        num_crtcs.serialize_into(bytes);
1710        let num_modes = u16::try_from(self.modes.len()).expect("`modes` has too many elements");
1711        num_modes.serialize_into(bytes);
1712        self.num_preferred.serialize_into(bytes);
1713        let num_clones = u16::try_from(self.clones.len()).expect("`clones` has too many elements");
1714        num_clones.serialize_into(bytes);
1715        let name_len = u16::try_from(self.name.len()).expect("`name` has too many elements");
1716        name_len.serialize_into(bytes);
1717        self.crtcs.serialize_into(bytes);
1718        self.modes.serialize_into(bytes);
1719        self.clones.serialize_into(bytes);
1720        bytes.extend_from_slice(&self.name);
1721    }
1722}
1723impl GetOutputInfoReply {
1724    /// Get the value of the `num_crtcs` field.
1725    ///
1726    /// The `num_crtcs` field is used as the length field of the `crtcs` field.
1727    /// This function computes the field's value again based on the length of the list.
1728    ///
1729    /// # Panics
1730    ///
1731    /// Panics if the value cannot be represented in the target type. This
1732    /// cannot happen with values of the struct received from the X11 server.
1733    pub fn num_crtcs(&self) -> u16 {
1734        self.crtcs.len()
1735            .try_into().unwrap()
1736    }
1737    /// Get the value of the `num_modes` field.
1738    ///
1739    /// The `num_modes` field is used as the length field of the `modes` field.
1740    /// This function computes the field's value again based on the length of the list.
1741    ///
1742    /// # Panics
1743    ///
1744    /// Panics if the value cannot be represented in the target type. This
1745    /// cannot happen with values of the struct received from the X11 server.
1746    pub fn num_modes(&self) -> u16 {
1747        self.modes.len()
1748            .try_into().unwrap()
1749    }
1750    /// Get the value of the `num_clones` field.
1751    ///
1752    /// The `num_clones` field is used as the length field of the `clones` field.
1753    /// This function computes the field's value again based on the length of the list.
1754    ///
1755    /// # Panics
1756    ///
1757    /// Panics if the value cannot be represented in the target type. This
1758    /// cannot happen with values of the struct received from the X11 server.
1759    pub fn num_clones(&self) -> u16 {
1760        self.clones.len()
1761            .try_into().unwrap()
1762    }
1763    /// Get the value of the `name_len` field.
1764    ///
1765    /// The `name_len` field is used as the length field of the `name` field.
1766    /// This function computes the field's value again based on the length of the list.
1767    ///
1768    /// # Panics
1769    ///
1770    /// Panics if the value cannot be represented in the target type. This
1771    /// cannot happen with values of the struct received from the X11 server.
1772    pub fn name_len(&self) -> u16 {
1773        self.name.len()
1774            .try_into().unwrap()
1775    }
1776}
1777
1778/// Opcode for the ListOutputProperties request
1779pub const LIST_OUTPUT_PROPERTIES_REQUEST: u8 = 10;
1780#[derive(Clone, Copy, Default)]
1781#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1782#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1783pub struct ListOutputPropertiesRequest {
1784    pub output: Output,
1785}
1786impl_debug_if_no_extra_traits!(ListOutputPropertiesRequest, "ListOutputPropertiesRequest");
1787impl ListOutputPropertiesRequest {
1788    /// Serialize this request into bytes for the provided connection
1789    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1790        let length_so_far = 0;
1791        let output_bytes = self.output.serialize();
1792        let mut request0 = vec![
1793            major_opcode,
1794            LIST_OUTPUT_PROPERTIES_REQUEST,
1795            0,
1796            0,
1797            output_bytes[0],
1798            output_bytes[1],
1799            output_bytes[2],
1800            output_bytes[3],
1801        ];
1802        let length_so_far = length_so_far + request0.len();
1803        assert_eq!(length_so_far % 4, 0);
1804        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1805        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1806        ([request0.into()], vec![])
1807    }
1808    /// Parse this request given its header, its body, and any fds that go along with it
1809    #[cfg(feature = "request-parsing")]
1810    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1811        if header.minor_opcode != LIST_OUTPUT_PROPERTIES_REQUEST {
1812            return Err(ParseError::InvalidValue);
1813        }
1814        let (output, remaining) = Output::try_parse(value)?;
1815        let _ = remaining;
1816        Ok(ListOutputPropertiesRequest {
1817            output,
1818        })
1819    }
1820}
1821impl Request for ListOutputPropertiesRequest {
1822    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1823
1824    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1825        let (bufs, fds) = self.serialize(major_opcode);
1826        // Flatten the buffers into a single vector
1827        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1828        (buf, fds)
1829    }
1830}
1831impl crate::x11_utils::ReplyRequest for ListOutputPropertiesRequest {
1832    type Reply = ListOutputPropertiesReply;
1833}
1834
1835#[derive(Clone, Default)]
1836#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1837#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1838pub struct ListOutputPropertiesReply {
1839    pub sequence: u16,
1840    pub length: u32,
1841    pub atoms: Vec<xproto::Atom>,
1842}
1843impl_debug_if_no_extra_traits!(ListOutputPropertiesReply, "ListOutputPropertiesReply");
1844impl TryParse for ListOutputPropertiesReply {
1845    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1846        let remaining = initial_value;
1847        let (response_type, remaining) = u8::try_parse(remaining)?;
1848        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1849        let (sequence, remaining) = u16::try_parse(remaining)?;
1850        let (length, remaining) = u32::try_parse(remaining)?;
1851        let (num_atoms, remaining) = u16::try_parse(remaining)?;
1852        let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?;
1853        let (atoms, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, num_atoms.try_to_usize()?)?;
1854        if response_type != 1 {
1855            return Err(ParseError::InvalidValue);
1856        }
1857        let result = ListOutputPropertiesReply { sequence, length, atoms };
1858        let _ = remaining;
1859        let remaining = initial_value.get(32 + length as usize * 4..)
1860            .ok_or(ParseError::InsufficientData)?;
1861        Ok((result, remaining))
1862    }
1863}
1864impl Serialize for ListOutputPropertiesReply {
1865    type Bytes = Vec<u8>;
1866    fn serialize(&self) -> Vec<u8> {
1867        let mut result = Vec::new();
1868        self.serialize_into(&mut result);
1869        result
1870    }
1871    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1872        bytes.reserve(32);
1873        let response_type_bytes = &[1];
1874        bytes.push(response_type_bytes[0]);
1875        bytes.extend_from_slice(&[0; 1]);
1876        self.sequence.serialize_into(bytes);
1877        self.length.serialize_into(bytes);
1878        let num_atoms = u16::try_from(self.atoms.len()).expect("`atoms` has too many elements");
1879        num_atoms.serialize_into(bytes);
1880        bytes.extend_from_slice(&[0; 22]);
1881        self.atoms.serialize_into(bytes);
1882    }
1883}
1884impl ListOutputPropertiesReply {
1885    /// Get the value of the `num_atoms` field.
1886    ///
1887    /// The `num_atoms` field is used as the length field of the `atoms` field.
1888    /// This function computes the field's value again based on the length of the list.
1889    ///
1890    /// # Panics
1891    ///
1892    /// Panics if the value cannot be represented in the target type. This
1893    /// cannot happen with values of the struct received from the X11 server.
1894    pub fn num_atoms(&self) -> u16 {
1895        self.atoms.len()
1896            .try_into().unwrap()
1897    }
1898}
1899
1900/// Opcode for the QueryOutputProperty request
1901pub const QUERY_OUTPUT_PROPERTY_REQUEST: u8 = 11;
1902#[derive(Clone, Copy, Default)]
1903#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1904#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1905pub struct QueryOutputPropertyRequest {
1906    pub output: Output,
1907    pub property: xproto::Atom,
1908}
1909impl_debug_if_no_extra_traits!(QueryOutputPropertyRequest, "QueryOutputPropertyRequest");
1910impl QueryOutputPropertyRequest {
1911    /// Serialize this request into bytes for the provided connection
1912    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1913        let length_so_far = 0;
1914        let output_bytes = self.output.serialize();
1915        let property_bytes = self.property.serialize();
1916        let mut request0 = vec![
1917            major_opcode,
1918            QUERY_OUTPUT_PROPERTY_REQUEST,
1919            0,
1920            0,
1921            output_bytes[0],
1922            output_bytes[1],
1923            output_bytes[2],
1924            output_bytes[3],
1925            property_bytes[0],
1926            property_bytes[1],
1927            property_bytes[2],
1928            property_bytes[3],
1929        ];
1930        let length_so_far = length_so_far + request0.len();
1931        assert_eq!(length_so_far % 4, 0);
1932        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1933        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1934        ([request0.into()], vec![])
1935    }
1936    /// Parse this request given its header, its body, and any fds that go along with it
1937    #[cfg(feature = "request-parsing")]
1938    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1939        if header.minor_opcode != QUERY_OUTPUT_PROPERTY_REQUEST {
1940            return Err(ParseError::InvalidValue);
1941        }
1942        let (output, remaining) = Output::try_parse(value)?;
1943        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
1944        let _ = remaining;
1945        Ok(QueryOutputPropertyRequest {
1946            output,
1947            property,
1948        })
1949    }
1950}
1951impl Request for QueryOutputPropertyRequest {
1952    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1953
1954    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1955        let (bufs, fds) = self.serialize(major_opcode);
1956        // Flatten the buffers into a single vector
1957        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1958        (buf, fds)
1959    }
1960}
1961impl crate::x11_utils::ReplyRequest for QueryOutputPropertyRequest {
1962    type Reply = QueryOutputPropertyReply;
1963}
1964
1965#[derive(Clone, Default)]
1966#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1967#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1968pub struct QueryOutputPropertyReply {
1969    pub sequence: u16,
1970    pub pending: bool,
1971    pub range: bool,
1972    pub immutable: bool,
1973    pub valid_values: Vec<i32>,
1974}
1975impl_debug_if_no_extra_traits!(QueryOutputPropertyReply, "QueryOutputPropertyReply");
1976impl TryParse for QueryOutputPropertyReply {
1977    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1978        let remaining = initial_value;
1979        let (response_type, remaining) = u8::try_parse(remaining)?;
1980        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1981        let (sequence, remaining) = u16::try_parse(remaining)?;
1982        let (length, remaining) = u32::try_parse(remaining)?;
1983        let (pending, remaining) = bool::try_parse(remaining)?;
1984        let (range, remaining) = bool::try_parse(remaining)?;
1985        let (immutable, remaining) = bool::try_parse(remaining)?;
1986        let remaining = remaining.get(21..).ok_or(ParseError::InsufficientData)?;
1987        let (valid_values, remaining) = crate::x11_utils::parse_list::<i32>(remaining, length.try_to_usize()?)?;
1988        if response_type != 1 {
1989            return Err(ParseError::InvalidValue);
1990        }
1991        let result = QueryOutputPropertyReply { sequence, pending, range, immutable, valid_values };
1992        let _ = remaining;
1993        let remaining = initial_value.get(32 + length as usize * 4..)
1994            .ok_or(ParseError::InsufficientData)?;
1995        Ok((result, remaining))
1996    }
1997}
1998impl Serialize for QueryOutputPropertyReply {
1999    type Bytes = Vec<u8>;
2000    fn serialize(&self) -> Vec<u8> {
2001        let mut result = Vec::new();
2002        self.serialize_into(&mut result);
2003        result
2004    }
2005    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2006        bytes.reserve(32);
2007        let response_type_bytes = &[1];
2008        bytes.push(response_type_bytes[0]);
2009        bytes.extend_from_slice(&[0; 1]);
2010        self.sequence.serialize_into(bytes);
2011        let length = u32::try_from(self.valid_values.len()).expect("`valid_values` has too many elements");
2012        length.serialize_into(bytes);
2013        self.pending.serialize_into(bytes);
2014        self.range.serialize_into(bytes);
2015        self.immutable.serialize_into(bytes);
2016        bytes.extend_from_slice(&[0; 21]);
2017        self.valid_values.serialize_into(bytes);
2018    }
2019}
2020impl QueryOutputPropertyReply {
2021    /// Get the value of the `length` field.
2022    ///
2023    /// The `length` field is used as the length field of the `validValues` field.
2024    /// This function computes the field's value again based on the length of the list.
2025    ///
2026    /// # Panics
2027    ///
2028    /// Panics if the value cannot be represented in the target type. This
2029    /// cannot happen with values of the struct received from the X11 server.
2030    pub fn length(&self) -> u32 {
2031        self.valid_values.len()
2032            .try_into().unwrap()
2033    }
2034}
2035
2036/// Opcode for the ConfigureOutputProperty request
2037pub const CONFIGURE_OUTPUT_PROPERTY_REQUEST: u8 = 12;
2038#[derive(Clone, Default)]
2039#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2040#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2041pub struct ConfigureOutputPropertyRequest<'input> {
2042    pub output: Output,
2043    pub property: xproto::Atom,
2044    pub pending: bool,
2045    pub range: bool,
2046    pub values: Cow<'input, [i32]>,
2047}
2048impl_debug_if_no_extra_traits!(ConfigureOutputPropertyRequest<'_>, "ConfigureOutputPropertyRequest");
2049impl<'input> ConfigureOutputPropertyRequest<'input> {
2050    /// Serialize this request into bytes for the provided connection
2051    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
2052        let length_so_far = 0;
2053        let output_bytes = self.output.serialize();
2054        let property_bytes = self.property.serialize();
2055        let pending_bytes = self.pending.serialize();
2056        let range_bytes = self.range.serialize();
2057        let mut request0 = vec![
2058            major_opcode,
2059            CONFIGURE_OUTPUT_PROPERTY_REQUEST,
2060            0,
2061            0,
2062            output_bytes[0],
2063            output_bytes[1],
2064            output_bytes[2],
2065            output_bytes[3],
2066            property_bytes[0],
2067            property_bytes[1],
2068            property_bytes[2],
2069            property_bytes[3],
2070            pending_bytes[0],
2071            range_bytes[0],
2072            0,
2073            0,
2074        ];
2075        let length_so_far = length_so_far + request0.len();
2076        let values_bytes = self.values.serialize();
2077        let length_so_far = length_so_far + values_bytes.len();
2078        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
2079        let length_so_far = length_so_far + padding0.len();
2080        assert_eq!(length_so_far % 4, 0);
2081        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2082        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2083        ([request0.into(), values_bytes.into(), padding0.into()], vec![])
2084    }
2085    /// Parse this request given its header, its body, and any fds that go along with it
2086    #[cfg(feature = "request-parsing")]
2087    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
2088        if header.minor_opcode != CONFIGURE_OUTPUT_PROPERTY_REQUEST {
2089            return Err(ParseError::InvalidValue);
2090        }
2091        let (output, remaining) = Output::try_parse(value)?;
2092        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
2093        let (pending, remaining) = bool::try_parse(remaining)?;
2094        let (range, remaining) = bool::try_parse(remaining)?;
2095        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2096        let mut remaining = remaining;
2097        // Length is 'everything left in the input'
2098        let mut values = Vec::new();
2099        while !remaining.is_empty() {
2100            let (v, new_remaining) = i32::try_parse(remaining)?;
2101            remaining = new_remaining;
2102            values.push(v);
2103        }
2104        let _ = remaining;
2105        Ok(ConfigureOutputPropertyRequest {
2106            output,
2107            property,
2108            pending,
2109            range,
2110            values: Cow::Owned(values),
2111        })
2112    }
2113    /// Clone all borrowed data in this ConfigureOutputPropertyRequest.
2114    pub fn into_owned(self) -> ConfigureOutputPropertyRequest<'static> {
2115        ConfigureOutputPropertyRequest {
2116            output: self.output,
2117            property: self.property,
2118            pending: self.pending,
2119            range: self.range,
2120            values: Cow::Owned(self.values.into_owned()),
2121        }
2122    }
2123}
2124impl<'input> Request for ConfigureOutputPropertyRequest<'input> {
2125    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2126
2127    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2128        let (bufs, fds) = self.serialize(major_opcode);
2129        // Flatten the buffers into a single vector
2130        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2131        (buf, fds)
2132    }
2133}
2134impl<'input> crate::x11_utils::VoidRequest for ConfigureOutputPropertyRequest<'input> {
2135}
2136
2137/// Opcode for the ChangeOutputProperty request
2138pub const CHANGE_OUTPUT_PROPERTY_REQUEST: u8 = 13;
2139#[derive(Clone, Default)]
2140#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2141#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2142pub struct ChangeOutputPropertyRequest<'input> {
2143    pub output: Output,
2144    pub property: xproto::Atom,
2145    pub type_: xproto::Atom,
2146    pub format: u8,
2147    pub mode: xproto::PropMode,
2148    pub num_units: u32,
2149    pub data: Cow<'input, [u8]>,
2150}
2151impl_debug_if_no_extra_traits!(ChangeOutputPropertyRequest<'_>, "ChangeOutputPropertyRequest");
2152impl<'input> ChangeOutputPropertyRequest<'input> {
2153    /// Serialize this request into bytes for the provided connection
2154    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
2155        let length_so_far = 0;
2156        let output_bytes = self.output.serialize();
2157        let property_bytes = self.property.serialize();
2158        let type_bytes = self.type_.serialize();
2159        let format_bytes = self.format.serialize();
2160        let mode_bytes = u8::from(self.mode).serialize();
2161        let num_units_bytes = self.num_units.serialize();
2162        let mut request0 = vec![
2163            major_opcode,
2164            CHANGE_OUTPUT_PROPERTY_REQUEST,
2165            0,
2166            0,
2167            output_bytes[0],
2168            output_bytes[1],
2169            output_bytes[2],
2170            output_bytes[3],
2171            property_bytes[0],
2172            property_bytes[1],
2173            property_bytes[2],
2174            property_bytes[3],
2175            type_bytes[0],
2176            type_bytes[1],
2177            type_bytes[2],
2178            type_bytes[3],
2179            format_bytes[0],
2180            mode_bytes[0],
2181            0,
2182            0,
2183            num_units_bytes[0],
2184            num_units_bytes[1],
2185            num_units_bytes[2],
2186            num_units_bytes[3],
2187        ];
2188        let length_so_far = length_so_far + request0.len();
2189        assert_eq!(self.data.len(), usize::try_from(u32::from(self.num_units).checked_mul(u32::from(self.format)).unwrap().checked_div(8u32).unwrap()).unwrap(), "`data` has an incorrect length");
2190        let length_so_far = length_so_far + self.data.len();
2191        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
2192        let length_so_far = length_so_far + padding0.len();
2193        assert_eq!(length_so_far % 4, 0);
2194        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2195        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2196        ([request0.into(), self.data, padding0.into()], vec![])
2197    }
2198    /// Parse this request given its header, its body, and any fds that go along with it
2199    #[cfg(feature = "request-parsing")]
2200    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
2201        if header.minor_opcode != CHANGE_OUTPUT_PROPERTY_REQUEST {
2202            return Err(ParseError::InvalidValue);
2203        }
2204        let (output, remaining) = Output::try_parse(value)?;
2205        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
2206        let (type_, remaining) = xproto::Atom::try_parse(remaining)?;
2207        let (format, remaining) = u8::try_parse(remaining)?;
2208        let (mode, remaining) = u8::try_parse(remaining)?;
2209        let mode = mode.into();
2210        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2211        let (num_units, remaining) = u32::try_parse(remaining)?;
2212        let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(num_units).checked_mul(u32::from(format)).ok_or(ParseError::InvalidExpression)?.checked_div(8u32).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?;
2213        let _ = remaining;
2214        Ok(ChangeOutputPropertyRequest {
2215            output,
2216            property,
2217            type_,
2218            format,
2219            mode,
2220            num_units,
2221            data: Cow::Borrowed(data),
2222        })
2223    }
2224    /// Clone all borrowed data in this ChangeOutputPropertyRequest.
2225    pub fn into_owned(self) -> ChangeOutputPropertyRequest<'static> {
2226        ChangeOutputPropertyRequest {
2227            output: self.output,
2228            property: self.property,
2229            type_: self.type_,
2230            format: self.format,
2231            mode: self.mode,
2232            num_units: self.num_units,
2233            data: Cow::Owned(self.data.into_owned()),
2234        }
2235    }
2236}
2237impl<'input> Request for ChangeOutputPropertyRequest<'input> {
2238    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2239
2240    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2241        let (bufs, fds) = self.serialize(major_opcode);
2242        // Flatten the buffers into a single vector
2243        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2244        (buf, fds)
2245    }
2246}
2247impl<'input> crate::x11_utils::VoidRequest for ChangeOutputPropertyRequest<'input> {
2248}
2249
2250/// Opcode for the DeleteOutputProperty request
2251pub const DELETE_OUTPUT_PROPERTY_REQUEST: u8 = 14;
2252#[derive(Clone, Copy, Default)]
2253#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2254#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2255pub struct DeleteOutputPropertyRequest {
2256    pub output: Output,
2257    pub property: xproto::Atom,
2258}
2259impl_debug_if_no_extra_traits!(DeleteOutputPropertyRequest, "DeleteOutputPropertyRequest");
2260impl DeleteOutputPropertyRequest {
2261    /// Serialize this request into bytes for the provided connection
2262    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2263        let length_so_far = 0;
2264        let output_bytes = self.output.serialize();
2265        let property_bytes = self.property.serialize();
2266        let mut request0 = vec![
2267            major_opcode,
2268            DELETE_OUTPUT_PROPERTY_REQUEST,
2269            0,
2270            0,
2271            output_bytes[0],
2272            output_bytes[1],
2273            output_bytes[2],
2274            output_bytes[3],
2275            property_bytes[0],
2276            property_bytes[1],
2277            property_bytes[2],
2278            property_bytes[3],
2279        ];
2280        let length_so_far = length_so_far + request0.len();
2281        assert_eq!(length_so_far % 4, 0);
2282        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2283        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2284        ([request0.into()], vec![])
2285    }
2286    /// Parse this request given its header, its body, and any fds that go along with it
2287    #[cfg(feature = "request-parsing")]
2288    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2289        if header.minor_opcode != DELETE_OUTPUT_PROPERTY_REQUEST {
2290            return Err(ParseError::InvalidValue);
2291        }
2292        let (output, remaining) = Output::try_parse(value)?;
2293        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
2294        let _ = remaining;
2295        Ok(DeleteOutputPropertyRequest {
2296            output,
2297            property,
2298        })
2299    }
2300}
2301impl Request for DeleteOutputPropertyRequest {
2302    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2303
2304    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2305        let (bufs, fds) = self.serialize(major_opcode);
2306        // Flatten the buffers into a single vector
2307        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2308        (buf, fds)
2309    }
2310}
2311impl crate::x11_utils::VoidRequest for DeleteOutputPropertyRequest {
2312}
2313
2314/// Opcode for the GetOutputProperty request
2315pub const GET_OUTPUT_PROPERTY_REQUEST: u8 = 15;
2316#[derive(Clone, Copy, Default)]
2317#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2318#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2319pub struct GetOutputPropertyRequest {
2320    pub output: Output,
2321    pub property: xproto::Atom,
2322    pub type_: xproto::Atom,
2323    pub long_offset: u32,
2324    pub long_length: u32,
2325    pub delete: bool,
2326    pub pending: bool,
2327}
2328impl_debug_if_no_extra_traits!(GetOutputPropertyRequest, "GetOutputPropertyRequest");
2329impl GetOutputPropertyRequest {
2330    /// Serialize this request into bytes for the provided connection
2331    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2332        let length_so_far = 0;
2333        let output_bytes = self.output.serialize();
2334        let property_bytes = self.property.serialize();
2335        let type_bytes = self.type_.serialize();
2336        let long_offset_bytes = self.long_offset.serialize();
2337        let long_length_bytes = self.long_length.serialize();
2338        let delete_bytes = self.delete.serialize();
2339        let pending_bytes = self.pending.serialize();
2340        let mut request0 = vec![
2341            major_opcode,
2342            GET_OUTPUT_PROPERTY_REQUEST,
2343            0,
2344            0,
2345            output_bytes[0],
2346            output_bytes[1],
2347            output_bytes[2],
2348            output_bytes[3],
2349            property_bytes[0],
2350            property_bytes[1],
2351            property_bytes[2],
2352            property_bytes[3],
2353            type_bytes[0],
2354            type_bytes[1],
2355            type_bytes[2],
2356            type_bytes[3],
2357            long_offset_bytes[0],
2358            long_offset_bytes[1],
2359            long_offset_bytes[2],
2360            long_offset_bytes[3],
2361            long_length_bytes[0],
2362            long_length_bytes[1],
2363            long_length_bytes[2],
2364            long_length_bytes[3],
2365            delete_bytes[0],
2366            pending_bytes[0],
2367            0,
2368            0,
2369        ];
2370        let length_so_far = length_so_far + request0.len();
2371        assert_eq!(length_so_far % 4, 0);
2372        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2373        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2374        ([request0.into()], vec![])
2375    }
2376    /// Parse this request given its header, its body, and any fds that go along with it
2377    #[cfg(feature = "request-parsing")]
2378    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2379        if header.minor_opcode != GET_OUTPUT_PROPERTY_REQUEST {
2380            return Err(ParseError::InvalidValue);
2381        }
2382        let (output, remaining) = Output::try_parse(value)?;
2383        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
2384        let (type_, remaining) = xproto::Atom::try_parse(remaining)?;
2385        let (long_offset, remaining) = u32::try_parse(remaining)?;
2386        let (long_length, remaining) = u32::try_parse(remaining)?;
2387        let (delete, remaining) = bool::try_parse(remaining)?;
2388        let (pending, remaining) = bool::try_parse(remaining)?;
2389        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2390        let _ = remaining;
2391        Ok(GetOutputPropertyRequest {
2392            output,
2393            property,
2394            type_,
2395            long_offset,
2396            long_length,
2397            delete,
2398            pending,
2399        })
2400    }
2401}
2402impl Request for GetOutputPropertyRequest {
2403    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2404
2405    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2406        let (bufs, fds) = self.serialize(major_opcode);
2407        // Flatten the buffers into a single vector
2408        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2409        (buf, fds)
2410    }
2411}
2412impl crate::x11_utils::ReplyRequest for GetOutputPropertyRequest {
2413    type Reply = GetOutputPropertyReply;
2414}
2415
2416#[derive(Clone, Default)]
2417#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2418#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2419pub struct GetOutputPropertyReply {
2420    pub format: u8,
2421    pub sequence: u16,
2422    pub length: u32,
2423    pub type_: xproto::Atom,
2424    pub bytes_after: u32,
2425    pub num_items: u32,
2426    pub data: Vec<u8>,
2427}
2428impl_debug_if_no_extra_traits!(GetOutputPropertyReply, "GetOutputPropertyReply");
2429impl TryParse for GetOutputPropertyReply {
2430    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2431        let remaining = initial_value;
2432        let (response_type, remaining) = u8::try_parse(remaining)?;
2433        let (format, remaining) = u8::try_parse(remaining)?;
2434        let (sequence, remaining) = u16::try_parse(remaining)?;
2435        let (length, remaining) = u32::try_parse(remaining)?;
2436        let (type_, remaining) = xproto::Atom::try_parse(remaining)?;
2437        let (bytes_after, remaining) = u32::try_parse(remaining)?;
2438        let (num_items, remaining) = u32::try_parse(remaining)?;
2439        let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
2440        let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(num_items).checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?;
2441        let data = data.to_vec();
2442        if response_type != 1 {
2443            return Err(ParseError::InvalidValue);
2444        }
2445        let result = GetOutputPropertyReply { format, sequence, length, type_, bytes_after, num_items, data };
2446        let _ = remaining;
2447        let remaining = initial_value.get(32 + length as usize * 4..)
2448            .ok_or(ParseError::InsufficientData)?;
2449        Ok((result, remaining))
2450    }
2451}
2452impl Serialize for GetOutputPropertyReply {
2453    type Bytes = Vec<u8>;
2454    fn serialize(&self) -> Vec<u8> {
2455        let mut result = Vec::new();
2456        self.serialize_into(&mut result);
2457        result
2458    }
2459    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2460        bytes.reserve(32);
2461        let response_type_bytes = &[1];
2462        bytes.push(response_type_bytes[0]);
2463        self.format.serialize_into(bytes);
2464        self.sequence.serialize_into(bytes);
2465        self.length.serialize_into(bytes);
2466        self.type_.serialize_into(bytes);
2467        self.bytes_after.serialize_into(bytes);
2468        self.num_items.serialize_into(bytes);
2469        bytes.extend_from_slice(&[0; 12]);
2470        assert_eq!(self.data.len(), usize::try_from(u32::from(self.num_items).checked_mul(u32::from(self.format).checked_div(8u32).unwrap()).unwrap()).unwrap(), "`data` has an incorrect length");
2471        bytes.extend_from_slice(&self.data);
2472    }
2473}
2474
2475/// Opcode for the CreateMode request
2476pub const CREATE_MODE_REQUEST: u8 = 16;
2477#[derive(Clone, Default)]
2478#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2479#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2480pub struct CreateModeRequest<'input> {
2481    pub window: xproto::Window,
2482    pub mode_info: ModeInfo,
2483    pub name: Cow<'input, [u8]>,
2484}
2485impl_debug_if_no_extra_traits!(CreateModeRequest<'_>, "CreateModeRequest");
2486impl<'input> CreateModeRequest<'input> {
2487    /// Serialize this request into bytes for the provided connection
2488    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
2489        let length_so_far = 0;
2490        let window_bytes = self.window.serialize();
2491        let mode_info_bytes = self.mode_info.serialize();
2492        let mut request0 = vec![
2493            major_opcode,
2494            CREATE_MODE_REQUEST,
2495            0,
2496            0,
2497            window_bytes[0],
2498            window_bytes[1],
2499            window_bytes[2],
2500            window_bytes[3],
2501            mode_info_bytes[0],
2502            mode_info_bytes[1],
2503            mode_info_bytes[2],
2504            mode_info_bytes[3],
2505            mode_info_bytes[4],
2506            mode_info_bytes[5],
2507            mode_info_bytes[6],
2508            mode_info_bytes[7],
2509            mode_info_bytes[8],
2510            mode_info_bytes[9],
2511            mode_info_bytes[10],
2512            mode_info_bytes[11],
2513            mode_info_bytes[12],
2514            mode_info_bytes[13],
2515            mode_info_bytes[14],
2516            mode_info_bytes[15],
2517            mode_info_bytes[16],
2518            mode_info_bytes[17],
2519            mode_info_bytes[18],
2520            mode_info_bytes[19],
2521            mode_info_bytes[20],
2522            mode_info_bytes[21],
2523            mode_info_bytes[22],
2524            mode_info_bytes[23],
2525            mode_info_bytes[24],
2526            mode_info_bytes[25],
2527            mode_info_bytes[26],
2528            mode_info_bytes[27],
2529            mode_info_bytes[28],
2530            mode_info_bytes[29],
2531            mode_info_bytes[30],
2532            mode_info_bytes[31],
2533        ];
2534        let length_so_far = length_so_far + request0.len();
2535        let length_so_far = length_so_far + self.name.len();
2536        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
2537        let length_so_far = length_so_far + padding0.len();
2538        assert_eq!(length_so_far % 4, 0);
2539        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2540        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2541        ([request0.into(), self.name, padding0.into()], vec![])
2542    }
2543    /// Parse this request given its header, its body, and any fds that go along with it
2544    #[cfg(feature = "request-parsing")]
2545    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
2546        if header.minor_opcode != CREATE_MODE_REQUEST {
2547            return Err(ParseError::InvalidValue);
2548        }
2549        let (window, remaining) = xproto::Window::try_parse(value)?;
2550        let (mode_info, remaining) = ModeInfo::try_parse(remaining)?;
2551        let (name, remaining) = remaining.split_at(remaining.len());
2552        let _ = remaining;
2553        Ok(CreateModeRequest {
2554            window,
2555            mode_info,
2556            name: Cow::Borrowed(name),
2557        })
2558    }
2559    /// Clone all borrowed data in this CreateModeRequest.
2560    pub fn into_owned(self) -> CreateModeRequest<'static> {
2561        CreateModeRequest {
2562            window: self.window,
2563            mode_info: self.mode_info,
2564            name: Cow::Owned(self.name.into_owned()),
2565        }
2566    }
2567}
2568impl<'input> Request for CreateModeRequest<'input> {
2569    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2570
2571    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2572        let (bufs, fds) = self.serialize(major_opcode);
2573        // Flatten the buffers into a single vector
2574        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2575        (buf, fds)
2576    }
2577}
2578impl<'input> crate::x11_utils::ReplyRequest for CreateModeRequest<'input> {
2579    type Reply = CreateModeReply;
2580}
2581
2582#[derive(Clone, Copy, Default)]
2583#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2584#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2585pub struct CreateModeReply {
2586    pub sequence: u16,
2587    pub length: u32,
2588    pub mode: Mode,
2589}
2590impl_debug_if_no_extra_traits!(CreateModeReply, "CreateModeReply");
2591impl TryParse for CreateModeReply {
2592    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2593        let remaining = initial_value;
2594        let (response_type, remaining) = u8::try_parse(remaining)?;
2595        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2596        let (sequence, remaining) = u16::try_parse(remaining)?;
2597        let (length, remaining) = u32::try_parse(remaining)?;
2598        let (mode, remaining) = Mode::try_parse(remaining)?;
2599        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
2600        if response_type != 1 {
2601            return Err(ParseError::InvalidValue);
2602        }
2603        let result = CreateModeReply { sequence, length, mode };
2604        let _ = remaining;
2605        let remaining = initial_value.get(32 + length as usize * 4..)
2606            .ok_or(ParseError::InsufficientData)?;
2607        Ok((result, remaining))
2608    }
2609}
2610impl Serialize for CreateModeReply {
2611    type Bytes = [u8; 32];
2612    fn serialize(&self) -> [u8; 32] {
2613        let response_type_bytes = &[1];
2614        let sequence_bytes = self.sequence.serialize();
2615        let length_bytes = self.length.serialize();
2616        let mode_bytes = self.mode.serialize();
2617        [
2618            response_type_bytes[0],
2619            0,
2620            sequence_bytes[0],
2621            sequence_bytes[1],
2622            length_bytes[0],
2623            length_bytes[1],
2624            length_bytes[2],
2625            length_bytes[3],
2626            mode_bytes[0],
2627            mode_bytes[1],
2628            mode_bytes[2],
2629            mode_bytes[3],
2630            0,
2631            0,
2632            0,
2633            0,
2634            0,
2635            0,
2636            0,
2637            0,
2638            0,
2639            0,
2640            0,
2641            0,
2642            0,
2643            0,
2644            0,
2645            0,
2646            0,
2647            0,
2648            0,
2649            0,
2650        ]
2651    }
2652    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2653        bytes.reserve(32);
2654        let response_type_bytes = &[1];
2655        bytes.push(response_type_bytes[0]);
2656        bytes.extend_from_slice(&[0; 1]);
2657        self.sequence.serialize_into(bytes);
2658        self.length.serialize_into(bytes);
2659        self.mode.serialize_into(bytes);
2660        bytes.extend_from_slice(&[0; 20]);
2661    }
2662}
2663
2664/// Opcode for the DestroyMode request
2665pub const DESTROY_MODE_REQUEST: u8 = 17;
2666#[derive(Clone, Copy, Default)]
2667#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2668#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2669pub struct DestroyModeRequest {
2670    pub mode: Mode,
2671}
2672impl_debug_if_no_extra_traits!(DestroyModeRequest, "DestroyModeRequest");
2673impl DestroyModeRequest {
2674    /// Serialize this request into bytes for the provided connection
2675    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2676        let length_so_far = 0;
2677        let mode_bytes = self.mode.serialize();
2678        let mut request0 = vec![
2679            major_opcode,
2680            DESTROY_MODE_REQUEST,
2681            0,
2682            0,
2683            mode_bytes[0],
2684            mode_bytes[1],
2685            mode_bytes[2],
2686            mode_bytes[3],
2687        ];
2688        let length_so_far = length_so_far + request0.len();
2689        assert_eq!(length_so_far % 4, 0);
2690        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2691        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2692        ([request0.into()], vec![])
2693    }
2694    /// Parse this request given its header, its body, and any fds that go along with it
2695    #[cfg(feature = "request-parsing")]
2696    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2697        if header.minor_opcode != DESTROY_MODE_REQUEST {
2698            return Err(ParseError::InvalidValue);
2699        }
2700        let (mode, remaining) = Mode::try_parse(value)?;
2701        let _ = remaining;
2702        Ok(DestroyModeRequest {
2703            mode,
2704        })
2705    }
2706}
2707impl Request for DestroyModeRequest {
2708    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2709
2710    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2711        let (bufs, fds) = self.serialize(major_opcode);
2712        // Flatten the buffers into a single vector
2713        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2714        (buf, fds)
2715    }
2716}
2717impl crate::x11_utils::VoidRequest for DestroyModeRequest {
2718}
2719
2720/// Opcode for the AddOutputMode request
2721pub const ADD_OUTPUT_MODE_REQUEST: u8 = 18;
2722#[derive(Clone, Copy, Default)]
2723#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2724#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2725pub struct AddOutputModeRequest {
2726    pub output: Output,
2727    pub mode: Mode,
2728}
2729impl_debug_if_no_extra_traits!(AddOutputModeRequest, "AddOutputModeRequest");
2730impl AddOutputModeRequest {
2731    /// Serialize this request into bytes for the provided connection
2732    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2733        let length_so_far = 0;
2734        let output_bytes = self.output.serialize();
2735        let mode_bytes = self.mode.serialize();
2736        let mut request0 = vec![
2737            major_opcode,
2738            ADD_OUTPUT_MODE_REQUEST,
2739            0,
2740            0,
2741            output_bytes[0],
2742            output_bytes[1],
2743            output_bytes[2],
2744            output_bytes[3],
2745            mode_bytes[0],
2746            mode_bytes[1],
2747            mode_bytes[2],
2748            mode_bytes[3],
2749        ];
2750        let length_so_far = length_so_far + request0.len();
2751        assert_eq!(length_so_far % 4, 0);
2752        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2753        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2754        ([request0.into()], vec![])
2755    }
2756    /// Parse this request given its header, its body, and any fds that go along with it
2757    #[cfg(feature = "request-parsing")]
2758    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2759        if header.minor_opcode != ADD_OUTPUT_MODE_REQUEST {
2760            return Err(ParseError::InvalidValue);
2761        }
2762        let (output, remaining) = Output::try_parse(value)?;
2763        let (mode, remaining) = Mode::try_parse(remaining)?;
2764        let _ = remaining;
2765        Ok(AddOutputModeRequest {
2766            output,
2767            mode,
2768        })
2769    }
2770}
2771impl Request for AddOutputModeRequest {
2772    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2773
2774    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2775        let (bufs, fds) = self.serialize(major_opcode);
2776        // Flatten the buffers into a single vector
2777        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2778        (buf, fds)
2779    }
2780}
2781impl crate::x11_utils::VoidRequest for AddOutputModeRequest {
2782}
2783
2784/// Opcode for the DeleteOutputMode request
2785pub const DELETE_OUTPUT_MODE_REQUEST: u8 = 19;
2786#[derive(Clone, Copy, Default)]
2787#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2788#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2789pub struct DeleteOutputModeRequest {
2790    pub output: Output,
2791    pub mode: Mode,
2792}
2793impl_debug_if_no_extra_traits!(DeleteOutputModeRequest, "DeleteOutputModeRequest");
2794impl DeleteOutputModeRequest {
2795    /// Serialize this request into bytes for the provided connection
2796    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2797        let length_so_far = 0;
2798        let output_bytes = self.output.serialize();
2799        let mode_bytes = self.mode.serialize();
2800        let mut request0 = vec![
2801            major_opcode,
2802            DELETE_OUTPUT_MODE_REQUEST,
2803            0,
2804            0,
2805            output_bytes[0],
2806            output_bytes[1],
2807            output_bytes[2],
2808            output_bytes[3],
2809            mode_bytes[0],
2810            mode_bytes[1],
2811            mode_bytes[2],
2812            mode_bytes[3],
2813        ];
2814        let length_so_far = length_so_far + request0.len();
2815        assert_eq!(length_so_far % 4, 0);
2816        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2817        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2818        ([request0.into()], vec![])
2819    }
2820    /// Parse this request given its header, its body, and any fds that go along with it
2821    #[cfg(feature = "request-parsing")]
2822    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2823        if header.minor_opcode != DELETE_OUTPUT_MODE_REQUEST {
2824            return Err(ParseError::InvalidValue);
2825        }
2826        let (output, remaining) = Output::try_parse(value)?;
2827        let (mode, remaining) = Mode::try_parse(remaining)?;
2828        let _ = remaining;
2829        Ok(DeleteOutputModeRequest {
2830            output,
2831            mode,
2832        })
2833    }
2834}
2835impl Request for DeleteOutputModeRequest {
2836    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2837
2838    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2839        let (bufs, fds) = self.serialize(major_opcode);
2840        // Flatten the buffers into a single vector
2841        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2842        (buf, fds)
2843    }
2844}
2845impl crate::x11_utils::VoidRequest for DeleteOutputModeRequest {
2846}
2847
2848/// Opcode for the GetCrtcInfo request
2849pub const GET_CRTC_INFO_REQUEST: u8 = 20;
2850#[derive(Clone, Copy, Default)]
2851#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2852#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2853pub struct GetCrtcInfoRequest {
2854    pub crtc: Crtc,
2855    pub config_timestamp: xproto::Timestamp,
2856}
2857impl_debug_if_no_extra_traits!(GetCrtcInfoRequest, "GetCrtcInfoRequest");
2858impl GetCrtcInfoRequest {
2859    /// Serialize this request into bytes for the provided connection
2860    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2861        let length_so_far = 0;
2862        let crtc_bytes = self.crtc.serialize();
2863        let config_timestamp_bytes = self.config_timestamp.serialize();
2864        let mut request0 = vec![
2865            major_opcode,
2866            GET_CRTC_INFO_REQUEST,
2867            0,
2868            0,
2869            crtc_bytes[0],
2870            crtc_bytes[1],
2871            crtc_bytes[2],
2872            crtc_bytes[3],
2873            config_timestamp_bytes[0],
2874            config_timestamp_bytes[1],
2875            config_timestamp_bytes[2],
2876            config_timestamp_bytes[3],
2877        ];
2878        let length_so_far = length_so_far + request0.len();
2879        assert_eq!(length_so_far % 4, 0);
2880        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2881        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2882        ([request0.into()], vec![])
2883    }
2884    /// Parse this request given its header, its body, and any fds that go along with it
2885    #[cfg(feature = "request-parsing")]
2886    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2887        if header.minor_opcode != GET_CRTC_INFO_REQUEST {
2888            return Err(ParseError::InvalidValue);
2889        }
2890        let (crtc, remaining) = Crtc::try_parse(value)?;
2891        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
2892        let _ = remaining;
2893        Ok(GetCrtcInfoRequest {
2894            crtc,
2895            config_timestamp,
2896        })
2897    }
2898}
2899impl Request for GetCrtcInfoRequest {
2900    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2901
2902    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2903        let (bufs, fds) = self.serialize(major_opcode);
2904        // Flatten the buffers into a single vector
2905        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2906        (buf, fds)
2907    }
2908}
2909impl crate::x11_utils::ReplyRequest for GetCrtcInfoRequest {
2910    type Reply = GetCrtcInfoReply;
2911}
2912
2913#[derive(Clone, Default)]
2914#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2915#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2916pub struct GetCrtcInfoReply {
2917    pub status: SetConfig,
2918    pub sequence: u16,
2919    pub length: u32,
2920    pub timestamp: xproto::Timestamp,
2921    pub x: i16,
2922    pub y: i16,
2923    pub width: u16,
2924    pub height: u16,
2925    pub mode: Mode,
2926    pub rotation: Rotation,
2927    pub rotations: Rotation,
2928    pub outputs: Vec<Output>,
2929    pub possible: Vec<Output>,
2930}
2931impl_debug_if_no_extra_traits!(GetCrtcInfoReply, "GetCrtcInfoReply");
2932impl TryParse for GetCrtcInfoReply {
2933    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2934        let remaining = initial_value;
2935        let (response_type, remaining) = u8::try_parse(remaining)?;
2936        let (status, remaining) = u8::try_parse(remaining)?;
2937        let (sequence, remaining) = u16::try_parse(remaining)?;
2938        let (length, remaining) = u32::try_parse(remaining)?;
2939        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
2940        let (x, remaining) = i16::try_parse(remaining)?;
2941        let (y, remaining) = i16::try_parse(remaining)?;
2942        let (width, remaining) = u16::try_parse(remaining)?;
2943        let (height, remaining) = u16::try_parse(remaining)?;
2944        let (mode, remaining) = Mode::try_parse(remaining)?;
2945        let (rotation, remaining) = u16::try_parse(remaining)?;
2946        let (rotations, remaining) = u16::try_parse(remaining)?;
2947        let (num_outputs, remaining) = u16::try_parse(remaining)?;
2948        let (num_possible_outputs, remaining) = u16::try_parse(remaining)?;
2949        let (outputs, remaining) = crate::x11_utils::parse_list::<Output>(remaining, num_outputs.try_to_usize()?)?;
2950        let (possible, remaining) = crate::x11_utils::parse_list::<Output>(remaining, num_possible_outputs.try_to_usize()?)?;
2951        if response_type != 1 {
2952            return Err(ParseError::InvalidValue);
2953        }
2954        let status = status.into();
2955        let rotation = rotation.into();
2956        let rotations = rotations.into();
2957        let result = GetCrtcInfoReply { status, sequence, length, timestamp, x, y, width, height, mode, rotation, rotations, outputs, possible };
2958        let _ = remaining;
2959        let remaining = initial_value.get(32 + length as usize * 4..)
2960            .ok_or(ParseError::InsufficientData)?;
2961        Ok((result, remaining))
2962    }
2963}
2964impl Serialize for GetCrtcInfoReply {
2965    type Bytes = Vec<u8>;
2966    fn serialize(&self) -> Vec<u8> {
2967        let mut result = Vec::new();
2968        self.serialize_into(&mut result);
2969        result
2970    }
2971    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2972        bytes.reserve(32);
2973        let response_type_bytes = &[1];
2974        bytes.push(response_type_bytes[0]);
2975        u8::from(self.status).serialize_into(bytes);
2976        self.sequence.serialize_into(bytes);
2977        self.length.serialize_into(bytes);
2978        self.timestamp.serialize_into(bytes);
2979        self.x.serialize_into(bytes);
2980        self.y.serialize_into(bytes);
2981        self.width.serialize_into(bytes);
2982        self.height.serialize_into(bytes);
2983        self.mode.serialize_into(bytes);
2984        u16::from(self.rotation).serialize_into(bytes);
2985        u16::from(self.rotations).serialize_into(bytes);
2986        let num_outputs = u16::try_from(self.outputs.len()).expect("`outputs` has too many elements");
2987        num_outputs.serialize_into(bytes);
2988        let num_possible_outputs = u16::try_from(self.possible.len()).expect("`possible` has too many elements");
2989        num_possible_outputs.serialize_into(bytes);
2990        self.outputs.serialize_into(bytes);
2991        self.possible.serialize_into(bytes);
2992    }
2993}
2994impl GetCrtcInfoReply {
2995    /// Get the value of the `num_outputs` field.
2996    ///
2997    /// The `num_outputs` field is used as the length field of the `outputs` field.
2998    /// This function computes the field's value again based on the length of the list.
2999    ///
3000    /// # Panics
3001    ///
3002    /// Panics if the value cannot be represented in the target type. This
3003    /// cannot happen with values of the struct received from the X11 server.
3004    pub fn num_outputs(&self) -> u16 {
3005        self.outputs.len()
3006            .try_into().unwrap()
3007    }
3008    /// Get the value of the `num_possible_outputs` field.
3009    ///
3010    /// The `num_possible_outputs` field is used as the length field of the `possible` field.
3011    /// This function computes the field's value again based on the length of the list.
3012    ///
3013    /// # Panics
3014    ///
3015    /// Panics if the value cannot be represented in the target type. This
3016    /// cannot happen with values of the struct received from the X11 server.
3017    pub fn num_possible_outputs(&self) -> u16 {
3018        self.possible.len()
3019            .try_into().unwrap()
3020    }
3021}
3022
3023/// Opcode for the SetCrtcConfig request
3024pub const SET_CRTC_CONFIG_REQUEST: u8 = 21;
3025#[derive(Clone, Default)]
3026#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
3027#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3028pub struct SetCrtcConfigRequest<'input> {
3029    pub crtc: Crtc,
3030    pub timestamp: xproto::Timestamp,
3031    pub config_timestamp: xproto::Timestamp,
3032    pub x: i16,
3033    pub y: i16,
3034    pub mode: Mode,
3035    pub rotation: Rotation,
3036    pub outputs: Cow<'input, [Output]>,
3037}
3038impl_debug_if_no_extra_traits!(SetCrtcConfigRequest<'_>, "SetCrtcConfigRequest");
3039impl<'input> SetCrtcConfigRequest<'input> {
3040    /// Serialize this request into bytes for the provided connection
3041    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
3042        let length_so_far = 0;
3043        let crtc_bytes = self.crtc.serialize();
3044        let timestamp_bytes = self.timestamp.serialize();
3045        let config_timestamp_bytes = self.config_timestamp.serialize();
3046        let x_bytes = self.x.serialize();
3047        let y_bytes = self.y.serialize();
3048        let mode_bytes = self.mode.serialize();
3049        let rotation_bytes = u16::from(self.rotation).serialize();
3050        let mut request0 = vec![
3051            major_opcode,
3052            SET_CRTC_CONFIG_REQUEST,
3053            0,
3054            0,
3055            crtc_bytes[0],
3056            crtc_bytes[1],
3057            crtc_bytes[2],
3058            crtc_bytes[3],
3059            timestamp_bytes[0],
3060            timestamp_bytes[1],
3061            timestamp_bytes[2],
3062            timestamp_bytes[3],
3063            config_timestamp_bytes[0],
3064            config_timestamp_bytes[1],
3065            config_timestamp_bytes[2],
3066            config_timestamp_bytes[3],
3067            x_bytes[0],
3068            x_bytes[1],
3069            y_bytes[0],
3070            y_bytes[1],
3071            mode_bytes[0],
3072            mode_bytes[1],
3073            mode_bytes[2],
3074            mode_bytes[3],
3075            rotation_bytes[0],
3076            rotation_bytes[1],
3077            0,
3078            0,
3079        ];
3080        let length_so_far = length_so_far + request0.len();
3081        let outputs_bytes = self.outputs.serialize();
3082        let length_so_far = length_so_far + outputs_bytes.len();
3083        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
3084        let length_so_far = length_so_far + padding0.len();
3085        assert_eq!(length_so_far % 4, 0);
3086        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
3087        request0[2..4].copy_from_slice(&length.to_ne_bytes());
3088        ([request0.into(), outputs_bytes.into(), padding0.into()], vec![])
3089    }
3090    /// Parse this request given its header, its body, and any fds that go along with it
3091    #[cfg(feature = "request-parsing")]
3092    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
3093        if header.minor_opcode != SET_CRTC_CONFIG_REQUEST {
3094            return Err(ParseError::InvalidValue);
3095        }
3096        let (crtc, remaining) = Crtc::try_parse(value)?;
3097        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
3098        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
3099        let (x, remaining) = i16::try_parse(remaining)?;
3100        let (y, remaining) = i16::try_parse(remaining)?;
3101        let (mode, remaining) = Mode::try_parse(remaining)?;
3102        let (rotation, remaining) = u16::try_parse(remaining)?;
3103        let rotation = rotation.into();
3104        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
3105        let mut remaining = remaining;
3106        // Length is 'everything left in the input'
3107        let mut outputs = Vec::new();
3108        while !remaining.is_empty() {
3109            let (v, new_remaining) = Output::try_parse(remaining)?;
3110            remaining = new_remaining;
3111            outputs.push(v);
3112        }
3113        let _ = remaining;
3114        Ok(SetCrtcConfigRequest {
3115            crtc,
3116            timestamp,
3117            config_timestamp,
3118            x,
3119            y,
3120            mode,
3121            rotation,
3122            outputs: Cow::Owned(outputs),
3123        })
3124    }
3125    /// Clone all borrowed data in this SetCrtcConfigRequest.
3126    pub fn into_owned(self) -> SetCrtcConfigRequest<'static> {
3127        SetCrtcConfigRequest {
3128            crtc: self.crtc,
3129            timestamp: self.timestamp,
3130            config_timestamp: self.config_timestamp,
3131            x: self.x,
3132            y: self.y,
3133            mode: self.mode,
3134            rotation: self.rotation,
3135            outputs: Cow::Owned(self.outputs.into_owned()),
3136        }
3137    }
3138}
3139impl<'input> Request for SetCrtcConfigRequest<'input> {
3140    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
3141
3142    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
3143        let (bufs, fds) = self.serialize(major_opcode);
3144        // Flatten the buffers into a single vector
3145        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
3146        (buf, fds)
3147    }
3148}
3149impl<'input> crate::x11_utils::ReplyRequest for SetCrtcConfigRequest<'input> {
3150    type Reply = SetCrtcConfigReply;
3151}
3152
3153#[derive(Clone, Copy, Default)]
3154#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
3155#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3156pub struct SetCrtcConfigReply {
3157    pub status: SetConfig,
3158    pub sequence: u16,
3159    pub length: u32,
3160    pub timestamp: xproto::Timestamp,
3161}
3162impl_debug_if_no_extra_traits!(SetCrtcConfigReply, "SetCrtcConfigReply");
3163impl TryParse for SetCrtcConfigReply {
3164    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3165        let remaining = initial_value;
3166        let (response_type, remaining) = u8::try_parse(remaining)?;
3167        let (status, remaining) = u8::try_parse(remaining)?;
3168        let (sequence, remaining) = u16::try_parse(remaining)?;
3169        let (length, remaining) = u32::try_parse(remaining)?;
3170        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
3171        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
3172        if response_type != 1 {
3173            return Err(ParseError::InvalidValue);
3174        }
3175        let status = status.into();
3176        let result = SetCrtcConfigReply { status, sequence, length, timestamp };
3177        let _ = remaining;
3178        let remaining = initial_value.get(32 + length as usize * 4..)
3179            .ok_or(ParseError::InsufficientData)?;
3180        Ok((result, remaining))
3181    }
3182}
3183impl Serialize for SetCrtcConfigReply {
3184    type Bytes = [u8; 32];
3185    fn serialize(&self) -> [u8; 32] {
3186        let response_type_bytes = &[1];
3187        let status_bytes = u8::from(self.status).serialize();
3188        let sequence_bytes = self.sequence.serialize();
3189        let length_bytes = self.length.serialize();
3190        let timestamp_bytes = self.timestamp.serialize();
3191        [
3192            response_type_bytes[0],
3193            status_bytes[0],
3194            sequence_bytes[0],
3195            sequence_bytes[1],
3196            length_bytes[0],
3197            length_bytes[1],
3198            length_bytes[2],
3199            length_bytes[3],
3200            timestamp_bytes[0],
3201            timestamp_bytes[1],
3202            timestamp_bytes[2],
3203            timestamp_bytes[3],
3204            0,
3205            0,
3206            0,
3207            0,
3208            0,
3209            0,
3210            0,
3211            0,
3212            0,
3213            0,
3214            0,
3215            0,
3216            0,
3217            0,
3218            0,
3219            0,
3220            0,
3221            0,
3222            0,
3223            0,
3224        ]
3225    }
3226    fn serialize_into(&self, bytes: &mut Vec<u8>) {
3227        bytes.reserve(32);
3228        let response_type_bytes = &[1];
3229        bytes.push(response_type_bytes[0]);
3230        u8::from(self.status).serialize_into(bytes);
3231        self.sequence.serialize_into(bytes);
3232        self.length.serialize_into(bytes);
3233        self.timestamp.serialize_into(bytes);
3234        bytes.extend_from_slice(&[0; 20]);
3235    }
3236}
3237
3238/// Opcode for the GetCrtcGammaSize request
3239pub const GET_CRTC_GAMMA_SIZE_REQUEST: u8 = 22;
3240#[derive(Clone, Copy, Default)]
3241#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
3242#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3243pub struct GetCrtcGammaSizeRequest {
3244    pub crtc: Crtc,
3245}
3246impl_debug_if_no_extra_traits!(GetCrtcGammaSizeRequest, "GetCrtcGammaSizeRequest");
3247impl GetCrtcGammaSizeRequest {
3248    /// Serialize this request into bytes for the provided connection
3249    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
3250        let length_so_far = 0;
3251        let crtc_bytes = self.crtc.serialize();
3252        let mut request0 = vec![
3253            major_opcode,
3254            GET_CRTC_GAMMA_SIZE_REQUEST,
3255            0,
3256            0,
3257            crtc_bytes[0],
3258            crtc_bytes[1],
3259            crtc_bytes[2],
3260            crtc_bytes[3],
3261        ];
3262        let length_so_far = length_so_far + request0.len();
3263        assert_eq!(length_so_far % 4, 0);
3264        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
3265        request0[2..4].copy_from_slice(&length.to_ne_bytes());
3266        ([request0.into()], vec![])
3267    }
3268    /// Parse this request given its header, its body, and any fds that go along with it
3269    #[cfg(feature = "request-parsing")]
3270    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
3271        if header.minor_opcode != GET_CRTC_GAMMA_SIZE_REQUEST {
3272            return Err(ParseError::InvalidValue);
3273        }
3274        let (crtc, remaining) = Crtc::try_parse(value)?;
3275        let _ = remaining;
3276        Ok(GetCrtcGammaSizeRequest {
3277            crtc,
3278        })
3279    }
3280}
3281impl Request for GetCrtcGammaSizeRequest {
3282    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
3283
3284    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
3285        let (bufs, fds) = self.serialize(major_opcode);
3286        // Flatten the buffers into a single vector
3287        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
3288        (buf, fds)
3289    }
3290}
3291impl crate::x11_utils::ReplyRequest for GetCrtcGammaSizeRequest {
3292    type Reply = GetCrtcGammaSizeReply;
3293}
3294
3295#[derive(Clone, Copy, Default)]
3296#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
3297#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3298pub struct GetCrtcGammaSizeReply {
3299    pub sequence: u16,
3300    pub length: u32,
3301    pub size: u16,
3302}
3303impl_debug_if_no_extra_traits!(GetCrtcGammaSizeReply, "GetCrtcGammaSizeReply");
3304impl TryParse for GetCrtcGammaSizeReply {
3305    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3306        let remaining = initial_value;
3307        let (response_type, remaining) = u8::try_parse(remaining)?;
3308        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
3309        let (sequence, remaining) = u16::try_parse(remaining)?;
3310        let (length, remaining) = u32::try_parse(remaining)?;
3311        let (size, remaining) = u16::try_parse(remaining)?;
3312        let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?;
3313        if response_type != 1 {
3314            return Err(ParseError::InvalidValue);
3315        }
3316        let result = GetCrtcGammaSizeReply { sequence, length, size };
3317        let _ = remaining;
3318        let remaining = initial_value.get(32 + length as usize * 4..)
3319            .ok_or(ParseError::InsufficientData)?;
3320        Ok((result, remaining))
3321    }
3322}
3323impl Serialize for GetCrtcGammaSizeReply {
3324    type Bytes = [u8; 32];
3325    fn serialize(&self) -> [u8; 32] {
3326        let response_type_bytes = &[1];
3327        let sequence_bytes = self.sequence.serialize();
3328        let length_bytes = self.length.serialize();
3329        let size_bytes = self.size.serialize();
3330        [
3331            response_type_bytes[0],
3332            0,
3333            sequence_bytes[0],
3334            sequence_bytes[1],
3335            length_bytes[0],
3336            length_bytes[1],
3337            length_bytes[2],
3338            length_bytes[3],
3339            size_bytes[0],
3340            size_bytes[1],
3341            0,
3342            0,
3343            0,
3344            0,
3345            0,
3346            0,
3347            0,
3348            0,
3349            0,
3350            0,
3351            0,
3352            0,
3353            0,
3354            0,
3355            0,
3356            0,
3357            0,
3358            0,
3359            0,
3360            0,
3361            0,
3362            0,
3363        ]
3364    }
3365    fn serialize_into(&self, bytes: &mut Vec<u8>) {
3366        bytes.reserve(32);
3367        let response_type_bytes = &[1];
3368        bytes.push(response_type_bytes[0]);
3369        bytes.extend_from_slice(&[0; 1]);
3370        self.sequence.serialize_into(bytes);
3371        self.length.serialize_into(bytes);
3372        self.size.serialize_into(bytes);
3373        bytes.extend_from_slice(&[0; 22]);
3374    }
3375}
3376
3377/// Opcode for the GetCrtcGamma request
3378pub const GET_CRTC_GAMMA_REQUEST: u8 = 23;
3379#[derive(Clone, Copy, Default)]
3380#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
3381#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3382pub struct GetCrtcGammaRequest {
3383    pub crtc: Crtc,
3384}
3385impl_debug_if_no_extra_traits!(GetCrtcGammaRequest, "GetCrtcGammaRequest");
3386impl GetCrtcGammaRequest {
3387    /// Serialize this request into bytes for the provided connection
3388    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
3389        let length_so_far = 0;
3390        let crtc_bytes = self.crtc.serialize();
3391        let mut request0 = vec![
3392            major_opcode,
3393            GET_CRTC_GAMMA_REQUEST,
3394            0,
3395            0,
3396            crtc_bytes[0],
3397            crtc_bytes[1],
3398            crtc_bytes[2],
3399            crtc_bytes[3],
3400        ];
3401        let length_so_far = length_so_far + request0.len();
3402        assert_eq!(length_so_far % 4, 0);
3403        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
3404        request0[2..4].copy_from_slice(&length.to_ne_bytes());
3405        ([request0.into()], vec![])
3406    }
3407    /// Parse this request given its header, its body, and any fds that go along with it
3408    #[cfg(feature = "request-parsing")]
3409    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
3410        if header.minor_opcode != GET_CRTC_GAMMA_REQUEST {
3411            return Err(ParseError::InvalidValue);
3412        }
3413        let (crtc, remaining) = Crtc::try_parse(value)?;
3414        let _ = remaining;
3415        Ok(GetCrtcGammaRequest {
3416            crtc,
3417        })
3418    }
3419}
3420impl Request for GetCrtcGammaRequest {
3421    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
3422
3423    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
3424        let (bufs, fds) = self.serialize(major_opcode);
3425        // Flatten the buffers into a single vector
3426        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
3427        (buf, fds)
3428    }
3429}
3430impl crate::x11_utils::ReplyRequest for GetCrtcGammaRequest {
3431    type Reply = GetCrtcGammaReply;
3432}
3433
3434#[derive(Clone, Default)]
3435#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
3436#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3437pub struct GetCrtcGammaReply {
3438    pub sequence: u16,
3439    pub length: u32,
3440    pub red: Vec<u16>,
3441    pub green: Vec<u16>,
3442    pub blue: Vec<u16>,
3443}
3444impl_debug_if_no_extra_traits!(GetCrtcGammaReply, "GetCrtcGammaReply");
3445impl TryParse for GetCrtcGammaReply {
3446    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3447        let remaining = initial_value;
3448        let (response_type, remaining) = u8::try_parse(remaining)?;
3449        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
3450        let (sequence, remaining) = u16::try_parse(remaining)?;
3451        let (length, remaining) = u32::try_parse(remaining)?;
3452        let (size, remaining) = u16::try_parse(remaining)?;
3453        let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?;
3454        let (red, remaining) = crate::x11_utils::parse_list::<u16>(remaining, size.try_to_usize()?)?;
3455        let (green, remaining) = crate::x11_utils::parse_list::<u16>(remaining, size.try_to_usize()?)?;
3456        let (blue, remaining) = crate::x11_utils::parse_list::<u16>(remaining, size.try_to_usize()?)?;
3457        if response_type != 1 {
3458            return Err(ParseError::InvalidValue);
3459        }
3460        let result = GetCrtcGammaReply { sequence, length, red, green, blue };
3461        let _ = remaining;
3462        let remaining = initial_value.get(32 + length as usize * 4..)
3463            .ok_or(ParseError::InsufficientData)?;
3464        Ok((result, remaining))
3465    }
3466}
3467impl Serialize for GetCrtcGammaReply {
3468    type Bytes = Vec<u8>;
3469    fn serialize(&self) -> Vec<u8> {
3470        let mut result = Vec::new();
3471        self.serialize_into(&mut result);
3472        result
3473    }
3474    fn serialize_into(&self, bytes: &mut Vec<u8>) {
3475        bytes.reserve(32);
3476        let response_type_bytes = &[1];
3477        bytes.push(response_type_bytes[0]);
3478        bytes.extend_from_slice(&[0; 1]);
3479        self.sequence.serialize_into(bytes);
3480        self.length.serialize_into(bytes);
3481        let size = u16::try_from(self.red.len()).expect("`red` has too many elements");
3482        size.serialize_into(bytes);
3483        bytes.extend_from_slice(&[0; 22]);
3484        self.red.serialize_into(bytes);
3485        assert_eq!(self.green.len(), usize::try_from(size).unwrap(), "`green` has an incorrect length");
3486        self.green.serialize_into(bytes);
3487        assert_eq!(self.blue.len(), usize::try_from(size).unwrap(), "`blue` has an incorrect length");
3488        self.blue.serialize_into(bytes);
3489    }
3490}
3491impl GetCrtcGammaReply {
3492    /// Get the value of the `size` field.
3493    ///
3494    /// The `size` field is used as the length field of the `red` field.
3495    /// This function computes the field's value again based on the length of the list.
3496    ///
3497    /// # Panics
3498    ///
3499    /// Panics if the value cannot be represented in the target type. This
3500    /// cannot happen with values of the struct received from the X11 server.
3501    pub fn size(&self) -> u16 {
3502        self.red.len()
3503            .try_into().unwrap()
3504    }
3505}
3506
3507/// Opcode for the SetCrtcGamma request
3508pub const SET_CRTC_GAMMA_REQUEST: u8 = 24;
3509#[derive(Clone, Default)]
3510#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
3511#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3512pub struct SetCrtcGammaRequest<'input> {
3513    pub crtc: Crtc,
3514    pub red: Cow<'input, [u16]>,
3515    pub green: Cow<'input, [u16]>,
3516    pub blue: Cow<'input, [u16]>,
3517}
3518impl_debug_if_no_extra_traits!(SetCrtcGammaRequest<'_>, "SetCrtcGammaRequest");
3519impl<'input> SetCrtcGammaRequest<'input> {
3520    /// Serialize this request into bytes for the provided connection
3521    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 5]> {
3522        let length_so_far = 0;
3523        let crtc_bytes = self.crtc.serialize();
3524        let size = u16::try_from(self.red.len()).expect("`red` has too many elements");
3525        let size_bytes = size.serialize();
3526        let mut request0 = vec![
3527            major_opcode,
3528            SET_CRTC_GAMMA_REQUEST,
3529            0,
3530            0,
3531            crtc_bytes[0],
3532            crtc_bytes[1],
3533            crtc_bytes[2],
3534            crtc_bytes[3],
3535            size_bytes[0],
3536            size_bytes[1],
3537            0,
3538            0,
3539        ];
3540        let length_so_far = length_so_far + request0.len();
3541        let red_bytes = self.red.serialize();
3542        let length_so_far = length_so_far + red_bytes.len();
3543        assert_eq!(self.green.len(), usize::try_from(size).unwrap(), "`green` has an incorrect length");
3544        let green_bytes = self.green.serialize();
3545        let length_so_far = length_so_far + green_bytes.len();
3546        assert_eq!(self.blue.len(), usize::try_from(size).unwrap(), "`blue` has an incorrect length");
3547        let blue_bytes = self.blue.serialize();
3548        let length_so_far = length_so_far + blue_bytes.len();
3549        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
3550        let length_so_far = length_so_far + padding0.len();
3551        assert_eq!(length_so_far % 4, 0);
3552        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
3553        request0[2..4].copy_from_slice(&length.to_ne_bytes());
3554        ([request0.into(), red_bytes.into(), green_bytes.into(), blue_bytes.into(), padding0.into()], vec![])
3555    }
3556    /// Parse this request given its header, its body, and any fds that go along with it
3557    #[cfg(feature = "request-parsing")]
3558    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
3559        if header.minor_opcode != SET_CRTC_GAMMA_REQUEST {
3560            return Err(ParseError::InvalidValue);
3561        }
3562        let (crtc, remaining) = Crtc::try_parse(value)?;
3563        let (size, remaining) = u16::try_parse(remaining)?;
3564        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
3565        let (red, remaining) = crate::x11_utils::parse_list::<u16>(remaining, size.try_to_usize()?)?;
3566        let (green, remaining) = crate::x11_utils::parse_list::<u16>(remaining, size.try_to_usize()?)?;
3567        let (blue, remaining) = crate::x11_utils::parse_list::<u16>(remaining, size.try_to_usize()?)?;
3568        let _ = remaining;
3569        Ok(SetCrtcGammaRequest {
3570            crtc,
3571            red: Cow::Owned(red),
3572            green: Cow::Owned(green),
3573            blue: Cow::Owned(blue),
3574        })
3575    }
3576    /// Clone all borrowed data in this SetCrtcGammaRequest.
3577    pub fn into_owned(self) -> SetCrtcGammaRequest<'static> {
3578        SetCrtcGammaRequest {
3579            crtc: self.crtc,
3580            red: Cow::Owned(self.red.into_owned()),
3581            green: Cow::Owned(self.green.into_owned()),
3582            blue: Cow::Owned(self.blue.into_owned()),
3583        }
3584    }
3585}
3586impl<'input> Request for SetCrtcGammaRequest<'input> {
3587    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
3588
3589    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
3590        let (bufs, fds) = self.serialize(major_opcode);
3591        // Flatten the buffers into a single vector
3592        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
3593        (buf, fds)
3594    }
3595}
3596impl<'input> crate::x11_utils::VoidRequest for SetCrtcGammaRequest<'input> {
3597}
3598
3599/// Opcode for the GetScreenResourcesCurrent request
3600pub const GET_SCREEN_RESOURCES_CURRENT_REQUEST: u8 = 25;
3601#[derive(Clone, Copy, Default)]
3602#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
3603#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3604pub struct GetScreenResourcesCurrentRequest {
3605    pub window: xproto::Window,
3606}
3607impl_debug_if_no_extra_traits!(GetScreenResourcesCurrentRequest, "GetScreenResourcesCurrentRequest");
3608impl GetScreenResourcesCurrentRequest {
3609    /// Serialize this request into bytes for the provided connection
3610    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
3611        let length_so_far = 0;
3612        let window_bytes = self.window.serialize();
3613        let mut request0 = vec![
3614            major_opcode,
3615            GET_SCREEN_RESOURCES_CURRENT_REQUEST,
3616            0,
3617            0,
3618            window_bytes[0],
3619            window_bytes[1],
3620            window_bytes[2],
3621            window_bytes[3],
3622        ];
3623        let length_so_far = length_so_far + request0.len();
3624        assert_eq!(length_so_far % 4, 0);
3625        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
3626        request0[2..4].copy_from_slice(&length.to_ne_bytes());
3627        ([request0.into()], vec![])
3628    }
3629    /// Parse this request given its header, its body, and any fds that go along with it
3630    #[cfg(feature = "request-parsing")]
3631    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
3632        if header.minor_opcode != GET_SCREEN_RESOURCES_CURRENT_REQUEST {
3633            return Err(ParseError::InvalidValue);
3634        }
3635        let (window, remaining) = xproto::Window::try_parse(value)?;
3636        let _ = remaining;
3637        Ok(GetScreenResourcesCurrentRequest {
3638            window,
3639        })
3640    }
3641}
3642impl Request for GetScreenResourcesCurrentRequest {
3643    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
3644
3645    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
3646        let (bufs, fds) = self.serialize(major_opcode);
3647        // Flatten the buffers into a single vector
3648        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
3649        (buf, fds)
3650    }
3651}
3652impl crate::x11_utils::ReplyRequest for GetScreenResourcesCurrentRequest {
3653    type Reply = GetScreenResourcesCurrentReply;
3654}
3655
3656#[derive(Clone, Default)]
3657#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
3658#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3659pub struct GetScreenResourcesCurrentReply {
3660    pub sequence: u16,
3661    pub length: u32,
3662    pub timestamp: xproto::Timestamp,
3663    pub config_timestamp: xproto::Timestamp,
3664    pub crtcs: Vec<Crtc>,
3665    pub outputs: Vec<Output>,
3666    pub modes: Vec<ModeInfo>,
3667    pub names: Vec<u8>,
3668}
3669impl_debug_if_no_extra_traits!(GetScreenResourcesCurrentReply, "GetScreenResourcesCurrentReply");
3670impl TryParse for GetScreenResourcesCurrentReply {
3671    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3672        let remaining = initial_value;
3673        let (response_type, remaining) = u8::try_parse(remaining)?;
3674        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
3675        let (sequence, remaining) = u16::try_parse(remaining)?;
3676        let (length, remaining) = u32::try_parse(remaining)?;
3677        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
3678        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
3679        let (num_crtcs, remaining) = u16::try_parse(remaining)?;
3680        let (num_outputs, remaining) = u16::try_parse(remaining)?;
3681        let (num_modes, remaining) = u16::try_parse(remaining)?;
3682        let (names_len, remaining) = u16::try_parse(remaining)?;
3683        let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?;
3684        let (crtcs, remaining) = crate::x11_utils::parse_list::<Crtc>(remaining, num_crtcs.try_to_usize()?)?;
3685        let (outputs, remaining) = crate::x11_utils::parse_list::<Output>(remaining, num_outputs.try_to_usize()?)?;
3686        let (modes, remaining) = crate::x11_utils::parse_list::<ModeInfo>(remaining, num_modes.try_to_usize()?)?;
3687        let (names, remaining) = crate::x11_utils::parse_u8_list(remaining, names_len.try_to_usize()?)?;
3688        let names = names.to_vec();
3689        if response_type != 1 {
3690            return Err(ParseError::InvalidValue);
3691        }
3692        let result = GetScreenResourcesCurrentReply { sequence, length, timestamp, config_timestamp, crtcs, outputs, modes, names };
3693        let _ = remaining;
3694        let remaining = initial_value.get(32 + length as usize * 4..)
3695            .ok_or(ParseError::InsufficientData)?;
3696        Ok((result, remaining))
3697    }
3698}
3699impl Serialize for GetScreenResourcesCurrentReply {
3700    type Bytes = Vec<u8>;
3701    fn serialize(&self) -> Vec<u8> {
3702        let mut result = Vec::new();
3703        self.serialize_into(&mut result);
3704        result
3705    }
3706    fn serialize_into(&self, bytes: &mut Vec<u8>) {
3707        bytes.reserve(32);
3708        let response_type_bytes = &[1];
3709        bytes.push(response_type_bytes[0]);
3710        bytes.extend_from_slice(&[0; 1]);
3711        self.sequence.serialize_into(bytes);
3712        self.length.serialize_into(bytes);
3713        self.timestamp.serialize_into(bytes);
3714        self.config_timestamp.serialize_into(bytes);
3715        let num_crtcs = u16::try_from(self.crtcs.len()).expect("`crtcs` has too many elements");
3716        num_crtcs.serialize_into(bytes);
3717        let num_outputs = u16::try_from(self.outputs.len()).expect("`outputs` has too many elements");
3718        num_outputs.serialize_into(bytes);
3719        let num_modes = u16::try_from(self.modes.len()).expect("`modes` has too many elements");
3720        num_modes.serialize_into(bytes);
3721        let names_len = u16::try_from(self.names.len()).expect("`names` has too many elements");
3722        names_len.serialize_into(bytes);
3723        bytes.extend_from_slice(&[0; 8]);
3724        self.crtcs.serialize_into(bytes);
3725        self.outputs.serialize_into(bytes);
3726        self.modes.serialize_into(bytes);
3727        bytes.extend_from_slice(&self.names);
3728    }
3729}
3730impl GetScreenResourcesCurrentReply {
3731    /// Get the value of the `num_crtcs` field.
3732    ///
3733    /// The `num_crtcs` field is used as the length field of the `crtcs` field.
3734    /// This function computes the field's value again based on the length of the list.
3735    ///
3736    /// # Panics
3737    ///
3738    /// Panics if the value cannot be represented in the target type. This
3739    /// cannot happen with values of the struct received from the X11 server.
3740    pub fn num_crtcs(&self) -> u16 {
3741        self.crtcs.len()
3742            .try_into().unwrap()
3743    }
3744    /// Get the value of the `num_outputs` field.
3745    ///
3746    /// The `num_outputs` field is used as the length field of the `outputs` field.
3747    /// This function computes the field's value again based on the length of the list.
3748    ///
3749    /// # Panics
3750    ///
3751    /// Panics if the value cannot be represented in the target type. This
3752    /// cannot happen with values of the struct received from the X11 server.
3753    pub fn num_outputs(&self) -> u16 {
3754        self.outputs.len()
3755            .try_into().unwrap()
3756    }
3757    /// Get the value of the `num_modes` field.
3758    ///
3759    /// The `num_modes` field is used as the length field of the `modes` field.
3760    /// This function computes the field's value again based on the length of the list.
3761    ///
3762    /// # Panics
3763    ///
3764    /// Panics if the value cannot be represented in the target type. This
3765    /// cannot happen with values of the struct received from the X11 server.
3766    pub fn num_modes(&self) -> u16 {
3767        self.modes.len()
3768            .try_into().unwrap()
3769    }
3770    /// Get the value of the `names_len` field.
3771    ///
3772    /// The `names_len` field is used as the length field of the `names` field.
3773    /// This function computes the field's value again based on the length of the list.
3774    ///
3775    /// # Panics
3776    ///
3777    /// Panics if the value cannot be represented in the target type. This
3778    /// cannot happen with values of the struct received from the X11 server.
3779    pub fn names_len(&self) -> u16 {
3780        self.names.len()
3781            .try_into().unwrap()
3782    }
3783}
3784
3785#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
3786#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3787pub struct Transform(u8);
3788impl Transform {
3789    pub const UNIT: Self = Self(1 << 0);
3790    pub const SCALE_UP: Self = Self(1 << 1);
3791    pub const SCALE_DOWN: Self = Self(1 << 2);
3792    pub const PROJECTIVE: Self = Self(1 << 3);
3793}
3794impl From<Transform> for u8 {
3795    #[inline]
3796    fn from(input: Transform) -> Self {
3797        input.0
3798    }
3799}
3800impl From<Transform> for Option<u8> {
3801    #[inline]
3802    fn from(input: Transform) -> Self {
3803        Some(input.0)
3804    }
3805}
3806impl From<Transform> for u16 {
3807    #[inline]
3808    fn from(input: Transform) -> Self {
3809        u16::from(input.0)
3810    }
3811}
3812impl From<Transform> for Option<u16> {
3813    #[inline]
3814    fn from(input: Transform) -> Self {
3815        Some(u16::from(input.0))
3816    }
3817}
3818impl From<Transform> for u32 {
3819    #[inline]
3820    fn from(input: Transform) -> Self {
3821        u32::from(input.0)
3822    }
3823}
3824impl From<Transform> for Option<u32> {
3825    #[inline]
3826    fn from(input: Transform) -> Self {
3827        Some(u32::from(input.0))
3828    }
3829}
3830impl From<u8> for Transform {
3831    #[inline]
3832    fn from(value: u8) -> Self {
3833        Self(value)
3834    }
3835}
3836impl core::fmt::Debug for Transform  {
3837    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
3838        let variants = [
3839            (Self::UNIT.0.into(), "UNIT", "Unit"),
3840            (Self::SCALE_UP.0.into(), "SCALE_UP", "ScaleUp"),
3841            (Self::SCALE_DOWN.0.into(), "SCALE_DOWN", "ScaleDown"),
3842            (Self::PROJECTIVE.0.into(), "PROJECTIVE", "Projective"),
3843        ];
3844        pretty_print_bitmask(fmt, self.0.into(), &variants)
3845    }
3846}
3847bitmask_binop!(Transform, u8);
3848
3849/// Opcode for the SetCrtcTransform request
3850pub const SET_CRTC_TRANSFORM_REQUEST: u8 = 26;
3851#[derive(Clone, Default)]
3852#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
3853#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3854pub struct SetCrtcTransformRequest<'input> {
3855    pub crtc: Crtc,
3856    pub transform: render::Transform,
3857    pub filter_name: Cow<'input, [u8]>,
3858    pub filter_params: Cow<'input, [render::Fixed]>,
3859}
3860impl_debug_if_no_extra_traits!(SetCrtcTransformRequest<'_>, "SetCrtcTransformRequest");
3861impl<'input> SetCrtcTransformRequest<'input> {
3862    /// Serialize this request into bytes for the provided connection
3863    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 5]> {
3864        let length_so_far = 0;
3865        let crtc_bytes = self.crtc.serialize();
3866        let transform_bytes = self.transform.serialize();
3867        let filter_len = u16::try_from(self.filter_name.len()).expect("`filter_name` has too many elements");
3868        let filter_len_bytes = filter_len.serialize();
3869        let mut request0 = vec![
3870            major_opcode,
3871            SET_CRTC_TRANSFORM_REQUEST,
3872            0,
3873            0,
3874            crtc_bytes[0],
3875            crtc_bytes[1],
3876            crtc_bytes[2],
3877            crtc_bytes[3],
3878            transform_bytes[0],
3879            transform_bytes[1],
3880            transform_bytes[2],
3881            transform_bytes[3],
3882            transform_bytes[4],
3883            transform_bytes[5],
3884            transform_bytes[6],
3885            transform_bytes[7],
3886            transform_bytes[8],
3887            transform_bytes[9],
3888            transform_bytes[10],
3889            transform_bytes[11],
3890            transform_bytes[12],
3891            transform_bytes[13],
3892            transform_bytes[14],
3893            transform_bytes[15],
3894            transform_bytes[16],
3895            transform_bytes[17],
3896            transform_bytes[18],
3897            transform_bytes[19],
3898            transform_bytes[20],
3899            transform_bytes[21],
3900            transform_bytes[22],
3901            transform_bytes[23],
3902            transform_bytes[24],
3903            transform_bytes[25],
3904            transform_bytes[26],
3905            transform_bytes[27],
3906            transform_bytes[28],
3907            transform_bytes[29],
3908            transform_bytes[30],
3909            transform_bytes[31],
3910            transform_bytes[32],
3911            transform_bytes[33],
3912            transform_bytes[34],
3913            transform_bytes[35],
3914            filter_len_bytes[0],
3915            filter_len_bytes[1],
3916            0,
3917            0,
3918        ];
3919        let length_so_far = length_so_far + request0.len();
3920        let length_so_far = length_so_far + self.filter_name.len();
3921        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
3922        let length_so_far = length_so_far + padding0.len();
3923        let filter_params_bytes = self.filter_params.serialize();
3924        let length_so_far = length_so_far + filter_params_bytes.len();
3925        let padding1 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
3926        let length_so_far = length_so_far + padding1.len();
3927        assert_eq!(length_so_far % 4, 0);
3928        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
3929        request0[2..4].copy_from_slice(&length.to_ne_bytes());
3930        ([request0.into(), self.filter_name, padding0.into(), filter_params_bytes.into(), padding1.into()], vec![])
3931    }
3932    /// Parse this request given its header, its body, and any fds that go along with it
3933    #[cfg(feature = "request-parsing")]
3934    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
3935        if header.minor_opcode != SET_CRTC_TRANSFORM_REQUEST {
3936            return Err(ParseError::InvalidValue);
3937        }
3938        let (crtc, remaining) = Crtc::try_parse(value)?;
3939        let (transform, remaining) = render::Transform::try_parse(remaining)?;
3940        let (filter_len, remaining) = u16::try_parse(remaining)?;
3941        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
3942        let (filter_name, remaining) = crate::x11_utils::parse_u8_list(remaining, filter_len.try_to_usize()?)?;
3943        // Align offset to multiple of 4
3944        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
3945        let misalignment = (4 - (offset % 4)) % 4;
3946        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
3947        let mut remaining = remaining;
3948        // Length is 'everything left in the input'
3949        let mut filter_params = Vec::new();
3950        while !remaining.is_empty() {
3951            let (v, new_remaining) = render::Fixed::try_parse(remaining)?;
3952            remaining = new_remaining;
3953            filter_params.push(v);
3954        }
3955        let _ = remaining;
3956        Ok(SetCrtcTransformRequest {
3957            crtc,
3958            transform,
3959            filter_name: Cow::Borrowed(filter_name),
3960            filter_params: Cow::Owned(filter_params),
3961        })
3962    }
3963    /// Clone all borrowed data in this SetCrtcTransformRequest.
3964    pub fn into_owned(self) -> SetCrtcTransformRequest<'static> {
3965        SetCrtcTransformRequest {
3966            crtc: self.crtc,
3967            transform: self.transform,
3968            filter_name: Cow::Owned(self.filter_name.into_owned()),
3969            filter_params: Cow::Owned(self.filter_params.into_owned()),
3970        }
3971    }
3972}
3973impl<'input> Request for SetCrtcTransformRequest<'input> {
3974    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
3975
3976    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
3977        let (bufs, fds) = self.serialize(major_opcode);
3978        // Flatten the buffers into a single vector
3979        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
3980        (buf, fds)
3981    }
3982}
3983impl<'input> crate::x11_utils::VoidRequest for SetCrtcTransformRequest<'input> {
3984}
3985
3986/// Opcode for the GetCrtcTransform request
3987pub const GET_CRTC_TRANSFORM_REQUEST: u8 = 27;
3988#[derive(Clone, Copy, Default)]
3989#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
3990#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
3991pub struct GetCrtcTransformRequest {
3992    pub crtc: Crtc,
3993}
3994impl_debug_if_no_extra_traits!(GetCrtcTransformRequest, "GetCrtcTransformRequest");
3995impl GetCrtcTransformRequest {
3996    /// Serialize this request into bytes for the provided connection
3997    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
3998        let length_so_far = 0;
3999        let crtc_bytes = self.crtc.serialize();
4000        let mut request0 = vec![
4001            major_opcode,
4002            GET_CRTC_TRANSFORM_REQUEST,
4003            0,
4004            0,
4005            crtc_bytes[0],
4006            crtc_bytes[1],
4007            crtc_bytes[2],
4008            crtc_bytes[3],
4009        ];
4010        let length_so_far = length_so_far + request0.len();
4011        assert_eq!(length_so_far % 4, 0);
4012        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
4013        request0[2..4].copy_from_slice(&length.to_ne_bytes());
4014        ([request0.into()], vec![])
4015    }
4016    /// Parse this request given its header, its body, and any fds that go along with it
4017    #[cfg(feature = "request-parsing")]
4018    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
4019        if header.minor_opcode != GET_CRTC_TRANSFORM_REQUEST {
4020            return Err(ParseError::InvalidValue);
4021        }
4022        let (crtc, remaining) = Crtc::try_parse(value)?;
4023        let _ = remaining;
4024        Ok(GetCrtcTransformRequest {
4025            crtc,
4026        })
4027    }
4028}
4029impl Request for GetCrtcTransformRequest {
4030    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
4031
4032    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
4033        let (bufs, fds) = self.serialize(major_opcode);
4034        // Flatten the buffers into a single vector
4035        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
4036        (buf, fds)
4037    }
4038}
4039impl crate::x11_utils::ReplyRequest for GetCrtcTransformRequest {
4040    type Reply = GetCrtcTransformReply;
4041}
4042
4043#[derive(Clone, Default)]
4044#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
4045#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4046pub struct GetCrtcTransformReply {
4047    pub sequence: u16,
4048    pub length: u32,
4049    pub pending_transform: render::Transform,
4050    pub has_transforms: bool,
4051    pub current_transform: render::Transform,
4052    pub pending_filter_name: Vec<u8>,
4053    pub pending_params: Vec<render::Fixed>,
4054    pub current_filter_name: Vec<u8>,
4055    pub current_params: Vec<render::Fixed>,
4056}
4057impl_debug_if_no_extra_traits!(GetCrtcTransformReply, "GetCrtcTransformReply");
4058impl TryParse for GetCrtcTransformReply {
4059    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4060        let remaining = initial_value;
4061        let value = remaining;
4062        let (response_type, remaining) = u8::try_parse(remaining)?;
4063        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
4064        let (sequence, remaining) = u16::try_parse(remaining)?;
4065        let (length, remaining) = u32::try_parse(remaining)?;
4066        let (pending_transform, remaining) = render::Transform::try_parse(remaining)?;
4067        let (has_transforms, remaining) = bool::try_parse(remaining)?;
4068        let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
4069        let (current_transform, remaining) = render::Transform::try_parse(remaining)?;
4070        let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?;
4071        let (pending_len, remaining) = u16::try_parse(remaining)?;
4072        let (pending_nparams, remaining) = u16::try_parse(remaining)?;
4073        let (current_len, remaining) = u16::try_parse(remaining)?;
4074        let (current_nparams, remaining) = u16::try_parse(remaining)?;
4075        let (pending_filter_name, remaining) = crate::x11_utils::parse_u8_list(remaining, pending_len.try_to_usize()?)?;
4076        let pending_filter_name = pending_filter_name.to_vec();
4077        // Align offset to multiple of 4
4078        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
4079        let misalignment = (4 - (offset % 4)) % 4;
4080        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
4081        let (pending_params, remaining) = crate::x11_utils::parse_list::<render::Fixed>(remaining, pending_nparams.try_to_usize()?)?;
4082        let (current_filter_name, remaining) = crate::x11_utils::parse_u8_list(remaining, current_len.try_to_usize()?)?;
4083        let current_filter_name = current_filter_name.to_vec();
4084        // Align offset to multiple of 4
4085        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
4086        let misalignment = (4 - (offset % 4)) % 4;
4087        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
4088        let (current_params, remaining) = crate::x11_utils::parse_list::<render::Fixed>(remaining, current_nparams.try_to_usize()?)?;
4089        if response_type != 1 {
4090            return Err(ParseError::InvalidValue);
4091        }
4092        let result = GetCrtcTransformReply { sequence, length, pending_transform, has_transforms, current_transform, pending_filter_name, pending_params, current_filter_name, current_params };
4093        let _ = remaining;
4094        let remaining = initial_value.get(32 + length as usize * 4..)
4095            .ok_or(ParseError::InsufficientData)?;
4096        Ok((result, remaining))
4097    }
4098}
4099impl Serialize for GetCrtcTransformReply {
4100    type Bytes = Vec<u8>;
4101    fn serialize(&self) -> Vec<u8> {
4102        let mut result = Vec::new();
4103        self.serialize_into(&mut result);
4104        result
4105    }
4106    fn serialize_into(&self, bytes: &mut Vec<u8>) {
4107        bytes.reserve(96);
4108        let response_type_bytes = &[1];
4109        bytes.push(response_type_bytes[0]);
4110        bytes.extend_from_slice(&[0; 1]);
4111        self.sequence.serialize_into(bytes);
4112        self.length.serialize_into(bytes);
4113        self.pending_transform.serialize_into(bytes);
4114        self.has_transforms.serialize_into(bytes);
4115        bytes.extend_from_slice(&[0; 3]);
4116        self.current_transform.serialize_into(bytes);
4117        bytes.extend_from_slice(&[0; 4]);
4118        let pending_len = u16::try_from(self.pending_filter_name.len()).expect("`pending_filter_name` has too many elements");
4119        pending_len.serialize_into(bytes);
4120        let pending_nparams = u16::try_from(self.pending_params.len()).expect("`pending_params` has too many elements");
4121        pending_nparams.serialize_into(bytes);
4122        let current_len = u16::try_from(self.current_filter_name.len()).expect("`current_filter_name` has too many elements");
4123        current_len.serialize_into(bytes);
4124        let current_nparams = u16::try_from(self.current_params.len()).expect("`current_params` has too many elements");
4125        current_nparams.serialize_into(bytes);
4126        bytes.extend_from_slice(&self.pending_filter_name);
4127        bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]);
4128        self.pending_params.serialize_into(bytes);
4129        bytes.extend_from_slice(&self.current_filter_name);
4130        bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]);
4131        self.current_params.serialize_into(bytes);
4132    }
4133}
4134impl GetCrtcTransformReply {
4135    /// Get the value of the `pending_len` field.
4136    ///
4137    /// The `pending_len` field is used as the length field of the `pending_filter_name` field.
4138    /// This function computes the field's value again based on the length of the list.
4139    ///
4140    /// # Panics
4141    ///
4142    /// Panics if the value cannot be represented in the target type. This
4143    /// cannot happen with values of the struct received from the X11 server.
4144    pub fn pending_len(&self) -> u16 {
4145        self.pending_filter_name.len()
4146            .try_into().unwrap()
4147    }
4148    /// Get the value of the `pending_nparams` field.
4149    ///
4150    /// The `pending_nparams` field is used as the length field of the `pending_params` field.
4151    /// This function computes the field's value again based on the length of the list.
4152    ///
4153    /// # Panics
4154    ///
4155    /// Panics if the value cannot be represented in the target type. This
4156    /// cannot happen with values of the struct received from the X11 server.
4157    pub fn pending_nparams(&self) -> u16 {
4158        self.pending_params.len()
4159            .try_into().unwrap()
4160    }
4161    /// Get the value of the `current_len` field.
4162    ///
4163    /// The `current_len` field is used as the length field of the `current_filter_name` field.
4164    /// This function computes the field's value again based on the length of the list.
4165    ///
4166    /// # Panics
4167    ///
4168    /// Panics if the value cannot be represented in the target type. This
4169    /// cannot happen with values of the struct received from the X11 server.
4170    pub fn current_len(&self) -> u16 {
4171        self.current_filter_name.len()
4172            .try_into().unwrap()
4173    }
4174    /// Get the value of the `current_nparams` field.
4175    ///
4176    /// The `current_nparams` field is used as the length field of the `current_params` field.
4177    /// This function computes the field's value again based on the length of the list.
4178    ///
4179    /// # Panics
4180    ///
4181    /// Panics if the value cannot be represented in the target type. This
4182    /// cannot happen with values of the struct received from the X11 server.
4183    pub fn current_nparams(&self) -> u16 {
4184        self.current_params.len()
4185            .try_into().unwrap()
4186    }
4187}
4188
4189/// Opcode for the GetPanning request
4190pub const GET_PANNING_REQUEST: u8 = 28;
4191#[derive(Clone, Copy, Default)]
4192#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
4193#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4194pub struct GetPanningRequest {
4195    pub crtc: Crtc,
4196}
4197impl_debug_if_no_extra_traits!(GetPanningRequest, "GetPanningRequest");
4198impl GetPanningRequest {
4199    /// Serialize this request into bytes for the provided connection
4200    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
4201        let length_so_far = 0;
4202        let crtc_bytes = self.crtc.serialize();
4203        let mut request0 = vec![
4204            major_opcode,
4205            GET_PANNING_REQUEST,
4206            0,
4207            0,
4208            crtc_bytes[0],
4209            crtc_bytes[1],
4210            crtc_bytes[2],
4211            crtc_bytes[3],
4212        ];
4213        let length_so_far = length_so_far + request0.len();
4214        assert_eq!(length_so_far % 4, 0);
4215        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
4216        request0[2..4].copy_from_slice(&length.to_ne_bytes());
4217        ([request0.into()], vec![])
4218    }
4219    /// Parse this request given its header, its body, and any fds that go along with it
4220    #[cfg(feature = "request-parsing")]
4221    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
4222        if header.minor_opcode != GET_PANNING_REQUEST {
4223            return Err(ParseError::InvalidValue);
4224        }
4225        let (crtc, remaining) = Crtc::try_parse(value)?;
4226        let _ = remaining;
4227        Ok(GetPanningRequest {
4228            crtc,
4229        })
4230    }
4231}
4232impl Request for GetPanningRequest {
4233    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
4234
4235    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
4236        let (bufs, fds) = self.serialize(major_opcode);
4237        // Flatten the buffers into a single vector
4238        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
4239        (buf, fds)
4240    }
4241}
4242impl crate::x11_utils::ReplyRequest for GetPanningRequest {
4243    type Reply = GetPanningReply;
4244}
4245
4246#[derive(Clone, Copy, Default)]
4247#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
4248#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4249pub struct GetPanningReply {
4250    pub status: SetConfig,
4251    pub sequence: u16,
4252    pub length: u32,
4253    pub timestamp: xproto::Timestamp,
4254    pub left: u16,
4255    pub top: u16,
4256    pub width: u16,
4257    pub height: u16,
4258    pub track_left: u16,
4259    pub track_top: u16,
4260    pub track_width: u16,
4261    pub track_height: u16,
4262    pub border_left: i16,
4263    pub border_top: i16,
4264    pub border_right: i16,
4265    pub border_bottom: i16,
4266}
4267impl_debug_if_no_extra_traits!(GetPanningReply, "GetPanningReply");
4268impl TryParse for GetPanningReply {
4269    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4270        let remaining = initial_value;
4271        let (response_type, remaining) = u8::try_parse(remaining)?;
4272        let (status, remaining) = u8::try_parse(remaining)?;
4273        let (sequence, remaining) = u16::try_parse(remaining)?;
4274        let (length, remaining) = u32::try_parse(remaining)?;
4275        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
4276        let (left, remaining) = u16::try_parse(remaining)?;
4277        let (top, remaining) = u16::try_parse(remaining)?;
4278        let (width, remaining) = u16::try_parse(remaining)?;
4279        let (height, remaining) = u16::try_parse(remaining)?;
4280        let (track_left, remaining) = u16::try_parse(remaining)?;
4281        let (track_top, remaining) = u16::try_parse(remaining)?;
4282        let (track_width, remaining) = u16::try_parse(remaining)?;
4283        let (track_height, remaining) = u16::try_parse(remaining)?;
4284        let (border_left, remaining) = i16::try_parse(remaining)?;
4285        let (border_top, remaining) = i16::try_parse(remaining)?;
4286        let (border_right, remaining) = i16::try_parse(remaining)?;
4287        let (border_bottom, remaining) = i16::try_parse(remaining)?;
4288        if response_type != 1 {
4289            return Err(ParseError::InvalidValue);
4290        }
4291        let status = status.into();
4292        let result = GetPanningReply { status, sequence, length, timestamp, left, top, width, height, track_left, track_top, track_width, track_height, border_left, border_top, border_right, border_bottom };
4293        let _ = remaining;
4294        let remaining = initial_value.get(32 + length as usize * 4..)
4295            .ok_or(ParseError::InsufficientData)?;
4296        Ok((result, remaining))
4297    }
4298}
4299impl Serialize for GetPanningReply {
4300    type Bytes = [u8; 36];
4301    fn serialize(&self) -> [u8; 36] {
4302        let response_type_bytes = &[1];
4303        let status_bytes = u8::from(self.status).serialize();
4304        let sequence_bytes = self.sequence.serialize();
4305        let length_bytes = self.length.serialize();
4306        let timestamp_bytes = self.timestamp.serialize();
4307        let left_bytes = self.left.serialize();
4308        let top_bytes = self.top.serialize();
4309        let width_bytes = self.width.serialize();
4310        let height_bytes = self.height.serialize();
4311        let track_left_bytes = self.track_left.serialize();
4312        let track_top_bytes = self.track_top.serialize();
4313        let track_width_bytes = self.track_width.serialize();
4314        let track_height_bytes = self.track_height.serialize();
4315        let border_left_bytes = self.border_left.serialize();
4316        let border_top_bytes = self.border_top.serialize();
4317        let border_right_bytes = self.border_right.serialize();
4318        let border_bottom_bytes = self.border_bottom.serialize();
4319        [
4320            response_type_bytes[0],
4321            status_bytes[0],
4322            sequence_bytes[0],
4323            sequence_bytes[1],
4324            length_bytes[0],
4325            length_bytes[1],
4326            length_bytes[2],
4327            length_bytes[3],
4328            timestamp_bytes[0],
4329            timestamp_bytes[1],
4330            timestamp_bytes[2],
4331            timestamp_bytes[3],
4332            left_bytes[0],
4333            left_bytes[1],
4334            top_bytes[0],
4335            top_bytes[1],
4336            width_bytes[0],
4337            width_bytes[1],
4338            height_bytes[0],
4339            height_bytes[1],
4340            track_left_bytes[0],
4341            track_left_bytes[1],
4342            track_top_bytes[0],
4343            track_top_bytes[1],
4344            track_width_bytes[0],
4345            track_width_bytes[1],
4346            track_height_bytes[0],
4347            track_height_bytes[1],
4348            border_left_bytes[0],
4349            border_left_bytes[1],
4350            border_top_bytes[0],
4351            border_top_bytes[1],
4352            border_right_bytes[0],
4353            border_right_bytes[1],
4354            border_bottom_bytes[0],
4355            border_bottom_bytes[1],
4356        ]
4357    }
4358    fn serialize_into(&self, bytes: &mut Vec<u8>) {
4359        bytes.reserve(36);
4360        let response_type_bytes = &[1];
4361        bytes.push(response_type_bytes[0]);
4362        u8::from(self.status).serialize_into(bytes);
4363        self.sequence.serialize_into(bytes);
4364        self.length.serialize_into(bytes);
4365        self.timestamp.serialize_into(bytes);
4366        self.left.serialize_into(bytes);
4367        self.top.serialize_into(bytes);
4368        self.width.serialize_into(bytes);
4369        self.height.serialize_into(bytes);
4370        self.track_left.serialize_into(bytes);
4371        self.track_top.serialize_into(bytes);
4372        self.track_width.serialize_into(bytes);
4373        self.track_height.serialize_into(bytes);
4374        self.border_left.serialize_into(bytes);
4375        self.border_top.serialize_into(bytes);
4376        self.border_right.serialize_into(bytes);
4377        self.border_bottom.serialize_into(bytes);
4378    }
4379}
4380
4381/// Opcode for the SetPanning request
4382pub const SET_PANNING_REQUEST: u8 = 29;
4383#[derive(Clone, Copy, Default)]
4384#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
4385#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4386pub struct SetPanningRequest {
4387    pub crtc: Crtc,
4388    pub timestamp: xproto::Timestamp,
4389    pub left: u16,
4390    pub top: u16,
4391    pub width: u16,
4392    pub height: u16,
4393    pub track_left: u16,
4394    pub track_top: u16,
4395    pub track_width: u16,
4396    pub track_height: u16,
4397    pub border_left: i16,
4398    pub border_top: i16,
4399    pub border_right: i16,
4400    pub border_bottom: i16,
4401}
4402impl_debug_if_no_extra_traits!(SetPanningRequest, "SetPanningRequest");
4403impl SetPanningRequest {
4404    /// Serialize this request into bytes for the provided connection
4405    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
4406        let length_so_far = 0;
4407        let crtc_bytes = self.crtc.serialize();
4408        let timestamp_bytes = self.timestamp.serialize();
4409        let left_bytes = self.left.serialize();
4410        let top_bytes = self.top.serialize();
4411        let width_bytes = self.width.serialize();
4412        let height_bytes = self.height.serialize();
4413        let track_left_bytes = self.track_left.serialize();
4414        let track_top_bytes = self.track_top.serialize();
4415        let track_width_bytes = self.track_width.serialize();
4416        let track_height_bytes = self.track_height.serialize();
4417        let border_left_bytes = self.border_left.serialize();
4418        let border_top_bytes = self.border_top.serialize();
4419        let border_right_bytes = self.border_right.serialize();
4420        let border_bottom_bytes = self.border_bottom.serialize();
4421        let mut request0 = vec![
4422            major_opcode,
4423            SET_PANNING_REQUEST,
4424            0,
4425            0,
4426            crtc_bytes[0],
4427            crtc_bytes[1],
4428            crtc_bytes[2],
4429            crtc_bytes[3],
4430            timestamp_bytes[0],
4431            timestamp_bytes[1],
4432            timestamp_bytes[2],
4433            timestamp_bytes[3],
4434            left_bytes[0],
4435            left_bytes[1],
4436            top_bytes[0],
4437            top_bytes[1],
4438            width_bytes[0],
4439            width_bytes[1],
4440            height_bytes[0],
4441            height_bytes[1],
4442            track_left_bytes[0],
4443            track_left_bytes[1],
4444            track_top_bytes[0],
4445            track_top_bytes[1],
4446            track_width_bytes[0],
4447            track_width_bytes[1],
4448            track_height_bytes[0],
4449            track_height_bytes[1],
4450            border_left_bytes[0],
4451            border_left_bytes[1],
4452            border_top_bytes[0],
4453            border_top_bytes[1],
4454            border_right_bytes[0],
4455            border_right_bytes[1],
4456            border_bottom_bytes[0],
4457            border_bottom_bytes[1],
4458        ];
4459        let length_so_far = length_so_far + request0.len();
4460        assert_eq!(length_so_far % 4, 0);
4461        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
4462        request0[2..4].copy_from_slice(&length.to_ne_bytes());
4463        ([request0.into()], vec![])
4464    }
4465    /// Parse this request given its header, its body, and any fds that go along with it
4466    #[cfg(feature = "request-parsing")]
4467    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
4468        if header.minor_opcode != SET_PANNING_REQUEST {
4469            return Err(ParseError::InvalidValue);
4470        }
4471        let (crtc, remaining) = Crtc::try_parse(value)?;
4472        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
4473        let (left, remaining) = u16::try_parse(remaining)?;
4474        let (top, remaining) = u16::try_parse(remaining)?;
4475        let (width, remaining) = u16::try_parse(remaining)?;
4476        let (height, remaining) = u16::try_parse(remaining)?;
4477        let (track_left, remaining) = u16::try_parse(remaining)?;
4478        let (track_top, remaining) = u16::try_parse(remaining)?;
4479        let (track_width, remaining) = u16::try_parse(remaining)?;
4480        let (track_height, remaining) = u16::try_parse(remaining)?;
4481        let (border_left, remaining) = i16::try_parse(remaining)?;
4482        let (border_top, remaining) = i16::try_parse(remaining)?;
4483        let (border_right, remaining) = i16::try_parse(remaining)?;
4484        let (border_bottom, remaining) = i16::try_parse(remaining)?;
4485        let _ = remaining;
4486        Ok(SetPanningRequest {
4487            crtc,
4488            timestamp,
4489            left,
4490            top,
4491            width,
4492            height,
4493            track_left,
4494            track_top,
4495            track_width,
4496            track_height,
4497            border_left,
4498            border_top,
4499            border_right,
4500            border_bottom,
4501        })
4502    }
4503}
4504impl Request for SetPanningRequest {
4505    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
4506
4507    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
4508        let (bufs, fds) = self.serialize(major_opcode);
4509        // Flatten the buffers into a single vector
4510        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
4511        (buf, fds)
4512    }
4513}
4514impl crate::x11_utils::ReplyRequest for SetPanningRequest {
4515    type Reply = SetPanningReply;
4516}
4517
4518#[derive(Clone, Copy, Default)]
4519#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
4520#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4521pub struct SetPanningReply {
4522    pub status: SetConfig,
4523    pub sequence: u16,
4524    pub length: u32,
4525    pub timestamp: xproto::Timestamp,
4526}
4527impl_debug_if_no_extra_traits!(SetPanningReply, "SetPanningReply");
4528impl TryParse for SetPanningReply {
4529    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4530        let remaining = initial_value;
4531        let (response_type, remaining) = u8::try_parse(remaining)?;
4532        let (status, remaining) = u8::try_parse(remaining)?;
4533        let (sequence, remaining) = u16::try_parse(remaining)?;
4534        let (length, remaining) = u32::try_parse(remaining)?;
4535        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
4536        if response_type != 1 {
4537            return Err(ParseError::InvalidValue);
4538        }
4539        let status = status.into();
4540        let result = SetPanningReply { status, sequence, length, timestamp };
4541        let _ = remaining;
4542        let remaining = initial_value.get(32 + length as usize * 4..)
4543            .ok_or(ParseError::InsufficientData)?;
4544        Ok((result, remaining))
4545    }
4546}
4547impl Serialize for SetPanningReply {
4548    type Bytes = [u8; 12];
4549    fn serialize(&self) -> [u8; 12] {
4550        let response_type_bytes = &[1];
4551        let status_bytes = u8::from(self.status).serialize();
4552        let sequence_bytes = self.sequence.serialize();
4553        let length_bytes = self.length.serialize();
4554        let timestamp_bytes = self.timestamp.serialize();
4555        [
4556            response_type_bytes[0],
4557            status_bytes[0],
4558            sequence_bytes[0],
4559            sequence_bytes[1],
4560            length_bytes[0],
4561            length_bytes[1],
4562            length_bytes[2],
4563            length_bytes[3],
4564            timestamp_bytes[0],
4565            timestamp_bytes[1],
4566            timestamp_bytes[2],
4567            timestamp_bytes[3],
4568        ]
4569    }
4570    fn serialize_into(&self, bytes: &mut Vec<u8>) {
4571        bytes.reserve(12);
4572        let response_type_bytes = &[1];
4573        bytes.push(response_type_bytes[0]);
4574        u8::from(self.status).serialize_into(bytes);
4575        self.sequence.serialize_into(bytes);
4576        self.length.serialize_into(bytes);
4577        self.timestamp.serialize_into(bytes);
4578    }
4579}
4580
4581/// Opcode for the SetOutputPrimary request
4582pub const SET_OUTPUT_PRIMARY_REQUEST: u8 = 30;
4583#[derive(Clone, Copy, Default)]
4584#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
4585#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4586pub struct SetOutputPrimaryRequest {
4587    pub window: xproto::Window,
4588    pub output: Output,
4589}
4590impl_debug_if_no_extra_traits!(SetOutputPrimaryRequest, "SetOutputPrimaryRequest");
4591impl SetOutputPrimaryRequest {
4592    /// Serialize this request into bytes for the provided connection
4593    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
4594        let length_so_far = 0;
4595        let window_bytes = self.window.serialize();
4596        let output_bytes = self.output.serialize();
4597        let mut request0 = vec![
4598            major_opcode,
4599            SET_OUTPUT_PRIMARY_REQUEST,
4600            0,
4601            0,
4602            window_bytes[0],
4603            window_bytes[1],
4604            window_bytes[2],
4605            window_bytes[3],
4606            output_bytes[0],
4607            output_bytes[1],
4608            output_bytes[2],
4609            output_bytes[3],
4610        ];
4611        let length_so_far = length_so_far + request0.len();
4612        assert_eq!(length_so_far % 4, 0);
4613        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
4614        request0[2..4].copy_from_slice(&length.to_ne_bytes());
4615        ([request0.into()], vec![])
4616    }
4617    /// Parse this request given its header, its body, and any fds that go along with it
4618    #[cfg(feature = "request-parsing")]
4619    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
4620        if header.minor_opcode != SET_OUTPUT_PRIMARY_REQUEST {
4621            return Err(ParseError::InvalidValue);
4622        }
4623        let (window, remaining) = xproto::Window::try_parse(value)?;
4624        let (output, remaining) = Output::try_parse(remaining)?;
4625        let _ = remaining;
4626        Ok(SetOutputPrimaryRequest {
4627            window,
4628            output,
4629        })
4630    }
4631}
4632impl Request for SetOutputPrimaryRequest {
4633    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
4634
4635    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
4636        let (bufs, fds) = self.serialize(major_opcode);
4637        // Flatten the buffers into a single vector
4638        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
4639        (buf, fds)
4640    }
4641}
4642impl crate::x11_utils::VoidRequest for SetOutputPrimaryRequest {
4643}
4644
4645/// Opcode for the GetOutputPrimary request
4646pub const GET_OUTPUT_PRIMARY_REQUEST: u8 = 31;
4647#[derive(Clone, Copy, Default)]
4648#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
4649#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4650pub struct GetOutputPrimaryRequest {
4651    pub window: xproto::Window,
4652}
4653impl_debug_if_no_extra_traits!(GetOutputPrimaryRequest, "GetOutputPrimaryRequest");
4654impl GetOutputPrimaryRequest {
4655    /// Serialize this request into bytes for the provided connection
4656    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
4657        let length_so_far = 0;
4658        let window_bytes = self.window.serialize();
4659        let mut request0 = vec![
4660            major_opcode,
4661            GET_OUTPUT_PRIMARY_REQUEST,
4662            0,
4663            0,
4664            window_bytes[0],
4665            window_bytes[1],
4666            window_bytes[2],
4667            window_bytes[3],
4668        ];
4669        let length_so_far = length_so_far + request0.len();
4670        assert_eq!(length_so_far % 4, 0);
4671        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
4672        request0[2..4].copy_from_slice(&length.to_ne_bytes());
4673        ([request0.into()], vec![])
4674    }
4675    /// Parse this request given its header, its body, and any fds that go along with it
4676    #[cfg(feature = "request-parsing")]
4677    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
4678        if header.minor_opcode != GET_OUTPUT_PRIMARY_REQUEST {
4679            return Err(ParseError::InvalidValue);
4680        }
4681        let (window, remaining) = xproto::Window::try_parse(value)?;
4682        let _ = remaining;
4683        Ok(GetOutputPrimaryRequest {
4684            window,
4685        })
4686    }
4687}
4688impl Request for GetOutputPrimaryRequest {
4689    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
4690
4691    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
4692        let (bufs, fds) = self.serialize(major_opcode);
4693        // Flatten the buffers into a single vector
4694        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
4695        (buf, fds)
4696    }
4697}
4698impl crate::x11_utils::ReplyRequest for GetOutputPrimaryRequest {
4699    type Reply = GetOutputPrimaryReply;
4700}
4701
4702#[derive(Clone, Copy, Default)]
4703#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
4704#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4705pub struct GetOutputPrimaryReply {
4706    pub sequence: u16,
4707    pub length: u32,
4708    pub output: Output,
4709}
4710impl_debug_if_no_extra_traits!(GetOutputPrimaryReply, "GetOutputPrimaryReply");
4711impl TryParse for GetOutputPrimaryReply {
4712    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4713        let remaining = initial_value;
4714        let (response_type, remaining) = u8::try_parse(remaining)?;
4715        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
4716        let (sequence, remaining) = u16::try_parse(remaining)?;
4717        let (length, remaining) = u32::try_parse(remaining)?;
4718        let (output, remaining) = Output::try_parse(remaining)?;
4719        if response_type != 1 {
4720            return Err(ParseError::InvalidValue);
4721        }
4722        let result = GetOutputPrimaryReply { sequence, length, output };
4723        let _ = remaining;
4724        let remaining = initial_value.get(32 + length as usize * 4..)
4725            .ok_or(ParseError::InsufficientData)?;
4726        Ok((result, remaining))
4727    }
4728}
4729impl Serialize for GetOutputPrimaryReply {
4730    type Bytes = [u8; 12];
4731    fn serialize(&self) -> [u8; 12] {
4732        let response_type_bytes = &[1];
4733        let sequence_bytes = self.sequence.serialize();
4734        let length_bytes = self.length.serialize();
4735        let output_bytes = self.output.serialize();
4736        [
4737            response_type_bytes[0],
4738            0,
4739            sequence_bytes[0],
4740            sequence_bytes[1],
4741            length_bytes[0],
4742            length_bytes[1],
4743            length_bytes[2],
4744            length_bytes[3],
4745            output_bytes[0],
4746            output_bytes[1],
4747            output_bytes[2],
4748            output_bytes[3],
4749        ]
4750    }
4751    fn serialize_into(&self, bytes: &mut Vec<u8>) {
4752        bytes.reserve(12);
4753        let response_type_bytes = &[1];
4754        bytes.push(response_type_bytes[0]);
4755        bytes.extend_from_slice(&[0; 1]);
4756        self.sequence.serialize_into(bytes);
4757        self.length.serialize_into(bytes);
4758        self.output.serialize_into(bytes);
4759    }
4760}
4761
4762/// Opcode for the GetProviders request
4763pub const GET_PROVIDERS_REQUEST: u8 = 32;
4764#[derive(Clone, Copy, Default)]
4765#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
4766#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4767pub struct GetProvidersRequest {
4768    pub window: xproto::Window,
4769}
4770impl_debug_if_no_extra_traits!(GetProvidersRequest, "GetProvidersRequest");
4771impl GetProvidersRequest {
4772    /// Serialize this request into bytes for the provided connection
4773    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
4774        let length_so_far = 0;
4775        let window_bytes = self.window.serialize();
4776        let mut request0 = vec![
4777            major_opcode,
4778            GET_PROVIDERS_REQUEST,
4779            0,
4780            0,
4781            window_bytes[0],
4782            window_bytes[1],
4783            window_bytes[2],
4784            window_bytes[3],
4785        ];
4786        let length_so_far = length_so_far + request0.len();
4787        assert_eq!(length_so_far % 4, 0);
4788        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
4789        request0[2..4].copy_from_slice(&length.to_ne_bytes());
4790        ([request0.into()], vec![])
4791    }
4792    /// Parse this request given its header, its body, and any fds that go along with it
4793    #[cfg(feature = "request-parsing")]
4794    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
4795        if header.minor_opcode != GET_PROVIDERS_REQUEST {
4796            return Err(ParseError::InvalidValue);
4797        }
4798        let (window, remaining) = xproto::Window::try_parse(value)?;
4799        let _ = remaining;
4800        Ok(GetProvidersRequest {
4801            window,
4802        })
4803    }
4804}
4805impl Request for GetProvidersRequest {
4806    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
4807
4808    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
4809        let (bufs, fds) = self.serialize(major_opcode);
4810        // Flatten the buffers into a single vector
4811        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
4812        (buf, fds)
4813    }
4814}
4815impl crate::x11_utils::ReplyRequest for GetProvidersRequest {
4816    type Reply = GetProvidersReply;
4817}
4818
4819#[derive(Clone, Default)]
4820#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
4821#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4822pub struct GetProvidersReply {
4823    pub sequence: u16,
4824    pub length: u32,
4825    pub timestamp: xproto::Timestamp,
4826    pub providers: Vec<Provider>,
4827}
4828impl_debug_if_no_extra_traits!(GetProvidersReply, "GetProvidersReply");
4829impl TryParse for GetProvidersReply {
4830    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
4831        let remaining = initial_value;
4832        let (response_type, remaining) = u8::try_parse(remaining)?;
4833        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
4834        let (sequence, remaining) = u16::try_parse(remaining)?;
4835        let (length, remaining) = u32::try_parse(remaining)?;
4836        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
4837        let (num_providers, remaining) = u16::try_parse(remaining)?;
4838        let remaining = remaining.get(18..).ok_or(ParseError::InsufficientData)?;
4839        let (providers, remaining) = crate::x11_utils::parse_list::<Provider>(remaining, num_providers.try_to_usize()?)?;
4840        if response_type != 1 {
4841            return Err(ParseError::InvalidValue);
4842        }
4843        let result = GetProvidersReply { sequence, length, timestamp, providers };
4844        let _ = remaining;
4845        let remaining = initial_value.get(32 + length as usize * 4..)
4846            .ok_or(ParseError::InsufficientData)?;
4847        Ok((result, remaining))
4848    }
4849}
4850impl Serialize for GetProvidersReply {
4851    type Bytes = Vec<u8>;
4852    fn serialize(&self) -> Vec<u8> {
4853        let mut result = Vec::new();
4854        self.serialize_into(&mut result);
4855        result
4856    }
4857    fn serialize_into(&self, bytes: &mut Vec<u8>) {
4858        bytes.reserve(32);
4859        let response_type_bytes = &[1];
4860        bytes.push(response_type_bytes[0]);
4861        bytes.extend_from_slice(&[0; 1]);
4862        self.sequence.serialize_into(bytes);
4863        self.length.serialize_into(bytes);
4864        self.timestamp.serialize_into(bytes);
4865        let num_providers = u16::try_from(self.providers.len()).expect("`providers` has too many elements");
4866        num_providers.serialize_into(bytes);
4867        bytes.extend_from_slice(&[0; 18]);
4868        self.providers.serialize_into(bytes);
4869    }
4870}
4871impl GetProvidersReply {
4872    /// Get the value of the `num_providers` field.
4873    ///
4874    /// The `num_providers` field is used as the length field of the `providers` field.
4875    /// This function computes the field's value again based on the length of the list.
4876    ///
4877    /// # Panics
4878    ///
4879    /// Panics if the value cannot be represented in the target type. This
4880    /// cannot happen with values of the struct received from the X11 server.
4881    pub fn num_providers(&self) -> u16 {
4882        self.providers.len()
4883            .try_into().unwrap()
4884    }
4885}
4886
4887#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
4888#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4889pub struct ProviderCapability(u32);
4890impl ProviderCapability {
4891    pub const SOURCE_OUTPUT: Self = Self(1 << 0);
4892    pub const SINK_OUTPUT: Self = Self(1 << 1);
4893    pub const SOURCE_OFFLOAD: Self = Self(1 << 2);
4894    pub const SINK_OFFLOAD: Self = Self(1 << 3);
4895}
4896impl From<ProviderCapability> for u32 {
4897    #[inline]
4898    fn from(input: ProviderCapability) -> Self {
4899        input.0
4900    }
4901}
4902impl From<ProviderCapability> for Option<u32> {
4903    #[inline]
4904    fn from(input: ProviderCapability) -> Self {
4905        Some(input.0)
4906    }
4907}
4908impl From<u8> for ProviderCapability {
4909    #[inline]
4910    fn from(value: u8) -> Self {
4911        Self(value.into())
4912    }
4913}
4914impl From<u16> for ProviderCapability {
4915    #[inline]
4916    fn from(value: u16) -> Self {
4917        Self(value.into())
4918    }
4919}
4920impl From<u32> for ProviderCapability {
4921    #[inline]
4922    fn from(value: u32) -> Self {
4923        Self(value)
4924    }
4925}
4926impl core::fmt::Debug for ProviderCapability  {
4927    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
4928        let variants = [
4929            (Self::SOURCE_OUTPUT.0, "SOURCE_OUTPUT", "SourceOutput"),
4930            (Self::SINK_OUTPUT.0, "SINK_OUTPUT", "SinkOutput"),
4931            (Self::SOURCE_OFFLOAD.0, "SOURCE_OFFLOAD", "SourceOffload"),
4932            (Self::SINK_OFFLOAD.0, "SINK_OFFLOAD", "SinkOffload"),
4933        ];
4934        pretty_print_bitmask(fmt, self.0, &variants)
4935    }
4936}
4937bitmask_binop!(ProviderCapability, u32);
4938
4939/// Opcode for the GetProviderInfo request
4940pub const GET_PROVIDER_INFO_REQUEST: u8 = 33;
4941#[derive(Clone, Copy, Default)]
4942#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
4943#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
4944pub struct GetProviderInfoRequest {
4945    pub provider: Provider,
4946    pub config_timestamp: xproto::Timestamp,
4947}
4948impl_debug_if_no_extra_traits!(GetProviderInfoRequest, "GetProviderInfoRequest");
4949impl GetProviderInfoRequest {
4950    /// Serialize this request into bytes for the provided connection
4951    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
4952        let length_so_far = 0;
4953        let provider_bytes = self.provider.serialize();
4954        let config_timestamp_bytes = self.config_timestamp.serialize();
4955        let mut request0 = vec![
4956            major_opcode,
4957            GET_PROVIDER_INFO_REQUEST,
4958            0,
4959            0,
4960            provider_bytes[0],
4961            provider_bytes[1],
4962            provider_bytes[2],
4963            provider_bytes[3],
4964            config_timestamp_bytes[0],
4965            config_timestamp_bytes[1],
4966            config_timestamp_bytes[2],
4967            config_timestamp_bytes[3],
4968        ];
4969        let length_so_far = length_so_far + request0.len();
4970        assert_eq!(length_so_far % 4, 0);
4971        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
4972        request0[2..4].copy_from_slice(&length.to_ne_bytes());
4973        ([request0.into()], vec![])
4974    }
4975    /// Parse this request given its header, its body, and any fds that go along with it
4976    #[cfg(feature = "request-parsing")]
4977    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
4978        if header.minor_opcode != GET_PROVIDER_INFO_REQUEST {
4979            return Err(ParseError::InvalidValue);
4980        }
4981        let (provider, remaining) = Provider::try_parse(value)?;
4982        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
4983        let _ = remaining;
4984        Ok(GetProviderInfoRequest {
4985            provider,
4986            config_timestamp,
4987        })
4988    }
4989}
4990impl Request for GetProviderInfoRequest {
4991    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
4992
4993    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
4994        let (bufs, fds) = self.serialize(major_opcode);
4995        // Flatten the buffers into a single vector
4996        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
4997        (buf, fds)
4998    }
4999}
5000impl crate::x11_utils::ReplyRequest for GetProviderInfoRequest {
5001    type Reply = GetProviderInfoReply;
5002}
5003
5004#[derive(Clone, Default)]
5005#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5006#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5007pub struct GetProviderInfoReply {
5008    pub status: u8,
5009    pub sequence: u16,
5010    pub length: u32,
5011    pub timestamp: xproto::Timestamp,
5012    pub capabilities: ProviderCapability,
5013    pub crtcs: Vec<Crtc>,
5014    pub outputs: Vec<Output>,
5015    pub associated_providers: Vec<Provider>,
5016    pub associated_capability: Vec<u32>,
5017    pub name: Vec<u8>,
5018}
5019impl_debug_if_no_extra_traits!(GetProviderInfoReply, "GetProviderInfoReply");
5020impl TryParse for GetProviderInfoReply {
5021    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5022        let remaining = initial_value;
5023        let (response_type, remaining) = u8::try_parse(remaining)?;
5024        let (status, remaining) = u8::try_parse(remaining)?;
5025        let (sequence, remaining) = u16::try_parse(remaining)?;
5026        let (length, remaining) = u32::try_parse(remaining)?;
5027        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
5028        let (capabilities, remaining) = u32::try_parse(remaining)?;
5029        let (num_crtcs, remaining) = u16::try_parse(remaining)?;
5030        let (num_outputs, remaining) = u16::try_parse(remaining)?;
5031        let (num_associated_providers, remaining) = u16::try_parse(remaining)?;
5032        let (name_len, remaining) = u16::try_parse(remaining)?;
5033        let remaining = remaining.get(8..).ok_or(ParseError::InsufficientData)?;
5034        let (crtcs, remaining) = crate::x11_utils::parse_list::<Crtc>(remaining, num_crtcs.try_to_usize()?)?;
5035        let (outputs, remaining) = crate::x11_utils::parse_list::<Output>(remaining, num_outputs.try_to_usize()?)?;
5036        let (associated_providers, remaining) = crate::x11_utils::parse_list::<Provider>(remaining, num_associated_providers.try_to_usize()?)?;
5037        let (associated_capability, remaining) = crate::x11_utils::parse_list::<u32>(remaining, num_associated_providers.try_to_usize()?)?;
5038        let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?;
5039        let name = name.to_vec();
5040        if response_type != 1 {
5041            return Err(ParseError::InvalidValue);
5042        }
5043        let capabilities = capabilities.into();
5044        let result = GetProviderInfoReply { status, sequence, length, timestamp, capabilities, crtcs, outputs, associated_providers, associated_capability, name };
5045        let _ = remaining;
5046        let remaining = initial_value.get(32 + length as usize * 4..)
5047            .ok_or(ParseError::InsufficientData)?;
5048        Ok((result, remaining))
5049    }
5050}
5051impl Serialize for GetProviderInfoReply {
5052    type Bytes = Vec<u8>;
5053    fn serialize(&self) -> Vec<u8> {
5054        let mut result = Vec::new();
5055        self.serialize_into(&mut result);
5056        result
5057    }
5058    fn serialize_into(&self, bytes: &mut Vec<u8>) {
5059        bytes.reserve(32);
5060        let response_type_bytes = &[1];
5061        bytes.push(response_type_bytes[0]);
5062        self.status.serialize_into(bytes);
5063        self.sequence.serialize_into(bytes);
5064        self.length.serialize_into(bytes);
5065        self.timestamp.serialize_into(bytes);
5066        u32::from(self.capabilities).serialize_into(bytes);
5067        let num_crtcs = u16::try_from(self.crtcs.len()).expect("`crtcs` has too many elements");
5068        num_crtcs.serialize_into(bytes);
5069        let num_outputs = u16::try_from(self.outputs.len()).expect("`outputs` has too many elements");
5070        num_outputs.serialize_into(bytes);
5071        let num_associated_providers = u16::try_from(self.associated_providers.len()).expect("`associated_providers` has too many elements");
5072        num_associated_providers.serialize_into(bytes);
5073        let name_len = u16::try_from(self.name.len()).expect("`name` has too many elements");
5074        name_len.serialize_into(bytes);
5075        bytes.extend_from_slice(&[0; 8]);
5076        self.crtcs.serialize_into(bytes);
5077        self.outputs.serialize_into(bytes);
5078        self.associated_providers.serialize_into(bytes);
5079        assert_eq!(self.associated_capability.len(), usize::try_from(num_associated_providers).unwrap(), "`associated_capability` has an incorrect length");
5080        self.associated_capability.serialize_into(bytes);
5081        bytes.extend_from_slice(&self.name);
5082    }
5083}
5084impl GetProviderInfoReply {
5085    /// Get the value of the `num_crtcs` field.
5086    ///
5087    /// The `num_crtcs` field is used as the length field of the `crtcs` field.
5088    /// This function computes the field's value again based on the length of the list.
5089    ///
5090    /// # Panics
5091    ///
5092    /// Panics if the value cannot be represented in the target type. This
5093    /// cannot happen with values of the struct received from the X11 server.
5094    pub fn num_crtcs(&self) -> u16 {
5095        self.crtcs.len()
5096            .try_into().unwrap()
5097    }
5098    /// Get the value of the `num_outputs` field.
5099    ///
5100    /// The `num_outputs` field is used as the length field of the `outputs` field.
5101    /// This function computes the field's value again based on the length of the list.
5102    ///
5103    /// # Panics
5104    ///
5105    /// Panics if the value cannot be represented in the target type. This
5106    /// cannot happen with values of the struct received from the X11 server.
5107    pub fn num_outputs(&self) -> u16 {
5108        self.outputs.len()
5109            .try_into().unwrap()
5110    }
5111    /// Get the value of the `num_associated_providers` field.
5112    ///
5113    /// The `num_associated_providers` field is used as the length field of the `associated_providers` field.
5114    /// This function computes the field's value again based on the length of the list.
5115    ///
5116    /// # Panics
5117    ///
5118    /// Panics if the value cannot be represented in the target type. This
5119    /// cannot happen with values of the struct received from the X11 server.
5120    pub fn num_associated_providers(&self) -> u16 {
5121        self.associated_providers.len()
5122            .try_into().unwrap()
5123    }
5124    /// Get the value of the `name_len` field.
5125    ///
5126    /// The `name_len` field is used as the length field of the `name` field.
5127    /// This function computes the field's value again based on the length of the list.
5128    ///
5129    /// # Panics
5130    ///
5131    /// Panics if the value cannot be represented in the target type. This
5132    /// cannot happen with values of the struct received from the X11 server.
5133    pub fn name_len(&self) -> u16 {
5134        self.name.len()
5135            .try_into().unwrap()
5136    }
5137}
5138
5139/// Opcode for the SetProviderOffloadSink request
5140pub const SET_PROVIDER_OFFLOAD_SINK_REQUEST: u8 = 34;
5141#[derive(Clone, Copy, Default)]
5142#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5143#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5144pub struct SetProviderOffloadSinkRequest {
5145    pub provider: Provider,
5146    pub sink_provider: Provider,
5147    pub config_timestamp: xproto::Timestamp,
5148}
5149impl_debug_if_no_extra_traits!(SetProviderOffloadSinkRequest, "SetProviderOffloadSinkRequest");
5150impl SetProviderOffloadSinkRequest {
5151    /// Serialize this request into bytes for the provided connection
5152    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
5153        let length_so_far = 0;
5154        let provider_bytes = self.provider.serialize();
5155        let sink_provider_bytes = self.sink_provider.serialize();
5156        let config_timestamp_bytes = self.config_timestamp.serialize();
5157        let mut request0 = vec![
5158            major_opcode,
5159            SET_PROVIDER_OFFLOAD_SINK_REQUEST,
5160            0,
5161            0,
5162            provider_bytes[0],
5163            provider_bytes[1],
5164            provider_bytes[2],
5165            provider_bytes[3],
5166            sink_provider_bytes[0],
5167            sink_provider_bytes[1],
5168            sink_provider_bytes[2],
5169            sink_provider_bytes[3],
5170            config_timestamp_bytes[0],
5171            config_timestamp_bytes[1],
5172            config_timestamp_bytes[2],
5173            config_timestamp_bytes[3],
5174        ];
5175        let length_so_far = length_so_far + request0.len();
5176        assert_eq!(length_so_far % 4, 0);
5177        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
5178        request0[2..4].copy_from_slice(&length.to_ne_bytes());
5179        ([request0.into()], vec![])
5180    }
5181    /// Parse this request given its header, its body, and any fds that go along with it
5182    #[cfg(feature = "request-parsing")]
5183    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
5184        if header.minor_opcode != SET_PROVIDER_OFFLOAD_SINK_REQUEST {
5185            return Err(ParseError::InvalidValue);
5186        }
5187        let (provider, remaining) = Provider::try_parse(value)?;
5188        let (sink_provider, remaining) = Provider::try_parse(remaining)?;
5189        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
5190        let _ = remaining;
5191        Ok(SetProviderOffloadSinkRequest {
5192            provider,
5193            sink_provider,
5194            config_timestamp,
5195        })
5196    }
5197}
5198impl Request for SetProviderOffloadSinkRequest {
5199    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
5200
5201    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
5202        let (bufs, fds) = self.serialize(major_opcode);
5203        // Flatten the buffers into a single vector
5204        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
5205        (buf, fds)
5206    }
5207}
5208impl crate::x11_utils::VoidRequest for SetProviderOffloadSinkRequest {
5209}
5210
5211/// Opcode for the SetProviderOutputSource request
5212pub const SET_PROVIDER_OUTPUT_SOURCE_REQUEST: u8 = 35;
5213#[derive(Clone, Copy, Default)]
5214#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5215#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5216pub struct SetProviderOutputSourceRequest {
5217    pub provider: Provider,
5218    pub source_provider: Provider,
5219    pub config_timestamp: xproto::Timestamp,
5220}
5221impl_debug_if_no_extra_traits!(SetProviderOutputSourceRequest, "SetProviderOutputSourceRequest");
5222impl SetProviderOutputSourceRequest {
5223    /// Serialize this request into bytes for the provided connection
5224    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
5225        let length_so_far = 0;
5226        let provider_bytes = self.provider.serialize();
5227        let source_provider_bytes = self.source_provider.serialize();
5228        let config_timestamp_bytes = self.config_timestamp.serialize();
5229        let mut request0 = vec![
5230            major_opcode,
5231            SET_PROVIDER_OUTPUT_SOURCE_REQUEST,
5232            0,
5233            0,
5234            provider_bytes[0],
5235            provider_bytes[1],
5236            provider_bytes[2],
5237            provider_bytes[3],
5238            source_provider_bytes[0],
5239            source_provider_bytes[1],
5240            source_provider_bytes[2],
5241            source_provider_bytes[3],
5242            config_timestamp_bytes[0],
5243            config_timestamp_bytes[1],
5244            config_timestamp_bytes[2],
5245            config_timestamp_bytes[3],
5246        ];
5247        let length_so_far = length_so_far + request0.len();
5248        assert_eq!(length_so_far % 4, 0);
5249        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
5250        request0[2..4].copy_from_slice(&length.to_ne_bytes());
5251        ([request0.into()], vec![])
5252    }
5253    /// Parse this request given its header, its body, and any fds that go along with it
5254    #[cfg(feature = "request-parsing")]
5255    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
5256        if header.minor_opcode != SET_PROVIDER_OUTPUT_SOURCE_REQUEST {
5257            return Err(ParseError::InvalidValue);
5258        }
5259        let (provider, remaining) = Provider::try_parse(value)?;
5260        let (source_provider, remaining) = Provider::try_parse(remaining)?;
5261        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
5262        let _ = remaining;
5263        Ok(SetProviderOutputSourceRequest {
5264            provider,
5265            source_provider,
5266            config_timestamp,
5267        })
5268    }
5269}
5270impl Request for SetProviderOutputSourceRequest {
5271    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
5272
5273    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
5274        let (bufs, fds) = self.serialize(major_opcode);
5275        // Flatten the buffers into a single vector
5276        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
5277        (buf, fds)
5278    }
5279}
5280impl crate::x11_utils::VoidRequest for SetProviderOutputSourceRequest {
5281}
5282
5283/// Opcode for the ListProviderProperties request
5284pub const LIST_PROVIDER_PROPERTIES_REQUEST: u8 = 36;
5285#[derive(Clone, Copy, Default)]
5286#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5287#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5288pub struct ListProviderPropertiesRequest {
5289    pub provider: Provider,
5290}
5291impl_debug_if_no_extra_traits!(ListProviderPropertiesRequest, "ListProviderPropertiesRequest");
5292impl ListProviderPropertiesRequest {
5293    /// Serialize this request into bytes for the provided connection
5294    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
5295        let length_so_far = 0;
5296        let provider_bytes = self.provider.serialize();
5297        let mut request0 = vec![
5298            major_opcode,
5299            LIST_PROVIDER_PROPERTIES_REQUEST,
5300            0,
5301            0,
5302            provider_bytes[0],
5303            provider_bytes[1],
5304            provider_bytes[2],
5305            provider_bytes[3],
5306        ];
5307        let length_so_far = length_so_far + request0.len();
5308        assert_eq!(length_so_far % 4, 0);
5309        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
5310        request0[2..4].copy_from_slice(&length.to_ne_bytes());
5311        ([request0.into()], vec![])
5312    }
5313    /// Parse this request given its header, its body, and any fds that go along with it
5314    #[cfg(feature = "request-parsing")]
5315    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
5316        if header.minor_opcode != LIST_PROVIDER_PROPERTIES_REQUEST {
5317            return Err(ParseError::InvalidValue);
5318        }
5319        let (provider, remaining) = Provider::try_parse(value)?;
5320        let _ = remaining;
5321        Ok(ListProviderPropertiesRequest {
5322            provider,
5323        })
5324    }
5325}
5326impl Request for ListProviderPropertiesRequest {
5327    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
5328
5329    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
5330        let (bufs, fds) = self.serialize(major_opcode);
5331        // Flatten the buffers into a single vector
5332        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
5333        (buf, fds)
5334    }
5335}
5336impl crate::x11_utils::ReplyRequest for ListProviderPropertiesRequest {
5337    type Reply = ListProviderPropertiesReply;
5338}
5339
5340#[derive(Clone, Default)]
5341#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5342#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5343pub struct ListProviderPropertiesReply {
5344    pub sequence: u16,
5345    pub length: u32,
5346    pub atoms: Vec<xproto::Atom>,
5347}
5348impl_debug_if_no_extra_traits!(ListProviderPropertiesReply, "ListProviderPropertiesReply");
5349impl TryParse for ListProviderPropertiesReply {
5350    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5351        let remaining = initial_value;
5352        let (response_type, remaining) = u8::try_parse(remaining)?;
5353        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
5354        let (sequence, remaining) = u16::try_parse(remaining)?;
5355        let (length, remaining) = u32::try_parse(remaining)?;
5356        let (num_atoms, remaining) = u16::try_parse(remaining)?;
5357        let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?;
5358        let (atoms, remaining) = crate::x11_utils::parse_list::<xproto::Atom>(remaining, num_atoms.try_to_usize()?)?;
5359        if response_type != 1 {
5360            return Err(ParseError::InvalidValue);
5361        }
5362        let result = ListProviderPropertiesReply { sequence, length, atoms };
5363        let _ = remaining;
5364        let remaining = initial_value.get(32 + length as usize * 4..)
5365            .ok_or(ParseError::InsufficientData)?;
5366        Ok((result, remaining))
5367    }
5368}
5369impl Serialize for ListProviderPropertiesReply {
5370    type Bytes = Vec<u8>;
5371    fn serialize(&self) -> Vec<u8> {
5372        let mut result = Vec::new();
5373        self.serialize_into(&mut result);
5374        result
5375    }
5376    fn serialize_into(&self, bytes: &mut Vec<u8>) {
5377        bytes.reserve(32);
5378        let response_type_bytes = &[1];
5379        bytes.push(response_type_bytes[0]);
5380        bytes.extend_from_slice(&[0; 1]);
5381        self.sequence.serialize_into(bytes);
5382        self.length.serialize_into(bytes);
5383        let num_atoms = u16::try_from(self.atoms.len()).expect("`atoms` has too many elements");
5384        num_atoms.serialize_into(bytes);
5385        bytes.extend_from_slice(&[0; 22]);
5386        self.atoms.serialize_into(bytes);
5387    }
5388}
5389impl ListProviderPropertiesReply {
5390    /// Get the value of the `num_atoms` field.
5391    ///
5392    /// The `num_atoms` field is used as the length field of the `atoms` field.
5393    /// This function computes the field's value again based on the length of the list.
5394    ///
5395    /// # Panics
5396    ///
5397    /// Panics if the value cannot be represented in the target type. This
5398    /// cannot happen with values of the struct received from the X11 server.
5399    pub fn num_atoms(&self) -> u16 {
5400        self.atoms.len()
5401            .try_into().unwrap()
5402    }
5403}
5404
5405/// Opcode for the QueryProviderProperty request
5406pub const QUERY_PROVIDER_PROPERTY_REQUEST: u8 = 37;
5407#[derive(Clone, Copy, Default)]
5408#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5409#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5410pub struct QueryProviderPropertyRequest {
5411    pub provider: Provider,
5412    pub property: xproto::Atom,
5413}
5414impl_debug_if_no_extra_traits!(QueryProviderPropertyRequest, "QueryProviderPropertyRequest");
5415impl QueryProviderPropertyRequest {
5416    /// Serialize this request into bytes for the provided connection
5417    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
5418        let length_so_far = 0;
5419        let provider_bytes = self.provider.serialize();
5420        let property_bytes = self.property.serialize();
5421        let mut request0 = vec![
5422            major_opcode,
5423            QUERY_PROVIDER_PROPERTY_REQUEST,
5424            0,
5425            0,
5426            provider_bytes[0],
5427            provider_bytes[1],
5428            provider_bytes[2],
5429            provider_bytes[3],
5430            property_bytes[0],
5431            property_bytes[1],
5432            property_bytes[2],
5433            property_bytes[3],
5434        ];
5435        let length_so_far = length_so_far + request0.len();
5436        assert_eq!(length_so_far % 4, 0);
5437        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
5438        request0[2..4].copy_from_slice(&length.to_ne_bytes());
5439        ([request0.into()], vec![])
5440    }
5441    /// Parse this request given its header, its body, and any fds that go along with it
5442    #[cfg(feature = "request-parsing")]
5443    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
5444        if header.minor_opcode != QUERY_PROVIDER_PROPERTY_REQUEST {
5445            return Err(ParseError::InvalidValue);
5446        }
5447        let (provider, remaining) = Provider::try_parse(value)?;
5448        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
5449        let _ = remaining;
5450        Ok(QueryProviderPropertyRequest {
5451            provider,
5452            property,
5453        })
5454    }
5455}
5456impl Request for QueryProviderPropertyRequest {
5457    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
5458
5459    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
5460        let (bufs, fds) = self.serialize(major_opcode);
5461        // Flatten the buffers into a single vector
5462        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
5463        (buf, fds)
5464    }
5465}
5466impl crate::x11_utils::ReplyRequest for QueryProviderPropertyRequest {
5467    type Reply = QueryProviderPropertyReply;
5468}
5469
5470#[derive(Clone, Default)]
5471#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5472#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5473pub struct QueryProviderPropertyReply {
5474    pub sequence: u16,
5475    pub pending: bool,
5476    pub range: bool,
5477    pub immutable: bool,
5478    pub valid_values: Vec<i32>,
5479}
5480impl_debug_if_no_extra_traits!(QueryProviderPropertyReply, "QueryProviderPropertyReply");
5481impl TryParse for QueryProviderPropertyReply {
5482    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5483        let remaining = initial_value;
5484        let (response_type, remaining) = u8::try_parse(remaining)?;
5485        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
5486        let (sequence, remaining) = u16::try_parse(remaining)?;
5487        let (length, remaining) = u32::try_parse(remaining)?;
5488        let (pending, remaining) = bool::try_parse(remaining)?;
5489        let (range, remaining) = bool::try_parse(remaining)?;
5490        let (immutable, remaining) = bool::try_parse(remaining)?;
5491        let remaining = remaining.get(21..).ok_or(ParseError::InsufficientData)?;
5492        let (valid_values, remaining) = crate::x11_utils::parse_list::<i32>(remaining, length.try_to_usize()?)?;
5493        if response_type != 1 {
5494            return Err(ParseError::InvalidValue);
5495        }
5496        let result = QueryProviderPropertyReply { sequence, pending, range, immutable, valid_values };
5497        let _ = remaining;
5498        let remaining = initial_value.get(32 + length as usize * 4..)
5499            .ok_or(ParseError::InsufficientData)?;
5500        Ok((result, remaining))
5501    }
5502}
5503impl Serialize for QueryProviderPropertyReply {
5504    type Bytes = Vec<u8>;
5505    fn serialize(&self) -> Vec<u8> {
5506        let mut result = Vec::new();
5507        self.serialize_into(&mut result);
5508        result
5509    }
5510    fn serialize_into(&self, bytes: &mut Vec<u8>) {
5511        bytes.reserve(32);
5512        let response_type_bytes = &[1];
5513        bytes.push(response_type_bytes[0]);
5514        bytes.extend_from_slice(&[0; 1]);
5515        self.sequence.serialize_into(bytes);
5516        let length = u32::try_from(self.valid_values.len()).expect("`valid_values` has too many elements");
5517        length.serialize_into(bytes);
5518        self.pending.serialize_into(bytes);
5519        self.range.serialize_into(bytes);
5520        self.immutable.serialize_into(bytes);
5521        bytes.extend_from_slice(&[0; 21]);
5522        self.valid_values.serialize_into(bytes);
5523    }
5524}
5525impl QueryProviderPropertyReply {
5526    /// Get the value of the `length` field.
5527    ///
5528    /// The `length` field is used as the length field of the `valid_values` field.
5529    /// This function computes the field's value again based on the length of the list.
5530    ///
5531    /// # Panics
5532    ///
5533    /// Panics if the value cannot be represented in the target type. This
5534    /// cannot happen with values of the struct received from the X11 server.
5535    pub fn length(&self) -> u32 {
5536        self.valid_values.len()
5537            .try_into().unwrap()
5538    }
5539}
5540
5541/// Opcode for the ConfigureProviderProperty request
5542pub const CONFIGURE_PROVIDER_PROPERTY_REQUEST: u8 = 38;
5543#[derive(Clone, Default)]
5544#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5545#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5546pub struct ConfigureProviderPropertyRequest<'input> {
5547    pub provider: Provider,
5548    pub property: xproto::Atom,
5549    pub pending: bool,
5550    pub range: bool,
5551    pub values: Cow<'input, [i32]>,
5552}
5553impl_debug_if_no_extra_traits!(ConfigureProviderPropertyRequest<'_>, "ConfigureProviderPropertyRequest");
5554impl<'input> ConfigureProviderPropertyRequest<'input> {
5555    /// Serialize this request into bytes for the provided connection
5556    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
5557        let length_so_far = 0;
5558        let provider_bytes = self.provider.serialize();
5559        let property_bytes = self.property.serialize();
5560        let pending_bytes = self.pending.serialize();
5561        let range_bytes = self.range.serialize();
5562        let mut request0 = vec![
5563            major_opcode,
5564            CONFIGURE_PROVIDER_PROPERTY_REQUEST,
5565            0,
5566            0,
5567            provider_bytes[0],
5568            provider_bytes[1],
5569            provider_bytes[2],
5570            provider_bytes[3],
5571            property_bytes[0],
5572            property_bytes[1],
5573            property_bytes[2],
5574            property_bytes[3],
5575            pending_bytes[0],
5576            range_bytes[0],
5577            0,
5578            0,
5579        ];
5580        let length_so_far = length_so_far + request0.len();
5581        let values_bytes = self.values.serialize();
5582        let length_so_far = length_so_far + values_bytes.len();
5583        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
5584        let length_so_far = length_so_far + padding0.len();
5585        assert_eq!(length_so_far % 4, 0);
5586        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
5587        request0[2..4].copy_from_slice(&length.to_ne_bytes());
5588        ([request0.into(), values_bytes.into(), padding0.into()], vec![])
5589    }
5590    /// Parse this request given its header, its body, and any fds that go along with it
5591    #[cfg(feature = "request-parsing")]
5592    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
5593        if header.minor_opcode != CONFIGURE_PROVIDER_PROPERTY_REQUEST {
5594            return Err(ParseError::InvalidValue);
5595        }
5596        let (provider, remaining) = Provider::try_parse(value)?;
5597        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
5598        let (pending, remaining) = bool::try_parse(remaining)?;
5599        let (range, remaining) = bool::try_parse(remaining)?;
5600        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
5601        let mut remaining = remaining;
5602        // Length is 'everything left in the input'
5603        let mut values = Vec::new();
5604        while !remaining.is_empty() {
5605            let (v, new_remaining) = i32::try_parse(remaining)?;
5606            remaining = new_remaining;
5607            values.push(v);
5608        }
5609        let _ = remaining;
5610        Ok(ConfigureProviderPropertyRequest {
5611            provider,
5612            property,
5613            pending,
5614            range,
5615            values: Cow::Owned(values),
5616        })
5617    }
5618    /// Clone all borrowed data in this ConfigureProviderPropertyRequest.
5619    pub fn into_owned(self) -> ConfigureProviderPropertyRequest<'static> {
5620        ConfigureProviderPropertyRequest {
5621            provider: self.provider,
5622            property: self.property,
5623            pending: self.pending,
5624            range: self.range,
5625            values: Cow::Owned(self.values.into_owned()),
5626        }
5627    }
5628}
5629impl<'input> Request for ConfigureProviderPropertyRequest<'input> {
5630    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
5631
5632    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
5633        let (bufs, fds) = self.serialize(major_opcode);
5634        // Flatten the buffers into a single vector
5635        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
5636        (buf, fds)
5637    }
5638}
5639impl<'input> crate::x11_utils::VoidRequest for ConfigureProviderPropertyRequest<'input> {
5640}
5641
5642/// Opcode for the ChangeProviderProperty request
5643pub const CHANGE_PROVIDER_PROPERTY_REQUEST: u8 = 39;
5644#[derive(Clone, Default)]
5645#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5646#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5647pub struct ChangeProviderPropertyRequest<'input> {
5648    pub provider: Provider,
5649    pub property: xproto::Atom,
5650    pub type_: xproto::Atom,
5651    pub format: u8,
5652    pub mode: u8,
5653    pub num_items: u32,
5654    pub data: Cow<'input, [u8]>,
5655}
5656impl_debug_if_no_extra_traits!(ChangeProviderPropertyRequest<'_>, "ChangeProviderPropertyRequest");
5657impl<'input> ChangeProviderPropertyRequest<'input> {
5658    /// Serialize this request into bytes for the provided connection
5659    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
5660        let length_so_far = 0;
5661        let provider_bytes = self.provider.serialize();
5662        let property_bytes = self.property.serialize();
5663        let type_bytes = self.type_.serialize();
5664        let format_bytes = self.format.serialize();
5665        let mode_bytes = self.mode.serialize();
5666        let num_items_bytes = self.num_items.serialize();
5667        let mut request0 = vec![
5668            major_opcode,
5669            CHANGE_PROVIDER_PROPERTY_REQUEST,
5670            0,
5671            0,
5672            provider_bytes[0],
5673            provider_bytes[1],
5674            provider_bytes[2],
5675            provider_bytes[3],
5676            property_bytes[0],
5677            property_bytes[1],
5678            property_bytes[2],
5679            property_bytes[3],
5680            type_bytes[0],
5681            type_bytes[1],
5682            type_bytes[2],
5683            type_bytes[3],
5684            format_bytes[0],
5685            mode_bytes[0],
5686            0,
5687            0,
5688            num_items_bytes[0],
5689            num_items_bytes[1],
5690            num_items_bytes[2],
5691            num_items_bytes[3],
5692        ];
5693        let length_so_far = length_so_far + request0.len();
5694        assert_eq!(self.data.len(), usize::try_from(u32::from(self.num_items).checked_mul(u32::from(self.format).checked_div(8u32).unwrap()).unwrap()).unwrap(), "`data` has an incorrect length");
5695        let length_so_far = length_so_far + self.data.len();
5696        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
5697        let length_so_far = length_so_far + padding0.len();
5698        assert_eq!(length_so_far % 4, 0);
5699        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
5700        request0[2..4].copy_from_slice(&length.to_ne_bytes());
5701        ([request0.into(), self.data, padding0.into()], vec![])
5702    }
5703    /// Parse this request given its header, its body, and any fds that go along with it
5704    #[cfg(feature = "request-parsing")]
5705    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
5706        if header.minor_opcode != CHANGE_PROVIDER_PROPERTY_REQUEST {
5707            return Err(ParseError::InvalidValue);
5708        }
5709        let (provider, remaining) = Provider::try_parse(value)?;
5710        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
5711        let (type_, remaining) = xproto::Atom::try_parse(remaining)?;
5712        let (format, remaining) = u8::try_parse(remaining)?;
5713        let (mode, remaining) = u8::try_parse(remaining)?;
5714        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
5715        let (num_items, remaining) = u32::try_parse(remaining)?;
5716        let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(num_items).checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?;
5717        let _ = remaining;
5718        Ok(ChangeProviderPropertyRequest {
5719            provider,
5720            property,
5721            type_,
5722            format,
5723            mode,
5724            num_items,
5725            data: Cow::Borrowed(data),
5726        })
5727    }
5728    /// Clone all borrowed data in this ChangeProviderPropertyRequest.
5729    pub fn into_owned(self) -> ChangeProviderPropertyRequest<'static> {
5730        ChangeProviderPropertyRequest {
5731            provider: self.provider,
5732            property: self.property,
5733            type_: self.type_,
5734            format: self.format,
5735            mode: self.mode,
5736            num_items: self.num_items,
5737            data: Cow::Owned(self.data.into_owned()),
5738        }
5739    }
5740}
5741impl<'input> Request for ChangeProviderPropertyRequest<'input> {
5742    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
5743
5744    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
5745        let (bufs, fds) = self.serialize(major_opcode);
5746        // Flatten the buffers into a single vector
5747        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
5748        (buf, fds)
5749    }
5750}
5751impl<'input> crate::x11_utils::VoidRequest for ChangeProviderPropertyRequest<'input> {
5752}
5753
5754/// Opcode for the DeleteProviderProperty request
5755pub const DELETE_PROVIDER_PROPERTY_REQUEST: u8 = 40;
5756#[derive(Clone, Copy, Default)]
5757#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5758#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5759pub struct DeleteProviderPropertyRequest {
5760    pub provider: Provider,
5761    pub property: xproto::Atom,
5762}
5763impl_debug_if_no_extra_traits!(DeleteProviderPropertyRequest, "DeleteProviderPropertyRequest");
5764impl DeleteProviderPropertyRequest {
5765    /// Serialize this request into bytes for the provided connection
5766    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
5767        let length_so_far = 0;
5768        let provider_bytes = self.provider.serialize();
5769        let property_bytes = self.property.serialize();
5770        let mut request0 = vec![
5771            major_opcode,
5772            DELETE_PROVIDER_PROPERTY_REQUEST,
5773            0,
5774            0,
5775            provider_bytes[0],
5776            provider_bytes[1],
5777            provider_bytes[2],
5778            provider_bytes[3],
5779            property_bytes[0],
5780            property_bytes[1],
5781            property_bytes[2],
5782            property_bytes[3],
5783        ];
5784        let length_so_far = length_so_far + request0.len();
5785        assert_eq!(length_so_far % 4, 0);
5786        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
5787        request0[2..4].copy_from_slice(&length.to_ne_bytes());
5788        ([request0.into()], vec![])
5789    }
5790    /// Parse this request given its header, its body, and any fds that go along with it
5791    #[cfg(feature = "request-parsing")]
5792    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
5793        if header.minor_opcode != DELETE_PROVIDER_PROPERTY_REQUEST {
5794            return Err(ParseError::InvalidValue);
5795        }
5796        let (provider, remaining) = Provider::try_parse(value)?;
5797        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
5798        let _ = remaining;
5799        Ok(DeleteProviderPropertyRequest {
5800            provider,
5801            property,
5802        })
5803    }
5804}
5805impl Request for DeleteProviderPropertyRequest {
5806    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
5807
5808    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
5809        let (bufs, fds) = self.serialize(major_opcode);
5810        // Flatten the buffers into a single vector
5811        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
5812        (buf, fds)
5813    }
5814}
5815impl crate::x11_utils::VoidRequest for DeleteProviderPropertyRequest {
5816}
5817
5818/// Opcode for the GetProviderProperty request
5819pub const GET_PROVIDER_PROPERTY_REQUEST: u8 = 41;
5820#[derive(Clone, Copy, Default)]
5821#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5822#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5823pub struct GetProviderPropertyRequest {
5824    pub provider: Provider,
5825    pub property: xproto::Atom,
5826    pub type_: xproto::Atom,
5827    pub long_offset: u32,
5828    pub long_length: u32,
5829    pub delete: bool,
5830    pub pending: bool,
5831}
5832impl_debug_if_no_extra_traits!(GetProviderPropertyRequest, "GetProviderPropertyRequest");
5833impl GetProviderPropertyRequest {
5834    /// Serialize this request into bytes for the provided connection
5835    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
5836        let length_so_far = 0;
5837        let provider_bytes = self.provider.serialize();
5838        let property_bytes = self.property.serialize();
5839        let type_bytes = self.type_.serialize();
5840        let long_offset_bytes = self.long_offset.serialize();
5841        let long_length_bytes = self.long_length.serialize();
5842        let delete_bytes = self.delete.serialize();
5843        let pending_bytes = self.pending.serialize();
5844        let mut request0 = vec![
5845            major_opcode,
5846            GET_PROVIDER_PROPERTY_REQUEST,
5847            0,
5848            0,
5849            provider_bytes[0],
5850            provider_bytes[1],
5851            provider_bytes[2],
5852            provider_bytes[3],
5853            property_bytes[0],
5854            property_bytes[1],
5855            property_bytes[2],
5856            property_bytes[3],
5857            type_bytes[0],
5858            type_bytes[1],
5859            type_bytes[2],
5860            type_bytes[3],
5861            long_offset_bytes[0],
5862            long_offset_bytes[1],
5863            long_offset_bytes[2],
5864            long_offset_bytes[3],
5865            long_length_bytes[0],
5866            long_length_bytes[1],
5867            long_length_bytes[2],
5868            long_length_bytes[3],
5869            delete_bytes[0],
5870            pending_bytes[0],
5871            0,
5872            0,
5873        ];
5874        let length_so_far = length_so_far + request0.len();
5875        assert_eq!(length_so_far % 4, 0);
5876        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
5877        request0[2..4].copy_from_slice(&length.to_ne_bytes());
5878        ([request0.into()], vec![])
5879    }
5880    /// Parse this request given its header, its body, and any fds that go along with it
5881    #[cfg(feature = "request-parsing")]
5882    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
5883        if header.minor_opcode != GET_PROVIDER_PROPERTY_REQUEST {
5884            return Err(ParseError::InvalidValue);
5885        }
5886        let (provider, remaining) = Provider::try_parse(value)?;
5887        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
5888        let (type_, remaining) = xproto::Atom::try_parse(remaining)?;
5889        let (long_offset, remaining) = u32::try_parse(remaining)?;
5890        let (long_length, remaining) = u32::try_parse(remaining)?;
5891        let (delete, remaining) = bool::try_parse(remaining)?;
5892        let (pending, remaining) = bool::try_parse(remaining)?;
5893        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
5894        let _ = remaining;
5895        Ok(GetProviderPropertyRequest {
5896            provider,
5897            property,
5898            type_,
5899            long_offset,
5900            long_length,
5901            delete,
5902            pending,
5903        })
5904    }
5905}
5906impl Request for GetProviderPropertyRequest {
5907    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
5908
5909    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
5910        let (bufs, fds) = self.serialize(major_opcode);
5911        // Flatten the buffers into a single vector
5912        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
5913        (buf, fds)
5914    }
5915}
5916impl crate::x11_utils::ReplyRequest for GetProviderPropertyRequest {
5917    type Reply = GetProviderPropertyReply;
5918}
5919
5920#[derive(Clone, Default)]
5921#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5922#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5923pub struct GetProviderPropertyReply {
5924    pub format: u8,
5925    pub sequence: u16,
5926    pub length: u32,
5927    pub type_: xproto::Atom,
5928    pub bytes_after: u32,
5929    pub num_items: u32,
5930    pub data: Vec<u8>,
5931}
5932impl_debug_if_no_extra_traits!(GetProviderPropertyReply, "GetProviderPropertyReply");
5933impl TryParse for GetProviderPropertyReply {
5934    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
5935        let remaining = initial_value;
5936        let (response_type, remaining) = u8::try_parse(remaining)?;
5937        let (format, remaining) = u8::try_parse(remaining)?;
5938        let (sequence, remaining) = u16::try_parse(remaining)?;
5939        let (length, remaining) = u32::try_parse(remaining)?;
5940        let (type_, remaining) = xproto::Atom::try_parse(remaining)?;
5941        let (bytes_after, remaining) = u32::try_parse(remaining)?;
5942        let (num_items, remaining) = u32::try_parse(remaining)?;
5943        let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
5944        let (data, remaining) = crate::x11_utils::parse_u8_list(remaining, u32::from(num_items).checked_mul(u32::from(format).checked_div(8u32).ok_or(ParseError::InvalidExpression)?).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?;
5945        let data = data.to_vec();
5946        if response_type != 1 {
5947            return Err(ParseError::InvalidValue);
5948        }
5949        let result = GetProviderPropertyReply { format, sequence, length, type_, bytes_after, num_items, data };
5950        let _ = remaining;
5951        let remaining = initial_value.get(32 + length as usize * 4..)
5952            .ok_or(ParseError::InsufficientData)?;
5953        Ok((result, remaining))
5954    }
5955}
5956impl Serialize for GetProviderPropertyReply {
5957    type Bytes = Vec<u8>;
5958    fn serialize(&self) -> Vec<u8> {
5959        let mut result = Vec::new();
5960        self.serialize_into(&mut result);
5961        result
5962    }
5963    fn serialize_into(&self, bytes: &mut Vec<u8>) {
5964        bytes.reserve(32);
5965        let response_type_bytes = &[1];
5966        bytes.push(response_type_bytes[0]);
5967        self.format.serialize_into(bytes);
5968        self.sequence.serialize_into(bytes);
5969        self.length.serialize_into(bytes);
5970        self.type_.serialize_into(bytes);
5971        self.bytes_after.serialize_into(bytes);
5972        self.num_items.serialize_into(bytes);
5973        bytes.extend_from_slice(&[0; 12]);
5974        assert_eq!(self.data.len(), usize::try_from(u32::from(self.num_items).checked_mul(u32::from(self.format).checked_div(8u32).unwrap()).unwrap()).unwrap(), "`data` has an incorrect length");
5975        bytes.extend_from_slice(&self.data);
5976    }
5977}
5978
5979/// Opcode for the ScreenChangeNotify event
5980pub const SCREEN_CHANGE_NOTIFY_EVENT: u8 = 0;
5981#[derive(Clone, Copy, Default)]
5982#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
5983#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
5984pub struct ScreenChangeNotifyEvent {
5985    pub response_type: u8,
5986    pub rotation: Rotation,
5987    pub sequence: u16,
5988    pub timestamp: xproto::Timestamp,
5989    pub config_timestamp: xproto::Timestamp,
5990    pub root: xproto::Window,
5991    pub request_window: xproto::Window,
5992    pub size_id: u16,
5993    pub subpixel_order: render::SubPixel,
5994    pub width: u16,
5995    pub height: u16,
5996    pub mwidth: u16,
5997    pub mheight: u16,
5998}
5999impl_debug_if_no_extra_traits!(ScreenChangeNotifyEvent, "ScreenChangeNotifyEvent");
6000impl TryParse for ScreenChangeNotifyEvent {
6001    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6002        let remaining = initial_value;
6003        let (response_type, remaining) = u8::try_parse(remaining)?;
6004        let (rotation, remaining) = u8::try_parse(remaining)?;
6005        let (sequence, remaining) = u16::try_parse(remaining)?;
6006        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
6007        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
6008        let (root, remaining) = xproto::Window::try_parse(remaining)?;
6009        let (request_window, remaining) = xproto::Window::try_parse(remaining)?;
6010        let (size_id, remaining) = u16::try_parse(remaining)?;
6011        let (subpixel_order, remaining) = u16::try_parse(remaining)?;
6012        let (width, remaining) = u16::try_parse(remaining)?;
6013        let (height, remaining) = u16::try_parse(remaining)?;
6014        let (mwidth, remaining) = u16::try_parse(remaining)?;
6015        let (mheight, remaining) = u16::try_parse(remaining)?;
6016        let rotation = rotation.into();
6017        let subpixel_order = subpixel_order.into();
6018        let result = ScreenChangeNotifyEvent { response_type, rotation, sequence, timestamp, config_timestamp, root, request_window, size_id, subpixel_order, width, height, mwidth, mheight };
6019        let _ = remaining;
6020        let remaining = initial_value.get(32..)
6021            .ok_or(ParseError::InsufficientData)?;
6022        Ok((result, remaining))
6023    }
6024}
6025impl Serialize for ScreenChangeNotifyEvent {
6026    type Bytes = [u8; 32];
6027    fn serialize(&self) -> [u8; 32] {
6028        let response_type_bytes = self.response_type.serialize();
6029        let rotation_bytes = (u16::from(self.rotation) as u8).serialize();
6030        let sequence_bytes = self.sequence.serialize();
6031        let timestamp_bytes = self.timestamp.serialize();
6032        let config_timestamp_bytes = self.config_timestamp.serialize();
6033        let root_bytes = self.root.serialize();
6034        let request_window_bytes = self.request_window.serialize();
6035        let size_id_bytes = self.size_id.serialize();
6036        let subpixel_order_bytes = (u32::from(self.subpixel_order) as u16).serialize();
6037        let width_bytes = self.width.serialize();
6038        let height_bytes = self.height.serialize();
6039        let mwidth_bytes = self.mwidth.serialize();
6040        let mheight_bytes = self.mheight.serialize();
6041        [
6042            response_type_bytes[0],
6043            rotation_bytes[0],
6044            sequence_bytes[0],
6045            sequence_bytes[1],
6046            timestamp_bytes[0],
6047            timestamp_bytes[1],
6048            timestamp_bytes[2],
6049            timestamp_bytes[3],
6050            config_timestamp_bytes[0],
6051            config_timestamp_bytes[1],
6052            config_timestamp_bytes[2],
6053            config_timestamp_bytes[3],
6054            root_bytes[0],
6055            root_bytes[1],
6056            root_bytes[2],
6057            root_bytes[3],
6058            request_window_bytes[0],
6059            request_window_bytes[1],
6060            request_window_bytes[2],
6061            request_window_bytes[3],
6062            size_id_bytes[0],
6063            size_id_bytes[1],
6064            subpixel_order_bytes[0],
6065            subpixel_order_bytes[1],
6066            width_bytes[0],
6067            width_bytes[1],
6068            height_bytes[0],
6069            height_bytes[1],
6070            mwidth_bytes[0],
6071            mwidth_bytes[1],
6072            mheight_bytes[0],
6073            mheight_bytes[1],
6074        ]
6075    }
6076    fn serialize_into(&self, bytes: &mut Vec<u8>) {
6077        bytes.reserve(32);
6078        self.response_type.serialize_into(bytes);
6079        (u16::from(self.rotation) as u8).serialize_into(bytes);
6080        self.sequence.serialize_into(bytes);
6081        self.timestamp.serialize_into(bytes);
6082        self.config_timestamp.serialize_into(bytes);
6083        self.root.serialize_into(bytes);
6084        self.request_window.serialize_into(bytes);
6085        self.size_id.serialize_into(bytes);
6086        (u32::from(self.subpixel_order) as u16).serialize_into(bytes);
6087        self.width.serialize_into(bytes);
6088        self.height.serialize_into(bytes);
6089        self.mwidth.serialize_into(bytes);
6090        self.mheight.serialize_into(bytes);
6091    }
6092}
6093impl From<&ScreenChangeNotifyEvent> for [u8; 32] {
6094    fn from(input: &ScreenChangeNotifyEvent) -> Self {
6095        let response_type_bytes = input.response_type.serialize();
6096        let rotation_bytes = (u16::from(input.rotation) as u8).serialize();
6097        let sequence_bytes = input.sequence.serialize();
6098        let timestamp_bytes = input.timestamp.serialize();
6099        let config_timestamp_bytes = input.config_timestamp.serialize();
6100        let root_bytes = input.root.serialize();
6101        let request_window_bytes = input.request_window.serialize();
6102        let size_id_bytes = input.size_id.serialize();
6103        let subpixel_order_bytes = (u32::from(input.subpixel_order) as u16).serialize();
6104        let width_bytes = input.width.serialize();
6105        let height_bytes = input.height.serialize();
6106        let mwidth_bytes = input.mwidth.serialize();
6107        let mheight_bytes = input.mheight.serialize();
6108        [
6109            response_type_bytes[0],
6110            rotation_bytes[0],
6111            sequence_bytes[0],
6112            sequence_bytes[1],
6113            timestamp_bytes[0],
6114            timestamp_bytes[1],
6115            timestamp_bytes[2],
6116            timestamp_bytes[3],
6117            config_timestamp_bytes[0],
6118            config_timestamp_bytes[1],
6119            config_timestamp_bytes[2],
6120            config_timestamp_bytes[3],
6121            root_bytes[0],
6122            root_bytes[1],
6123            root_bytes[2],
6124            root_bytes[3],
6125            request_window_bytes[0],
6126            request_window_bytes[1],
6127            request_window_bytes[2],
6128            request_window_bytes[3],
6129            size_id_bytes[0],
6130            size_id_bytes[1],
6131            subpixel_order_bytes[0],
6132            subpixel_order_bytes[1],
6133            width_bytes[0],
6134            width_bytes[1],
6135            height_bytes[0],
6136            height_bytes[1],
6137            mwidth_bytes[0],
6138            mwidth_bytes[1],
6139            mheight_bytes[0],
6140            mheight_bytes[1],
6141        ]
6142    }
6143}
6144impl From<ScreenChangeNotifyEvent> for [u8; 32] {
6145    fn from(input: ScreenChangeNotifyEvent) -> Self {
6146        Self::from(&input)
6147    }
6148}
6149
6150#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
6151#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6152pub struct Notify(u8);
6153impl Notify {
6154    pub const CRTC_CHANGE: Self = Self(0);
6155    pub const OUTPUT_CHANGE: Self = Self(1);
6156    pub const OUTPUT_PROPERTY: Self = Self(2);
6157    pub const PROVIDER_CHANGE: Self = Self(3);
6158    pub const PROVIDER_PROPERTY: Self = Self(4);
6159    pub const RESOURCE_CHANGE: Self = Self(5);
6160    pub const LEASE: Self = Self(6);
6161}
6162impl From<Notify> for u8 {
6163    #[inline]
6164    fn from(input: Notify) -> Self {
6165        input.0
6166    }
6167}
6168impl From<Notify> for Option<u8> {
6169    #[inline]
6170    fn from(input: Notify) -> Self {
6171        Some(input.0)
6172    }
6173}
6174impl From<Notify> for u16 {
6175    #[inline]
6176    fn from(input: Notify) -> Self {
6177        u16::from(input.0)
6178    }
6179}
6180impl From<Notify> for Option<u16> {
6181    #[inline]
6182    fn from(input: Notify) -> Self {
6183        Some(u16::from(input.0))
6184    }
6185}
6186impl From<Notify> for u32 {
6187    #[inline]
6188    fn from(input: Notify) -> Self {
6189        u32::from(input.0)
6190    }
6191}
6192impl From<Notify> for Option<u32> {
6193    #[inline]
6194    fn from(input: Notify) -> Self {
6195        Some(u32::from(input.0))
6196    }
6197}
6198impl From<u8> for Notify {
6199    #[inline]
6200    fn from(value: u8) -> Self {
6201        Self(value)
6202    }
6203}
6204impl core::fmt::Debug for Notify  {
6205    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
6206        let variants = [
6207            (Self::CRTC_CHANGE.0.into(), "CRTC_CHANGE", "CrtcChange"),
6208            (Self::OUTPUT_CHANGE.0.into(), "OUTPUT_CHANGE", "OutputChange"),
6209            (Self::OUTPUT_PROPERTY.0.into(), "OUTPUT_PROPERTY", "OutputProperty"),
6210            (Self::PROVIDER_CHANGE.0.into(), "PROVIDER_CHANGE", "ProviderChange"),
6211            (Self::PROVIDER_PROPERTY.0.into(), "PROVIDER_PROPERTY", "ProviderProperty"),
6212            (Self::RESOURCE_CHANGE.0.into(), "RESOURCE_CHANGE", "ResourceChange"),
6213            (Self::LEASE.0.into(), "LEASE", "Lease"),
6214        ];
6215        pretty_print_enum(fmt, self.0.into(), &variants)
6216    }
6217}
6218
6219#[derive(Clone, Copy, Default)]
6220#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
6221#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6222pub struct CrtcChange {
6223    pub timestamp: xproto::Timestamp,
6224    pub window: xproto::Window,
6225    pub crtc: Crtc,
6226    pub mode: Mode,
6227    pub rotation: Rotation,
6228    pub x: i16,
6229    pub y: i16,
6230    pub width: u16,
6231    pub height: u16,
6232}
6233impl_debug_if_no_extra_traits!(CrtcChange, "CrtcChange");
6234impl TryParse for CrtcChange {
6235    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6236        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
6237        let (window, remaining) = xproto::Window::try_parse(remaining)?;
6238        let (crtc, remaining) = Crtc::try_parse(remaining)?;
6239        let (mode, remaining) = Mode::try_parse(remaining)?;
6240        let (rotation, remaining) = u16::try_parse(remaining)?;
6241        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
6242        let (x, remaining) = i16::try_parse(remaining)?;
6243        let (y, remaining) = i16::try_parse(remaining)?;
6244        let (width, remaining) = u16::try_parse(remaining)?;
6245        let (height, remaining) = u16::try_parse(remaining)?;
6246        let rotation = rotation.into();
6247        let result = CrtcChange { timestamp, window, crtc, mode, rotation, x, y, width, height };
6248        Ok((result, remaining))
6249    }
6250}
6251impl Serialize for CrtcChange {
6252    type Bytes = [u8; 28];
6253    fn serialize(&self) -> [u8; 28] {
6254        let timestamp_bytes = self.timestamp.serialize();
6255        let window_bytes = self.window.serialize();
6256        let crtc_bytes = self.crtc.serialize();
6257        let mode_bytes = self.mode.serialize();
6258        let rotation_bytes = u16::from(self.rotation).serialize();
6259        let x_bytes = self.x.serialize();
6260        let y_bytes = self.y.serialize();
6261        let width_bytes = self.width.serialize();
6262        let height_bytes = self.height.serialize();
6263        [
6264            timestamp_bytes[0],
6265            timestamp_bytes[1],
6266            timestamp_bytes[2],
6267            timestamp_bytes[3],
6268            window_bytes[0],
6269            window_bytes[1],
6270            window_bytes[2],
6271            window_bytes[3],
6272            crtc_bytes[0],
6273            crtc_bytes[1],
6274            crtc_bytes[2],
6275            crtc_bytes[3],
6276            mode_bytes[0],
6277            mode_bytes[1],
6278            mode_bytes[2],
6279            mode_bytes[3],
6280            rotation_bytes[0],
6281            rotation_bytes[1],
6282            0,
6283            0,
6284            x_bytes[0],
6285            x_bytes[1],
6286            y_bytes[0],
6287            y_bytes[1],
6288            width_bytes[0],
6289            width_bytes[1],
6290            height_bytes[0],
6291            height_bytes[1],
6292        ]
6293    }
6294    fn serialize_into(&self, bytes: &mut Vec<u8>) {
6295        bytes.reserve(28);
6296        self.timestamp.serialize_into(bytes);
6297        self.window.serialize_into(bytes);
6298        self.crtc.serialize_into(bytes);
6299        self.mode.serialize_into(bytes);
6300        u16::from(self.rotation).serialize_into(bytes);
6301        bytes.extend_from_slice(&[0; 2]);
6302        self.x.serialize_into(bytes);
6303        self.y.serialize_into(bytes);
6304        self.width.serialize_into(bytes);
6305        self.height.serialize_into(bytes);
6306    }
6307}
6308
6309#[derive(Clone, Copy, Default)]
6310#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
6311#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6312pub struct OutputChange {
6313    pub timestamp: xproto::Timestamp,
6314    pub config_timestamp: xproto::Timestamp,
6315    pub window: xproto::Window,
6316    pub output: Output,
6317    pub crtc: Crtc,
6318    pub mode: Mode,
6319    pub rotation: Rotation,
6320    pub connection: Connection,
6321    pub subpixel_order: render::SubPixel,
6322}
6323impl_debug_if_no_extra_traits!(OutputChange, "OutputChange");
6324impl TryParse for OutputChange {
6325    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6326        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
6327        let (config_timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
6328        let (window, remaining) = xproto::Window::try_parse(remaining)?;
6329        let (output, remaining) = Output::try_parse(remaining)?;
6330        let (crtc, remaining) = Crtc::try_parse(remaining)?;
6331        let (mode, remaining) = Mode::try_parse(remaining)?;
6332        let (rotation, remaining) = u16::try_parse(remaining)?;
6333        let (connection, remaining) = u8::try_parse(remaining)?;
6334        let (subpixel_order, remaining) = u8::try_parse(remaining)?;
6335        let rotation = rotation.into();
6336        let connection = connection.into();
6337        let subpixel_order = subpixel_order.into();
6338        let result = OutputChange { timestamp, config_timestamp, window, output, crtc, mode, rotation, connection, subpixel_order };
6339        Ok((result, remaining))
6340    }
6341}
6342impl Serialize for OutputChange {
6343    type Bytes = [u8; 28];
6344    fn serialize(&self) -> [u8; 28] {
6345        let timestamp_bytes = self.timestamp.serialize();
6346        let config_timestamp_bytes = self.config_timestamp.serialize();
6347        let window_bytes = self.window.serialize();
6348        let output_bytes = self.output.serialize();
6349        let crtc_bytes = self.crtc.serialize();
6350        let mode_bytes = self.mode.serialize();
6351        let rotation_bytes = u16::from(self.rotation).serialize();
6352        let connection_bytes = u8::from(self.connection).serialize();
6353        let subpixel_order_bytes = (u32::from(self.subpixel_order) as u8).serialize();
6354        [
6355            timestamp_bytes[0],
6356            timestamp_bytes[1],
6357            timestamp_bytes[2],
6358            timestamp_bytes[3],
6359            config_timestamp_bytes[0],
6360            config_timestamp_bytes[1],
6361            config_timestamp_bytes[2],
6362            config_timestamp_bytes[3],
6363            window_bytes[0],
6364            window_bytes[1],
6365            window_bytes[2],
6366            window_bytes[3],
6367            output_bytes[0],
6368            output_bytes[1],
6369            output_bytes[2],
6370            output_bytes[3],
6371            crtc_bytes[0],
6372            crtc_bytes[1],
6373            crtc_bytes[2],
6374            crtc_bytes[3],
6375            mode_bytes[0],
6376            mode_bytes[1],
6377            mode_bytes[2],
6378            mode_bytes[3],
6379            rotation_bytes[0],
6380            rotation_bytes[1],
6381            connection_bytes[0],
6382            subpixel_order_bytes[0],
6383        ]
6384    }
6385    fn serialize_into(&self, bytes: &mut Vec<u8>) {
6386        bytes.reserve(28);
6387        self.timestamp.serialize_into(bytes);
6388        self.config_timestamp.serialize_into(bytes);
6389        self.window.serialize_into(bytes);
6390        self.output.serialize_into(bytes);
6391        self.crtc.serialize_into(bytes);
6392        self.mode.serialize_into(bytes);
6393        u16::from(self.rotation).serialize_into(bytes);
6394        u8::from(self.connection).serialize_into(bytes);
6395        (u32::from(self.subpixel_order) as u8).serialize_into(bytes);
6396    }
6397}
6398
6399#[derive(Clone, Copy, Default)]
6400#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
6401#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6402pub struct OutputProperty {
6403    pub window: xproto::Window,
6404    pub output: Output,
6405    pub atom: xproto::Atom,
6406    pub timestamp: xproto::Timestamp,
6407    pub status: xproto::Property,
6408}
6409impl_debug_if_no_extra_traits!(OutputProperty, "OutputProperty");
6410impl TryParse for OutputProperty {
6411    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6412        let (window, remaining) = xproto::Window::try_parse(remaining)?;
6413        let (output, remaining) = Output::try_parse(remaining)?;
6414        let (atom, remaining) = xproto::Atom::try_parse(remaining)?;
6415        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
6416        let (status, remaining) = u8::try_parse(remaining)?;
6417        let remaining = remaining.get(11..).ok_or(ParseError::InsufficientData)?;
6418        let status = status.into();
6419        let result = OutputProperty { window, output, atom, timestamp, status };
6420        Ok((result, remaining))
6421    }
6422}
6423impl Serialize for OutputProperty {
6424    type Bytes = [u8; 28];
6425    fn serialize(&self) -> [u8; 28] {
6426        let window_bytes = self.window.serialize();
6427        let output_bytes = self.output.serialize();
6428        let atom_bytes = self.atom.serialize();
6429        let timestamp_bytes = self.timestamp.serialize();
6430        let status_bytes = u8::from(self.status).serialize();
6431        [
6432            window_bytes[0],
6433            window_bytes[1],
6434            window_bytes[2],
6435            window_bytes[3],
6436            output_bytes[0],
6437            output_bytes[1],
6438            output_bytes[2],
6439            output_bytes[3],
6440            atom_bytes[0],
6441            atom_bytes[1],
6442            atom_bytes[2],
6443            atom_bytes[3],
6444            timestamp_bytes[0],
6445            timestamp_bytes[1],
6446            timestamp_bytes[2],
6447            timestamp_bytes[3],
6448            status_bytes[0],
6449            0,
6450            0,
6451            0,
6452            0,
6453            0,
6454            0,
6455            0,
6456            0,
6457            0,
6458            0,
6459            0,
6460        ]
6461    }
6462    fn serialize_into(&self, bytes: &mut Vec<u8>) {
6463        bytes.reserve(28);
6464        self.window.serialize_into(bytes);
6465        self.output.serialize_into(bytes);
6466        self.atom.serialize_into(bytes);
6467        self.timestamp.serialize_into(bytes);
6468        u8::from(self.status).serialize_into(bytes);
6469        bytes.extend_from_slice(&[0; 11]);
6470    }
6471}
6472
6473#[derive(Clone, Copy, Default)]
6474#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
6475#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6476pub struct ProviderChange {
6477    pub timestamp: xproto::Timestamp,
6478    pub window: xproto::Window,
6479    pub provider: Provider,
6480}
6481impl_debug_if_no_extra_traits!(ProviderChange, "ProviderChange");
6482impl TryParse for ProviderChange {
6483    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6484        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
6485        let (window, remaining) = xproto::Window::try_parse(remaining)?;
6486        let (provider, remaining) = Provider::try_parse(remaining)?;
6487        let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
6488        let result = ProviderChange { timestamp, window, provider };
6489        Ok((result, remaining))
6490    }
6491}
6492impl Serialize for ProviderChange {
6493    type Bytes = [u8; 28];
6494    fn serialize(&self) -> [u8; 28] {
6495        let timestamp_bytes = self.timestamp.serialize();
6496        let window_bytes = self.window.serialize();
6497        let provider_bytes = self.provider.serialize();
6498        [
6499            timestamp_bytes[0],
6500            timestamp_bytes[1],
6501            timestamp_bytes[2],
6502            timestamp_bytes[3],
6503            window_bytes[0],
6504            window_bytes[1],
6505            window_bytes[2],
6506            window_bytes[3],
6507            provider_bytes[0],
6508            provider_bytes[1],
6509            provider_bytes[2],
6510            provider_bytes[3],
6511            0,
6512            0,
6513            0,
6514            0,
6515            0,
6516            0,
6517            0,
6518            0,
6519            0,
6520            0,
6521            0,
6522            0,
6523            0,
6524            0,
6525            0,
6526            0,
6527        ]
6528    }
6529    fn serialize_into(&self, bytes: &mut Vec<u8>) {
6530        bytes.reserve(28);
6531        self.timestamp.serialize_into(bytes);
6532        self.window.serialize_into(bytes);
6533        self.provider.serialize_into(bytes);
6534        bytes.extend_from_slice(&[0; 16]);
6535    }
6536}
6537
6538#[derive(Clone, Copy, Default)]
6539#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
6540#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6541pub struct ProviderProperty {
6542    pub window: xproto::Window,
6543    pub provider: Provider,
6544    pub atom: xproto::Atom,
6545    pub timestamp: xproto::Timestamp,
6546    pub state: u8,
6547}
6548impl_debug_if_no_extra_traits!(ProviderProperty, "ProviderProperty");
6549impl TryParse for ProviderProperty {
6550    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6551        let (window, remaining) = xproto::Window::try_parse(remaining)?;
6552        let (provider, remaining) = Provider::try_parse(remaining)?;
6553        let (atom, remaining) = xproto::Atom::try_parse(remaining)?;
6554        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
6555        let (state, remaining) = u8::try_parse(remaining)?;
6556        let remaining = remaining.get(11..).ok_or(ParseError::InsufficientData)?;
6557        let result = ProviderProperty { window, provider, atom, timestamp, state };
6558        Ok((result, remaining))
6559    }
6560}
6561impl Serialize for ProviderProperty {
6562    type Bytes = [u8; 28];
6563    fn serialize(&self) -> [u8; 28] {
6564        let window_bytes = self.window.serialize();
6565        let provider_bytes = self.provider.serialize();
6566        let atom_bytes = self.atom.serialize();
6567        let timestamp_bytes = self.timestamp.serialize();
6568        let state_bytes = self.state.serialize();
6569        [
6570            window_bytes[0],
6571            window_bytes[1],
6572            window_bytes[2],
6573            window_bytes[3],
6574            provider_bytes[0],
6575            provider_bytes[1],
6576            provider_bytes[2],
6577            provider_bytes[3],
6578            atom_bytes[0],
6579            atom_bytes[1],
6580            atom_bytes[2],
6581            atom_bytes[3],
6582            timestamp_bytes[0],
6583            timestamp_bytes[1],
6584            timestamp_bytes[2],
6585            timestamp_bytes[3],
6586            state_bytes[0],
6587            0,
6588            0,
6589            0,
6590            0,
6591            0,
6592            0,
6593            0,
6594            0,
6595            0,
6596            0,
6597            0,
6598        ]
6599    }
6600    fn serialize_into(&self, bytes: &mut Vec<u8>) {
6601        bytes.reserve(28);
6602        self.window.serialize_into(bytes);
6603        self.provider.serialize_into(bytes);
6604        self.atom.serialize_into(bytes);
6605        self.timestamp.serialize_into(bytes);
6606        self.state.serialize_into(bytes);
6607        bytes.extend_from_slice(&[0; 11]);
6608    }
6609}
6610
6611#[derive(Clone, Copy, Default)]
6612#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
6613#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6614pub struct ResourceChange {
6615    pub timestamp: xproto::Timestamp,
6616    pub window: xproto::Window,
6617}
6618impl_debug_if_no_extra_traits!(ResourceChange, "ResourceChange");
6619impl TryParse for ResourceChange {
6620    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6621        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
6622        let (window, remaining) = xproto::Window::try_parse(remaining)?;
6623        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
6624        let result = ResourceChange { timestamp, window };
6625        Ok((result, remaining))
6626    }
6627}
6628impl Serialize for ResourceChange {
6629    type Bytes = [u8; 28];
6630    fn serialize(&self) -> [u8; 28] {
6631        let timestamp_bytes = self.timestamp.serialize();
6632        let window_bytes = self.window.serialize();
6633        [
6634            timestamp_bytes[0],
6635            timestamp_bytes[1],
6636            timestamp_bytes[2],
6637            timestamp_bytes[3],
6638            window_bytes[0],
6639            window_bytes[1],
6640            window_bytes[2],
6641            window_bytes[3],
6642            0,
6643            0,
6644            0,
6645            0,
6646            0,
6647            0,
6648            0,
6649            0,
6650            0,
6651            0,
6652            0,
6653            0,
6654            0,
6655            0,
6656            0,
6657            0,
6658            0,
6659            0,
6660            0,
6661            0,
6662        ]
6663    }
6664    fn serialize_into(&self, bytes: &mut Vec<u8>) {
6665        bytes.reserve(28);
6666        self.timestamp.serialize_into(bytes);
6667        self.window.serialize_into(bytes);
6668        bytes.extend_from_slice(&[0; 20]);
6669    }
6670}
6671
6672#[derive(Clone, Default)]
6673#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
6674#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6675pub struct MonitorInfo {
6676    pub name: xproto::Atom,
6677    pub primary: bool,
6678    pub automatic: bool,
6679    pub x: i16,
6680    pub y: i16,
6681    pub width: u16,
6682    pub height: u16,
6683    pub width_in_millimeters: u32,
6684    pub height_in_millimeters: u32,
6685    pub outputs: Vec<Output>,
6686}
6687impl_debug_if_no_extra_traits!(MonitorInfo, "MonitorInfo");
6688impl TryParse for MonitorInfo {
6689    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6690        let (name, remaining) = xproto::Atom::try_parse(remaining)?;
6691        let (primary, remaining) = bool::try_parse(remaining)?;
6692        let (automatic, remaining) = bool::try_parse(remaining)?;
6693        let (n_output, remaining) = u16::try_parse(remaining)?;
6694        let (x, remaining) = i16::try_parse(remaining)?;
6695        let (y, remaining) = i16::try_parse(remaining)?;
6696        let (width, remaining) = u16::try_parse(remaining)?;
6697        let (height, remaining) = u16::try_parse(remaining)?;
6698        let (width_in_millimeters, remaining) = u32::try_parse(remaining)?;
6699        let (height_in_millimeters, remaining) = u32::try_parse(remaining)?;
6700        let (outputs, remaining) = crate::x11_utils::parse_list::<Output>(remaining, n_output.try_to_usize()?)?;
6701        let result = MonitorInfo { name, primary, automatic, x, y, width, height, width_in_millimeters, height_in_millimeters, outputs };
6702        Ok((result, remaining))
6703    }
6704}
6705impl Serialize for MonitorInfo {
6706    type Bytes = Vec<u8>;
6707    fn serialize(&self) -> Vec<u8> {
6708        let mut result = Vec::new();
6709        self.serialize_into(&mut result);
6710        result
6711    }
6712    fn serialize_into(&self, bytes: &mut Vec<u8>) {
6713        bytes.reserve(24);
6714        self.name.serialize_into(bytes);
6715        self.primary.serialize_into(bytes);
6716        self.automatic.serialize_into(bytes);
6717        let n_output = u16::try_from(self.outputs.len()).expect("`outputs` has too many elements");
6718        n_output.serialize_into(bytes);
6719        self.x.serialize_into(bytes);
6720        self.y.serialize_into(bytes);
6721        self.width.serialize_into(bytes);
6722        self.height.serialize_into(bytes);
6723        self.width_in_millimeters.serialize_into(bytes);
6724        self.height_in_millimeters.serialize_into(bytes);
6725        self.outputs.serialize_into(bytes);
6726    }
6727}
6728impl MonitorInfo {
6729    /// Get the value of the `nOutput` field.
6730    ///
6731    /// The `nOutput` field is used as the length field of the `outputs` field.
6732    /// This function computes the field's value again based on the length of the list.
6733    ///
6734    /// # Panics
6735    ///
6736    /// Panics if the value cannot be represented in the target type. This
6737    /// cannot happen with values of the struct received from the X11 server.
6738    pub fn n_output(&self) -> u16 {
6739        self.outputs.len()
6740            .try_into().unwrap()
6741    }
6742}
6743
6744/// Opcode for the GetMonitors request
6745pub const GET_MONITORS_REQUEST: u8 = 42;
6746#[derive(Clone, Copy, Default)]
6747#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
6748#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6749pub struct GetMonitorsRequest {
6750    pub window: xproto::Window,
6751    pub get_active: bool,
6752}
6753impl_debug_if_no_extra_traits!(GetMonitorsRequest, "GetMonitorsRequest");
6754impl GetMonitorsRequest {
6755    /// Serialize this request into bytes for the provided connection
6756    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
6757        let length_so_far = 0;
6758        let window_bytes = self.window.serialize();
6759        let get_active_bytes = self.get_active.serialize();
6760        let mut request0 = vec![
6761            major_opcode,
6762            GET_MONITORS_REQUEST,
6763            0,
6764            0,
6765            window_bytes[0],
6766            window_bytes[1],
6767            window_bytes[2],
6768            window_bytes[3],
6769            get_active_bytes[0],
6770            0,
6771            0,
6772            0,
6773        ];
6774        let length_so_far = length_so_far + request0.len();
6775        assert_eq!(length_so_far % 4, 0);
6776        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
6777        request0[2..4].copy_from_slice(&length.to_ne_bytes());
6778        ([request0.into()], vec![])
6779    }
6780    /// Parse this request given its header, its body, and any fds that go along with it
6781    #[cfg(feature = "request-parsing")]
6782    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
6783        if header.minor_opcode != GET_MONITORS_REQUEST {
6784            return Err(ParseError::InvalidValue);
6785        }
6786        let (window, remaining) = xproto::Window::try_parse(value)?;
6787        let (get_active, remaining) = bool::try_parse(remaining)?;
6788        let _ = remaining;
6789        Ok(GetMonitorsRequest {
6790            window,
6791            get_active,
6792        })
6793    }
6794}
6795impl Request for GetMonitorsRequest {
6796    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
6797
6798    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
6799        let (bufs, fds) = self.serialize(major_opcode);
6800        // Flatten the buffers into a single vector
6801        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
6802        (buf, fds)
6803    }
6804}
6805impl crate::x11_utils::ReplyRequest for GetMonitorsRequest {
6806    type Reply = GetMonitorsReply;
6807}
6808
6809#[derive(Clone, Default)]
6810#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
6811#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6812pub struct GetMonitorsReply {
6813    pub sequence: u16,
6814    pub length: u32,
6815    pub timestamp: xproto::Timestamp,
6816    pub n_outputs: u32,
6817    pub monitors: Vec<MonitorInfo>,
6818}
6819impl_debug_if_no_extra_traits!(GetMonitorsReply, "GetMonitorsReply");
6820impl TryParse for GetMonitorsReply {
6821    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
6822        let remaining = initial_value;
6823        let (response_type, remaining) = u8::try_parse(remaining)?;
6824        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
6825        let (sequence, remaining) = u16::try_parse(remaining)?;
6826        let (length, remaining) = u32::try_parse(remaining)?;
6827        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
6828        let (n_monitors, remaining) = u32::try_parse(remaining)?;
6829        let (n_outputs, remaining) = u32::try_parse(remaining)?;
6830        let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
6831        let (monitors, remaining) = crate::x11_utils::parse_list::<MonitorInfo>(remaining, n_monitors.try_to_usize()?)?;
6832        if response_type != 1 {
6833            return Err(ParseError::InvalidValue);
6834        }
6835        let result = GetMonitorsReply { sequence, length, timestamp, n_outputs, monitors };
6836        let _ = remaining;
6837        let remaining = initial_value.get(32 + length as usize * 4..)
6838            .ok_or(ParseError::InsufficientData)?;
6839        Ok((result, remaining))
6840    }
6841}
6842impl Serialize for GetMonitorsReply {
6843    type Bytes = Vec<u8>;
6844    fn serialize(&self) -> Vec<u8> {
6845        let mut result = Vec::new();
6846        self.serialize_into(&mut result);
6847        result
6848    }
6849    fn serialize_into(&self, bytes: &mut Vec<u8>) {
6850        bytes.reserve(32);
6851        let response_type_bytes = &[1];
6852        bytes.push(response_type_bytes[0]);
6853        bytes.extend_from_slice(&[0; 1]);
6854        self.sequence.serialize_into(bytes);
6855        self.length.serialize_into(bytes);
6856        self.timestamp.serialize_into(bytes);
6857        let n_monitors = u32::try_from(self.monitors.len()).expect("`monitors` has too many elements");
6858        n_monitors.serialize_into(bytes);
6859        self.n_outputs.serialize_into(bytes);
6860        bytes.extend_from_slice(&[0; 12]);
6861        self.monitors.serialize_into(bytes);
6862    }
6863}
6864impl GetMonitorsReply {
6865    /// Get the value of the `nMonitors` field.
6866    ///
6867    /// The `nMonitors` field is used as the length field of the `monitors` field.
6868    /// This function computes the field's value again based on the length of the list.
6869    ///
6870    /// # Panics
6871    ///
6872    /// Panics if the value cannot be represented in the target type. This
6873    /// cannot happen with values of the struct received from the X11 server.
6874    pub fn n_monitors(&self) -> u32 {
6875        self.monitors.len()
6876            .try_into().unwrap()
6877    }
6878}
6879
6880/// Opcode for the SetMonitor request
6881pub const SET_MONITOR_REQUEST: u8 = 43;
6882#[derive(Clone, Default)]
6883#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
6884#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6885pub struct SetMonitorRequest {
6886    pub window: xproto::Window,
6887    pub monitorinfo: MonitorInfo,
6888}
6889impl_debug_if_no_extra_traits!(SetMonitorRequest, "SetMonitorRequest");
6890impl SetMonitorRequest {
6891    /// Serialize this request into bytes for the provided connection
6892    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 3]> {
6893        let length_so_far = 0;
6894        let window_bytes = self.window.serialize();
6895        let mut request0 = vec![
6896            major_opcode,
6897            SET_MONITOR_REQUEST,
6898            0,
6899            0,
6900            window_bytes[0],
6901            window_bytes[1],
6902            window_bytes[2],
6903            window_bytes[3],
6904        ];
6905        let length_so_far = length_so_far + request0.len();
6906        let monitorinfo_bytes = self.monitorinfo.serialize();
6907        let length_so_far = length_so_far + monitorinfo_bytes.len();
6908        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
6909        let length_so_far = length_so_far + padding0.len();
6910        assert_eq!(length_so_far % 4, 0);
6911        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
6912        request0[2..4].copy_from_slice(&length.to_ne_bytes());
6913        ([request0.into(), monitorinfo_bytes.into(), padding0.into()], vec![])
6914    }
6915    /// Parse this request given its header, its body, and any fds that go along with it
6916    #[cfg(feature = "request-parsing")]
6917    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
6918        if header.minor_opcode != SET_MONITOR_REQUEST {
6919            return Err(ParseError::InvalidValue);
6920        }
6921        let (window, remaining) = xproto::Window::try_parse(value)?;
6922        let (monitorinfo, remaining) = MonitorInfo::try_parse(remaining)?;
6923        let _ = remaining;
6924        Ok(SetMonitorRequest {
6925            window,
6926            monitorinfo,
6927        })
6928    }
6929}
6930impl Request for SetMonitorRequest {
6931    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
6932
6933    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
6934        let (bufs, fds) = self.serialize(major_opcode);
6935        // Flatten the buffers into a single vector
6936        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
6937        (buf, fds)
6938    }
6939}
6940impl crate::x11_utils::VoidRequest for SetMonitorRequest {
6941}
6942
6943/// Opcode for the DeleteMonitor request
6944pub const DELETE_MONITOR_REQUEST: u8 = 44;
6945#[derive(Clone, Copy, Default)]
6946#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
6947#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
6948pub struct DeleteMonitorRequest {
6949    pub window: xproto::Window,
6950    pub name: xproto::Atom,
6951}
6952impl_debug_if_no_extra_traits!(DeleteMonitorRequest, "DeleteMonitorRequest");
6953impl DeleteMonitorRequest {
6954    /// Serialize this request into bytes for the provided connection
6955    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
6956        let length_so_far = 0;
6957        let window_bytes = self.window.serialize();
6958        let name_bytes = self.name.serialize();
6959        let mut request0 = vec![
6960            major_opcode,
6961            DELETE_MONITOR_REQUEST,
6962            0,
6963            0,
6964            window_bytes[0],
6965            window_bytes[1],
6966            window_bytes[2],
6967            window_bytes[3],
6968            name_bytes[0],
6969            name_bytes[1],
6970            name_bytes[2],
6971            name_bytes[3],
6972        ];
6973        let length_so_far = length_so_far + request0.len();
6974        assert_eq!(length_so_far % 4, 0);
6975        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
6976        request0[2..4].copy_from_slice(&length.to_ne_bytes());
6977        ([request0.into()], vec![])
6978    }
6979    /// Parse this request given its header, its body, and any fds that go along with it
6980    #[cfg(feature = "request-parsing")]
6981    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
6982        if header.minor_opcode != DELETE_MONITOR_REQUEST {
6983            return Err(ParseError::InvalidValue);
6984        }
6985        let (window, remaining) = xproto::Window::try_parse(value)?;
6986        let (name, remaining) = xproto::Atom::try_parse(remaining)?;
6987        let _ = remaining;
6988        Ok(DeleteMonitorRequest {
6989            window,
6990            name,
6991        })
6992    }
6993}
6994impl Request for DeleteMonitorRequest {
6995    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
6996
6997    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
6998        let (bufs, fds) = self.serialize(major_opcode);
6999        // Flatten the buffers into a single vector
7000        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
7001        (buf, fds)
7002    }
7003}
7004impl crate::x11_utils::VoidRequest for DeleteMonitorRequest {
7005}
7006
7007/// Opcode for the CreateLease request
7008pub const CREATE_LEASE_REQUEST: u8 = 45;
7009#[derive(Clone, Default)]
7010#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
7011#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7012pub struct CreateLeaseRequest<'input> {
7013    pub window: xproto::Window,
7014    pub lid: Lease,
7015    pub crtcs: Cow<'input, [Crtc]>,
7016    pub outputs: Cow<'input, [Output]>,
7017}
7018impl_debug_if_no_extra_traits!(CreateLeaseRequest<'_>, "CreateLeaseRequest");
7019impl<'input> CreateLeaseRequest<'input> {
7020    /// Serialize this request into bytes for the provided connection
7021    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 4]> {
7022        let length_so_far = 0;
7023        let window_bytes = self.window.serialize();
7024        let lid_bytes = self.lid.serialize();
7025        let num_crtcs = u16::try_from(self.crtcs.len()).expect("`crtcs` has too many elements");
7026        let num_crtcs_bytes = num_crtcs.serialize();
7027        let num_outputs = u16::try_from(self.outputs.len()).expect("`outputs` has too many elements");
7028        let num_outputs_bytes = num_outputs.serialize();
7029        let mut request0 = vec![
7030            major_opcode,
7031            CREATE_LEASE_REQUEST,
7032            0,
7033            0,
7034            window_bytes[0],
7035            window_bytes[1],
7036            window_bytes[2],
7037            window_bytes[3],
7038            lid_bytes[0],
7039            lid_bytes[1],
7040            lid_bytes[2],
7041            lid_bytes[3],
7042            num_crtcs_bytes[0],
7043            num_crtcs_bytes[1],
7044            num_outputs_bytes[0],
7045            num_outputs_bytes[1],
7046        ];
7047        let length_so_far = length_so_far + request0.len();
7048        let crtcs_bytes = self.crtcs.serialize();
7049        let length_so_far = length_so_far + crtcs_bytes.len();
7050        let outputs_bytes = self.outputs.serialize();
7051        let length_so_far = length_so_far + outputs_bytes.len();
7052        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
7053        let length_so_far = length_so_far + padding0.len();
7054        assert_eq!(length_so_far % 4, 0);
7055        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
7056        request0[2..4].copy_from_slice(&length.to_ne_bytes());
7057        ([request0.into(), crtcs_bytes.into(), outputs_bytes.into(), padding0.into()], vec![])
7058    }
7059    /// Parse this request given its header, its body, and any fds that go along with it
7060    #[cfg(feature = "request-parsing")]
7061    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
7062        if header.minor_opcode != CREATE_LEASE_REQUEST {
7063            return Err(ParseError::InvalidValue);
7064        }
7065        let (window, remaining) = xproto::Window::try_parse(value)?;
7066        let (lid, remaining) = Lease::try_parse(remaining)?;
7067        let (num_crtcs, remaining) = u16::try_parse(remaining)?;
7068        let (num_outputs, remaining) = u16::try_parse(remaining)?;
7069        let (crtcs, remaining) = crate::x11_utils::parse_list::<Crtc>(remaining, num_crtcs.try_to_usize()?)?;
7070        let (outputs, remaining) = crate::x11_utils::parse_list::<Output>(remaining, num_outputs.try_to_usize()?)?;
7071        let _ = remaining;
7072        Ok(CreateLeaseRequest {
7073            window,
7074            lid,
7075            crtcs: Cow::Owned(crtcs),
7076            outputs: Cow::Owned(outputs),
7077        })
7078    }
7079    /// Clone all borrowed data in this CreateLeaseRequest.
7080    pub fn into_owned(self) -> CreateLeaseRequest<'static> {
7081        CreateLeaseRequest {
7082            window: self.window,
7083            lid: self.lid,
7084            crtcs: Cow::Owned(self.crtcs.into_owned()),
7085            outputs: Cow::Owned(self.outputs.into_owned()),
7086        }
7087    }
7088}
7089impl<'input> Request for CreateLeaseRequest<'input> {
7090    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
7091
7092    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
7093        let (bufs, fds) = self.serialize(major_opcode);
7094        // Flatten the buffers into a single vector
7095        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
7096        (buf, fds)
7097    }
7098}
7099impl<'input> crate::x11_utils::ReplyFDsRequest for CreateLeaseRequest<'input> {
7100    type Reply = CreateLeaseReply;
7101}
7102
7103#[cfg_attr(feature = "extra-traits", derive(Debug))]
7104pub struct CreateLeaseReply {
7105    pub nfd: u8,
7106    pub sequence: u16,
7107    pub length: u32,
7108    pub master_fd: RawFdContainer,
7109}
7110impl_debug_if_no_extra_traits!(CreateLeaseReply, "CreateLeaseReply");
7111impl TryParseFd for CreateLeaseReply {
7112    fn try_parse_fd<'a>(initial_value: &'a [u8], fds: &mut Vec<RawFdContainer>) -> Result<(Self, &'a [u8]), ParseError> {
7113        let remaining = initial_value;
7114        let (response_type, remaining) = u8::try_parse(remaining)?;
7115        let (nfd, remaining) = u8::try_parse(remaining)?;
7116        let (sequence, remaining) = u16::try_parse(remaining)?;
7117        let (length, remaining) = u32::try_parse(remaining)?;
7118        if fds.is_empty() { return Err(ParseError::MissingFileDescriptors) }
7119        let master_fd = fds.remove(0);
7120        let remaining = remaining.get(24..).ok_or(ParseError::InsufficientData)?;
7121        if response_type != 1 {
7122            return Err(ParseError::InvalidValue);
7123        }
7124        let result = CreateLeaseReply { nfd, sequence, length, master_fd };
7125        let _ = remaining;
7126        let remaining = initial_value.get(32 + length as usize * 4..)
7127            .ok_or(ParseError::InsufficientData)?;
7128        Ok((result, remaining))
7129    }
7130}
7131impl Serialize for CreateLeaseReply {
7132    type Bytes = [u8; 32];
7133    fn serialize(&self) -> [u8; 32] {
7134        let response_type_bytes = &[1];
7135        let nfd_bytes = self.nfd.serialize();
7136        let sequence_bytes = self.sequence.serialize();
7137        let length_bytes = self.length.serialize();
7138        [
7139            response_type_bytes[0],
7140            nfd_bytes[0],
7141            sequence_bytes[0],
7142            sequence_bytes[1],
7143            length_bytes[0],
7144            length_bytes[1],
7145            length_bytes[2],
7146            length_bytes[3],
7147            0,
7148            0,
7149            0,
7150            0,
7151            0,
7152            0,
7153            0,
7154            0,
7155            0,
7156            0,
7157            0,
7158            0,
7159            0,
7160            0,
7161            0,
7162            0,
7163            0,
7164            0,
7165            0,
7166            0,
7167            0,
7168            0,
7169            0,
7170            0,
7171        ]
7172    }
7173    fn serialize_into(&self, bytes: &mut Vec<u8>) {
7174        bytes.reserve(32);
7175        let response_type_bytes = &[1];
7176        bytes.push(response_type_bytes[0]);
7177        self.nfd.serialize_into(bytes);
7178        self.sequence.serialize_into(bytes);
7179        self.length.serialize_into(bytes);
7180        bytes.extend_from_slice(&[0; 24]);
7181    }
7182}
7183
7184/// Opcode for the FreeLease request
7185pub const FREE_LEASE_REQUEST: u8 = 46;
7186#[derive(Clone, Copy, Default)]
7187#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
7188#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7189pub struct FreeLeaseRequest {
7190    pub lid: Lease,
7191    pub terminate: u8,
7192}
7193impl_debug_if_no_extra_traits!(FreeLeaseRequest, "FreeLeaseRequest");
7194impl FreeLeaseRequest {
7195    /// Serialize this request into bytes for the provided connection
7196    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
7197        let length_so_far = 0;
7198        let lid_bytes = self.lid.serialize();
7199        let terminate_bytes = self.terminate.serialize();
7200        let mut request0 = vec![
7201            major_opcode,
7202            FREE_LEASE_REQUEST,
7203            0,
7204            0,
7205            lid_bytes[0],
7206            lid_bytes[1],
7207            lid_bytes[2],
7208            lid_bytes[3],
7209            terminate_bytes[0],
7210            0,
7211            0,
7212            0,
7213        ];
7214        let length_so_far = length_so_far + request0.len();
7215        assert_eq!(length_so_far % 4, 0);
7216        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
7217        request0[2..4].copy_from_slice(&length.to_ne_bytes());
7218        ([request0.into()], vec![])
7219    }
7220    /// Parse this request given its header, its body, and any fds that go along with it
7221    #[cfg(feature = "request-parsing")]
7222    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
7223        if header.minor_opcode != FREE_LEASE_REQUEST {
7224            return Err(ParseError::InvalidValue);
7225        }
7226        let (lid, remaining) = Lease::try_parse(value)?;
7227        let (terminate, remaining) = u8::try_parse(remaining)?;
7228        let _ = remaining;
7229        Ok(FreeLeaseRequest {
7230            lid,
7231            terminate,
7232        })
7233    }
7234}
7235impl Request for FreeLeaseRequest {
7236    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
7237
7238    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
7239        let (bufs, fds) = self.serialize(major_opcode);
7240        // Flatten the buffers into a single vector
7241        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
7242        (buf, fds)
7243    }
7244}
7245impl crate::x11_utils::VoidRequest for FreeLeaseRequest {
7246}
7247
7248#[derive(Clone, Copy, Default)]
7249#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
7250#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7251pub struct LeaseNotify {
7252    pub timestamp: xproto::Timestamp,
7253    pub window: xproto::Window,
7254    pub lease: Lease,
7255    pub created: u8,
7256}
7257impl_debug_if_no_extra_traits!(LeaseNotify, "LeaseNotify");
7258impl TryParse for LeaseNotify {
7259    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
7260        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
7261        let (window, remaining) = xproto::Window::try_parse(remaining)?;
7262        let (lease, remaining) = Lease::try_parse(remaining)?;
7263        let (created, remaining) = u8::try_parse(remaining)?;
7264        let remaining = remaining.get(15..).ok_or(ParseError::InsufficientData)?;
7265        let result = LeaseNotify { timestamp, window, lease, created };
7266        Ok((result, remaining))
7267    }
7268}
7269impl Serialize for LeaseNotify {
7270    type Bytes = [u8; 28];
7271    fn serialize(&self) -> [u8; 28] {
7272        let timestamp_bytes = self.timestamp.serialize();
7273        let window_bytes = self.window.serialize();
7274        let lease_bytes = self.lease.serialize();
7275        let created_bytes = self.created.serialize();
7276        [
7277            timestamp_bytes[0],
7278            timestamp_bytes[1],
7279            timestamp_bytes[2],
7280            timestamp_bytes[3],
7281            window_bytes[0],
7282            window_bytes[1],
7283            window_bytes[2],
7284            window_bytes[3],
7285            lease_bytes[0],
7286            lease_bytes[1],
7287            lease_bytes[2],
7288            lease_bytes[3],
7289            created_bytes[0],
7290            0,
7291            0,
7292            0,
7293            0,
7294            0,
7295            0,
7296            0,
7297            0,
7298            0,
7299            0,
7300            0,
7301            0,
7302            0,
7303            0,
7304            0,
7305        ]
7306    }
7307    fn serialize_into(&self, bytes: &mut Vec<u8>) {
7308        bytes.reserve(28);
7309        self.timestamp.serialize_into(bytes);
7310        self.window.serialize_into(bytes);
7311        self.lease.serialize_into(bytes);
7312        self.created.serialize_into(bytes);
7313        bytes.extend_from_slice(&[0; 15]);
7314    }
7315}
7316
7317#[derive(Debug, Copy, Clone)]
7318#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7319pub struct NotifyData([u8; 28]);
7320impl NotifyData {
7321    pub fn as_cc(&self) -> CrtcChange {
7322        fn do_the_parse(remaining: &[u8]) -> Result<CrtcChange, ParseError> {
7323            let (cc, remaining) = CrtcChange::try_parse(remaining)?;
7324            let _ = remaining;
7325            Ok(cc)
7326        }
7327        do_the_parse(&self.0).unwrap()
7328    }
7329    pub fn as_oc(&self) -> OutputChange {
7330        fn do_the_parse(remaining: &[u8]) -> Result<OutputChange, ParseError> {
7331            let (oc, remaining) = OutputChange::try_parse(remaining)?;
7332            let _ = remaining;
7333            Ok(oc)
7334        }
7335        do_the_parse(&self.0).unwrap()
7336    }
7337    pub fn as_op(&self) -> OutputProperty {
7338        fn do_the_parse(remaining: &[u8]) -> Result<OutputProperty, ParseError> {
7339            let (op, remaining) = OutputProperty::try_parse(remaining)?;
7340            let _ = remaining;
7341            Ok(op)
7342        }
7343        do_the_parse(&self.0).unwrap()
7344    }
7345    pub fn as_pc(&self) -> ProviderChange {
7346        fn do_the_parse(remaining: &[u8]) -> Result<ProviderChange, ParseError> {
7347            let (pc, remaining) = ProviderChange::try_parse(remaining)?;
7348            let _ = remaining;
7349            Ok(pc)
7350        }
7351        do_the_parse(&self.0).unwrap()
7352    }
7353    pub fn as_pp(&self) -> ProviderProperty {
7354        fn do_the_parse(remaining: &[u8]) -> Result<ProviderProperty, ParseError> {
7355            let (pp, remaining) = ProviderProperty::try_parse(remaining)?;
7356            let _ = remaining;
7357            Ok(pp)
7358        }
7359        do_the_parse(&self.0).unwrap()
7360    }
7361    pub fn as_rc(&self) -> ResourceChange {
7362        fn do_the_parse(remaining: &[u8]) -> Result<ResourceChange, ParseError> {
7363            let (rc, remaining) = ResourceChange::try_parse(remaining)?;
7364            let _ = remaining;
7365            Ok(rc)
7366        }
7367        do_the_parse(&self.0).unwrap()
7368    }
7369    pub fn as_lc(&self) -> LeaseNotify {
7370        fn do_the_parse(remaining: &[u8]) -> Result<LeaseNotify, ParseError> {
7371            let (lc, remaining) = LeaseNotify::try_parse(remaining)?;
7372            let _ = remaining;
7373            Ok(lc)
7374        }
7375        do_the_parse(&self.0).unwrap()
7376    }
7377}
7378impl Serialize for NotifyData {
7379    type Bytes = [u8; 28];
7380    fn serialize(&self) -> [u8; 28] {
7381        self.0
7382    }
7383    fn serialize_into(&self, bytes: &mut Vec<u8>) {
7384        bytes.extend_from_slice(&self.0);
7385    }
7386}
7387impl TryParse for NotifyData {
7388    fn try_parse(value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
7389        let inner: [u8; 28] = value.get(..28)
7390            .ok_or(ParseError::InsufficientData)?
7391            .try_into()
7392            .unwrap();
7393        let result = NotifyData(inner);
7394        Ok((result, &value[28..]))
7395    }
7396}
7397impl From<CrtcChange> for NotifyData {
7398    fn from(cc: CrtcChange) -> Self {
7399        let cc_bytes = cc.serialize();
7400        Self(cc_bytes)
7401    }
7402}
7403impl From<OutputChange> for NotifyData {
7404    fn from(oc: OutputChange) -> Self {
7405        let oc_bytes = oc.serialize();
7406        Self(oc_bytes)
7407    }
7408}
7409impl From<OutputProperty> for NotifyData {
7410    fn from(op: OutputProperty) -> Self {
7411        let op_bytes = op.serialize();
7412        Self(op_bytes)
7413    }
7414}
7415impl From<ProviderChange> for NotifyData {
7416    fn from(pc: ProviderChange) -> Self {
7417        let pc_bytes = pc.serialize();
7418        Self(pc_bytes)
7419    }
7420}
7421impl From<ProviderProperty> for NotifyData {
7422    fn from(pp: ProviderProperty) -> Self {
7423        let pp_bytes = pp.serialize();
7424        Self(pp_bytes)
7425    }
7426}
7427impl From<ResourceChange> for NotifyData {
7428    fn from(rc: ResourceChange) -> Self {
7429        let rc_bytes = rc.serialize();
7430        Self(rc_bytes)
7431    }
7432}
7433impl From<LeaseNotify> for NotifyData {
7434    fn from(lc: LeaseNotify) -> Self {
7435        let lc_bytes = lc.serialize();
7436        Self(lc_bytes)
7437    }
7438}
7439
7440/// Opcode for the Notify event
7441pub const NOTIFY_EVENT: u8 = 1;
7442#[derive(Clone, Copy)]
7443#[cfg_attr(feature = "extra-traits", derive(Debug))]
7444#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
7445pub struct NotifyEvent {
7446    pub response_type: u8,
7447    pub sub_code: Notify,
7448    pub sequence: u16,
7449    pub u: NotifyData,
7450}
7451impl_debug_if_no_extra_traits!(NotifyEvent, "NotifyEvent");
7452impl TryParse for NotifyEvent {
7453    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
7454        let remaining = initial_value;
7455        let (response_type, remaining) = u8::try_parse(remaining)?;
7456        let (sub_code, remaining) = u8::try_parse(remaining)?;
7457        let (sequence, remaining) = u16::try_parse(remaining)?;
7458        let (u, remaining) = NotifyData::try_parse(remaining)?;
7459        let sub_code = sub_code.into();
7460        let result = NotifyEvent { response_type, sub_code, sequence, u };
7461        let _ = remaining;
7462        let remaining = initial_value.get(32..)
7463            .ok_or(ParseError::InsufficientData)?;
7464        Ok((result, remaining))
7465    }
7466}
7467impl Serialize for NotifyEvent {
7468    type Bytes = [u8; 32];
7469    fn serialize(&self) -> [u8; 32] {
7470        let response_type_bytes = self.response_type.serialize();
7471        let sub_code_bytes = u8::from(self.sub_code).serialize();
7472        let sequence_bytes = self.sequence.serialize();
7473        let u_bytes = self.u.serialize();
7474        [
7475            response_type_bytes[0],
7476            sub_code_bytes[0],
7477            sequence_bytes[0],
7478            sequence_bytes[1],
7479            u_bytes[0],
7480            u_bytes[1],
7481            u_bytes[2],
7482            u_bytes[3],
7483            u_bytes[4],
7484            u_bytes[5],
7485            u_bytes[6],
7486            u_bytes[7],
7487            u_bytes[8],
7488            u_bytes[9],
7489            u_bytes[10],
7490            u_bytes[11],
7491            u_bytes[12],
7492            u_bytes[13],
7493            u_bytes[14],
7494            u_bytes[15],
7495            u_bytes[16],
7496            u_bytes[17],
7497            u_bytes[18],
7498            u_bytes[19],
7499            u_bytes[20],
7500            u_bytes[21],
7501            u_bytes[22],
7502            u_bytes[23],
7503            u_bytes[24],
7504            u_bytes[25],
7505            u_bytes[26],
7506            u_bytes[27],
7507        ]
7508    }
7509    fn serialize_into(&self, bytes: &mut Vec<u8>) {
7510        bytes.reserve(32);
7511        self.response_type.serialize_into(bytes);
7512        u8::from(self.sub_code).serialize_into(bytes);
7513        self.sequence.serialize_into(bytes);
7514        self.u.serialize_into(bytes);
7515    }
7516}
7517impl From<&NotifyEvent> for [u8; 32] {
7518    fn from(input: &NotifyEvent) -> Self {
7519        let response_type_bytes = input.response_type.serialize();
7520        let sub_code_bytes = u8::from(input.sub_code).serialize();
7521        let sequence_bytes = input.sequence.serialize();
7522        let u_bytes = input.u.serialize();
7523        [
7524            response_type_bytes[0],
7525            sub_code_bytes[0],
7526            sequence_bytes[0],
7527            sequence_bytes[1],
7528            u_bytes[0],
7529            u_bytes[1],
7530            u_bytes[2],
7531            u_bytes[3],
7532            u_bytes[4],
7533            u_bytes[5],
7534            u_bytes[6],
7535            u_bytes[7],
7536            u_bytes[8],
7537            u_bytes[9],
7538            u_bytes[10],
7539            u_bytes[11],
7540            u_bytes[12],
7541            u_bytes[13],
7542            u_bytes[14],
7543            u_bytes[15],
7544            u_bytes[16],
7545            u_bytes[17],
7546            u_bytes[18],
7547            u_bytes[19],
7548            u_bytes[20],
7549            u_bytes[21],
7550            u_bytes[22],
7551            u_bytes[23],
7552            u_bytes[24],
7553            u_bytes[25],
7554            u_bytes[26],
7555            u_bytes[27],
7556        ]
7557    }
7558}
7559impl From<NotifyEvent> for [u8; 32] {
7560    fn from(input: NotifyEvent) -> Self {
7561        Self::from(&input)
7562    }
7563}
7564