x11rb_protocol/protocol/
dpms.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `DPMS` 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 = "DPMS";
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) = (1, 2);
38
39/// Opcode for the GetVersion request
40pub const GET_VERSION_REQUEST: u8 = 0;
41#[derive(Clone, Copy, Default)]
42#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
43#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
44pub struct GetVersionRequest {
45    pub client_major_version: u16,
46    pub client_minor_version: u16,
47}
48impl_debug_if_no_extra_traits!(GetVersionRequest, "GetVersionRequest");
49impl GetVersionRequest {
50    /// Serialize this request into bytes for the provided connection
51    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
52        let length_so_far = 0;
53        let client_major_version_bytes = self.client_major_version.serialize();
54        let client_minor_version_bytes = self.client_minor_version.serialize();
55        let mut request0 = vec![
56            major_opcode,
57            GET_VERSION_REQUEST,
58            0,
59            0,
60            client_major_version_bytes[0],
61            client_major_version_bytes[1],
62            client_minor_version_bytes[0],
63            client_minor_version_bytes[1],
64        ];
65        let length_so_far = length_so_far + request0.len();
66        assert_eq!(length_so_far % 4, 0);
67        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
68        request0[2..4].copy_from_slice(&length.to_ne_bytes());
69        ([request0.into()], vec![])
70    }
71    /// Parse this request given its header, its body, and any fds that go along with it
72    #[cfg(feature = "request-parsing")]
73    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
74        if header.minor_opcode != GET_VERSION_REQUEST {
75            return Err(ParseError::InvalidValue);
76        }
77        let (client_major_version, remaining) = u16::try_parse(value)?;
78        let (client_minor_version, remaining) = u16::try_parse(remaining)?;
79        let _ = remaining;
80        Ok(GetVersionRequest {
81            client_major_version,
82            client_minor_version,
83        })
84    }
85}
86impl Request for GetVersionRequest {
87    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
88
89    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
90        let (bufs, fds) = self.serialize(major_opcode);
91        // Flatten the buffers into a single vector
92        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
93        (buf, fds)
94    }
95}
96impl crate::x11_utils::ReplyRequest for GetVersionRequest {
97    type Reply = GetVersionReply;
98}
99
100#[derive(Clone, Copy, Default)]
101#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
102#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
103pub struct GetVersionReply {
104    pub sequence: u16,
105    pub length: u32,
106    pub server_major_version: u16,
107    pub server_minor_version: u16,
108}
109impl_debug_if_no_extra_traits!(GetVersionReply, "GetVersionReply");
110impl TryParse for GetVersionReply {
111    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
112        let remaining = initial_value;
113        let (response_type, remaining) = u8::try_parse(remaining)?;
114        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
115        let (sequence, remaining) = u16::try_parse(remaining)?;
116        let (length, remaining) = u32::try_parse(remaining)?;
117        let (server_major_version, remaining) = u16::try_parse(remaining)?;
118        let (server_minor_version, remaining) = u16::try_parse(remaining)?;
119        if response_type != 1 {
120            return Err(ParseError::InvalidValue);
121        }
122        let result = GetVersionReply { sequence, length, server_major_version, server_minor_version };
123        let _ = remaining;
124        let remaining = initial_value.get(32 + length as usize * 4..)
125            .ok_or(ParseError::InsufficientData)?;
126        Ok((result, remaining))
127    }
128}
129impl Serialize for GetVersionReply {
130    type Bytes = [u8; 12];
131    fn serialize(&self) -> [u8; 12] {
132        let response_type_bytes = &[1];
133        let sequence_bytes = self.sequence.serialize();
134        let length_bytes = self.length.serialize();
135        let server_major_version_bytes = self.server_major_version.serialize();
136        let server_minor_version_bytes = self.server_minor_version.serialize();
137        [
138            response_type_bytes[0],
139            0,
140            sequence_bytes[0],
141            sequence_bytes[1],
142            length_bytes[0],
143            length_bytes[1],
144            length_bytes[2],
145            length_bytes[3],
146            server_major_version_bytes[0],
147            server_major_version_bytes[1],
148            server_minor_version_bytes[0],
149            server_minor_version_bytes[1],
150        ]
151    }
152    fn serialize_into(&self, bytes: &mut Vec<u8>) {
153        bytes.reserve(12);
154        let response_type_bytes = &[1];
155        bytes.push(response_type_bytes[0]);
156        bytes.extend_from_slice(&[0; 1]);
157        self.sequence.serialize_into(bytes);
158        self.length.serialize_into(bytes);
159        self.server_major_version.serialize_into(bytes);
160        self.server_minor_version.serialize_into(bytes);
161    }
162}
163
164/// Opcode for the Capable request
165pub const CAPABLE_REQUEST: u8 = 1;
166#[derive(Clone, Copy, Default)]
167#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
168#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
169pub struct CapableRequest;
170impl_debug_if_no_extra_traits!(CapableRequest, "CapableRequest");
171impl CapableRequest {
172    /// Serialize this request into bytes for the provided connection
173    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
174        let length_so_far = 0;
175        let mut request0 = vec![
176            major_opcode,
177            CAPABLE_REQUEST,
178            0,
179            0,
180        ];
181        let length_so_far = length_so_far + request0.len();
182        assert_eq!(length_so_far % 4, 0);
183        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
184        request0[2..4].copy_from_slice(&length.to_ne_bytes());
185        ([request0.into()], vec![])
186    }
187    /// Parse this request given its header, its body, and any fds that go along with it
188    #[cfg(feature = "request-parsing")]
189    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
190        if header.minor_opcode != CAPABLE_REQUEST {
191            return Err(ParseError::InvalidValue);
192        }
193        let _ = value;
194        Ok(CapableRequest
195        )
196    }
197}
198impl Request for CapableRequest {
199    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
200
201    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
202        let (bufs, fds) = self.serialize(major_opcode);
203        // Flatten the buffers into a single vector
204        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
205        (buf, fds)
206    }
207}
208impl crate::x11_utils::ReplyRequest for CapableRequest {
209    type Reply = CapableReply;
210}
211
212#[derive(Clone, Copy, Default)]
213#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
214#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
215pub struct CapableReply {
216    pub sequence: u16,
217    pub length: u32,
218    pub capable: bool,
219}
220impl_debug_if_no_extra_traits!(CapableReply, "CapableReply");
221impl TryParse for CapableReply {
222    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
223        let remaining = initial_value;
224        let (response_type, remaining) = u8::try_parse(remaining)?;
225        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
226        let (sequence, remaining) = u16::try_parse(remaining)?;
227        let (length, remaining) = u32::try_parse(remaining)?;
228        let (capable, remaining) = bool::try_parse(remaining)?;
229        let remaining = remaining.get(23..).ok_or(ParseError::InsufficientData)?;
230        if response_type != 1 {
231            return Err(ParseError::InvalidValue);
232        }
233        let result = CapableReply { sequence, length, capable };
234        let _ = remaining;
235        let remaining = initial_value.get(32 + length as usize * 4..)
236            .ok_or(ParseError::InsufficientData)?;
237        Ok((result, remaining))
238    }
239}
240impl Serialize for CapableReply {
241    type Bytes = [u8; 32];
242    fn serialize(&self) -> [u8; 32] {
243        let response_type_bytes = &[1];
244        let sequence_bytes = self.sequence.serialize();
245        let length_bytes = self.length.serialize();
246        let capable_bytes = self.capable.serialize();
247        [
248            response_type_bytes[0],
249            0,
250            sequence_bytes[0],
251            sequence_bytes[1],
252            length_bytes[0],
253            length_bytes[1],
254            length_bytes[2],
255            length_bytes[3],
256            capable_bytes[0],
257            0,
258            0,
259            0,
260            0,
261            0,
262            0,
263            0,
264            0,
265            0,
266            0,
267            0,
268            0,
269            0,
270            0,
271            0,
272            0,
273            0,
274            0,
275            0,
276            0,
277            0,
278            0,
279            0,
280        ]
281    }
282    fn serialize_into(&self, bytes: &mut Vec<u8>) {
283        bytes.reserve(32);
284        let response_type_bytes = &[1];
285        bytes.push(response_type_bytes[0]);
286        bytes.extend_from_slice(&[0; 1]);
287        self.sequence.serialize_into(bytes);
288        self.length.serialize_into(bytes);
289        self.capable.serialize_into(bytes);
290        bytes.extend_from_slice(&[0; 23]);
291    }
292}
293
294/// Opcode for the GetTimeouts request
295pub const GET_TIMEOUTS_REQUEST: u8 = 2;
296#[derive(Clone, Copy, Default)]
297#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
298#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
299pub struct GetTimeoutsRequest;
300impl_debug_if_no_extra_traits!(GetTimeoutsRequest, "GetTimeoutsRequest");
301impl GetTimeoutsRequest {
302    /// Serialize this request into bytes for the provided connection
303    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
304        let length_so_far = 0;
305        let mut request0 = vec![
306            major_opcode,
307            GET_TIMEOUTS_REQUEST,
308            0,
309            0,
310        ];
311        let length_so_far = length_so_far + request0.len();
312        assert_eq!(length_so_far % 4, 0);
313        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
314        request0[2..4].copy_from_slice(&length.to_ne_bytes());
315        ([request0.into()], vec![])
316    }
317    /// Parse this request given its header, its body, and any fds that go along with it
318    #[cfg(feature = "request-parsing")]
319    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
320        if header.minor_opcode != GET_TIMEOUTS_REQUEST {
321            return Err(ParseError::InvalidValue);
322        }
323        let _ = value;
324        Ok(GetTimeoutsRequest
325        )
326    }
327}
328impl Request for GetTimeoutsRequest {
329    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
330
331    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
332        let (bufs, fds) = self.serialize(major_opcode);
333        // Flatten the buffers into a single vector
334        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
335        (buf, fds)
336    }
337}
338impl crate::x11_utils::ReplyRequest for GetTimeoutsRequest {
339    type Reply = GetTimeoutsReply;
340}
341
342#[derive(Clone, Copy, Default)]
343#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
344#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
345pub struct GetTimeoutsReply {
346    pub sequence: u16,
347    pub length: u32,
348    pub standby_timeout: u16,
349    pub suspend_timeout: u16,
350    pub off_timeout: u16,
351}
352impl_debug_if_no_extra_traits!(GetTimeoutsReply, "GetTimeoutsReply");
353impl TryParse for GetTimeoutsReply {
354    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
355        let remaining = initial_value;
356        let (response_type, remaining) = u8::try_parse(remaining)?;
357        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
358        let (sequence, remaining) = u16::try_parse(remaining)?;
359        let (length, remaining) = u32::try_parse(remaining)?;
360        let (standby_timeout, remaining) = u16::try_parse(remaining)?;
361        let (suspend_timeout, remaining) = u16::try_parse(remaining)?;
362        let (off_timeout, remaining) = u16::try_parse(remaining)?;
363        let remaining = remaining.get(18..).ok_or(ParseError::InsufficientData)?;
364        if response_type != 1 {
365            return Err(ParseError::InvalidValue);
366        }
367        let result = GetTimeoutsReply { sequence, length, standby_timeout, suspend_timeout, off_timeout };
368        let _ = remaining;
369        let remaining = initial_value.get(32 + length as usize * 4..)
370            .ok_or(ParseError::InsufficientData)?;
371        Ok((result, remaining))
372    }
373}
374impl Serialize for GetTimeoutsReply {
375    type Bytes = [u8; 32];
376    fn serialize(&self) -> [u8; 32] {
377        let response_type_bytes = &[1];
378        let sequence_bytes = self.sequence.serialize();
379        let length_bytes = self.length.serialize();
380        let standby_timeout_bytes = self.standby_timeout.serialize();
381        let suspend_timeout_bytes = self.suspend_timeout.serialize();
382        let off_timeout_bytes = self.off_timeout.serialize();
383        [
384            response_type_bytes[0],
385            0,
386            sequence_bytes[0],
387            sequence_bytes[1],
388            length_bytes[0],
389            length_bytes[1],
390            length_bytes[2],
391            length_bytes[3],
392            standby_timeout_bytes[0],
393            standby_timeout_bytes[1],
394            suspend_timeout_bytes[0],
395            suspend_timeout_bytes[1],
396            off_timeout_bytes[0],
397            off_timeout_bytes[1],
398            0,
399            0,
400            0,
401            0,
402            0,
403            0,
404            0,
405            0,
406            0,
407            0,
408            0,
409            0,
410            0,
411            0,
412            0,
413            0,
414            0,
415            0,
416        ]
417    }
418    fn serialize_into(&self, bytes: &mut Vec<u8>) {
419        bytes.reserve(32);
420        let response_type_bytes = &[1];
421        bytes.push(response_type_bytes[0]);
422        bytes.extend_from_slice(&[0; 1]);
423        self.sequence.serialize_into(bytes);
424        self.length.serialize_into(bytes);
425        self.standby_timeout.serialize_into(bytes);
426        self.suspend_timeout.serialize_into(bytes);
427        self.off_timeout.serialize_into(bytes);
428        bytes.extend_from_slice(&[0; 18]);
429    }
430}
431
432/// Opcode for the SetTimeouts request
433pub const SET_TIMEOUTS_REQUEST: u8 = 3;
434#[derive(Clone, Copy, Default)]
435#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
436#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
437pub struct SetTimeoutsRequest {
438    pub standby_timeout: u16,
439    pub suspend_timeout: u16,
440    pub off_timeout: u16,
441}
442impl_debug_if_no_extra_traits!(SetTimeoutsRequest, "SetTimeoutsRequest");
443impl SetTimeoutsRequest {
444    /// Serialize this request into bytes for the provided connection
445    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
446        let length_so_far = 0;
447        let standby_timeout_bytes = self.standby_timeout.serialize();
448        let suspend_timeout_bytes = self.suspend_timeout.serialize();
449        let off_timeout_bytes = self.off_timeout.serialize();
450        let mut request0 = vec![
451            major_opcode,
452            SET_TIMEOUTS_REQUEST,
453            0,
454            0,
455            standby_timeout_bytes[0],
456            standby_timeout_bytes[1],
457            suspend_timeout_bytes[0],
458            suspend_timeout_bytes[1],
459            off_timeout_bytes[0],
460            off_timeout_bytes[1],
461            0,
462            0,
463        ];
464        let length_so_far = length_so_far + request0.len();
465        assert_eq!(length_so_far % 4, 0);
466        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
467        request0[2..4].copy_from_slice(&length.to_ne_bytes());
468        ([request0.into()], vec![])
469    }
470    /// Parse this request given its header, its body, and any fds that go along with it
471    #[cfg(feature = "request-parsing")]
472    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
473        if header.minor_opcode != SET_TIMEOUTS_REQUEST {
474            return Err(ParseError::InvalidValue);
475        }
476        let (standby_timeout, remaining) = u16::try_parse(value)?;
477        let (suspend_timeout, remaining) = u16::try_parse(remaining)?;
478        let (off_timeout, remaining) = u16::try_parse(remaining)?;
479        let _ = remaining;
480        Ok(SetTimeoutsRequest {
481            standby_timeout,
482            suspend_timeout,
483            off_timeout,
484        })
485    }
486}
487impl Request for SetTimeoutsRequest {
488    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
489
490    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
491        let (bufs, fds) = self.serialize(major_opcode);
492        // Flatten the buffers into a single vector
493        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
494        (buf, fds)
495    }
496}
497impl crate::x11_utils::VoidRequest for SetTimeoutsRequest {
498}
499
500/// Opcode for the Enable request
501pub const ENABLE_REQUEST: u8 = 4;
502#[derive(Clone, Copy, Default)]
503#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
504#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
505pub struct EnableRequest;
506impl_debug_if_no_extra_traits!(EnableRequest, "EnableRequest");
507impl EnableRequest {
508    /// Serialize this request into bytes for the provided connection
509    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
510        let length_so_far = 0;
511        let mut request0 = vec![
512            major_opcode,
513            ENABLE_REQUEST,
514            0,
515            0,
516        ];
517        let length_so_far = length_so_far + request0.len();
518        assert_eq!(length_so_far % 4, 0);
519        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
520        request0[2..4].copy_from_slice(&length.to_ne_bytes());
521        ([request0.into()], vec![])
522    }
523    /// Parse this request given its header, its body, and any fds that go along with it
524    #[cfg(feature = "request-parsing")]
525    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
526        if header.minor_opcode != ENABLE_REQUEST {
527            return Err(ParseError::InvalidValue);
528        }
529        let _ = value;
530        Ok(EnableRequest
531        )
532    }
533}
534impl Request for EnableRequest {
535    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
536
537    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
538        let (bufs, fds) = self.serialize(major_opcode);
539        // Flatten the buffers into a single vector
540        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
541        (buf, fds)
542    }
543}
544impl crate::x11_utils::VoidRequest for EnableRequest {
545}
546
547/// Opcode for the Disable request
548pub const DISABLE_REQUEST: u8 = 5;
549#[derive(Clone, Copy, Default)]
550#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
551#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
552pub struct DisableRequest;
553impl_debug_if_no_extra_traits!(DisableRequest, "DisableRequest");
554impl DisableRequest {
555    /// Serialize this request into bytes for the provided connection
556    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
557        let length_so_far = 0;
558        let mut request0 = vec![
559            major_opcode,
560            DISABLE_REQUEST,
561            0,
562            0,
563        ];
564        let length_so_far = length_so_far + request0.len();
565        assert_eq!(length_so_far % 4, 0);
566        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
567        request0[2..4].copy_from_slice(&length.to_ne_bytes());
568        ([request0.into()], vec![])
569    }
570    /// Parse this request given its header, its body, and any fds that go along with it
571    #[cfg(feature = "request-parsing")]
572    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
573        if header.minor_opcode != DISABLE_REQUEST {
574            return Err(ParseError::InvalidValue);
575        }
576        let _ = value;
577        Ok(DisableRequest
578        )
579    }
580}
581impl Request for DisableRequest {
582    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
583
584    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
585        let (bufs, fds) = self.serialize(major_opcode);
586        // Flatten the buffers into a single vector
587        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
588        (buf, fds)
589    }
590}
591impl crate::x11_utils::VoidRequest for DisableRequest {
592}
593
594#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
595#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
596pub struct DPMSMode(u16);
597impl DPMSMode {
598    pub const ON: Self = Self(0);
599    pub const STANDBY: Self = Self(1);
600    pub const SUSPEND: Self = Self(2);
601    pub const OFF: Self = Self(3);
602}
603impl From<DPMSMode> for u16 {
604    #[inline]
605    fn from(input: DPMSMode) -> Self {
606        input.0
607    }
608}
609impl From<DPMSMode> for Option<u16> {
610    #[inline]
611    fn from(input: DPMSMode) -> Self {
612        Some(input.0)
613    }
614}
615impl From<DPMSMode> for u32 {
616    #[inline]
617    fn from(input: DPMSMode) -> Self {
618        u32::from(input.0)
619    }
620}
621impl From<DPMSMode> for Option<u32> {
622    #[inline]
623    fn from(input: DPMSMode) -> Self {
624        Some(u32::from(input.0))
625    }
626}
627impl From<u8> for DPMSMode {
628    #[inline]
629    fn from(value: u8) -> Self {
630        Self(value.into())
631    }
632}
633impl From<u16> for DPMSMode {
634    #[inline]
635    fn from(value: u16) -> Self {
636        Self(value)
637    }
638}
639impl core::fmt::Debug for DPMSMode  {
640    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
641        let variants = [
642            (Self::ON.0.into(), "ON", "On"),
643            (Self::STANDBY.0.into(), "STANDBY", "Standby"),
644            (Self::SUSPEND.0.into(), "SUSPEND", "Suspend"),
645            (Self::OFF.0.into(), "OFF", "Off"),
646        ];
647        pretty_print_enum(fmt, self.0.into(), &variants)
648    }
649}
650
651/// Opcode for the ForceLevel request
652pub const FORCE_LEVEL_REQUEST: u8 = 6;
653#[derive(Clone, Copy, Default)]
654#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
655#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
656pub struct ForceLevelRequest {
657    pub power_level: DPMSMode,
658}
659impl_debug_if_no_extra_traits!(ForceLevelRequest, "ForceLevelRequest");
660impl ForceLevelRequest {
661    /// Serialize this request into bytes for the provided connection
662    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
663        let length_so_far = 0;
664        let power_level_bytes = u16::from(self.power_level).serialize();
665        let mut request0 = vec![
666            major_opcode,
667            FORCE_LEVEL_REQUEST,
668            0,
669            0,
670            power_level_bytes[0],
671            power_level_bytes[1],
672            0,
673            0,
674        ];
675        let length_so_far = length_so_far + request0.len();
676        assert_eq!(length_so_far % 4, 0);
677        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
678        request0[2..4].copy_from_slice(&length.to_ne_bytes());
679        ([request0.into()], vec![])
680    }
681    /// Parse this request given its header, its body, and any fds that go along with it
682    #[cfg(feature = "request-parsing")]
683    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
684        if header.minor_opcode != FORCE_LEVEL_REQUEST {
685            return Err(ParseError::InvalidValue);
686        }
687        let (power_level, remaining) = u16::try_parse(value)?;
688        let power_level = power_level.into();
689        let _ = remaining;
690        Ok(ForceLevelRequest {
691            power_level,
692        })
693    }
694}
695impl Request for ForceLevelRequest {
696    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
697
698    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
699        let (bufs, fds) = self.serialize(major_opcode);
700        // Flatten the buffers into a single vector
701        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
702        (buf, fds)
703    }
704}
705impl crate::x11_utils::VoidRequest for ForceLevelRequest {
706}
707
708/// Opcode for the Info request
709pub const INFO_REQUEST: u8 = 7;
710#[derive(Clone, Copy, Default)]
711#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
712#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
713pub struct InfoRequest;
714impl_debug_if_no_extra_traits!(InfoRequest, "InfoRequest");
715impl InfoRequest {
716    /// Serialize this request into bytes for the provided connection
717    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
718        let length_so_far = 0;
719        let mut request0 = vec![
720            major_opcode,
721            INFO_REQUEST,
722            0,
723            0,
724        ];
725        let length_so_far = length_so_far + request0.len();
726        assert_eq!(length_so_far % 4, 0);
727        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
728        request0[2..4].copy_from_slice(&length.to_ne_bytes());
729        ([request0.into()], vec![])
730    }
731    /// Parse this request given its header, its body, and any fds that go along with it
732    #[cfg(feature = "request-parsing")]
733    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
734        if header.minor_opcode != INFO_REQUEST {
735            return Err(ParseError::InvalidValue);
736        }
737        let _ = value;
738        Ok(InfoRequest
739        )
740    }
741}
742impl Request for InfoRequest {
743    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
744
745    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
746        let (bufs, fds) = self.serialize(major_opcode);
747        // Flatten the buffers into a single vector
748        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
749        (buf, fds)
750    }
751}
752impl crate::x11_utils::ReplyRequest for InfoRequest {
753    type Reply = InfoReply;
754}
755
756#[derive(Clone, Copy, Default)]
757#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
758#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
759pub struct InfoReply {
760    pub sequence: u16,
761    pub length: u32,
762    pub power_level: DPMSMode,
763    pub state: bool,
764}
765impl_debug_if_no_extra_traits!(InfoReply, "InfoReply");
766impl TryParse for InfoReply {
767    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
768        let remaining = initial_value;
769        let (response_type, remaining) = u8::try_parse(remaining)?;
770        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
771        let (sequence, remaining) = u16::try_parse(remaining)?;
772        let (length, remaining) = u32::try_parse(remaining)?;
773        let (power_level, remaining) = u16::try_parse(remaining)?;
774        let (state, remaining) = bool::try_parse(remaining)?;
775        let remaining = remaining.get(21..).ok_or(ParseError::InsufficientData)?;
776        if response_type != 1 {
777            return Err(ParseError::InvalidValue);
778        }
779        let power_level = power_level.into();
780        let result = InfoReply { sequence, length, power_level, state };
781        let _ = remaining;
782        let remaining = initial_value.get(32 + length as usize * 4..)
783            .ok_or(ParseError::InsufficientData)?;
784        Ok((result, remaining))
785    }
786}
787impl Serialize for InfoReply {
788    type Bytes = [u8; 32];
789    fn serialize(&self) -> [u8; 32] {
790        let response_type_bytes = &[1];
791        let sequence_bytes = self.sequence.serialize();
792        let length_bytes = self.length.serialize();
793        let power_level_bytes = u16::from(self.power_level).serialize();
794        let state_bytes = self.state.serialize();
795        [
796            response_type_bytes[0],
797            0,
798            sequence_bytes[0],
799            sequence_bytes[1],
800            length_bytes[0],
801            length_bytes[1],
802            length_bytes[2],
803            length_bytes[3],
804            power_level_bytes[0],
805            power_level_bytes[1],
806            state_bytes[0],
807            0,
808            0,
809            0,
810            0,
811            0,
812            0,
813            0,
814            0,
815            0,
816            0,
817            0,
818            0,
819            0,
820            0,
821            0,
822            0,
823            0,
824            0,
825            0,
826            0,
827            0,
828        ]
829    }
830    fn serialize_into(&self, bytes: &mut Vec<u8>) {
831        bytes.reserve(32);
832        let response_type_bytes = &[1];
833        bytes.push(response_type_bytes[0]);
834        bytes.extend_from_slice(&[0; 1]);
835        self.sequence.serialize_into(bytes);
836        self.length.serialize_into(bytes);
837        u16::from(self.power_level).serialize_into(bytes);
838        self.state.serialize_into(bytes);
839        bytes.extend_from_slice(&[0; 21]);
840    }
841}
842
843#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
844#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
845pub struct EventMask(u32);
846impl EventMask {
847    pub const INFO_NOTIFY: Self = Self(1 << 0);
848}
849impl From<EventMask> for u32 {
850    #[inline]
851    fn from(input: EventMask) -> Self {
852        input.0
853    }
854}
855impl From<EventMask> for Option<u32> {
856    #[inline]
857    fn from(input: EventMask) -> Self {
858        Some(input.0)
859    }
860}
861impl From<u8> for EventMask {
862    #[inline]
863    fn from(value: u8) -> Self {
864        Self(value.into())
865    }
866}
867impl From<u16> for EventMask {
868    #[inline]
869    fn from(value: u16) -> Self {
870        Self(value.into())
871    }
872}
873impl From<u32> for EventMask {
874    #[inline]
875    fn from(value: u32) -> Self {
876        Self(value)
877    }
878}
879impl core::fmt::Debug for EventMask  {
880    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
881        let variants = [
882            (Self::INFO_NOTIFY.0, "INFO_NOTIFY", "InfoNotify"),
883        ];
884        pretty_print_bitmask(fmt, self.0, &variants)
885    }
886}
887bitmask_binop!(EventMask, u32);
888
889/// Opcode for the SelectInput request
890pub const SELECT_INPUT_REQUEST: u8 = 8;
891#[derive(Clone, Copy, Default)]
892#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
893#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
894pub struct SelectInputRequest {
895    pub event_mask: EventMask,
896}
897impl_debug_if_no_extra_traits!(SelectInputRequest, "SelectInputRequest");
898impl SelectInputRequest {
899    /// Serialize this request into bytes for the provided connection
900    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
901        let length_so_far = 0;
902        let event_mask_bytes = u32::from(self.event_mask).serialize();
903        let mut request0 = vec![
904            major_opcode,
905            SELECT_INPUT_REQUEST,
906            0,
907            0,
908            event_mask_bytes[0],
909            event_mask_bytes[1],
910            event_mask_bytes[2],
911            event_mask_bytes[3],
912        ];
913        let length_so_far = length_so_far + request0.len();
914        assert_eq!(length_so_far % 4, 0);
915        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
916        request0[2..4].copy_from_slice(&length.to_ne_bytes());
917        ([request0.into()], vec![])
918    }
919    /// Parse this request given its header, its body, and any fds that go along with it
920    #[cfg(feature = "request-parsing")]
921    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
922        if header.minor_opcode != SELECT_INPUT_REQUEST {
923            return Err(ParseError::InvalidValue);
924        }
925        let (event_mask, remaining) = u32::try_parse(value)?;
926        let event_mask = event_mask.into();
927        let _ = remaining;
928        Ok(SelectInputRequest {
929            event_mask,
930        })
931    }
932}
933impl Request for SelectInputRequest {
934    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
935
936    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
937        let (bufs, fds) = self.serialize(major_opcode);
938        // Flatten the buffers into a single vector
939        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
940        (buf, fds)
941    }
942}
943impl crate::x11_utils::VoidRequest for SelectInputRequest {
944}
945
946/// Opcode for the InfoNotify event
947pub const INFO_NOTIFY_EVENT: u16 = 0;
948#[derive(Clone, Copy, Default)]
949#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
950#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
951pub struct InfoNotifyEvent {
952    pub response_type: u8,
953    pub extension: u8,
954    pub sequence: u16,
955    pub length: u32,
956    pub event_type: u16,
957    pub timestamp: xproto::Timestamp,
958    pub power_level: DPMSMode,
959    pub state: bool,
960}
961impl_debug_if_no_extra_traits!(InfoNotifyEvent, "InfoNotifyEvent");
962impl TryParse for InfoNotifyEvent {
963    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
964        let remaining = initial_value;
965        let (response_type, remaining) = u8::try_parse(remaining)?;
966        let (extension, remaining) = u8::try_parse(remaining)?;
967        let (sequence, remaining) = u16::try_parse(remaining)?;
968        let (length, remaining) = u32::try_parse(remaining)?;
969        let (event_type, remaining) = u16::try_parse(remaining)?;
970        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
971        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
972        let (power_level, remaining) = u16::try_parse(remaining)?;
973        let (state, remaining) = bool::try_parse(remaining)?;
974        let remaining = remaining.get(21..).ok_or(ParseError::InsufficientData)?;
975        let power_level = power_level.into();
976        let result = InfoNotifyEvent { response_type, extension, sequence, length, event_type, timestamp, power_level, state };
977        let _ = remaining;
978        let remaining = initial_value.get(32 + length as usize * 4..)
979            .ok_or(ParseError::InsufficientData)?;
980        Ok((result, remaining))
981    }
982}
983impl Serialize for InfoNotifyEvent {
984    type Bytes = [u8; 40];
985    fn serialize(&self) -> [u8; 40] {
986        let response_type_bytes = self.response_type.serialize();
987        let extension_bytes = self.extension.serialize();
988        let sequence_bytes = self.sequence.serialize();
989        let length_bytes = self.length.serialize();
990        let event_type_bytes = self.event_type.serialize();
991        let timestamp_bytes = self.timestamp.serialize();
992        let power_level_bytes = u16::from(self.power_level).serialize();
993        let state_bytes = self.state.serialize();
994        [
995            response_type_bytes[0],
996            extension_bytes[0],
997            sequence_bytes[0],
998            sequence_bytes[1],
999            length_bytes[0],
1000            length_bytes[1],
1001            length_bytes[2],
1002            length_bytes[3],
1003            event_type_bytes[0],
1004            event_type_bytes[1],
1005            0,
1006            0,
1007            timestamp_bytes[0],
1008            timestamp_bytes[1],
1009            timestamp_bytes[2],
1010            timestamp_bytes[3],
1011            power_level_bytes[0],
1012            power_level_bytes[1],
1013            state_bytes[0],
1014            0,
1015            0,
1016            0,
1017            0,
1018            0,
1019            0,
1020            0,
1021            0,
1022            0,
1023            0,
1024            0,
1025            0,
1026            0,
1027            0,
1028            0,
1029            0,
1030            0,
1031            0,
1032            0,
1033            0,
1034            0,
1035        ]
1036    }
1037    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1038        bytes.reserve(40);
1039        self.response_type.serialize_into(bytes);
1040        self.extension.serialize_into(bytes);
1041        self.sequence.serialize_into(bytes);
1042        self.length.serialize_into(bytes);
1043        self.event_type.serialize_into(bytes);
1044        bytes.extend_from_slice(&[0; 2]);
1045        self.timestamp.serialize_into(bytes);
1046        u16::from(self.power_level).serialize_into(bytes);
1047        self.state.serialize_into(bytes);
1048        bytes.extend_from_slice(&[0; 21]);
1049    }
1050}
1051