x11rb_protocol/protocol/
sync.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `Sync` 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::xproto;
27
28/// The X11 name of the extension for QueryExtension
29pub const X11_EXTENSION_NAME: &str = "SYNC";
30
31/// The version number of this extension that this client library supports.
32///
33/// This constant contains the version number of this extension that is supported
34/// by this build of x11rb. For most things, it does not make sense to use this
35/// information. If you need to send a `QueryVersion`, it is recommended to instead
36/// send the maximum version of the extension that you need.
37pub const X11_XML_VERSION: (u32, u32) = (3, 1);
38
39pub type Alarm = u32;
40
41#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
42#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
43pub struct ALARMSTATE(u8);
44impl ALARMSTATE {
45    pub const ACTIVE: Self = Self(0);
46    pub const INACTIVE: Self = Self(1);
47    pub const DESTROYED: Self = Self(2);
48}
49impl From<ALARMSTATE> for u8 {
50    #[inline]
51    fn from(input: ALARMSTATE) -> Self {
52        input.0
53    }
54}
55impl From<ALARMSTATE> for Option<u8> {
56    #[inline]
57    fn from(input: ALARMSTATE) -> Self {
58        Some(input.0)
59    }
60}
61impl From<ALARMSTATE> for u16 {
62    #[inline]
63    fn from(input: ALARMSTATE) -> Self {
64        u16::from(input.0)
65    }
66}
67impl From<ALARMSTATE> for Option<u16> {
68    #[inline]
69    fn from(input: ALARMSTATE) -> Self {
70        Some(u16::from(input.0))
71    }
72}
73impl From<ALARMSTATE> for u32 {
74    #[inline]
75    fn from(input: ALARMSTATE) -> Self {
76        u32::from(input.0)
77    }
78}
79impl From<ALARMSTATE> for Option<u32> {
80    #[inline]
81    fn from(input: ALARMSTATE) -> Self {
82        Some(u32::from(input.0))
83    }
84}
85impl From<u8> for ALARMSTATE {
86    #[inline]
87    fn from(value: u8) -> Self {
88        Self(value)
89    }
90}
91impl core::fmt::Debug for ALARMSTATE  {
92    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
93        let variants = [
94            (Self::ACTIVE.0.into(), "ACTIVE", "Active"),
95            (Self::INACTIVE.0.into(), "INACTIVE", "Inactive"),
96            (Self::DESTROYED.0.into(), "DESTROYED", "Destroyed"),
97        ];
98        pretty_print_enum(fmt, self.0.into(), &variants)
99    }
100}
101
102pub type Counter = u32;
103
104pub type Fence = u32;
105
106#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
107#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
108pub struct TESTTYPE(u32);
109impl TESTTYPE {
110    pub const POSITIVE_TRANSITION: Self = Self(0);
111    pub const NEGATIVE_TRANSITION: Self = Self(1);
112    pub const POSITIVE_COMPARISON: Self = Self(2);
113    pub const NEGATIVE_COMPARISON: Self = Self(3);
114}
115impl From<TESTTYPE> for u32 {
116    #[inline]
117    fn from(input: TESTTYPE) -> Self {
118        input.0
119    }
120}
121impl From<TESTTYPE> for Option<u32> {
122    #[inline]
123    fn from(input: TESTTYPE) -> Self {
124        Some(input.0)
125    }
126}
127impl From<u8> for TESTTYPE {
128    #[inline]
129    fn from(value: u8) -> Self {
130        Self(value.into())
131    }
132}
133impl From<u16> for TESTTYPE {
134    #[inline]
135    fn from(value: u16) -> Self {
136        Self(value.into())
137    }
138}
139impl From<u32> for TESTTYPE {
140    #[inline]
141    fn from(value: u32) -> Self {
142        Self(value)
143    }
144}
145impl core::fmt::Debug for TESTTYPE  {
146    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
147        let variants = [
148            (Self::POSITIVE_TRANSITION.0, "POSITIVE_TRANSITION", "PositiveTransition"),
149            (Self::NEGATIVE_TRANSITION.0, "NEGATIVE_TRANSITION", "NegativeTransition"),
150            (Self::POSITIVE_COMPARISON.0, "POSITIVE_COMPARISON", "PositiveComparison"),
151            (Self::NEGATIVE_COMPARISON.0, "NEGATIVE_COMPARISON", "NegativeComparison"),
152        ];
153        pretty_print_enum(fmt, self.0, &variants)
154    }
155}
156
157#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
158#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
159pub struct VALUETYPE(u32);
160impl VALUETYPE {
161    pub const ABSOLUTE: Self = Self(0);
162    pub const RELATIVE: Self = Self(1);
163}
164impl From<VALUETYPE> for u32 {
165    #[inline]
166    fn from(input: VALUETYPE) -> Self {
167        input.0
168    }
169}
170impl From<VALUETYPE> for Option<u32> {
171    #[inline]
172    fn from(input: VALUETYPE) -> Self {
173        Some(input.0)
174    }
175}
176impl From<u8> for VALUETYPE {
177    #[inline]
178    fn from(value: u8) -> Self {
179        Self(value.into())
180    }
181}
182impl From<u16> for VALUETYPE {
183    #[inline]
184    fn from(value: u16) -> Self {
185        Self(value.into())
186    }
187}
188impl From<u32> for VALUETYPE {
189    #[inline]
190    fn from(value: u32) -> Self {
191        Self(value)
192    }
193}
194impl core::fmt::Debug for VALUETYPE  {
195    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
196        let variants = [
197            (Self::ABSOLUTE.0, "ABSOLUTE", "Absolute"),
198            (Self::RELATIVE.0, "RELATIVE", "Relative"),
199        ];
200        pretty_print_enum(fmt, self.0, &variants)
201    }
202}
203
204#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
205#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
206pub struct CA(u32);
207impl CA {
208    pub const COUNTER: Self = Self(1 << 0);
209    pub const VALUE_TYPE: Self = Self(1 << 1);
210    pub const VALUE: Self = Self(1 << 2);
211    pub const TEST_TYPE: Self = Self(1 << 3);
212    pub const DELTA: Self = Self(1 << 4);
213    pub const EVENTS: Self = Self(1 << 5);
214}
215impl From<CA> for u32 {
216    #[inline]
217    fn from(input: CA) -> Self {
218        input.0
219    }
220}
221impl From<CA> for Option<u32> {
222    #[inline]
223    fn from(input: CA) -> Self {
224        Some(input.0)
225    }
226}
227impl From<u8> for CA {
228    #[inline]
229    fn from(value: u8) -> Self {
230        Self(value.into())
231    }
232}
233impl From<u16> for CA {
234    #[inline]
235    fn from(value: u16) -> Self {
236        Self(value.into())
237    }
238}
239impl From<u32> for CA {
240    #[inline]
241    fn from(value: u32) -> Self {
242        Self(value)
243    }
244}
245impl core::fmt::Debug for CA  {
246    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
247        let variants = [
248            (Self::COUNTER.0, "COUNTER", "Counter"),
249            (Self::VALUE_TYPE.0, "VALUE_TYPE", "ValueType"),
250            (Self::VALUE.0, "VALUE", "Value"),
251            (Self::TEST_TYPE.0, "TEST_TYPE", "TestType"),
252            (Self::DELTA.0, "DELTA", "Delta"),
253            (Self::EVENTS.0, "EVENTS", "Events"),
254        ];
255        pretty_print_bitmask(fmt, self.0, &variants)
256    }
257}
258bitmask_binop!(CA, u32);
259
260#[derive(Clone, Copy, Default)]
261#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
262#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
263pub struct Int64 {
264    pub hi: i32,
265    pub lo: u32,
266}
267impl_debug_if_no_extra_traits!(Int64, "Int64");
268impl TryParse for Int64 {
269    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
270        let (hi, remaining) = i32::try_parse(remaining)?;
271        let (lo, remaining) = u32::try_parse(remaining)?;
272        let result = Int64 { hi, lo };
273        Ok((result, remaining))
274    }
275}
276impl Serialize for Int64 {
277    type Bytes = [u8; 8];
278    fn serialize(&self) -> [u8; 8] {
279        let hi_bytes = self.hi.serialize();
280        let lo_bytes = self.lo.serialize();
281        [
282            hi_bytes[0],
283            hi_bytes[1],
284            hi_bytes[2],
285            hi_bytes[3],
286            lo_bytes[0],
287            lo_bytes[1],
288            lo_bytes[2],
289            lo_bytes[3],
290        ]
291    }
292    fn serialize_into(&self, bytes: &mut Vec<u8>) {
293        bytes.reserve(8);
294        self.hi.serialize_into(bytes);
295        self.lo.serialize_into(bytes);
296    }
297}
298
299#[derive(Clone, Default)]
300#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
301#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
302pub struct Systemcounter {
303    pub counter: Counter,
304    pub resolution: Int64,
305    pub name: Vec<u8>,
306}
307impl_debug_if_no_extra_traits!(Systemcounter, "Systemcounter");
308impl TryParse for Systemcounter {
309    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
310        let value = remaining;
311        let (counter, remaining) = Counter::try_parse(remaining)?;
312        let (resolution, remaining) = Int64::try_parse(remaining)?;
313        let (name_len, remaining) = u16::try_parse(remaining)?;
314        let (name, remaining) = crate::x11_utils::parse_u8_list(remaining, name_len.try_to_usize()?)?;
315        let name = name.to_vec();
316        // Align offset to multiple of 4
317        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
318        let misalignment = (4 - (offset % 4)) % 4;
319        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
320        let result = Systemcounter { counter, resolution, name };
321        Ok((result, remaining))
322    }
323}
324impl Serialize for Systemcounter {
325    type Bytes = Vec<u8>;
326    fn serialize(&self) -> Vec<u8> {
327        let mut result = Vec::new();
328        self.serialize_into(&mut result);
329        result
330    }
331    fn serialize_into(&self, bytes: &mut Vec<u8>) {
332        bytes.reserve(14);
333        self.counter.serialize_into(bytes);
334        self.resolution.serialize_into(bytes);
335        let name_len = u16::try_from(self.name.len()).expect("`name` has too many elements");
336        name_len.serialize_into(bytes);
337        bytes.extend_from_slice(&self.name);
338        bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]);
339    }
340}
341impl Systemcounter {
342    /// Get the value of the `name_len` field.
343    ///
344    /// The `name_len` field is used as the length field of the `name` field.
345    /// This function computes the field's value again based on the length of the list.
346    ///
347    /// # Panics
348    ///
349    /// Panics if the value cannot be represented in the target type. This
350    /// cannot happen with values of the struct received from the X11 server.
351    pub fn name_len(&self) -> u16 {
352        self.name.len()
353            .try_into().unwrap()
354    }
355}
356
357#[derive(Clone, Copy, Default)]
358#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
359#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
360pub struct Trigger {
361    pub counter: Counter,
362    pub wait_type: VALUETYPE,
363    pub wait_value: Int64,
364    pub test_type: TESTTYPE,
365}
366impl_debug_if_no_extra_traits!(Trigger, "Trigger");
367impl TryParse for Trigger {
368    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
369        let (counter, remaining) = Counter::try_parse(remaining)?;
370        let (wait_type, remaining) = u32::try_parse(remaining)?;
371        let (wait_value, remaining) = Int64::try_parse(remaining)?;
372        let (test_type, remaining) = u32::try_parse(remaining)?;
373        let wait_type = wait_type.into();
374        let test_type = test_type.into();
375        let result = Trigger { counter, wait_type, wait_value, test_type };
376        Ok((result, remaining))
377    }
378}
379impl Serialize for Trigger {
380    type Bytes = [u8; 20];
381    fn serialize(&self) -> [u8; 20] {
382        let counter_bytes = self.counter.serialize();
383        let wait_type_bytes = u32::from(self.wait_type).serialize();
384        let wait_value_bytes = self.wait_value.serialize();
385        let test_type_bytes = u32::from(self.test_type).serialize();
386        [
387            counter_bytes[0],
388            counter_bytes[1],
389            counter_bytes[2],
390            counter_bytes[3],
391            wait_type_bytes[0],
392            wait_type_bytes[1],
393            wait_type_bytes[2],
394            wait_type_bytes[3],
395            wait_value_bytes[0],
396            wait_value_bytes[1],
397            wait_value_bytes[2],
398            wait_value_bytes[3],
399            wait_value_bytes[4],
400            wait_value_bytes[5],
401            wait_value_bytes[6],
402            wait_value_bytes[7],
403            test_type_bytes[0],
404            test_type_bytes[1],
405            test_type_bytes[2],
406            test_type_bytes[3],
407        ]
408    }
409    fn serialize_into(&self, bytes: &mut Vec<u8>) {
410        bytes.reserve(20);
411        self.counter.serialize_into(bytes);
412        u32::from(self.wait_type).serialize_into(bytes);
413        self.wait_value.serialize_into(bytes);
414        u32::from(self.test_type).serialize_into(bytes);
415    }
416}
417
418#[derive(Clone, Copy, Default)]
419#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
420#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
421pub struct Waitcondition {
422    pub trigger: Trigger,
423    pub event_threshold: Int64,
424}
425impl_debug_if_no_extra_traits!(Waitcondition, "Waitcondition");
426impl TryParse for Waitcondition {
427    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
428        let (trigger, remaining) = Trigger::try_parse(remaining)?;
429        let (event_threshold, remaining) = Int64::try_parse(remaining)?;
430        let result = Waitcondition { trigger, event_threshold };
431        Ok((result, remaining))
432    }
433}
434impl Serialize for Waitcondition {
435    type Bytes = [u8; 28];
436    fn serialize(&self) -> [u8; 28] {
437        let trigger_bytes = self.trigger.serialize();
438        let event_threshold_bytes = self.event_threshold.serialize();
439        [
440            trigger_bytes[0],
441            trigger_bytes[1],
442            trigger_bytes[2],
443            trigger_bytes[3],
444            trigger_bytes[4],
445            trigger_bytes[5],
446            trigger_bytes[6],
447            trigger_bytes[7],
448            trigger_bytes[8],
449            trigger_bytes[9],
450            trigger_bytes[10],
451            trigger_bytes[11],
452            trigger_bytes[12],
453            trigger_bytes[13],
454            trigger_bytes[14],
455            trigger_bytes[15],
456            trigger_bytes[16],
457            trigger_bytes[17],
458            trigger_bytes[18],
459            trigger_bytes[19],
460            event_threshold_bytes[0],
461            event_threshold_bytes[1],
462            event_threshold_bytes[2],
463            event_threshold_bytes[3],
464            event_threshold_bytes[4],
465            event_threshold_bytes[5],
466            event_threshold_bytes[6],
467            event_threshold_bytes[7],
468        ]
469    }
470    fn serialize_into(&self, bytes: &mut Vec<u8>) {
471        bytes.reserve(28);
472        self.trigger.serialize_into(bytes);
473        self.event_threshold.serialize_into(bytes);
474    }
475}
476
477/// Opcode for the Counter error
478pub const COUNTER_ERROR: u8 = 0;
479
480/// Opcode for the Alarm error
481pub const ALARM_ERROR: u8 = 1;
482
483/// Opcode for the Initialize request
484pub const INITIALIZE_REQUEST: u8 = 0;
485#[derive(Clone, Copy, Default)]
486#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
487#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
488pub struct InitializeRequest {
489    pub desired_major_version: u8,
490    pub desired_minor_version: u8,
491}
492impl_debug_if_no_extra_traits!(InitializeRequest, "InitializeRequest");
493impl InitializeRequest {
494    /// Serialize this request into bytes for the provided connection
495    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
496        let length_so_far = 0;
497        let desired_major_version_bytes = self.desired_major_version.serialize();
498        let desired_minor_version_bytes = self.desired_minor_version.serialize();
499        let mut request0 = vec![
500            major_opcode,
501            INITIALIZE_REQUEST,
502            0,
503            0,
504            desired_major_version_bytes[0],
505            desired_minor_version_bytes[0],
506            0,
507            0,
508        ];
509        let length_so_far = length_so_far + request0.len();
510        assert_eq!(length_so_far % 4, 0);
511        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
512        request0[2..4].copy_from_slice(&length.to_ne_bytes());
513        ([request0.into()], vec![])
514    }
515    /// Parse this request given its header, its body, and any fds that go along with it
516    #[cfg(feature = "request-parsing")]
517    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
518        if header.minor_opcode != INITIALIZE_REQUEST {
519            return Err(ParseError::InvalidValue);
520        }
521        let (desired_major_version, remaining) = u8::try_parse(value)?;
522        let (desired_minor_version, remaining) = u8::try_parse(remaining)?;
523        let _ = remaining;
524        Ok(InitializeRequest {
525            desired_major_version,
526            desired_minor_version,
527        })
528    }
529}
530impl Request for InitializeRequest {
531    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
532
533    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
534        let (bufs, fds) = self.serialize(major_opcode);
535        // Flatten the buffers into a single vector
536        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
537        (buf, fds)
538    }
539}
540impl crate::x11_utils::ReplyRequest for InitializeRequest {
541    type Reply = InitializeReply;
542}
543
544#[derive(Clone, Copy, Default)]
545#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
546#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
547pub struct InitializeReply {
548    pub sequence: u16,
549    pub length: u32,
550    pub major_version: u8,
551    pub minor_version: u8,
552}
553impl_debug_if_no_extra_traits!(InitializeReply, "InitializeReply");
554impl TryParse for InitializeReply {
555    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
556        let remaining = initial_value;
557        let (response_type, remaining) = u8::try_parse(remaining)?;
558        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
559        let (sequence, remaining) = u16::try_parse(remaining)?;
560        let (length, remaining) = u32::try_parse(remaining)?;
561        let (major_version, remaining) = u8::try_parse(remaining)?;
562        let (minor_version, remaining) = u8::try_parse(remaining)?;
563        let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?;
564        if response_type != 1 {
565            return Err(ParseError::InvalidValue);
566        }
567        let result = InitializeReply { sequence, length, major_version, minor_version };
568        let _ = remaining;
569        let remaining = initial_value.get(32 + length as usize * 4..)
570            .ok_or(ParseError::InsufficientData)?;
571        Ok((result, remaining))
572    }
573}
574impl Serialize for InitializeReply {
575    type Bytes = [u8; 32];
576    fn serialize(&self) -> [u8; 32] {
577        let response_type_bytes = &[1];
578        let sequence_bytes = self.sequence.serialize();
579        let length_bytes = self.length.serialize();
580        let major_version_bytes = self.major_version.serialize();
581        let minor_version_bytes = self.minor_version.serialize();
582        [
583            response_type_bytes[0],
584            0,
585            sequence_bytes[0],
586            sequence_bytes[1],
587            length_bytes[0],
588            length_bytes[1],
589            length_bytes[2],
590            length_bytes[3],
591            major_version_bytes[0],
592            minor_version_bytes[0],
593            0,
594            0,
595            0,
596            0,
597            0,
598            0,
599            0,
600            0,
601            0,
602            0,
603            0,
604            0,
605            0,
606            0,
607            0,
608            0,
609            0,
610            0,
611            0,
612            0,
613            0,
614            0,
615        ]
616    }
617    fn serialize_into(&self, bytes: &mut Vec<u8>) {
618        bytes.reserve(32);
619        let response_type_bytes = &[1];
620        bytes.push(response_type_bytes[0]);
621        bytes.extend_from_slice(&[0; 1]);
622        self.sequence.serialize_into(bytes);
623        self.length.serialize_into(bytes);
624        self.major_version.serialize_into(bytes);
625        self.minor_version.serialize_into(bytes);
626        bytes.extend_from_slice(&[0; 22]);
627    }
628}
629
630/// Opcode for the ListSystemCounters request
631pub const LIST_SYSTEM_COUNTERS_REQUEST: u8 = 1;
632#[derive(Clone, Copy, Default)]
633#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
634#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
635pub struct ListSystemCountersRequest;
636impl_debug_if_no_extra_traits!(ListSystemCountersRequest, "ListSystemCountersRequest");
637impl ListSystemCountersRequest {
638    /// Serialize this request into bytes for the provided connection
639    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
640        let length_so_far = 0;
641        let mut request0 = vec![
642            major_opcode,
643            LIST_SYSTEM_COUNTERS_REQUEST,
644            0,
645            0,
646        ];
647        let length_so_far = length_so_far + request0.len();
648        assert_eq!(length_so_far % 4, 0);
649        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
650        request0[2..4].copy_from_slice(&length.to_ne_bytes());
651        ([request0.into()], vec![])
652    }
653    /// Parse this request given its header, its body, and any fds that go along with it
654    #[cfg(feature = "request-parsing")]
655    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
656        if header.minor_opcode != LIST_SYSTEM_COUNTERS_REQUEST {
657            return Err(ParseError::InvalidValue);
658        }
659        let _ = value;
660        Ok(ListSystemCountersRequest
661        )
662    }
663}
664impl Request for ListSystemCountersRequest {
665    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
666
667    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
668        let (bufs, fds) = self.serialize(major_opcode);
669        // Flatten the buffers into a single vector
670        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
671        (buf, fds)
672    }
673}
674impl crate::x11_utils::ReplyRequest for ListSystemCountersRequest {
675    type Reply = ListSystemCountersReply;
676}
677
678#[derive(Clone, Default)]
679#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
680#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
681pub struct ListSystemCountersReply {
682    pub sequence: u16,
683    pub length: u32,
684    pub counters: Vec<Systemcounter>,
685}
686impl_debug_if_no_extra_traits!(ListSystemCountersReply, "ListSystemCountersReply");
687impl TryParse for ListSystemCountersReply {
688    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
689        let remaining = initial_value;
690        let (response_type, remaining) = u8::try_parse(remaining)?;
691        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
692        let (sequence, remaining) = u16::try_parse(remaining)?;
693        let (length, remaining) = u32::try_parse(remaining)?;
694        let (counters_len, remaining) = u32::try_parse(remaining)?;
695        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
696        let (counters, remaining) = crate::x11_utils::parse_list::<Systemcounter>(remaining, counters_len.try_to_usize()?)?;
697        if response_type != 1 {
698            return Err(ParseError::InvalidValue);
699        }
700        let result = ListSystemCountersReply { sequence, length, counters };
701        let _ = remaining;
702        let remaining = initial_value.get(32 + length as usize * 4..)
703            .ok_or(ParseError::InsufficientData)?;
704        Ok((result, remaining))
705    }
706}
707impl Serialize for ListSystemCountersReply {
708    type Bytes = Vec<u8>;
709    fn serialize(&self) -> Vec<u8> {
710        let mut result = Vec::new();
711        self.serialize_into(&mut result);
712        result
713    }
714    fn serialize_into(&self, bytes: &mut Vec<u8>) {
715        bytes.reserve(32);
716        let response_type_bytes = &[1];
717        bytes.push(response_type_bytes[0]);
718        bytes.extend_from_slice(&[0; 1]);
719        self.sequence.serialize_into(bytes);
720        self.length.serialize_into(bytes);
721        let counters_len = u32::try_from(self.counters.len()).expect("`counters` has too many elements");
722        counters_len.serialize_into(bytes);
723        bytes.extend_from_slice(&[0; 20]);
724        self.counters.serialize_into(bytes);
725    }
726}
727impl ListSystemCountersReply {
728    /// Get the value of the `counters_len` field.
729    ///
730    /// The `counters_len` field is used as the length field of the `counters` field.
731    /// This function computes the field's value again based on the length of the list.
732    ///
733    /// # Panics
734    ///
735    /// Panics if the value cannot be represented in the target type. This
736    /// cannot happen with values of the struct received from the X11 server.
737    pub fn counters_len(&self) -> u32 {
738        self.counters.len()
739            .try_into().unwrap()
740    }
741}
742
743/// Opcode for the CreateCounter request
744pub const CREATE_COUNTER_REQUEST: u8 = 2;
745#[derive(Clone, Copy, Default)]
746#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
747#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
748pub struct CreateCounterRequest {
749    pub id: Counter,
750    pub initial_value: Int64,
751}
752impl_debug_if_no_extra_traits!(CreateCounterRequest, "CreateCounterRequest");
753impl CreateCounterRequest {
754    /// Serialize this request into bytes for the provided connection
755    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
756        let length_so_far = 0;
757        let id_bytes = self.id.serialize();
758        let initial_value_bytes = self.initial_value.serialize();
759        let mut request0 = vec![
760            major_opcode,
761            CREATE_COUNTER_REQUEST,
762            0,
763            0,
764            id_bytes[0],
765            id_bytes[1],
766            id_bytes[2],
767            id_bytes[3],
768            initial_value_bytes[0],
769            initial_value_bytes[1],
770            initial_value_bytes[2],
771            initial_value_bytes[3],
772            initial_value_bytes[4],
773            initial_value_bytes[5],
774            initial_value_bytes[6],
775            initial_value_bytes[7],
776        ];
777        let length_so_far = length_so_far + request0.len();
778        assert_eq!(length_so_far % 4, 0);
779        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
780        request0[2..4].copy_from_slice(&length.to_ne_bytes());
781        ([request0.into()], vec![])
782    }
783    /// Parse this request given its header, its body, and any fds that go along with it
784    #[cfg(feature = "request-parsing")]
785    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
786        if header.minor_opcode != CREATE_COUNTER_REQUEST {
787            return Err(ParseError::InvalidValue);
788        }
789        let (id, remaining) = Counter::try_parse(value)?;
790        let (initial_value, remaining) = Int64::try_parse(remaining)?;
791        let _ = remaining;
792        Ok(CreateCounterRequest {
793            id,
794            initial_value,
795        })
796    }
797}
798impl Request for CreateCounterRequest {
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::VoidRequest for CreateCounterRequest {
809}
810
811/// Opcode for the DestroyCounter request
812pub const DESTROY_COUNTER_REQUEST: u8 = 6;
813#[derive(Clone, Copy, Default)]
814#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
815#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
816pub struct DestroyCounterRequest {
817    pub counter: Counter,
818}
819impl_debug_if_no_extra_traits!(DestroyCounterRequest, "DestroyCounterRequest");
820impl DestroyCounterRequest {
821    /// Serialize this request into bytes for the provided connection
822    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
823        let length_so_far = 0;
824        let counter_bytes = self.counter.serialize();
825        let mut request0 = vec![
826            major_opcode,
827            DESTROY_COUNTER_REQUEST,
828            0,
829            0,
830            counter_bytes[0],
831            counter_bytes[1],
832            counter_bytes[2],
833            counter_bytes[3],
834        ];
835        let length_so_far = length_so_far + request0.len();
836        assert_eq!(length_so_far % 4, 0);
837        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
838        request0[2..4].copy_from_slice(&length.to_ne_bytes());
839        ([request0.into()], vec![])
840    }
841    /// Parse this request given its header, its body, and any fds that go along with it
842    #[cfg(feature = "request-parsing")]
843    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
844        if header.minor_opcode != DESTROY_COUNTER_REQUEST {
845            return Err(ParseError::InvalidValue);
846        }
847        let (counter, remaining) = Counter::try_parse(value)?;
848        let _ = remaining;
849        Ok(DestroyCounterRequest {
850            counter,
851        })
852    }
853}
854impl Request for DestroyCounterRequest {
855    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
856
857    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
858        let (bufs, fds) = self.serialize(major_opcode);
859        // Flatten the buffers into a single vector
860        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
861        (buf, fds)
862    }
863}
864impl crate::x11_utils::VoidRequest for DestroyCounterRequest {
865}
866
867/// Opcode for the QueryCounter request
868pub const QUERY_COUNTER_REQUEST: u8 = 5;
869#[derive(Clone, Copy, Default)]
870#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
871#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
872pub struct QueryCounterRequest {
873    pub counter: Counter,
874}
875impl_debug_if_no_extra_traits!(QueryCounterRequest, "QueryCounterRequest");
876impl QueryCounterRequest {
877    /// Serialize this request into bytes for the provided connection
878    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
879        let length_so_far = 0;
880        let counter_bytes = self.counter.serialize();
881        let mut request0 = vec![
882            major_opcode,
883            QUERY_COUNTER_REQUEST,
884            0,
885            0,
886            counter_bytes[0],
887            counter_bytes[1],
888            counter_bytes[2],
889            counter_bytes[3],
890        ];
891        let length_so_far = length_so_far + request0.len();
892        assert_eq!(length_so_far % 4, 0);
893        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
894        request0[2..4].copy_from_slice(&length.to_ne_bytes());
895        ([request0.into()], vec![])
896    }
897    /// Parse this request given its header, its body, and any fds that go along with it
898    #[cfg(feature = "request-parsing")]
899    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
900        if header.minor_opcode != QUERY_COUNTER_REQUEST {
901            return Err(ParseError::InvalidValue);
902        }
903        let (counter, remaining) = Counter::try_parse(value)?;
904        let _ = remaining;
905        Ok(QueryCounterRequest {
906            counter,
907        })
908    }
909}
910impl Request for QueryCounterRequest {
911    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
912
913    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
914        let (bufs, fds) = self.serialize(major_opcode);
915        // Flatten the buffers into a single vector
916        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
917        (buf, fds)
918    }
919}
920impl crate::x11_utils::ReplyRequest for QueryCounterRequest {
921    type Reply = QueryCounterReply;
922}
923
924#[derive(Clone, Copy, Default)]
925#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
926#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
927pub struct QueryCounterReply {
928    pub sequence: u16,
929    pub length: u32,
930    pub counter_value: Int64,
931}
932impl_debug_if_no_extra_traits!(QueryCounterReply, "QueryCounterReply");
933impl TryParse for QueryCounterReply {
934    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
935        let remaining = initial_value;
936        let (response_type, remaining) = u8::try_parse(remaining)?;
937        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
938        let (sequence, remaining) = u16::try_parse(remaining)?;
939        let (length, remaining) = u32::try_parse(remaining)?;
940        let (counter_value, remaining) = Int64::try_parse(remaining)?;
941        if response_type != 1 {
942            return Err(ParseError::InvalidValue);
943        }
944        let result = QueryCounterReply { sequence, length, counter_value };
945        let _ = remaining;
946        let remaining = initial_value.get(32 + length as usize * 4..)
947            .ok_or(ParseError::InsufficientData)?;
948        Ok((result, remaining))
949    }
950}
951impl Serialize for QueryCounterReply {
952    type Bytes = [u8; 16];
953    fn serialize(&self) -> [u8; 16] {
954        let response_type_bytes = &[1];
955        let sequence_bytes = self.sequence.serialize();
956        let length_bytes = self.length.serialize();
957        let counter_value_bytes = self.counter_value.serialize();
958        [
959            response_type_bytes[0],
960            0,
961            sequence_bytes[0],
962            sequence_bytes[1],
963            length_bytes[0],
964            length_bytes[1],
965            length_bytes[2],
966            length_bytes[3],
967            counter_value_bytes[0],
968            counter_value_bytes[1],
969            counter_value_bytes[2],
970            counter_value_bytes[3],
971            counter_value_bytes[4],
972            counter_value_bytes[5],
973            counter_value_bytes[6],
974            counter_value_bytes[7],
975        ]
976    }
977    fn serialize_into(&self, bytes: &mut Vec<u8>) {
978        bytes.reserve(16);
979        let response_type_bytes = &[1];
980        bytes.push(response_type_bytes[0]);
981        bytes.extend_from_slice(&[0; 1]);
982        self.sequence.serialize_into(bytes);
983        self.length.serialize_into(bytes);
984        self.counter_value.serialize_into(bytes);
985    }
986}
987
988/// Opcode for the Await request
989pub const AWAIT_REQUEST: u8 = 7;
990#[derive(Clone, Default)]
991#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
992#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
993pub struct AwaitRequest<'input> {
994    pub wait_list: Cow<'input, [Waitcondition]>,
995}
996impl_debug_if_no_extra_traits!(AwaitRequest<'_>, "AwaitRequest");
997impl<'input> AwaitRequest<'input> {
998    /// Serialize this request into bytes for the provided connection
999    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
1000        let length_so_far = 0;
1001        let mut request0 = vec![
1002            major_opcode,
1003            AWAIT_REQUEST,
1004            0,
1005            0,
1006        ];
1007        let length_so_far = length_so_far + request0.len();
1008        let wait_list_bytes = self.wait_list.serialize();
1009        let length_so_far = length_so_far + wait_list_bytes.len();
1010        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1011        let length_so_far = length_so_far + padding0.len();
1012        assert_eq!(length_so_far % 4, 0);
1013        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1014        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1015        ([request0.into(), wait_list_bytes.into(), padding0.into()], vec![])
1016    }
1017    /// Parse this request given its header, its body, and any fds that go along with it
1018    #[cfg(feature = "request-parsing")]
1019    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1020        if header.minor_opcode != AWAIT_REQUEST {
1021            return Err(ParseError::InvalidValue);
1022        }
1023        let mut remaining = value;
1024        // Length is 'everything left in the input'
1025        let mut wait_list = Vec::new();
1026        while !remaining.is_empty() {
1027            let (v, new_remaining) = Waitcondition::try_parse(value)?;
1028            remaining = new_remaining;
1029            wait_list.push(v);
1030        }
1031        let _ = remaining;
1032        Ok(AwaitRequest {
1033            wait_list: Cow::Owned(wait_list),
1034        })
1035    }
1036    /// Clone all borrowed data in this AwaitRequest.
1037    pub fn into_owned(self) -> AwaitRequest<'static> {
1038        AwaitRequest {
1039            wait_list: Cow::Owned(self.wait_list.into_owned()),
1040        }
1041    }
1042}
1043impl<'input> Request for AwaitRequest<'input> {
1044    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1045
1046    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1047        let (bufs, fds) = self.serialize(major_opcode);
1048        // Flatten the buffers into a single vector
1049        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1050        (buf, fds)
1051    }
1052}
1053impl<'input> crate::x11_utils::VoidRequest for AwaitRequest<'input> {
1054}
1055
1056/// Opcode for the ChangeCounter request
1057pub const CHANGE_COUNTER_REQUEST: u8 = 4;
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 ChangeCounterRequest {
1062    pub counter: Counter,
1063    pub amount: Int64,
1064}
1065impl_debug_if_no_extra_traits!(ChangeCounterRequest, "ChangeCounterRequest");
1066impl ChangeCounterRequest {
1067    /// Serialize this request into bytes for the provided connection
1068    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1069        let length_so_far = 0;
1070        let counter_bytes = self.counter.serialize();
1071        let amount_bytes = self.amount.serialize();
1072        let mut request0 = vec![
1073            major_opcode,
1074            CHANGE_COUNTER_REQUEST,
1075            0,
1076            0,
1077            counter_bytes[0],
1078            counter_bytes[1],
1079            counter_bytes[2],
1080            counter_bytes[3],
1081            amount_bytes[0],
1082            amount_bytes[1],
1083            amount_bytes[2],
1084            amount_bytes[3],
1085            amount_bytes[4],
1086            amount_bytes[5],
1087            amount_bytes[6],
1088            amount_bytes[7],
1089        ];
1090        let length_so_far = length_so_far + request0.len();
1091        assert_eq!(length_so_far % 4, 0);
1092        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1093        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1094        ([request0.into()], vec![])
1095    }
1096    /// Parse this request given its header, its body, and any fds that go along with it
1097    #[cfg(feature = "request-parsing")]
1098    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1099        if header.minor_opcode != CHANGE_COUNTER_REQUEST {
1100            return Err(ParseError::InvalidValue);
1101        }
1102        let (counter, remaining) = Counter::try_parse(value)?;
1103        let (amount, remaining) = Int64::try_parse(remaining)?;
1104        let _ = remaining;
1105        Ok(ChangeCounterRequest {
1106            counter,
1107            amount,
1108        })
1109    }
1110}
1111impl Request for ChangeCounterRequest {
1112    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1113
1114    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1115        let (bufs, fds) = self.serialize(major_opcode);
1116        // Flatten the buffers into a single vector
1117        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1118        (buf, fds)
1119    }
1120}
1121impl crate::x11_utils::VoidRequest for ChangeCounterRequest {
1122}
1123
1124/// Opcode for the SetCounter request
1125pub const SET_COUNTER_REQUEST: u8 = 3;
1126#[derive(Clone, Copy, Default)]
1127#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1128#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1129pub struct SetCounterRequest {
1130    pub counter: Counter,
1131    pub value: Int64,
1132}
1133impl_debug_if_no_extra_traits!(SetCounterRequest, "SetCounterRequest");
1134impl SetCounterRequest {
1135    /// Serialize this request into bytes for the provided connection
1136    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1137        let length_so_far = 0;
1138        let counter_bytes = self.counter.serialize();
1139        let value_bytes = self.value.serialize();
1140        let mut request0 = vec![
1141            major_opcode,
1142            SET_COUNTER_REQUEST,
1143            0,
1144            0,
1145            counter_bytes[0],
1146            counter_bytes[1],
1147            counter_bytes[2],
1148            counter_bytes[3],
1149            value_bytes[0],
1150            value_bytes[1],
1151            value_bytes[2],
1152            value_bytes[3],
1153            value_bytes[4],
1154            value_bytes[5],
1155            value_bytes[6],
1156            value_bytes[7],
1157        ];
1158        let length_so_far = length_so_far + request0.len();
1159        assert_eq!(length_so_far % 4, 0);
1160        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1161        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1162        ([request0.into()], vec![])
1163    }
1164    /// Parse this request given its header, its body, and any fds that go along with it
1165    #[cfg(feature = "request-parsing")]
1166    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1167        if header.minor_opcode != SET_COUNTER_REQUEST {
1168            return Err(ParseError::InvalidValue);
1169        }
1170        let (counter, remaining) = Counter::try_parse(value)?;
1171        let (value, remaining) = Int64::try_parse(remaining)?;
1172        let _ = remaining;
1173        Ok(SetCounterRequest {
1174            counter,
1175            value,
1176        })
1177    }
1178}
1179impl Request for SetCounterRequest {
1180    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1181
1182    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1183        let (bufs, fds) = self.serialize(major_opcode);
1184        // Flatten the buffers into a single vector
1185        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1186        (buf, fds)
1187    }
1188}
1189impl crate::x11_utils::VoidRequest for SetCounterRequest {
1190}
1191
1192/// Auxiliary and optional information for the `create_alarm` function
1193#[derive(Clone, Copy, Default)]
1194#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1195#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1196pub struct CreateAlarmAux {
1197    pub counter: Option<Counter>,
1198    pub value_type: Option<VALUETYPE>,
1199    pub value: Option<Int64>,
1200    pub test_type: Option<TESTTYPE>,
1201    pub delta: Option<Int64>,
1202    pub events: Option<u32>,
1203}
1204impl_debug_if_no_extra_traits!(CreateAlarmAux, "CreateAlarmAux");
1205impl CreateAlarmAux {
1206    #[cfg_attr(not(feature = "request-parsing"), allow(dead_code))]
1207    fn try_parse(value: &[u8], value_mask: u32) -> Result<(Self, &[u8]), ParseError> {
1208        let switch_expr = u32::from(value_mask);
1209        let mut outer_remaining = value;
1210        let counter = if switch_expr & u32::from(CA::COUNTER) != 0 {
1211            let remaining = outer_remaining;
1212            let (counter, remaining) = Counter::try_parse(remaining)?;
1213            outer_remaining = remaining;
1214            Some(counter)
1215        } else {
1216            None
1217        };
1218        let value_type = if switch_expr & u32::from(CA::VALUE_TYPE) != 0 {
1219            let remaining = outer_remaining;
1220            let (value_type, remaining) = u32::try_parse(remaining)?;
1221            let value_type = value_type.into();
1222            outer_remaining = remaining;
1223            Some(value_type)
1224        } else {
1225            None
1226        };
1227        let value = if switch_expr & u32::from(CA::VALUE) != 0 {
1228            let remaining = outer_remaining;
1229            let (value, remaining) = Int64::try_parse(remaining)?;
1230            outer_remaining = remaining;
1231            Some(value)
1232        } else {
1233            None
1234        };
1235        let test_type = if switch_expr & u32::from(CA::TEST_TYPE) != 0 {
1236            let remaining = outer_remaining;
1237            let (test_type, remaining) = u32::try_parse(remaining)?;
1238            let test_type = test_type.into();
1239            outer_remaining = remaining;
1240            Some(test_type)
1241        } else {
1242            None
1243        };
1244        let delta = if switch_expr & u32::from(CA::DELTA) != 0 {
1245            let remaining = outer_remaining;
1246            let (delta, remaining) = Int64::try_parse(remaining)?;
1247            outer_remaining = remaining;
1248            Some(delta)
1249        } else {
1250            None
1251        };
1252        let events = if switch_expr & u32::from(CA::EVENTS) != 0 {
1253            let remaining = outer_remaining;
1254            let (events, remaining) = u32::try_parse(remaining)?;
1255            outer_remaining = remaining;
1256            Some(events)
1257        } else {
1258            None
1259        };
1260        let result = CreateAlarmAux { counter, value_type, value, test_type, delta, events };
1261        Ok((result, outer_remaining))
1262    }
1263}
1264impl CreateAlarmAux {
1265    #[allow(dead_code)]
1266    fn serialize(&self, value_mask: u32) -> Vec<u8> {
1267        let mut result = Vec::new();
1268        self.serialize_into(&mut result, u32::from(value_mask));
1269        result
1270    }
1271    fn serialize_into(&self, bytes: &mut Vec<u8>, value_mask: u32) {
1272        assert_eq!(self.switch_expr(), u32::from(value_mask), "switch `value_list` has an inconsistent discriminant");
1273        if let Some(counter) = self.counter {
1274            counter.serialize_into(bytes);
1275        }
1276        if let Some(value_type) = self.value_type {
1277            u32::from(value_type).serialize_into(bytes);
1278        }
1279        if let Some(ref value) = self.value {
1280            value.serialize_into(bytes);
1281        }
1282        if let Some(test_type) = self.test_type {
1283            u32::from(test_type).serialize_into(bytes);
1284        }
1285        if let Some(ref delta) = self.delta {
1286            delta.serialize_into(bytes);
1287        }
1288        if let Some(events) = self.events {
1289            events.serialize_into(bytes);
1290        }
1291    }
1292}
1293impl CreateAlarmAux {
1294    fn switch_expr(&self) -> u32 {
1295        let mut expr_value = 0;
1296        if self.counter.is_some() {
1297            expr_value |= u32::from(CA::COUNTER);
1298        }
1299        if self.value_type.is_some() {
1300            expr_value |= u32::from(CA::VALUE_TYPE);
1301        }
1302        if self.value.is_some() {
1303            expr_value |= u32::from(CA::VALUE);
1304        }
1305        if self.test_type.is_some() {
1306            expr_value |= u32::from(CA::TEST_TYPE);
1307        }
1308        if self.delta.is_some() {
1309            expr_value |= u32::from(CA::DELTA);
1310        }
1311        if self.events.is_some() {
1312            expr_value |= u32::from(CA::EVENTS);
1313        }
1314        expr_value
1315    }
1316}
1317impl CreateAlarmAux {
1318    /// Create a new instance with all fields unset / not present.
1319    pub fn new() -> Self {
1320        Default::default()
1321    }
1322    /// Set the `counter` field of this structure.
1323    #[must_use]
1324    pub fn counter<I>(mut self, value: I) -> Self where I: Into<Option<Counter>> {
1325        self.counter = value.into();
1326        self
1327    }
1328    /// Set the `value_type` field of this structure.
1329    #[must_use]
1330    pub fn value_type<I>(mut self, value: I) -> Self where I: Into<Option<VALUETYPE>> {
1331        self.value_type = value.into();
1332        self
1333    }
1334    /// Set the `value` field of this structure.
1335    #[must_use]
1336    pub fn value<I>(mut self, value: I) -> Self where I: Into<Option<Int64>> {
1337        self.value = value.into();
1338        self
1339    }
1340    /// Set the `test_type` field of this structure.
1341    #[must_use]
1342    pub fn test_type<I>(mut self, value: I) -> Self where I: Into<Option<TESTTYPE>> {
1343        self.test_type = value.into();
1344        self
1345    }
1346    /// Set the `delta` field of this structure.
1347    #[must_use]
1348    pub fn delta<I>(mut self, value: I) -> Self where I: Into<Option<Int64>> {
1349        self.delta = value.into();
1350        self
1351    }
1352    /// Set the `events` field of this structure.
1353    #[must_use]
1354    pub fn events<I>(mut self, value: I) -> Self where I: Into<Option<u32>> {
1355        self.events = value.into();
1356        self
1357    }
1358}
1359
1360/// Opcode for the CreateAlarm request
1361pub const CREATE_ALARM_REQUEST: u8 = 8;
1362#[derive(Clone, Default)]
1363#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1364#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1365pub struct CreateAlarmRequest<'input> {
1366    pub id: Alarm,
1367    pub value_list: Cow<'input, CreateAlarmAux>,
1368}
1369impl_debug_if_no_extra_traits!(CreateAlarmRequest<'_>, "CreateAlarmRequest");
1370impl<'input> CreateAlarmRequest<'input> {
1371    /// Serialize this request into bytes for the provided connection
1372    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
1373        let length_so_far = 0;
1374        let id_bytes = self.id.serialize();
1375        let value_mask: u32 = self.value_list.switch_expr();
1376        let value_mask_bytes = value_mask.serialize();
1377        let mut request0 = vec![
1378            major_opcode,
1379            CREATE_ALARM_REQUEST,
1380            0,
1381            0,
1382            id_bytes[0],
1383            id_bytes[1],
1384            id_bytes[2],
1385            id_bytes[3],
1386            value_mask_bytes[0],
1387            value_mask_bytes[1],
1388            value_mask_bytes[2],
1389            value_mask_bytes[3],
1390        ];
1391        let length_so_far = length_so_far + request0.len();
1392        let value_list_bytes = self.value_list.serialize(u32::from(value_mask));
1393        let length_so_far = length_so_far + value_list_bytes.len();
1394        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1395        let length_so_far = length_so_far + padding0.len();
1396        assert_eq!(length_so_far % 4, 0);
1397        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1398        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1399        ([request0.into(), value_list_bytes.into(), padding0.into()], vec![])
1400    }
1401    /// Parse this request given its header, its body, and any fds that go along with it
1402    #[cfg(feature = "request-parsing")]
1403    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1404        if header.minor_opcode != CREATE_ALARM_REQUEST {
1405            return Err(ParseError::InvalidValue);
1406        }
1407        let (id, remaining) = Alarm::try_parse(value)?;
1408        let (value_mask, remaining) = u32::try_parse(remaining)?;
1409        let (value_list, remaining) = CreateAlarmAux::try_parse(remaining, u32::from(value_mask))?;
1410        let _ = remaining;
1411        Ok(CreateAlarmRequest {
1412            id,
1413            value_list: Cow::Owned(value_list),
1414        })
1415    }
1416    /// Clone all borrowed data in this CreateAlarmRequest.
1417    pub fn into_owned(self) -> CreateAlarmRequest<'static> {
1418        CreateAlarmRequest {
1419            id: self.id,
1420            value_list: Cow::Owned(self.value_list.into_owned()),
1421        }
1422    }
1423}
1424impl<'input> Request for CreateAlarmRequest<'input> {
1425    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1426
1427    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1428        let (bufs, fds) = self.serialize(major_opcode);
1429        // Flatten the buffers into a single vector
1430        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1431        (buf, fds)
1432    }
1433}
1434impl<'input> crate::x11_utils::VoidRequest for CreateAlarmRequest<'input> {
1435}
1436
1437/// Auxiliary and optional information for the `change_alarm` function
1438#[derive(Clone, Copy, Default)]
1439#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1440#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1441pub struct ChangeAlarmAux {
1442    pub counter: Option<Counter>,
1443    pub value_type: Option<VALUETYPE>,
1444    pub value: Option<Int64>,
1445    pub test_type: Option<TESTTYPE>,
1446    pub delta: Option<Int64>,
1447    pub events: Option<u32>,
1448}
1449impl_debug_if_no_extra_traits!(ChangeAlarmAux, "ChangeAlarmAux");
1450impl ChangeAlarmAux {
1451    #[cfg_attr(not(feature = "request-parsing"), allow(dead_code))]
1452    fn try_parse(value: &[u8], value_mask: u32) -> Result<(Self, &[u8]), ParseError> {
1453        let switch_expr = u32::from(value_mask);
1454        let mut outer_remaining = value;
1455        let counter = if switch_expr & u32::from(CA::COUNTER) != 0 {
1456            let remaining = outer_remaining;
1457            let (counter, remaining) = Counter::try_parse(remaining)?;
1458            outer_remaining = remaining;
1459            Some(counter)
1460        } else {
1461            None
1462        };
1463        let value_type = if switch_expr & u32::from(CA::VALUE_TYPE) != 0 {
1464            let remaining = outer_remaining;
1465            let (value_type, remaining) = u32::try_parse(remaining)?;
1466            let value_type = value_type.into();
1467            outer_remaining = remaining;
1468            Some(value_type)
1469        } else {
1470            None
1471        };
1472        let value = if switch_expr & u32::from(CA::VALUE) != 0 {
1473            let remaining = outer_remaining;
1474            let (value, remaining) = Int64::try_parse(remaining)?;
1475            outer_remaining = remaining;
1476            Some(value)
1477        } else {
1478            None
1479        };
1480        let test_type = if switch_expr & u32::from(CA::TEST_TYPE) != 0 {
1481            let remaining = outer_remaining;
1482            let (test_type, remaining) = u32::try_parse(remaining)?;
1483            let test_type = test_type.into();
1484            outer_remaining = remaining;
1485            Some(test_type)
1486        } else {
1487            None
1488        };
1489        let delta = if switch_expr & u32::from(CA::DELTA) != 0 {
1490            let remaining = outer_remaining;
1491            let (delta, remaining) = Int64::try_parse(remaining)?;
1492            outer_remaining = remaining;
1493            Some(delta)
1494        } else {
1495            None
1496        };
1497        let events = if switch_expr & u32::from(CA::EVENTS) != 0 {
1498            let remaining = outer_remaining;
1499            let (events, remaining) = u32::try_parse(remaining)?;
1500            outer_remaining = remaining;
1501            Some(events)
1502        } else {
1503            None
1504        };
1505        let result = ChangeAlarmAux { counter, value_type, value, test_type, delta, events };
1506        Ok((result, outer_remaining))
1507    }
1508}
1509impl ChangeAlarmAux {
1510    #[allow(dead_code)]
1511    fn serialize(&self, value_mask: u32) -> Vec<u8> {
1512        let mut result = Vec::new();
1513        self.serialize_into(&mut result, u32::from(value_mask));
1514        result
1515    }
1516    fn serialize_into(&self, bytes: &mut Vec<u8>, value_mask: u32) {
1517        assert_eq!(self.switch_expr(), u32::from(value_mask), "switch `value_list` has an inconsistent discriminant");
1518        if let Some(counter) = self.counter {
1519            counter.serialize_into(bytes);
1520        }
1521        if let Some(value_type) = self.value_type {
1522            u32::from(value_type).serialize_into(bytes);
1523        }
1524        if let Some(ref value) = self.value {
1525            value.serialize_into(bytes);
1526        }
1527        if let Some(test_type) = self.test_type {
1528            u32::from(test_type).serialize_into(bytes);
1529        }
1530        if let Some(ref delta) = self.delta {
1531            delta.serialize_into(bytes);
1532        }
1533        if let Some(events) = self.events {
1534            events.serialize_into(bytes);
1535        }
1536    }
1537}
1538impl ChangeAlarmAux {
1539    fn switch_expr(&self) -> u32 {
1540        let mut expr_value = 0;
1541        if self.counter.is_some() {
1542            expr_value |= u32::from(CA::COUNTER);
1543        }
1544        if self.value_type.is_some() {
1545            expr_value |= u32::from(CA::VALUE_TYPE);
1546        }
1547        if self.value.is_some() {
1548            expr_value |= u32::from(CA::VALUE);
1549        }
1550        if self.test_type.is_some() {
1551            expr_value |= u32::from(CA::TEST_TYPE);
1552        }
1553        if self.delta.is_some() {
1554            expr_value |= u32::from(CA::DELTA);
1555        }
1556        if self.events.is_some() {
1557            expr_value |= u32::from(CA::EVENTS);
1558        }
1559        expr_value
1560    }
1561}
1562impl ChangeAlarmAux {
1563    /// Create a new instance with all fields unset / not present.
1564    pub fn new() -> Self {
1565        Default::default()
1566    }
1567    /// Set the `counter` field of this structure.
1568    #[must_use]
1569    pub fn counter<I>(mut self, value: I) -> Self where I: Into<Option<Counter>> {
1570        self.counter = value.into();
1571        self
1572    }
1573    /// Set the `value_type` field of this structure.
1574    #[must_use]
1575    pub fn value_type<I>(mut self, value: I) -> Self where I: Into<Option<VALUETYPE>> {
1576        self.value_type = value.into();
1577        self
1578    }
1579    /// Set the `value` field of this structure.
1580    #[must_use]
1581    pub fn value<I>(mut self, value: I) -> Self where I: Into<Option<Int64>> {
1582        self.value = value.into();
1583        self
1584    }
1585    /// Set the `test_type` field of this structure.
1586    #[must_use]
1587    pub fn test_type<I>(mut self, value: I) -> Self where I: Into<Option<TESTTYPE>> {
1588        self.test_type = value.into();
1589        self
1590    }
1591    /// Set the `delta` field of this structure.
1592    #[must_use]
1593    pub fn delta<I>(mut self, value: I) -> Self where I: Into<Option<Int64>> {
1594        self.delta = value.into();
1595        self
1596    }
1597    /// Set the `events` field of this structure.
1598    #[must_use]
1599    pub fn events<I>(mut self, value: I) -> Self where I: Into<Option<u32>> {
1600        self.events = value.into();
1601        self
1602    }
1603}
1604
1605/// Opcode for the ChangeAlarm request
1606pub const CHANGE_ALARM_REQUEST: u8 = 9;
1607#[derive(Clone, Default)]
1608#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1609#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1610pub struct ChangeAlarmRequest<'input> {
1611    pub id: Alarm,
1612    pub value_list: Cow<'input, ChangeAlarmAux>,
1613}
1614impl_debug_if_no_extra_traits!(ChangeAlarmRequest<'_>, "ChangeAlarmRequest");
1615impl<'input> ChangeAlarmRequest<'input> {
1616    /// Serialize this request into bytes for the provided connection
1617    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
1618        let length_so_far = 0;
1619        let id_bytes = self.id.serialize();
1620        let value_mask: u32 = self.value_list.switch_expr();
1621        let value_mask_bytes = value_mask.serialize();
1622        let mut request0 = vec![
1623            major_opcode,
1624            CHANGE_ALARM_REQUEST,
1625            0,
1626            0,
1627            id_bytes[0],
1628            id_bytes[1],
1629            id_bytes[2],
1630            id_bytes[3],
1631            value_mask_bytes[0],
1632            value_mask_bytes[1],
1633            value_mask_bytes[2],
1634            value_mask_bytes[3],
1635        ];
1636        let length_so_far = length_so_far + request0.len();
1637        let value_list_bytes = self.value_list.serialize(u32::from(value_mask));
1638        let length_so_far = length_so_far + value_list_bytes.len();
1639        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1640        let length_so_far = length_so_far + padding0.len();
1641        assert_eq!(length_so_far % 4, 0);
1642        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1643        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1644        ([request0.into(), value_list_bytes.into(), padding0.into()], vec![])
1645    }
1646    /// Parse this request given its header, its body, and any fds that go along with it
1647    #[cfg(feature = "request-parsing")]
1648    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1649        if header.minor_opcode != CHANGE_ALARM_REQUEST {
1650            return Err(ParseError::InvalidValue);
1651        }
1652        let (id, remaining) = Alarm::try_parse(value)?;
1653        let (value_mask, remaining) = u32::try_parse(remaining)?;
1654        let (value_list, remaining) = ChangeAlarmAux::try_parse(remaining, u32::from(value_mask))?;
1655        let _ = remaining;
1656        Ok(ChangeAlarmRequest {
1657            id,
1658            value_list: Cow::Owned(value_list),
1659        })
1660    }
1661    /// Clone all borrowed data in this ChangeAlarmRequest.
1662    pub fn into_owned(self) -> ChangeAlarmRequest<'static> {
1663        ChangeAlarmRequest {
1664            id: self.id,
1665            value_list: Cow::Owned(self.value_list.into_owned()),
1666        }
1667    }
1668}
1669impl<'input> Request for ChangeAlarmRequest<'input> {
1670    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1671
1672    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1673        let (bufs, fds) = self.serialize(major_opcode);
1674        // Flatten the buffers into a single vector
1675        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1676        (buf, fds)
1677    }
1678}
1679impl<'input> crate::x11_utils::VoidRequest for ChangeAlarmRequest<'input> {
1680}
1681
1682/// Opcode for the DestroyAlarm request
1683pub const DESTROY_ALARM_REQUEST: u8 = 11;
1684#[derive(Clone, Copy, Default)]
1685#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1686#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1687pub struct DestroyAlarmRequest {
1688    pub alarm: Alarm,
1689}
1690impl_debug_if_no_extra_traits!(DestroyAlarmRequest, "DestroyAlarmRequest");
1691impl DestroyAlarmRequest {
1692    /// Serialize this request into bytes for the provided connection
1693    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1694        let length_so_far = 0;
1695        let alarm_bytes = self.alarm.serialize();
1696        let mut request0 = vec![
1697            major_opcode,
1698            DESTROY_ALARM_REQUEST,
1699            0,
1700            0,
1701            alarm_bytes[0],
1702            alarm_bytes[1],
1703            alarm_bytes[2],
1704            alarm_bytes[3],
1705        ];
1706        let length_so_far = length_so_far + request0.len();
1707        assert_eq!(length_so_far % 4, 0);
1708        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1709        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1710        ([request0.into()], vec![])
1711    }
1712    /// Parse this request given its header, its body, and any fds that go along with it
1713    #[cfg(feature = "request-parsing")]
1714    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1715        if header.minor_opcode != DESTROY_ALARM_REQUEST {
1716            return Err(ParseError::InvalidValue);
1717        }
1718        let (alarm, remaining) = Alarm::try_parse(value)?;
1719        let _ = remaining;
1720        Ok(DestroyAlarmRequest {
1721            alarm,
1722        })
1723    }
1724}
1725impl Request for DestroyAlarmRequest {
1726    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1727
1728    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1729        let (bufs, fds) = self.serialize(major_opcode);
1730        // Flatten the buffers into a single vector
1731        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1732        (buf, fds)
1733    }
1734}
1735impl crate::x11_utils::VoidRequest for DestroyAlarmRequest {
1736}
1737
1738/// Opcode for the QueryAlarm request
1739pub const QUERY_ALARM_REQUEST: u8 = 10;
1740#[derive(Clone, Copy, Default)]
1741#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1742#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1743pub struct QueryAlarmRequest {
1744    pub alarm: Alarm,
1745}
1746impl_debug_if_no_extra_traits!(QueryAlarmRequest, "QueryAlarmRequest");
1747impl QueryAlarmRequest {
1748    /// Serialize this request into bytes for the provided connection
1749    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1750        let length_so_far = 0;
1751        let alarm_bytes = self.alarm.serialize();
1752        let mut request0 = vec![
1753            major_opcode,
1754            QUERY_ALARM_REQUEST,
1755            0,
1756            0,
1757            alarm_bytes[0],
1758            alarm_bytes[1],
1759            alarm_bytes[2],
1760            alarm_bytes[3],
1761        ];
1762        let length_so_far = length_so_far + request0.len();
1763        assert_eq!(length_so_far % 4, 0);
1764        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1765        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1766        ([request0.into()], vec![])
1767    }
1768    /// Parse this request given its header, its body, and any fds that go along with it
1769    #[cfg(feature = "request-parsing")]
1770    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1771        if header.minor_opcode != QUERY_ALARM_REQUEST {
1772            return Err(ParseError::InvalidValue);
1773        }
1774        let (alarm, remaining) = Alarm::try_parse(value)?;
1775        let _ = remaining;
1776        Ok(QueryAlarmRequest {
1777            alarm,
1778        })
1779    }
1780}
1781impl Request for QueryAlarmRequest {
1782    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1783
1784    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1785        let (bufs, fds) = self.serialize(major_opcode);
1786        // Flatten the buffers into a single vector
1787        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1788        (buf, fds)
1789    }
1790}
1791impl crate::x11_utils::ReplyRequest for QueryAlarmRequest {
1792    type Reply = QueryAlarmReply;
1793}
1794
1795#[derive(Clone, Copy, Default)]
1796#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1797#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1798pub struct QueryAlarmReply {
1799    pub sequence: u16,
1800    pub length: u32,
1801    pub trigger: Trigger,
1802    pub delta: Int64,
1803    pub events: bool,
1804    pub state: ALARMSTATE,
1805}
1806impl_debug_if_no_extra_traits!(QueryAlarmReply, "QueryAlarmReply");
1807impl TryParse for QueryAlarmReply {
1808    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1809        let remaining = initial_value;
1810        let (response_type, remaining) = u8::try_parse(remaining)?;
1811        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1812        let (sequence, remaining) = u16::try_parse(remaining)?;
1813        let (length, remaining) = u32::try_parse(remaining)?;
1814        let (trigger, remaining) = Trigger::try_parse(remaining)?;
1815        let (delta, remaining) = Int64::try_parse(remaining)?;
1816        let (events, remaining) = bool::try_parse(remaining)?;
1817        let (state, remaining) = u8::try_parse(remaining)?;
1818        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
1819        if response_type != 1 {
1820            return Err(ParseError::InvalidValue);
1821        }
1822        let state = state.into();
1823        let result = QueryAlarmReply { sequence, length, trigger, delta, events, state };
1824        let _ = remaining;
1825        let remaining = initial_value.get(32 + length as usize * 4..)
1826            .ok_or(ParseError::InsufficientData)?;
1827        Ok((result, remaining))
1828    }
1829}
1830impl Serialize for QueryAlarmReply {
1831    type Bytes = [u8; 40];
1832    fn serialize(&self) -> [u8; 40] {
1833        let response_type_bytes = &[1];
1834        let sequence_bytes = self.sequence.serialize();
1835        let length_bytes = self.length.serialize();
1836        let trigger_bytes = self.trigger.serialize();
1837        let delta_bytes = self.delta.serialize();
1838        let events_bytes = self.events.serialize();
1839        let state_bytes = u8::from(self.state).serialize();
1840        [
1841            response_type_bytes[0],
1842            0,
1843            sequence_bytes[0],
1844            sequence_bytes[1],
1845            length_bytes[0],
1846            length_bytes[1],
1847            length_bytes[2],
1848            length_bytes[3],
1849            trigger_bytes[0],
1850            trigger_bytes[1],
1851            trigger_bytes[2],
1852            trigger_bytes[3],
1853            trigger_bytes[4],
1854            trigger_bytes[5],
1855            trigger_bytes[6],
1856            trigger_bytes[7],
1857            trigger_bytes[8],
1858            trigger_bytes[9],
1859            trigger_bytes[10],
1860            trigger_bytes[11],
1861            trigger_bytes[12],
1862            trigger_bytes[13],
1863            trigger_bytes[14],
1864            trigger_bytes[15],
1865            trigger_bytes[16],
1866            trigger_bytes[17],
1867            trigger_bytes[18],
1868            trigger_bytes[19],
1869            delta_bytes[0],
1870            delta_bytes[1],
1871            delta_bytes[2],
1872            delta_bytes[3],
1873            delta_bytes[4],
1874            delta_bytes[5],
1875            delta_bytes[6],
1876            delta_bytes[7],
1877            events_bytes[0],
1878            state_bytes[0],
1879            0,
1880            0,
1881        ]
1882    }
1883    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1884        bytes.reserve(40);
1885        let response_type_bytes = &[1];
1886        bytes.push(response_type_bytes[0]);
1887        bytes.extend_from_slice(&[0; 1]);
1888        self.sequence.serialize_into(bytes);
1889        self.length.serialize_into(bytes);
1890        self.trigger.serialize_into(bytes);
1891        self.delta.serialize_into(bytes);
1892        self.events.serialize_into(bytes);
1893        u8::from(self.state).serialize_into(bytes);
1894        bytes.extend_from_slice(&[0; 2]);
1895    }
1896}
1897
1898/// Opcode for the SetPriority request
1899pub const SET_PRIORITY_REQUEST: u8 = 12;
1900#[derive(Clone, Copy, Default)]
1901#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1902#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1903pub struct SetPriorityRequest {
1904    pub id: u32,
1905    pub priority: i32,
1906}
1907impl_debug_if_no_extra_traits!(SetPriorityRequest, "SetPriorityRequest");
1908impl SetPriorityRequest {
1909    /// Serialize this request into bytes for the provided connection
1910    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1911        let length_so_far = 0;
1912        let id_bytes = self.id.serialize();
1913        let priority_bytes = self.priority.serialize();
1914        let mut request0 = vec![
1915            major_opcode,
1916            SET_PRIORITY_REQUEST,
1917            0,
1918            0,
1919            id_bytes[0],
1920            id_bytes[1],
1921            id_bytes[2],
1922            id_bytes[3],
1923            priority_bytes[0],
1924            priority_bytes[1],
1925            priority_bytes[2],
1926            priority_bytes[3],
1927        ];
1928        let length_so_far = length_so_far + request0.len();
1929        assert_eq!(length_so_far % 4, 0);
1930        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1931        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1932        ([request0.into()], vec![])
1933    }
1934    /// Parse this request given its header, its body, and any fds that go along with it
1935    #[cfg(feature = "request-parsing")]
1936    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1937        if header.minor_opcode != SET_PRIORITY_REQUEST {
1938            return Err(ParseError::InvalidValue);
1939        }
1940        let (id, remaining) = u32::try_parse(value)?;
1941        let (priority, remaining) = i32::try_parse(remaining)?;
1942        let _ = remaining;
1943        Ok(SetPriorityRequest {
1944            id,
1945            priority,
1946        })
1947    }
1948}
1949impl Request for SetPriorityRequest {
1950    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1951
1952    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1953        let (bufs, fds) = self.serialize(major_opcode);
1954        // Flatten the buffers into a single vector
1955        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1956        (buf, fds)
1957    }
1958}
1959impl crate::x11_utils::VoidRequest for SetPriorityRequest {
1960}
1961
1962/// Opcode for the GetPriority request
1963pub const GET_PRIORITY_REQUEST: u8 = 13;
1964#[derive(Clone, Copy, Default)]
1965#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1966#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1967pub struct GetPriorityRequest {
1968    pub id: u32,
1969}
1970impl_debug_if_no_extra_traits!(GetPriorityRequest, "GetPriorityRequest");
1971impl GetPriorityRequest {
1972    /// Serialize this request into bytes for the provided connection
1973    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1974        let length_so_far = 0;
1975        let id_bytes = self.id.serialize();
1976        let mut request0 = vec![
1977            major_opcode,
1978            GET_PRIORITY_REQUEST,
1979            0,
1980            0,
1981            id_bytes[0],
1982            id_bytes[1],
1983            id_bytes[2],
1984            id_bytes[3],
1985        ];
1986        let length_so_far = length_so_far + request0.len();
1987        assert_eq!(length_so_far % 4, 0);
1988        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1989        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1990        ([request0.into()], vec![])
1991    }
1992    /// Parse this request given its header, its body, and any fds that go along with it
1993    #[cfg(feature = "request-parsing")]
1994    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1995        if header.minor_opcode != GET_PRIORITY_REQUEST {
1996            return Err(ParseError::InvalidValue);
1997        }
1998        let (id, remaining) = u32::try_parse(value)?;
1999        let _ = remaining;
2000        Ok(GetPriorityRequest {
2001            id,
2002        })
2003    }
2004}
2005impl Request for GetPriorityRequest {
2006    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2007
2008    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2009        let (bufs, fds) = self.serialize(major_opcode);
2010        // Flatten the buffers into a single vector
2011        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2012        (buf, fds)
2013    }
2014}
2015impl crate::x11_utils::ReplyRequest for GetPriorityRequest {
2016    type Reply = GetPriorityReply;
2017}
2018
2019#[derive(Clone, Copy, Default)]
2020#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2021#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2022pub struct GetPriorityReply {
2023    pub sequence: u16,
2024    pub length: u32,
2025    pub priority: i32,
2026}
2027impl_debug_if_no_extra_traits!(GetPriorityReply, "GetPriorityReply");
2028impl TryParse for GetPriorityReply {
2029    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2030        let remaining = initial_value;
2031        let (response_type, remaining) = u8::try_parse(remaining)?;
2032        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2033        let (sequence, remaining) = u16::try_parse(remaining)?;
2034        let (length, remaining) = u32::try_parse(remaining)?;
2035        let (priority, remaining) = i32::try_parse(remaining)?;
2036        if response_type != 1 {
2037            return Err(ParseError::InvalidValue);
2038        }
2039        let result = GetPriorityReply { sequence, length, priority };
2040        let _ = remaining;
2041        let remaining = initial_value.get(32 + length as usize * 4..)
2042            .ok_or(ParseError::InsufficientData)?;
2043        Ok((result, remaining))
2044    }
2045}
2046impl Serialize for GetPriorityReply {
2047    type Bytes = [u8; 12];
2048    fn serialize(&self) -> [u8; 12] {
2049        let response_type_bytes = &[1];
2050        let sequence_bytes = self.sequence.serialize();
2051        let length_bytes = self.length.serialize();
2052        let priority_bytes = self.priority.serialize();
2053        [
2054            response_type_bytes[0],
2055            0,
2056            sequence_bytes[0],
2057            sequence_bytes[1],
2058            length_bytes[0],
2059            length_bytes[1],
2060            length_bytes[2],
2061            length_bytes[3],
2062            priority_bytes[0],
2063            priority_bytes[1],
2064            priority_bytes[2],
2065            priority_bytes[3],
2066        ]
2067    }
2068    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2069        bytes.reserve(12);
2070        let response_type_bytes = &[1];
2071        bytes.push(response_type_bytes[0]);
2072        bytes.extend_from_slice(&[0; 1]);
2073        self.sequence.serialize_into(bytes);
2074        self.length.serialize_into(bytes);
2075        self.priority.serialize_into(bytes);
2076    }
2077}
2078
2079/// Opcode for the CreateFence request
2080pub const CREATE_FENCE_REQUEST: u8 = 14;
2081#[derive(Clone, Copy, Default)]
2082#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2083#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2084pub struct CreateFenceRequest {
2085    pub drawable: xproto::Drawable,
2086    pub fence: Fence,
2087    pub initially_triggered: bool,
2088}
2089impl_debug_if_no_extra_traits!(CreateFenceRequest, "CreateFenceRequest");
2090impl CreateFenceRequest {
2091    /// Serialize this request into bytes for the provided connection
2092    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2093        let length_so_far = 0;
2094        let drawable_bytes = self.drawable.serialize();
2095        let fence_bytes = self.fence.serialize();
2096        let initially_triggered_bytes = self.initially_triggered.serialize();
2097        let mut request0 = vec![
2098            major_opcode,
2099            CREATE_FENCE_REQUEST,
2100            0,
2101            0,
2102            drawable_bytes[0],
2103            drawable_bytes[1],
2104            drawable_bytes[2],
2105            drawable_bytes[3],
2106            fence_bytes[0],
2107            fence_bytes[1],
2108            fence_bytes[2],
2109            fence_bytes[3],
2110            initially_triggered_bytes[0],
2111            0,
2112            0,
2113            0,
2114        ];
2115        let length_so_far = length_so_far + request0.len();
2116        assert_eq!(length_so_far % 4, 0);
2117        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2118        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2119        ([request0.into()], vec![])
2120    }
2121    /// Parse this request given its header, its body, and any fds that go along with it
2122    #[cfg(feature = "request-parsing")]
2123    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2124        if header.minor_opcode != CREATE_FENCE_REQUEST {
2125            return Err(ParseError::InvalidValue);
2126        }
2127        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
2128        let (fence, remaining) = Fence::try_parse(remaining)?;
2129        let (initially_triggered, remaining) = bool::try_parse(remaining)?;
2130        let _ = remaining;
2131        Ok(CreateFenceRequest {
2132            drawable,
2133            fence,
2134            initially_triggered,
2135        })
2136    }
2137}
2138impl Request for CreateFenceRequest {
2139    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2140
2141    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2142        let (bufs, fds) = self.serialize(major_opcode);
2143        // Flatten the buffers into a single vector
2144        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2145        (buf, fds)
2146    }
2147}
2148impl crate::x11_utils::VoidRequest for CreateFenceRequest {
2149}
2150
2151/// Opcode for the TriggerFence request
2152pub const TRIGGER_FENCE_REQUEST: u8 = 15;
2153#[derive(Clone, Copy, Default)]
2154#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2155#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2156pub struct TriggerFenceRequest {
2157    pub fence: Fence,
2158}
2159impl_debug_if_no_extra_traits!(TriggerFenceRequest, "TriggerFenceRequest");
2160impl TriggerFenceRequest {
2161    /// Serialize this request into bytes for the provided connection
2162    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2163        let length_so_far = 0;
2164        let fence_bytes = self.fence.serialize();
2165        let mut request0 = vec![
2166            major_opcode,
2167            TRIGGER_FENCE_REQUEST,
2168            0,
2169            0,
2170            fence_bytes[0],
2171            fence_bytes[1],
2172            fence_bytes[2],
2173            fence_bytes[3],
2174        ];
2175        let length_so_far = length_so_far + request0.len();
2176        assert_eq!(length_so_far % 4, 0);
2177        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2178        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2179        ([request0.into()], vec![])
2180    }
2181    /// Parse this request given its header, its body, and any fds that go along with it
2182    #[cfg(feature = "request-parsing")]
2183    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2184        if header.minor_opcode != TRIGGER_FENCE_REQUEST {
2185            return Err(ParseError::InvalidValue);
2186        }
2187        let (fence, remaining) = Fence::try_parse(value)?;
2188        let _ = remaining;
2189        Ok(TriggerFenceRequest {
2190            fence,
2191        })
2192    }
2193}
2194impl Request for TriggerFenceRequest {
2195    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2196
2197    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2198        let (bufs, fds) = self.serialize(major_opcode);
2199        // Flatten the buffers into a single vector
2200        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2201        (buf, fds)
2202    }
2203}
2204impl crate::x11_utils::VoidRequest for TriggerFenceRequest {
2205}
2206
2207/// Opcode for the ResetFence request
2208pub const RESET_FENCE_REQUEST: u8 = 16;
2209#[derive(Clone, Copy, Default)]
2210#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2211#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2212pub struct ResetFenceRequest {
2213    pub fence: Fence,
2214}
2215impl_debug_if_no_extra_traits!(ResetFenceRequest, "ResetFenceRequest");
2216impl ResetFenceRequest {
2217    /// Serialize this request into bytes for the provided connection
2218    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2219        let length_so_far = 0;
2220        let fence_bytes = self.fence.serialize();
2221        let mut request0 = vec![
2222            major_opcode,
2223            RESET_FENCE_REQUEST,
2224            0,
2225            0,
2226            fence_bytes[0],
2227            fence_bytes[1],
2228            fence_bytes[2],
2229            fence_bytes[3],
2230        ];
2231        let length_so_far = length_so_far + request0.len();
2232        assert_eq!(length_so_far % 4, 0);
2233        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2234        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2235        ([request0.into()], vec![])
2236    }
2237    /// Parse this request given its header, its body, and any fds that go along with it
2238    #[cfg(feature = "request-parsing")]
2239    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2240        if header.minor_opcode != RESET_FENCE_REQUEST {
2241            return Err(ParseError::InvalidValue);
2242        }
2243        let (fence, remaining) = Fence::try_parse(value)?;
2244        let _ = remaining;
2245        Ok(ResetFenceRequest {
2246            fence,
2247        })
2248    }
2249}
2250impl Request for ResetFenceRequest {
2251    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2252
2253    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2254        let (bufs, fds) = self.serialize(major_opcode);
2255        // Flatten the buffers into a single vector
2256        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2257        (buf, fds)
2258    }
2259}
2260impl crate::x11_utils::VoidRequest for ResetFenceRequest {
2261}
2262
2263/// Opcode for the DestroyFence request
2264pub const DESTROY_FENCE_REQUEST: u8 = 17;
2265#[derive(Clone, Copy, Default)]
2266#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2267#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2268pub struct DestroyFenceRequest {
2269    pub fence: Fence,
2270}
2271impl_debug_if_no_extra_traits!(DestroyFenceRequest, "DestroyFenceRequest");
2272impl DestroyFenceRequest {
2273    /// Serialize this request into bytes for the provided connection
2274    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2275        let length_so_far = 0;
2276        let fence_bytes = self.fence.serialize();
2277        let mut request0 = vec![
2278            major_opcode,
2279            DESTROY_FENCE_REQUEST,
2280            0,
2281            0,
2282            fence_bytes[0],
2283            fence_bytes[1],
2284            fence_bytes[2],
2285            fence_bytes[3],
2286        ];
2287        let length_so_far = length_so_far + request0.len();
2288        assert_eq!(length_so_far % 4, 0);
2289        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2290        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2291        ([request0.into()], vec![])
2292    }
2293    /// Parse this request given its header, its body, and any fds that go along with it
2294    #[cfg(feature = "request-parsing")]
2295    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2296        if header.minor_opcode != DESTROY_FENCE_REQUEST {
2297            return Err(ParseError::InvalidValue);
2298        }
2299        let (fence, remaining) = Fence::try_parse(value)?;
2300        let _ = remaining;
2301        Ok(DestroyFenceRequest {
2302            fence,
2303        })
2304    }
2305}
2306impl Request for DestroyFenceRequest {
2307    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2308
2309    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2310        let (bufs, fds) = self.serialize(major_opcode);
2311        // Flatten the buffers into a single vector
2312        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2313        (buf, fds)
2314    }
2315}
2316impl crate::x11_utils::VoidRequest for DestroyFenceRequest {
2317}
2318
2319/// Opcode for the QueryFence request
2320pub const QUERY_FENCE_REQUEST: u8 = 18;
2321#[derive(Clone, Copy, Default)]
2322#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2323#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2324pub struct QueryFenceRequest {
2325    pub fence: Fence,
2326}
2327impl_debug_if_no_extra_traits!(QueryFenceRequest, "QueryFenceRequest");
2328impl QueryFenceRequest {
2329    /// Serialize this request into bytes for the provided connection
2330    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2331        let length_so_far = 0;
2332        let fence_bytes = self.fence.serialize();
2333        let mut request0 = vec![
2334            major_opcode,
2335            QUERY_FENCE_REQUEST,
2336            0,
2337            0,
2338            fence_bytes[0],
2339            fence_bytes[1],
2340            fence_bytes[2],
2341            fence_bytes[3],
2342        ];
2343        let length_so_far = length_so_far + request0.len();
2344        assert_eq!(length_so_far % 4, 0);
2345        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2346        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2347        ([request0.into()], vec![])
2348    }
2349    /// Parse this request given its header, its body, and any fds that go along with it
2350    #[cfg(feature = "request-parsing")]
2351    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2352        if header.minor_opcode != QUERY_FENCE_REQUEST {
2353            return Err(ParseError::InvalidValue);
2354        }
2355        let (fence, remaining) = Fence::try_parse(value)?;
2356        let _ = remaining;
2357        Ok(QueryFenceRequest {
2358            fence,
2359        })
2360    }
2361}
2362impl Request for QueryFenceRequest {
2363    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2364
2365    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2366        let (bufs, fds) = self.serialize(major_opcode);
2367        // Flatten the buffers into a single vector
2368        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2369        (buf, fds)
2370    }
2371}
2372impl crate::x11_utils::ReplyRequest for QueryFenceRequest {
2373    type Reply = QueryFenceReply;
2374}
2375
2376#[derive(Clone, Copy, Default)]
2377#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2378#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2379pub struct QueryFenceReply {
2380    pub sequence: u16,
2381    pub length: u32,
2382    pub triggered: bool,
2383}
2384impl_debug_if_no_extra_traits!(QueryFenceReply, "QueryFenceReply");
2385impl TryParse for QueryFenceReply {
2386    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2387        let remaining = initial_value;
2388        let (response_type, remaining) = u8::try_parse(remaining)?;
2389        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2390        let (sequence, remaining) = u16::try_parse(remaining)?;
2391        let (length, remaining) = u32::try_parse(remaining)?;
2392        let (triggered, remaining) = bool::try_parse(remaining)?;
2393        let remaining = remaining.get(23..).ok_or(ParseError::InsufficientData)?;
2394        if response_type != 1 {
2395            return Err(ParseError::InvalidValue);
2396        }
2397        let result = QueryFenceReply { sequence, length, triggered };
2398        let _ = remaining;
2399        let remaining = initial_value.get(32 + length as usize * 4..)
2400            .ok_or(ParseError::InsufficientData)?;
2401        Ok((result, remaining))
2402    }
2403}
2404impl Serialize for QueryFenceReply {
2405    type Bytes = [u8; 32];
2406    fn serialize(&self) -> [u8; 32] {
2407        let response_type_bytes = &[1];
2408        let sequence_bytes = self.sequence.serialize();
2409        let length_bytes = self.length.serialize();
2410        let triggered_bytes = self.triggered.serialize();
2411        [
2412            response_type_bytes[0],
2413            0,
2414            sequence_bytes[0],
2415            sequence_bytes[1],
2416            length_bytes[0],
2417            length_bytes[1],
2418            length_bytes[2],
2419            length_bytes[3],
2420            triggered_bytes[0],
2421            0,
2422            0,
2423            0,
2424            0,
2425            0,
2426            0,
2427            0,
2428            0,
2429            0,
2430            0,
2431            0,
2432            0,
2433            0,
2434            0,
2435            0,
2436            0,
2437            0,
2438            0,
2439            0,
2440            0,
2441            0,
2442            0,
2443            0,
2444        ]
2445    }
2446    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2447        bytes.reserve(32);
2448        let response_type_bytes = &[1];
2449        bytes.push(response_type_bytes[0]);
2450        bytes.extend_from_slice(&[0; 1]);
2451        self.sequence.serialize_into(bytes);
2452        self.length.serialize_into(bytes);
2453        self.triggered.serialize_into(bytes);
2454        bytes.extend_from_slice(&[0; 23]);
2455    }
2456}
2457
2458/// Opcode for the AwaitFence request
2459pub const AWAIT_FENCE_REQUEST: u8 = 19;
2460#[derive(Clone, Default)]
2461#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2462#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2463pub struct AwaitFenceRequest<'input> {
2464    pub fence_list: Cow<'input, [Fence]>,
2465}
2466impl_debug_if_no_extra_traits!(AwaitFenceRequest<'_>, "AwaitFenceRequest");
2467impl<'input> AwaitFenceRequest<'input> {
2468    /// Serialize this request into bytes for the provided connection
2469    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
2470        let length_so_far = 0;
2471        let mut request0 = vec![
2472            major_opcode,
2473            AWAIT_FENCE_REQUEST,
2474            0,
2475            0,
2476        ];
2477        let length_so_far = length_so_far + request0.len();
2478        let fence_list_bytes = self.fence_list.serialize();
2479        let length_so_far = length_so_far + fence_list_bytes.len();
2480        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
2481        let length_so_far = length_so_far + padding0.len();
2482        assert_eq!(length_so_far % 4, 0);
2483        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2484        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2485        ([request0.into(), fence_list_bytes.into(), padding0.into()], vec![])
2486    }
2487    /// Parse this request given its header, its body, and any fds that go along with it
2488    #[cfg(feature = "request-parsing")]
2489    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
2490        if header.minor_opcode != AWAIT_FENCE_REQUEST {
2491            return Err(ParseError::InvalidValue);
2492        }
2493        let mut remaining = value;
2494        // Length is 'everything left in the input'
2495        let mut fence_list = Vec::new();
2496        while !remaining.is_empty() {
2497            let (v, new_remaining) = Fence::try_parse(value)?;
2498            remaining = new_remaining;
2499            fence_list.push(v);
2500        }
2501        let _ = remaining;
2502        Ok(AwaitFenceRequest {
2503            fence_list: Cow::Owned(fence_list),
2504        })
2505    }
2506    /// Clone all borrowed data in this AwaitFenceRequest.
2507    pub fn into_owned(self) -> AwaitFenceRequest<'static> {
2508        AwaitFenceRequest {
2509            fence_list: Cow::Owned(self.fence_list.into_owned()),
2510        }
2511    }
2512}
2513impl<'input> Request for AwaitFenceRequest<'input> {
2514    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2515
2516    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2517        let (bufs, fds) = self.serialize(major_opcode);
2518        // Flatten the buffers into a single vector
2519        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2520        (buf, fds)
2521    }
2522}
2523impl<'input> crate::x11_utils::VoidRequest for AwaitFenceRequest<'input> {
2524}
2525
2526/// Opcode for the CounterNotify event
2527pub const COUNTER_NOTIFY_EVENT: u8 = 0;
2528#[derive(Clone, Copy, Default)]
2529#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2530#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2531pub struct CounterNotifyEvent {
2532    pub response_type: u8,
2533    pub kind: u8,
2534    pub sequence: u16,
2535    pub counter: Counter,
2536    pub wait_value: Int64,
2537    pub counter_value: Int64,
2538    pub timestamp: xproto::Timestamp,
2539    pub count: u16,
2540    pub destroyed: bool,
2541}
2542impl_debug_if_no_extra_traits!(CounterNotifyEvent, "CounterNotifyEvent");
2543impl TryParse for CounterNotifyEvent {
2544    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2545        let remaining = initial_value;
2546        let (response_type, remaining) = u8::try_parse(remaining)?;
2547        let (kind, remaining) = u8::try_parse(remaining)?;
2548        let (sequence, remaining) = u16::try_parse(remaining)?;
2549        let (counter, remaining) = Counter::try_parse(remaining)?;
2550        let (wait_value, remaining) = Int64::try_parse(remaining)?;
2551        let (counter_value, remaining) = Int64::try_parse(remaining)?;
2552        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
2553        let (count, remaining) = u16::try_parse(remaining)?;
2554        let (destroyed, remaining) = bool::try_parse(remaining)?;
2555        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2556        let result = CounterNotifyEvent { response_type, kind, sequence, counter, wait_value, counter_value, timestamp, count, destroyed };
2557        let _ = remaining;
2558        let remaining = initial_value.get(32..)
2559            .ok_or(ParseError::InsufficientData)?;
2560        Ok((result, remaining))
2561    }
2562}
2563impl Serialize for CounterNotifyEvent {
2564    type Bytes = [u8; 32];
2565    fn serialize(&self) -> [u8; 32] {
2566        let response_type_bytes = self.response_type.serialize();
2567        let kind_bytes = self.kind.serialize();
2568        let sequence_bytes = self.sequence.serialize();
2569        let counter_bytes = self.counter.serialize();
2570        let wait_value_bytes = self.wait_value.serialize();
2571        let counter_value_bytes = self.counter_value.serialize();
2572        let timestamp_bytes = self.timestamp.serialize();
2573        let count_bytes = self.count.serialize();
2574        let destroyed_bytes = self.destroyed.serialize();
2575        [
2576            response_type_bytes[0],
2577            kind_bytes[0],
2578            sequence_bytes[0],
2579            sequence_bytes[1],
2580            counter_bytes[0],
2581            counter_bytes[1],
2582            counter_bytes[2],
2583            counter_bytes[3],
2584            wait_value_bytes[0],
2585            wait_value_bytes[1],
2586            wait_value_bytes[2],
2587            wait_value_bytes[3],
2588            wait_value_bytes[4],
2589            wait_value_bytes[5],
2590            wait_value_bytes[6],
2591            wait_value_bytes[7],
2592            counter_value_bytes[0],
2593            counter_value_bytes[1],
2594            counter_value_bytes[2],
2595            counter_value_bytes[3],
2596            counter_value_bytes[4],
2597            counter_value_bytes[5],
2598            counter_value_bytes[6],
2599            counter_value_bytes[7],
2600            timestamp_bytes[0],
2601            timestamp_bytes[1],
2602            timestamp_bytes[2],
2603            timestamp_bytes[3],
2604            count_bytes[0],
2605            count_bytes[1],
2606            destroyed_bytes[0],
2607            0,
2608        ]
2609    }
2610    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2611        bytes.reserve(32);
2612        self.response_type.serialize_into(bytes);
2613        self.kind.serialize_into(bytes);
2614        self.sequence.serialize_into(bytes);
2615        self.counter.serialize_into(bytes);
2616        self.wait_value.serialize_into(bytes);
2617        self.counter_value.serialize_into(bytes);
2618        self.timestamp.serialize_into(bytes);
2619        self.count.serialize_into(bytes);
2620        self.destroyed.serialize_into(bytes);
2621        bytes.extend_from_slice(&[0; 1]);
2622    }
2623}
2624impl From<&CounterNotifyEvent> for [u8; 32] {
2625    fn from(input: &CounterNotifyEvent) -> Self {
2626        let response_type_bytes = input.response_type.serialize();
2627        let kind_bytes = input.kind.serialize();
2628        let sequence_bytes = input.sequence.serialize();
2629        let counter_bytes = input.counter.serialize();
2630        let wait_value_bytes = input.wait_value.serialize();
2631        let counter_value_bytes = input.counter_value.serialize();
2632        let timestamp_bytes = input.timestamp.serialize();
2633        let count_bytes = input.count.serialize();
2634        let destroyed_bytes = input.destroyed.serialize();
2635        [
2636            response_type_bytes[0],
2637            kind_bytes[0],
2638            sequence_bytes[0],
2639            sequence_bytes[1],
2640            counter_bytes[0],
2641            counter_bytes[1],
2642            counter_bytes[2],
2643            counter_bytes[3],
2644            wait_value_bytes[0],
2645            wait_value_bytes[1],
2646            wait_value_bytes[2],
2647            wait_value_bytes[3],
2648            wait_value_bytes[4],
2649            wait_value_bytes[5],
2650            wait_value_bytes[6],
2651            wait_value_bytes[7],
2652            counter_value_bytes[0],
2653            counter_value_bytes[1],
2654            counter_value_bytes[2],
2655            counter_value_bytes[3],
2656            counter_value_bytes[4],
2657            counter_value_bytes[5],
2658            counter_value_bytes[6],
2659            counter_value_bytes[7],
2660            timestamp_bytes[0],
2661            timestamp_bytes[1],
2662            timestamp_bytes[2],
2663            timestamp_bytes[3],
2664            count_bytes[0],
2665            count_bytes[1],
2666            destroyed_bytes[0],
2667            0,
2668        ]
2669    }
2670}
2671impl From<CounterNotifyEvent> for [u8; 32] {
2672    fn from(input: CounterNotifyEvent) -> Self {
2673        Self::from(&input)
2674    }
2675}
2676
2677/// Opcode for the AlarmNotify event
2678pub const ALARM_NOTIFY_EVENT: u8 = 1;
2679#[derive(Clone, Copy, Default)]
2680#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2681#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2682pub struct AlarmNotifyEvent {
2683    pub response_type: u8,
2684    pub kind: u8,
2685    pub sequence: u16,
2686    pub alarm: Alarm,
2687    pub counter_value: Int64,
2688    pub alarm_value: Int64,
2689    pub timestamp: xproto::Timestamp,
2690    pub state: ALARMSTATE,
2691}
2692impl_debug_if_no_extra_traits!(AlarmNotifyEvent, "AlarmNotifyEvent");
2693impl TryParse for AlarmNotifyEvent {
2694    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2695        let remaining = initial_value;
2696        let (response_type, remaining) = u8::try_parse(remaining)?;
2697        let (kind, remaining) = u8::try_parse(remaining)?;
2698        let (sequence, remaining) = u16::try_parse(remaining)?;
2699        let (alarm, remaining) = Alarm::try_parse(remaining)?;
2700        let (counter_value, remaining) = Int64::try_parse(remaining)?;
2701        let (alarm_value, remaining) = Int64::try_parse(remaining)?;
2702        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
2703        let (state, remaining) = u8::try_parse(remaining)?;
2704        let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
2705        let state = state.into();
2706        let result = AlarmNotifyEvent { response_type, kind, sequence, alarm, counter_value, alarm_value, timestamp, state };
2707        let _ = remaining;
2708        let remaining = initial_value.get(32..)
2709            .ok_or(ParseError::InsufficientData)?;
2710        Ok((result, remaining))
2711    }
2712}
2713impl Serialize for AlarmNotifyEvent {
2714    type Bytes = [u8; 32];
2715    fn serialize(&self) -> [u8; 32] {
2716        let response_type_bytes = self.response_type.serialize();
2717        let kind_bytes = self.kind.serialize();
2718        let sequence_bytes = self.sequence.serialize();
2719        let alarm_bytes = self.alarm.serialize();
2720        let counter_value_bytes = self.counter_value.serialize();
2721        let alarm_value_bytes = self.alarm_value.serialize();
2722        let timestamp_bytes = self.timestamp.serialize();
2723        let state_bytes = u8::from(self.state).serialize();
2724        [
2725            response_type_bytes[0],
2726            kind_bytes[0],
2727            sequence_bytes[0],
2728            sequence_bytes[1],
2729            alarm_bytes[0],
2730            alarm_bytes[1],
2731            alarm_bytes[2],
2732            alarm_bytes[3],
2733            counter_value_bytes[0],
2734            counter_value_bytes[1],
2735            counter_value_bytes[2],
2736            counter_value_bytes[3],
2737            counter_value_bytes[4],
2738            counter_value_bytes[5],
2739            counter_value_bytes[6],
2740            counter_value_bytes[7],
2741            alarm_value_bytes[0],
2742            alarm_value_bytes[1],
2743            alarm_value_bytes[2],
2744            alarm_value_bytes[3],
2745            alarm_value_bytes[4],
2746            alarm_value_bytes[5],
2747            alarm_value_bytes[6],
2748            alarm_value_bytes[7],
2749            timestamp_bytes[0],
2750            timestamp_bytes[1],
2751            timestamp_bytes[2],
2752            timestamp_bytes[3],
2753            state_bytes[0],
2754            0,
2755            0,
2756            0,
2757        ]
2758    }
2759    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2760        bytes.reserve(32);
2761        self.response_type.serialize_into(bytes);
2762        self.kind.serialize_into(bytes);
2763        self.sequence.serialize_into(bytes);
2764        self.alarm.serialize_into(bytes);
2765        self.counter_value.serialize_into(bytes);
2766        self.alarm_value.serialize_into(bytes);
2767        self.timestamp.serialize_into(bytes);
2768        u8::from(self.state).serialize_into(bytes);
2769        bytes.extend_from_slice(&[0; 3]);
2770    }
2771}
2772impl From<&AlarmNotifyEvent> for [u8; 32] {
2773    fn from(input: &AlarmNotifyEvent) -> Self {
2774        let response_type_bytes = input.response_type.serialize();
2775        let kind_bytes = input.kind.serialize();
2776        let sequence_bytes = input.sequence.serialize();
2777        let alarm_bytes = input.alarm.serialize();
2778        let counter_value_bytes = input.counter_value.serialize();
2779        let alarm_value_bytes = input.alarm_value.serialize();
2780        let timestamp_bytes = input.timestamp.serialize();
2781        let state_bytes = u8::from(input.state).serialize();
2782        [
2783            response_type_bytes[0],
2784            kind_bytes[0],
2785            sequence_bytes[0],
2786            sequence_bytes[1],
2787            alarm_bytes[0],
2788            alarm_bytes[1],
2789            alarm_bytes[2],
2790            alarm_bytes[3],
2791            counter_value_bytes[0],
2792            counter_value_bytes[1],
2793            counter_value_bytes[2],
2794            counter_value_bytes[3],
2795            counter_value_bytes[4],
2796            counter_value_bytes[5],
2797            counter_value_bytes[6],
2798            counter_value_bytes[7],
2799            alarm_value_bytes[0],
2800            alarm_value_bytes[1],
2801            alarm_value_bytes[2],
2802            alarm_value_bytes[3],
2803            alarm_value_bytes[4],
2804            alarm_value_bytes[5],
2805            alarm_value_bytes[6],
2806            alarm_value_bytes[7],
2807            timestamp_bytes[0],
2808            timestamp_bytes[1],
2809            timestamp_bytes[2],
2810            timestamp_bytes[3],
2811            state_bytes[0],
2812            0,
2813            0,
2814            0,
2815        ]
2816    }
2817}
2818impl From<AlarmNotifyEvent> for [u8; 32] {
2819    fn from(input: AlarmNotifyEvent) -> Self {
2820        Self::from(&input)
2821    }
2822}
2823