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 
8 #[allow(unused_imports)]
9 use std::borrow::Cow;
10 use std::convert::TryFrom;
11 #[allow(unused_imports)]
12 use std::convert::TryInto;
13 use std::io::IoSlice;
14 #[allow(unused_imports)]
15 use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum};
16 #[allow(unused_imports)]
17 use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd, TryIntoUSize};
18 use crate::connection::{BufWithFds, PiecewiseBuf, RequestConnection};
19 #[allow(unused_imports)]
20 use crate::cookie::{Cookie, CookieWithFds, VoidCookie};
21 use crate::errors::{ConnectionError, ParseError};
22 
23 /// The X11 name of the extension for QueryExtension
24 pub const X11_EXTENSION_NAME: &str = "DPMS";
25 
26 /// The version number of this extension that this client library supports.
27 ///
28 /// This constant contains the version number of this extension that is supported
29 /// by this build of x11rb. For most things, it does not make sense to use this
30 /// information. If you need to send a `QueryVersion`, it is recommended to instead
31 /// send the maximum version of the extension that you need.
32 pub const X11_XML_VERSION: (u32, u32) = (0, 0);
33 
34 /// Opcode for the GetVersion request
35 pub const GET_VERSION_REQUEST: u8 = 0;
36 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
37 pub struct GetVersionRequest {
38     pub client_major_version: u16,
39     pub client_minor_version: u16,
40 }
41 impl GetVersionRequest {
42     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,43     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
44     where
45         Conn: RequestConnection + ?Sized,
46     {
47         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
48             .ok_or(ConnectionError::UnsupportedExtension)?;
49         let length_so_far = 0;
50         let client_major_version_bytes = self.client_major_version.serialize();
51         let client_minor_version_bytes = self.client_minor_version.serialize();
52         let mut request0 = vec![
53             extension_information.major_opcode,
54             GET_VERSION_REQUEST,
55             0,
56             0,
57             client_major_version_bytes[0],
58             client_major_version_bytes[1],
59             client_minor_version_bytes[0],
60             client_minor_version_bytes[1],
61         ];
62         let length_so_far = length_so_far + request0.len();
63         assert_eq!(length_so_far % 4, 0);
64         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
65         request0[2..4].copy_from_slice(&length.to_ne_bytes());
66         Ok((vec![request0.into()], vec![]))
67     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetVersionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,68     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetVersionReply>, ConnectionError>
69     where
70         Conn: RequestConnection + ?Sized,
71     {
72         let (bytes, fds) = self.serialize(conn)?;
73         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
74         conn.send_request_with_reply(&slices, fds)
75     }
76     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>77     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
78         if header.minor_opcode != GET_VERSION_REQUEST {
79             return Err(ParseError::InvalidValue);
80         }
81         let (client_major_version, remaining) = u16::try_parse(value)?;
82         let (client_minor_version, remaining) = u16::try_parse(remaining)?;
83         let _ = remaining;
84         Ok(GetVersionRequest {
85             client_major_version,
86             client_minor_version,
87         })
88     }
89 }
90 impl Request for GetVersionRequest {
91     type Reply = GetVersionReply;
92 }
get_version<Conn>(conn: &Conn, client_major_version: u16, client_minor_version: u16) -> Result<Cookie<'_, Conn, GetVersionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,93 pub fn get_version<Conn>(conn: &Conn, client_major_version: u16, client_minor_version: u16) -> Result<Cookie<'_, Conn, GetVersionReply>, ConnectionError>
94 where
95     Conn: RequestConnection + ?Sized,
96 {
97     let request0 = GetVersionRequest {
98         client_major_version,
99         client_minor_version,
100     };
101     request0.send(conn)
102 }
103 
104 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
105 pub struct GetVersionReply {
106     pub sequence: u16,
107     pub length: u32,
108     pub server_major_version: u16,
109     pub server_minor_version: u16,
110 }
111 impl TryParse for GetVersionReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>112     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
113         let remaining = initial_value;
114         let (response_type, remaining) = u8::try_parse(remaining)?;
115         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
116         let (sequence, remaining) = u16::try_parse(remaining)?;
117         let (length, remaining) = u32::try_parse(remaining)?;
118         let (server_major_version, remaining) = u16::try_parse(remaining)?;
119         let (server_minor_version, remaining) = u16::try_parse(remaining)?;
120         if response_type != 1 {
121             return Err(ParseError::InvalidValue);
122         }
123         let result = GetVersionReply { sequence, length, server_major_version, server_minor_version };
124         let _ = remaining;
125         let remaining = initial_value.get(32 + length as usize * 4..)
126             .ok_or(ParseError::InsufficientData)?;
127         Ok((result, remaining))
128     }
129 }
130 
131 /// Opcode for the Capable request
132 pub const CAPABLE_REQUEST: u8 = 1;
133 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
134 pub struct CapableRequest;
135 impl CapableRequest {
136     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,137     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
138     where
139         Conn: RequestConnection + ?Sized,
140     {
141         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
142             .ok_or(ConnectionError::UnsupportedExtension)?;
143         let length_so_far = 0;
144         let mut request0 = vec![
145             extension_information.major_opcode,
146             CAPABLE_REQUEST,
147             0,
148             0,
149         ];
150         let length_so_far = length_so_far + request0.len();
151         assert_eq!(length_so_far % 4, 0);
152         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
153         request0[2..4].copy_from_slice(&length.to_ne_bytes());
154         Ok((vec![request0.into()], vec![]))
155     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, CapableReply>, ConnectionError> where Conn: RequestConnection + ?Sized,156     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, CapableReply>, ConnectionError>
157     where
158         Conn: RequestConnection + ?Sized,
159     {
160         let (bytes, fds) = self.serialize(conn)?;
161         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
162         conn.send_request_with_reply(&slices, fds)
163     }
164     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>165     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
166         if header.minor_opcode != CAPABLE_REQUEST {
167             return Err(ParseError::InvalidValue);
168         }
169         let _ = value;
170         Ok(CapableRequest
171         )
172     }
173 }
174 impl Request for CapableRequest {
175     type Reply = CapableReply;
176 }
capable<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, CapableReply>, ConnectionError> where Conn: RequestConnection + ?Sized,177 pub fn capable<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, CapableReply>, ConnectionError>
178 where
179     Conn: RequestConnection + ?Sized,
180 {
181     let request0 = CapableRequest;
182     request0.send(conn)
183 }
184 
185 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
186 pub struct CapableReply {
187     pub sequence: u16,
188     pub length: u32,
189     pub capable: bool,
190 }
191 impl TryParse for CapableReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>192     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
193         let remaining = initial_value;
194         let (response_type, remaining) = u8::try_parse(remaining)?;
195         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
196         let (sequence, remaining) = u16::try_parse(remaining)?;
197         let (length, remaining) = u32::try_parse(remaining)?;
198         let (capable, remaining) = bool::try_parse(remaining)?;
199         let remaining = remaining.get(23..).ok_or(ParseError::InsufficientData)?;
200         if response_type != 1 {
201             return Err(ParseError::InvalidValue);
202         }
203         let result = CapableReply { sequence, length, capable };
204         let _ = remaining;
205         let remaining = initial_value.get(32 + length as usize * 4..)
206             .ok_or(ParseError::InsufficientData)?;
207         Ok((result, remaining))
208     }
209 }
210 
211 /// Opcode for the GetTimeouts request
212 pub const GET_TIMEOUTS_REQUEST: u8 = 2;
213 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
214 pub struct GetTimeoutsRequest;
215 impl GetTimeoutsRequest {
216     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,217     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
218     where
219         Conn: RequestConnection + ?Sized,
220     {
221         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
222             .ok_or(ConnectionError::UnsupportedExtension)?;
223         let length_so_far = 0;
224         let mut request0 = vec![
225             extension_information.major_opcode,
226             GET_TIMEOUTS_REQUEST,
227             0,
228             0,
229         ];
230         let length_so_far = length_so_far + request0.len();
231         assert_eq!(length_so_far % 4, 0);
232         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
233         request0[2..4].copy_from_slice(&length.to_ne_bytes());
234         Ok((vec![request0.into()], vec![]))
235     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetTimeoutsReply>, ConnectionError> where Conn: RequestConnection + ?Sized,236     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetTimeoutsReply>, ConnectionError>
237     where
238         Conn: RequestConnection + ?Sized,
239     {
240         let (bytes, fds) = self.serialize(conn)?;
241         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
242         conn.send_request_with_reply(&slices, fds)
243     }
244     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>245     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
246         if header.minor_opcode != GET_TIMEOUTS_REQUEST {
247             return Err(ParseError::InvalidValue);
248         }
249         let _ = value;
250         Ok(GetTimeoutsRequest
251         )
252     }
253 }
254 impl Request for GetTimeoutsRequest {
255     type Reply = GetTimeoutsReply;
256 }
get_timeouts<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, GetTimeoutsReply>, ConnectionError> where Conn: RequestConnection + ?Sized,257 pub fn get_timeouts<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, GetTimeoutsReply>, ConnectionError>
258 where
259     Conn: RequestConnection + ?Sized,
260 {
261     let request0 = GetTimeoutsRequest;
262     request0.send(conn)
263 }
264 
265 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
266 pub struct GetTimeoutsReply {
267     pub sequence: u16,
268     pub length: u32,
269     pub standby_timeout: u16,
270     pub suspend_timeout: u16,
271     pub off_timeout: u16,
272 }
273 impl TryParse for GetTimeoutsReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>274     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
275         let remaining = initial_value;
276         let (response_type, remaining) = u8::try_parse(remaining)?;
277         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
278         let (sequence, remaining) = u16::try_parse(remaining)?;
279         let (length, remaining) = u32::try_parse(remaining)?;
280         let (standby_timeout, remaining) = u16::try_parse(remaining)?;
281         let (suspend_timeout, remaining) = u16::try_parse(remaining)?;
282         let (off_timeout, remaining) = u16::try_parse(remaining)?;
283         let remaining = remaining.get(18..).ok_or(ParseError::InsufficientData)?;
284         if response_type != 1 {
285             return Err(ParseError::InvalidValue);
286         }
287         let result = GetTimeoutsReply { sequence, length, standby_timeout, suspend_timeout, off_timeout };
288         let _ = remaining;
289         let remaining = initial_value.get(32 + length as usize * 4..)
290             .ok_or(ParseError::InsufficientData)?;
291         Ok((result, remaining))
292     }
293 }
294 
295 /// Opcode for the SetTimeouts request
296 pub const SET_TIMEOUTS_REQUEST: u8 = 3;
297 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
298 pub struct SetTimeoutsRequest {
299     pub standby_timeout: u16,
300     pub suspend_timeout: u16,
301     pub off_timeout: u16,
302 }
303 impl SetTimeoutsRequest {
304     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,305     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
306     where
307         Conn: RequestConnection + ?Sized,
308     {
309         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
310             .ok_or(ConnectionError::UnsupportedExtension)?;
311         let length_so_far = 0;
312         let standby_timeout_bytes = self.standby_timeout.serialize();
313         let suspend_timeout_bytes = self.suspend_timeout.serialize();
314         let off_timeout_bytes = self.off_timeout.serialize();
315         let mut request0 = vec![
316             extension_information.major_opcode,
317             SET_TIMEOUTS_REQUEST,
318             0,
319             0,
320             standby_timeout_bytes[0],
321             standby_timeout_bytes[1],
322             suspend_timeout_bytes[0],
323             suspend_timeout_bytes[1],
324             off_timeout_bytes[0],
325             off_timeout_bytes[1],
326             0,
327             0,
328         ];
329         let length_so_far = length_so_far + request0.len();
330         assert_eq!(length_so_far % 4, 0);
331         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
332         request0[2..4].copy_from_slice(&length.to_ne_bytes());
333         Ok((vec![request0.into()], vec![]))
334     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,335     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
336     where
337         Conn: RequestConnection + ?Sized,
338     {
339         let (bytes, fds) = self.serialize(conn)?;
340         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
341         conn.send_request_without_reply(&slices, fds)
342     }
343     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>344     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
345         if header.minor_opcode != SET_TIMEOUTS_REQUEST {
346             return Err(ParseError::InvalidValue);
347         }
348         let (standby_timeout, remaining) = u16::try_parse(value)?;
349         let (suspend_timeout, remaining) = u16::try_parse(remaining)?;
350         let (off_timeout, remaining) = u16::try_parse(remaining)?;
351         let _ = remaining;
352         Ok(SetTimeoutsRequest {
353             standby_timeout,
354             suspend_timeout,
355             off_timeout,
356         })
357     }
358 }
359 impl Request for SetTimeoutsRequest {
360     type Reply = ();
361 }
set_timeouts<Conn>(conn: &Conn, standby_timeout: u16, suspend_timeout: u16, off_timeout: u16) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,362 pub fn set_timeouts<Conn>(conn: &Conn, standby_timeout: u16, suspend_timeout: u16, off_timeout: u16) -> Result<VoidCookie<'_, Conn>, ConnectionError>
363 where
364     Conn: RequestConnection + ?Sized,
365 {
366     let request0 = SetTimeoutsRequest {
367         standby_timeout,
368         suspend_timeout,
369         off_timeout,
370     };
371     request0.send(conn)
372 }
373 
374 /// Opcode for the Enable request
375 pub const ENABLE_REQUEST: u8 = 4;
376 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
377 pub struct EnableRequest;
378 impl EnableRequest {
379     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,380     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
381     where
382         Conn: RequestConnection + ?Sized,
383     {
384         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
385             .ok_or(ConnectionError::UnsupportedExtension)?;
386         let length_so_far = 0;
387         let mut request0 = vec![
388             extension_information.major_opcode,
389             ENABLE_REQUEST,
390             0,
391             0,
392         ];
393         let length_so_far = length_so_far + request0.len();
394         assert_eq!(length_so_far % 4, 0);
395         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
396         request0[2..4].copy_from_slice(&length.to_ne_bytes());
397         Ok((vec![request0.into()], vec![]))
398     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,399     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
400     where
401         Conn: RequestConnection + ?Sized,
402     {
403         let (bytes, fds) = self.serialize(conn)?;
404         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
405         conn.send_request_without_reply(&slices, fds)
406     }
407     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>408     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
409         if header.minor_opcode != ENABLE_REQUEST {
410             return Err(ParseError::InvalidValue);
411         }
412         let _ = value;
413         Ok(EnableRequest
414         )
415     }
416 }
417 impl Request for EnableRequest {
418     type Reply = ();
419 }
enable<Conn>(conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,420 pub fn enable<Conn>(conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
421 where
422     Conn: RequestConnection + ?Sized,
423 {
424     let request0 = EnableRequest;
425     request0.send(conn)
426 }
427 
428 /// Opcode for the Disable request
429 pub const DISABLE_REQUEST: u8 = 5;
430 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
431 pub struct DisableRequest;
432 impl DisableRequest {
433     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,434     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
435     where
436         Conn: RequestConnection + ?Sized,
437     {
438         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
439             .ok_or(ConnectionError::UnsupportedExtension)?;
440         let length_so_far = 0;
441         let mut request0 = vec![
442             extension_information.major_opcode,
443             DISABLE_REQUEST,
444             0,
445             0,
446         ];
447         let length_so_far = length_so_far + request0.len();
448         assert_eq!(length_so_far % 4, 0);
449         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
450         request0[2..4].copy_from_slice(&length.to_ne_bytes());
451         Ok((vec![request0.into()], vec![]))
452     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,453     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
454     where
455         Conn: RequestConnection + ?Sized,
456     {
457         let (bytes, fds) = self.serialize(conn)?;
458         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
459         conn.send_request_without_reply(&slices, fds)
460     }
461     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>462     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
463         if header.minor_opcode != DISABLE_REQUEST {
464             return Err(ParseError::InvalidValue);
465         }
466         let _ = value;
467         Ok(DisableRequest
468         )
469     }
470 }
471 impl Request for DisableRequest {
472     type Reply = ();
473 }
disable<Conn>(conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,474 pub fn disable<Conn>(conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
475 where
476     Conn: RequestConnection + ?Sized,
477 {
478     let request0 = DisableRequest;
479     request0.send(conn)
480 }
481 
482 #[derive(Clone, Copy, PartialEq, Eq)]
483 pub struct DPMSMode(u16);
484 impl DPMSMode {
485     pub const ON: Self = Self(0);
486     pub const STANDBY: Self = Self(1);
487     pub const SUSPEND: Self = Self(2);
488     pub const OFF: Self = Self(3);
489 }
490 impl From<DPMSMode> for u16 {
491     #[inline]
from(input: DPMSMode) -> Self492     fn from(input: DPMSMode) -> Self {
493         input.0
494     }
495 }
496 impl From<DPMSMode> for Option<u16> {
497     #[inline]
from(input: DPMSMode) -> Self498     fn from(input: DPMSMode) -> Self {
499         Some(input.0)
500     }
501 }
502 impl From<DPMSMode> for u32 {
503     #[inline]
from(input: DPMSMode) -> Self504     fn from(input: DPMSMode) -> Self {
505         u32::from(input.0)
506     }
507 }
508 impl From<DPMSMode> for Option<u32> {
509     #[inline]
from(input: DPMSMode) -> Self510     fn from(input: DPMSMode) -> Self {
511         Some(u32::from(input.0))
512     }
513 }
514 impl From<u8> for DPMSMode {
515     #[inline]
from(value: u8) -> Self516     fn from(value: u8) -> Self {
517         Self(value.into())
518     }
519 }
520 impl From<u16> for DPMSMode {
521     #[inline]
from(value: u16) -> Self522     fn from(value: u16) -> Self {
523         Self(value)
524     }
525 }
526 impl std::fmt::Debug for DPMSMode  {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result527     fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
528         let variants = [
529             (Self::ON.0.into(), "ON", "On"),
530             (Self::STANDBY.0.into(), "STANDBY", "Standby"),
531             (Self::SUSPEND.0.into(), "SUSPEND", "Suspend"),
532             (Self::OFF.0.into(), "OFF", "Off"),
533         ];
534         pretty_print_enum(fmt, self.0.into(), &variants)
535     }
536 }
537 
538 /// Opcode for the ForceLevel request
539 pub const FORCE_LEVEL_REQUEST: u8 = 6;
540 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
541 pub struct ForceLevelRequest {
542     pub power_level: DPMSMode,
543 }
544 impl ForceLevelRequest {
545     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,546     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
547     where
548         Conn: RequestConnection + ?Sized,
549     {
550         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
551             .ok_or(ConnectionError::UnsupportedExtension)?;
552         let length_so_far = 0;
553         let power_level_bytes = u16::from(self.power_level).serialize();
554         let mut request0 = vec![
555             extension_information.major_opcode,
556             FORCE_LEVEL_REQUEST,
557             0,
558             0,
559             power_level_bytes[0],
560             power_level_bytes[1],
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         Ok((vec![request0.into()], vec![]))
569     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,570     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
571     where
572         Conn: RequestConnection + ?Sized,
573     {
574         let (bytes, fds) = self.serialize(conn)?;
575         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
576         conn.send_request_without_reply(&slices, fds)
577     }
578     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>579     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
580         if header.minor_opcode != FORCE_LEVEL_REQUEST {
581             return Err(ParseError::InvalidValue);
582         }
583         let (power_level, remaining) = u16::try_parse(value)?;
584         let power_level = power_level.into();
585         let _ = remaining;
586         Ok(ForceLevelRequest {
587             power_level,
588         })
589     }
590 }
591 impl Request for ForceLevelRequest {
592     type Reply = ();
593 }
force_level<Conn>(conn: &Conn, power_level: DPMSMode) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,594 pub fn force_level<Conn>(conn: &Conn, power_level: DPMSMode) -> Result<VoidCookie<'_, Conn>, ConnectionError>
595 where
596     Conn: RequestConnection + ?Sized,
597 {
598     let request0 = ForceLevelRequest {
599         power_level,
600     };
601     request0.send(conn)
602 }
603 
604 /// Opcode for the Info request
605 pub const INFO_REQUEST: u8 = 7;
606 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
607 pub struct InfoRequest;
608 impl InfoRequest {
609     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,610     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
611     where
612         Conn: RequestConnection + ?Sized,
613     {
614         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
615             .ok_or(ConnectionError::UnsupportedExtension)?;
616         let length_so_far = 0;
617         let mut request0 = vec![
618             extension_information.major_opcode,
619             INFO_REQUEST,
620             0,
621             0,
622         ];
623         let length_so_far = length_so_far + request0.len();
624         assert_eq!(length_so_far % 4, 0);
625         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
626         request0[2..4].copy_from_slice(&length.to_ne_bytes());
627         Ok((vec![request0.into()], vec![]))
628     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, InfoReply>, ConnectionError> where Conn: RequestConnection + ?Sized,629     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, InfoReply>, ConnectionError>
630     where
631         Conn: RequestConnection + ?Sized,
632     {
633         let (bytes, fds) = self.serialize(conn)?;
634         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
635         conn.send_request_with_reply(&slices, fds)
636     }
637     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError>638     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
639         if header.minor_opcode != INFO_REQUEST {
640             return Err(ParseError::InvalidValue);
641         }
642         let _ = value;
643         Ok(InfoRequest
644         )
645     }
646 }
647 impl Request for InfoRequest {
648     type Reply = InfoReply;
649 }
info<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, InfoReply>, ConnectionError> where Conn: RequestConnection + ?Sized,650 pub fn info<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, InfoReply>, ConnectionError>
651 where
652     Conn: RequestConnection + ?Sized,
653 {
654     let request0 = InfoRequest;
655     request0.send(conn)
656 }
657 
658 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
659 pub struct InfoReply {
660     pub sequence: u16,
661     pub length: u32,
662     pub power_level: DPMSMode,
663     pub state: bool,
664 }
665 impl TryParse for InfoReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>666     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
667         let remaining = initial_value;
668         let (response_type, remaining) = u8::try_parse(remaining)?;
669         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
670         let (sequence, remaining) = u16::try_parse(remaining)?;
671         let (length, remaining) = u32::try_parse(remaining)?;
672         let (power_level, remaining) = u16::try_parse(remaining)?;
673         let (state, remaining) = bool::try_parse(remaining)?;
674         let remaining = remaining.get(21..).ok_or(ParseError::InsufficientData)?;
675         if response_type != 1 {
676             return Err(ParseError::InvalidValue);
677         }
678         let power_level = power_level.into();
679         let result = InfoReply { sequence, length, power_level, state };
680         let _ = remaining;
681         let remaining = initial_value.get(32 + length as usize * 4..)
682             .ok_or(ParseError::InsufficientData)?;
683         Ok((result, remaining))
684     }
685 }
686 
687 /// Extension trait defining the requests of this extension.
688 pub trait ConnectionExt: RequestConnection {
dpms_get_version(&self, client_major_version: u16, client_minor_version: u16) -> Result<Cookie<'_, Self, GetVersionReply>, ConnectionError>689     fn dpms_get_version(&self, client_major_version: u16, client_minor_version: u16) -> Result<Cookie<'_, Self, GetVersionReply>, ConnectionError>
690     {
691         get_version(self, client_major_version, client_minor_version)
692     }
dpms_capable(&self) -> Result<Cookie<'_, Self, CapableReply>, ConnectionError>693     fn dpms_capable(&self) -> Result<Cookie<'_, Self, CapableReply>, ConnectionError>
694     {
695         capable(self)
696     }
dpms_get_timeouts(&self) -> Result<Cookie<'_, Self, GetTimeoutsReply>, ConnectionError>697     fn dpms_get_timeouts(&self) -> Result<Cookie<'_, Self, GetTimeoutsReply>, ConnectionError>
698     {
699         get_timeouts(self)
700     }
dpms_set_timeouts(&self, standby_timeout: u16, suspend_timeout: u16, off_timeout: u16) -> Result<VoidCookie<'_, Self>, ConnectionError>701     fn dpms_set_timeouts(&self, standby_timeout: u16, suspend_timeout: u16, off_timeout: u16) -> Result<VoidCookie<'_, Self>, ConnectionError>
702     {
703         set_timeouts(self, standby_timeout, suspend_timeout, off_timeout)
704     }
dpms_enable(&self) -> Result<VoidCookie<'_, Self>, ConnectionError>705     fn dpms_enable(&self) -> Result<VoidCookie<'_, Self>, ConnectionError>
706     {
707         enable(self)
708     }
dpms_disable(&self) -> Result<VoidCookie<'_, Self>, ConnectionError>709     fn dpms_disable(&self) -> Result<VoidCookie<'_, Self>, ConnectionError>
710     {
711         disable(self)
712     }
dpms_force_level(&self, power_level: DPMSMode) -> Result<VoidCookie<'_, Self>, ConnectionError>713     fn dpms_force_level(&self, power_level: DPMSMode) -> Result<VoidCookie<'_, Self>, ConnectionError>
714     {
715         force_level(self, power_level)
716     }
dpms_info(&self) -> Result<Cookie<'_, Self, InfoReply>, ConnectionError>717     fn dpms_info(&self) -> Result<Cookie<'_, Self, InfoReply>, ConnectionError>
718     {
719         info(self)
720     }
721 }
722 
723 impl<C: RequestConnection + ?Sized> ConnectionExt for C {}
724