1 // This file contains generated code. Do not edit directly.
2 // To regenerate this, run 'make'.
3 
4 //! Bindings to the `XF86VidMode` 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 = "XFree86-VidModeExtension";
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) = (2, 2);
33 
34 pub type Syncrange = u32;
35 
36 pub type Dotclock = u32;
37 
38 #[derive(Clone, Copy, PartialEq, Eq)]
39 pub struct ModeFlag(u16);
40 impl ModeFlag {
41     pub const POSITIVE_H_SYNC: Self = Self(1 << 0);
42     pub const NEGATIVE_H_SYNC: Self = Self(1 << 1);
43     pub const POSITIVE_V_SYNC: Self = Self(1 << 2);
44     pub const NEGATIVE_V_SYNC: Self = Self(1 << 3);
45     pub const INTERLACE: Self = Self(1 << 4);
46     pub const COMPOSITE_SYNC: Self = Self(1 << 5);
47     pub const POSITIVE_C_SYNC: Self = Self(1 << 6);
48     pub const NEGATIVE_C_SYNC: Self = Self(1 << 7);
49     pub const H_SKEW: Self = Self(1 << 8);
50     pub const BROADCAST: Self = Self(1 << 9);
51     pub const PIXMUX: Self = Self(1 << 10);
52     pub const DOUBLE_CLOCK: Self = Self(1 << 11);
53     pub const HALF_CLOCK: Self = Self(1 << 12);
54 }
55 impl From<ModeFlag> for u16 {
56     #[inline]
from(input: ModeFlag) -> Self57     fn from(input: ModeFlag) -> Self {
58         input.0
59     }
60 }
61 impl From<ModeFlag> for Option<u16> {
62     #[inline]
from(input: ModeFlag) -> Self63     fn from(input: ModeFlag) -> Self {
64         Some(input.0)
65     }
66 }
67 impl From<ModeFlag> for u32 {
68     #[inline]
from(input: ModeFlag) -> Self69     fn from(input: ModeFlag) -> Self {
70         u32::from(input.0)
71     }
72 }
73 impl From<ModeFlag> for Option<u32> {
74     #[inline]
from(input: ModeFlag) -> Self75     fn from(input: ModeFlag) -> Self {
76         Some(u32::from(input.0))
77     }
78 }
79 impl From<u8> for ModeFlag {
80     #[inline]
from(value: u8) -> Self81     fn from(value: u8) -> Self {
82         Self(value.into())
83     }
84 }
85 impl From<u16> for ModeFlag {
86     #[inline]
from(value: u16) -> Self87     fn from(value: u16) -> Self {
88         Self(value)
89     }
90 }
91 impl std::fmt::Debug for ModeFlag  {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result92     fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
93         let variants = [
94             (Self::POSITIVE_H_SYNC.0.into(), "POSITIVE_H_SYNC", "PositiveHSync"),
95             (Self::NEGATIVE_H_SYNC.0.into(), "NEGATIVE_H_SYNC", "NegativeHSync"),
96             (Self::POSITIVE_V_SYNC.0.into(), "POSITIVE_V_SYNC", "PositiveVSync"),
97             (Self::NEGATIVE_V_SYNC.0.into(), "NEGATIVE_V_SYNC", "NegativeVSync"),
98             (Self::INTERLACE.0.into(), "INTERLACE", "Interlace"),
99             (Self::COMPOSITE_SYNC.0.into(), "COMPOSITE_SYNC", "CompositeSync"),
100             (Self::POSITIVE_C_SYNC.0.into(), "POSITIVE_C_SYNC", "PositiveCSync"),
101             (Self::NEGATIVE_C_SYNC.0.into(), "NEGATIVE_C_SYNC", "NegativeCSync"),
102             (Self::H_SKEW.0.into(), "H_SKEW", "HSkew"),
103             (Self::BROADCAST.0.into(), "BROADCAST", "Broadcast"),
104             (Self::PIXMUX.0.into(), "PIXMUX", "Pixmux"),
105             (Self::DOUBLE_CLOCK.0.into(), "DOUBLE_CLOCK", "DoubleClock"),
106             (Self::HALF_CLOCK.0.into(), "HALF_CLOCK", "HalfClock"),
107         ];
108         pretty_print_bitmask(fmt, self.0.into(), &variants)
109     }
110 }
111 bitmask_binop!(ModeFlag, u16);
112 
113 #[derive(Clone, Copy, PartialEq, Eq)]
114 pub struct ClockFlag(u8);
115 impl ClockFlag {
116     pub const PROGRAMABLE: Self = Self(1 << 0);
117 }
118 impl From<ClockFlag> for u8 {
119     #[inline]
from(input: ClockFlag) -> Self120     fn from(input: ClockFlag) -> Self {
121         input.0
122     }
123 }
124 impl From<ClockFlag> for Option<u8> {
125     #[inline]
from(input: ClockFlag) -> Self126     fn from(input: ClockFlag) -> Self {
127         Some(input.0)
128     }
129 }
130 impl From<ClockFlag> for u16 {
131     #[inline]
from(input: ClockFlag) -> Self132     fn from(input: ClockFlag) -> Self {
133         u16::from(input.0)
134     }
135 }
136 impl From<ClockFlag> for Option<u16> {
137     #[inline]
from(input: ClockFlag) -> Self138     fn from(input: ClockFlag) -> Self {
139         Some(u16::from(input.0))
140     }
141 }
142 impl From<ClockFlag> for u32 {
143     #[inline]
from(input: ClockFlag) -> Self144     fn from(input: ClockFlag) -> Self {
145         u32::from(input.0)
146     }
147 }
148 impl From<ClockFlag> for Option<u32> {
149     #[inline]
from(input: ClockFlag) -> Self150     fn from(input: ClockFlag) -> Self {
151         Some(u32::from(input.0))
152     }
153 }
154 impl From<u8> for ClockFlag {
155     #[inline]
from(value: u8) -> Self156     fn from(value: u8) -> Self {
157         Self(value)
158     }
159 }
160 impl std::fmt::Debug for ClockFlag  {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result161     fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
162         let variants = [
163             (Self::PROGRAMABLE.0.into(), "PROGRAMABLE", "Programable"),
164         ];
165         pretty_print_bitmask(fmt, self.0.into(), &variants)
166     }
167 }
168 bitmask_binop!(ClockFlag, u8);
169 
170 #[derive(Clone, Copy, PartialEq, Eq)]
171 pub struct Permission(u8);
172 impl Permission {
173     pub const READ: Self = Self(1 << 0);
174     pub const WRITE: Self = Self(1 << 1);
175 }
176 impl From<Permission> for u8 {
177     #[inline]
from(input: Permission) -> Self178     fn from(input: Permission) -> Self {
179         input.0
180     }
181 }
182 impl From<Permission> for Option<u8> {
183     #[inline]
from(input: Permission) -> Self184     fn from(input: Permission) -> Self {
185         Some(input.0)
186     }
187 }
188 impl From<Permission> for u16 {
189     #[inline]
from(input: Permission) -> Self190     fn from(input: Permission) -> Self {
191         u16::from(input.0)
192     }
193 }
194 impl From<Permission> for Option<u16> {
195     #[inline]
from(input: Permission) -> Self196     fn from(input: Permission) -> Self {
197         Some(u16::from(input.0))
198     }
199 }
200 impl From<Permission> for u32 {
201     #[inline]
from(input: Permission) -> Self202     fn from(input: Permission) -> Self {
203         u32::from(input.0)
204     }
205 }
206 impl From<Permission> for Option<u32> {
207     #[inline]
from(input: Permission) -> Self208     fn from(input: Permission) -> Self {
209         Some(u32::from(input.0))
210     }
211 }
212 impl From<u8> for Permission {
213     #[inline]
from(value: u8) -> Self214     fn from(value: u8) -> Self {
215         Self(value)
216     }
217 }
218 impl std::fmt::Debug for Permission  {
fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result219     fn fmt(&self, fmt: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
220         let variants = [
221             (Self::READ.0.into(), "READ", "Read"),
222             (Self::WRITE.0.into(), "WRITE", "Write"),
223         ];
224         pretty_print_bitmask(fmt, self.0.into(), &variants)
225     }
226 }
227 bitmask_binop!(Permission, u8);
228 
229 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
230 pub struct ModeInfo {
231     pub dotclock: Dotclock,
232     pub hdisplay: u16,
233     pub hsyncstart: u16,
234     pub hsyncend: u16,
235     pub htotal: u16,
236     pub hskew: u32,
237     pub vdisplay: u16,
238     pub vsyncstart: u16,
239     pub vsyncend: u16,
240     pub vtotal: u16,
241     pub flags: u32,
242     pub privsize: u32,
243 }
244 impl TryParse for ModeInfo {
try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError>245     fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
246         let (dotclock, remaining) = Dotclock::try_parse(remaining)?;
247         let (hdisplay, remaining) = u16::try_parse(remaining)?;
248         let (hsyncstart, remaining) = u16::try_parse(remaining)?;
249         let (hsyncend, remaining) = u16::try_parse(remaining)?;
250         let (htotal, remaining) = u16::try_parse(remaining)?;
251         let (hskew, remaining) = u32::try_parse(remaining)?;
252         let (vdisplay, remaining) = u16::try_parse(remaining)?;
253         let (vsyncstart, remaining) = u16::try_parse(remaining)?;
254         let (vsyncend, remaining) = u16::try_parse(remaining)?;
255         let (vtotal, remaining) = u16::try_parse(remaining)?;
256         let remaining = remaining.get(4..).ok_or(ParseError::InsufficientData)?;
257         let (flags, remaining) = u32::try_parse(remaining)?;
258         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
259         let (privsize, remaining) = u32::try_parse(remaining)?;
260         let result = ModeInfo { dotclock, hdisplay, hsyncstart, hsyncend, htotal, hskew, vdisplay, vsyncstart, vsyncend, vtotal, flags, privsize };
261         Ok((result, remaining))
262     }
263 }
264 impl Serialize for ModeInfo {
265     type Bytes = [u8; 48];
serialize(&self) -> [u8; 48]266     fn serialize(&self) -> [u8; 48] {
267         let dotclock_bytes = self.dotclock.serialize();
268         let hdisplay_bytes = self.hdisplay.serialize();
269         let hsyncstart_bytes = self.hsyncstart.serialize();
270         let hsyncend_bytes = self.hsyncend.serialize();
271         let htotal_bytes = self.htotal.serialize();
272         let hskew_bytes = self.hskew.serialize();
273         let vdisplay_bytes = self.vdisplay.serialize();
274         let vsyncstart_bytes = self.vsyncstart.serialize();
275         let vsyncend_bytes = self.vsyncend.serialize();
276         let vtotal_bytes = self.vtotal.serialize();
277         let flags_bytes = self.flags.serialize();
278         let privsize_bytes = self.privsize.serialize();
279         [
280             dotclock_bytes[0],
281             dotclock_bytes[1],
282             dotclock_bytes[2],
283             dotclock_bytes[3],
284             hdisplay_bytes[0],
285             hdisplay_bytes[1],
286             hsyncstart_bytes[0],
287             hsyncstart_bytes[1],
288             hsyncend_bytes[0],
289             hsyncend_bytes[1],
290             htotal_bytes[0],
291             htotal_bytes[1],
292             hskew_bytes[0],
293             hskew_bytes[1],
294             hskew_bytes[2],
295             hskew_bytes[3],
296             vdisplay_bytes[0],
297             vdisplay_bytes[1],
298             vsyncstart_bytes[0],
299             vsyncstart_bytes[1],
300             vsyncend_bytes[0],
301             vsyncend_bytes[1],
302             vtotal_bytes[0],
303             vtotal_bytes[1],
304             0,
305             0,
306             0,
307             0,
308             flags_bytes[0],
309             flags_bytes[1],
310             flags_bytes[2],
311             flags_bytes[3],
312             0,
313             0,
314             0,
315             0,
316             0,
317             0,
318             0,
319             0,
320             0,
321             0,
322             0,
323             0,
324             privsize_bytes[0],
325             privsize_bytes[1],
326             privsize_bytes[2],
327             privsize_bytes[3],
328         ]
329     }
serialize_into(&self, bytes: &mut Vec<u8>)330     fn serialize_into(&self, bytes: &mut Vec<u8>) {
331         bytes.reserve(48);
332         self.dotclock.serialize_into(bytes);
333         self.hdisplay.serialize_into(bytes);
334         self.hsyncstart.serialize_into(bytes);
335         self.hsyncend.serialize_into(bytes);
336         self.htotal.serialize_into(bytes);
337         self.hskew.serialize_into(bytes);
338         self.vdisplay.serialize_into(bytes);
339         self.vsyncstart.serialize_into(bytes);
340         self.vsyncend.serialize_into(bytes);
341         self.vtotal.serialize_into(bytes);
342         bytes.extend_from_slice(&[0; 4]);
343         self.flags.serialize_into(bytes);
344         bytes.extend_from_slice(&[0; 12]);
345         self.privsize.serialize_into(bytes);
346     }
347 }
348 
349 /// Opcode for the QueryVersion request
350 pub const QUERY_VERSION_REQUEST: u8 = 0;
351 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
352 pub struct QueryVersionRequest;
353 impl QueryVersionRequest {
354     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,355     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
356     where
357         Conn: RequestConnection + ?Sized,
358     {
359         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
360             .ok_or(ConnectionError::UnsupportedExtension)?;
361         let length_so_far = 0;
362         let mut request0 = vec![
363             extension_information.major_opcode,
364             QUERY_VERSION_REQUEST,
365             0,
366             0,
367         ];
368         let length_so_far = length_so_far + request0.len();
369         assert_eq!(length_so_far % 4, 0);
370         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
371         request0[2..4].copy_from_slice(&length.to_ne_bytes());
372         Ok((vec![request0.into()], vec![]))
373     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,374     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
375     where
376         Conn: RequestConnection + ?Sized,
377     {
378         let (bytes, fds) = self.serialize(conn)?;
379         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
380         conn.send_request_with_reply(&slices, fds)
381     }
382     /// 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>383     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
384         if header.minor_opcode != QUERY_VERSION_REQUEST {
385             return Err(ParseError::InvalidValue);
386         }
387         let _ = value;
388         Ok(QueryVersionRequest
389         )
390     }
391 }
392 impl Request for QueryVersionRequest {
393     type Reply = QueryVersionReply;
394 }
query_version<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError> where Conn: RequestConnection + ?Sized,395 pub fn query_version<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
396 where
397     Conn: RequestConnection + ?Sized,
398 {
399     let request0 = QueryVersionRequest;
400     request0.send(conn)
401 }
402 
403 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
404 pub struct QueryVersionReply {
405     pub sequence: u16,
406     pub length: u32,
407     pub major_version: u16,
408     pub minor_version: u16,
409 }
410 impl TryParse for QueryVersionReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>411     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
412         let remaining = initial_value;
413         let (response_type, remaining) = u8::try_parse(remaining)?;
414         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
415         let (sequence, remaining) = u16::try_parse(remaining)?;
416         let (length, remaining) = u32::try_parse(remaining)?;
417         let (major_version, remaining) = u16::try_parse(remaining)?;
418         let (minor_version, remaining) = u16::try_parse(remaining)?;
419         if response_type != 1 {
420             return Err(ParseError::InvalidValue);
421         }
422         let result = QueryVersionReply { sequence, length, major_version, minor_version };
423         let _ = remaining;
424         let remaining = initial_value.get(32 + length as usize * 4..)
425             .ok_or(ParseError::InsufficientData)?;
426         Ok((result, remaining))
427     }
428 }
429 
430 /// Opcode for the GetModeLine request
431 pub const GET_MODE_LINE_REQUEST: u8 = 1;
432 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
433 pub struct GetModeLineRequest {
434     pub screen: u16,
435 }
436 impl GetModeLineRequest {
437     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,438     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
439     where
440         Conn: RequestConnection + ?Sized,
441     {
442         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
443             .ok_or(ConnectionError::UnsupportedExtension)?;
444         let length_so_far = 0;
445         let screen_bytes = self.screen.serialize();
446         let mut request0 = vec![
447             extension_information.major_opcode,
448             GET_MODE_LINE_REQUEST,
449             0,
450             0,
451             screen_bytes[0],
452             screen_bytes[1],
453             0,
454             0,
455         ];
456         let length_so_far = length_so_far + request0.len();
457         assert_eq!(length_so_far % 4, 0);
458         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
459         request0[2..4].copy_from_slice(&length.to_ne_bytes());
460         Ok((vec![request0.into()], vec![]))
461     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetModeLineReply>, ConnectionError> where Conn: RequestConnection + ?Sized,462     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetModeLineReply>, ConnectionError>
463     where
464         Conn: RequestConnection + ?Sized,
465     {
466         let (bytes, fds) = self.serialize(conn)?;
467         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
468         conn.send_request_with_reply(&slices, fds)
469     }
470     /// 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>471     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
472         if header.minor_opcode != GET_MODE_LINE_REQUEST {
473             return Err(ParseError::InvalidValue);
474         }
475         let (screen, remaining) = u16::try_parse(value)?;
476         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
477         let _ = remaining;
478         Ok(GetModeLineRequest {
479             screen,
480         })
481     }
482 }
483 impl Request for GetModeLineRequest {
484     type Reply = GetModeLineReply;
485 }
get_mode_line<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetModeLineReply>, ConnectionError> where Conn: RequestConnection + ?Sized,486 pub fn get_mode_line<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetModeLineReply>, ConnectionError>
487 where
488     Conn: RequestConnection + ?Sized,
489 {
490     let request0 = GetModeLineRequest {
491         screen,
492     };
493     request0.send(conn)
494 }
495 
496 #[derive(Debug, Clone, PartialEq, Eq)]
497 pub struct GetModeLineReply {
498     pub sequence: u16,
499     pub length: u32,
500     pub dotclock: Dotclock,
501     pub hdisplay: u16,
502     pub hsyncstart: u16,
503     pub hsyncend: u16,
504     pub htotal: u16,
505     pub hskew: u16,
506     pub vdisplay: u16,
507     pub vsyncstart: u16,
508     pub vsyncend: u16,
509     pub vtotal: u16,
510     pub flags: u32,
511     pub private: Vec<u8>,
512 }
513 impl TryParse for GetModeLineReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>514     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
515         let remaining = initial_value;
516         let (response_type, remaining) = u8::try_parse(remaining)?;
517         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
518         let (sequence, remaining) = u16::try_parse(remaining)?;
519         let (length, remaining) = u32::try_parse(remaining)?;
520         let (dotclock, remaining) = Dotclock::try_parse(remaining)?;
521         let (hdisplay, remaining) = u16::try_parse(remaining)?;
522         let (hsyncstart, remaining) = u16::try_parse(remaining)?;
523         let (hsyncend, remaining) = u16::try_parse(remaining)?;
524         let (htotal, remaining) = u16::try_parse(remaining)?;
525         let (hskew, remaining) = u16::try_parse(remaining)?;
526         let (vdisplay, remaining) = u16::try_parse(remaining)?;
527         let (vsyncstart, remaining) = u16::try_parse(remaining)?;
528         let (vsyncend, remaining) = u16::try_parse(remaining)?;
529         let (vtotal, remaining) = u16::try_parse(remaining)?;
530         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
531         let (flags, remaining) = u32::try_parse(remaining)?;
532         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
533         let (privsize, remaining) = u32::try_parse(remaining)?;
534         let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?;
535         let private = private.to_vec();
536         if response_type != 1 {
537             return Err(ParseError::InvalidValue);
538         }
539         let result = GetModeLineReply { sequence, length, dotclock, hdisplay, hsyncstart, hsyncend, htotal, hskew, vdisplay, vsyncstart, vsyncend, vtotal, flags, private };
540         let _ = remaining;
541         let remaining = initial_value.get(32 + length as usize * 4..)
542             .ok_or(ParseError::InsufficientData)?;
543         Ok((result, remaining))
544     }
545 }
546 impl GetModeLineReply {
547     /// Get the value of the `privsize` field.
548     ///
549     /// The `privsize` field is used as the length field of the `private` field.
550     /// This function computes the field's value again based on the length of the list.
551     ///
552     /// # Panics
553     ///
554     /// Panics if the value cannot be represented in the target type. This
555     /// cannot happen with values of the struct received from the X11 server.
privsize(&self) -> u32556     pub fn privsize(&self) -> u32 {
557         self.private.len()
558             .try_into().unwrap()
559     }
560 }
561 
562 /// Opcode for the ModModeLine request
563 pub const MOD_MODE_LINE_REQUEST: u8 = 2;
564 #[derive(Debug, Clone, PartialEq, Eq)]
565 pub struct ModModeLineRequest<'input> {
566     pub screen: u32,
567     pub hdisplay: u16,
568     pub hsyncstart: u16,
569     pub hsyncend: u16,
570     pub htotal: u16,
571     pub hskew: u16,
572     pub vdisplay: u16,
573     pub vsyncstart: u16,
574     pub vsyncend: u16,
575     pub vtotal: u16,
576     pub flags: u32,
577     pub private: Cow<'input, [u8]>,
578 }
579 impl<'input> ModModeLineRequest<'input> {
580     /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,581     fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
582     where
583         Conn: RequestConnection + ?Sized,
584     {
585         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
586             .ok_or(ConnectionError::UnsupportedExtension)?;
587         let length_so_far = 0;
588         let screen_bytes = self.screen.serialize();
589         let hdisplay_bytes = self.hdisplay.serialize();
590         let hsyncstart_bytes = self.hsyncstart.serialize();
591         let hsyncend_bytes = self.hsyncend.serialize();
592         let htotal_bytes = self.htotal.serialize();
593         let hskew_bytes = self.hskew.serialize();
594         let vdisplay_bytes = self.vdisplay.serialize();
595         let vsyncstart_bytes = self.vsyncstart.serialize();
596         let vsyncend_bytes = self.vsyncend.serialize();
597         let vtotal_bytes = self.vtotal.serialize();
598         let flags_bytes = self.flags.serialize();
599         let privsize = u32::try_from(self.private.len()).expect("`private` has too many elements");
600         let privsize_bytes = privsize.serialize();
601         let mut request0 = vec![
602             extension_information.major_opcode,
603             MOD_MODE_LINE_REQUEST,
604             0,
605             0,
606             screen_bytes[0],
607             screen_bytes[1],
608             screen_bytes[2],
609             screen_bytes[3],
610             hdisplay_bytes[0],
611             hdisplay_bytes[1],
612             hsyncstart_bytes[0],
613             hsyncstart_bytes[1],
614             hsyncend_bytes[0],
615             hsyncend_bytes[1],
616             htotal_bytes[0],
617             htotal_bytes[1],
618             hskew_bytes[0],
619             hskew_bytes[1],
620             vdisplay_bytes[0],
621             vdisplay_bytes[1],
622             vsyncstart_bytes[0],
623             vsyncstart_bytes[1],
624             vsyncend_bytes[0],
625             vsyncend_bytes[1],
626             vtotal_bytes[0],
627             vtotal_bytes[1],
628             0,
629             0,
630             flags_bytes[0],
631             flags_bytes[1],
632             flags_bytes[2],
633             flags_bytes[3],
634             0,
635             0,
636             0,
637             0,
638             0,
639             0,
640             0,
641             0,
642             0,
643             0,
644             0,
645             0,
646             privsize_bytes[0],
647             privsize_bytes[1],
648             privsize_bytes[2],
649             privsize_bytes[3],
650         ];
651         let length_so_far = length_so_far + request0.len();
652         let length_so_far = length_so_far + self.private.len();
653         let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
654         let length_so_far = length_so_far + padding0.len();
655         assert_eq!(length_so_far % 4, 0);
656         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
657         request0[2..4].copy_from_slice(&length.to_ne_bytes());
658         Ok((vec![request0.into(), self.private, padding0.into()], vec![]))
659     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,660     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
661     where
662         Conn: RequestConnection + ?Sized,
663     {
664         let (bytes, fds) = self.serialize(conn)?;
665         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
666         conn.send_request_without_reply(&slices, fds)
667     }
668     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError>669     pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
670         if header.minor_opcode != MOD_MODE_LINE_REQUEST {
671             return Err(ParseError::InvalidValue);
672         }
673         let (screen, remaining) = u32::try_parse(value)?;
674         let (hdisplay, remaining) = u16::try_parse(remaining)?;
675         let (hsyncstart, remaining) = u16::try_parse(remaining)?;
676         let (hsyncend, remaining) = u16::try_parse(remaining)?;
677         let (htotal, remaining) = u16::try_parse(remaining)?;
678         let (hskew, remaining) = u16::try_parse(remaining)?;
679         let (vdisplay, remaining) = u16::try_parse(remaining)?;
680         let (vsyncstart, remaining) = u16::try_parse(remaining)?;
681         let (vsyncend, remaining) = u16::try_parse(remaining)?;
682         let (vtotal, remaining) = u16::try_parse(remaining)?;
683         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
684         let (flags, remaining) = u32::try_parse(remaining)?;
685         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
686         let (privsize, remaining) = u32::try_parse(remaining)?;
687         let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?;
688         let _ = remaining;
689         Ok(ModModeLineRequest {
690             screen,
691             hdisplay,
692             hsyncstart,
693             hsyncend,
694             htotal,
695             hskew,
696             vdisplay,
697             vsyncstart,
698             vsyncend,
699             vtotal,
700             flags,
701             private: Cow::Borrowed(private),
702         })
703     }
704     /// Clone all borrowed data in this ModModeLineRequest.
into_owned(self) -> ModModeLineRequest<'static>705     pub fn into_owned(self) -> ModModeLineRequest<'static> {
706         ModModeLineRequest {
707             screen: self.screen,
708             hdisplay: self.hdisplay,
709             hsyncstart: self.hsyncstart,
710             hsyncend: self.hsyncend,
711             htotal: self.htotal,
712             hskew: self.hskew,
713             vdisplay: self.vdisplay,
714             vsyncstart: self.vsyncstart,
715             vsyncend: self.vsyncend,
716             vtotal: self.vtotal,
717             flags: self.flags,
718             private: Cow::Owned(self.private.into_owned()),
719         }
720     }
721 }
722 impl<'input> Request for ModModeLineRequest<'input> {
723     type Reply = ();
724 }
mod_mode_line<'c, 'input, Conn, A>(conn: &'c Conn, screen: u32, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u32>,725 pub fn mod_mode_line<'c, 'input, Conn, A>(conn: &'c Conn, screen: u32, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
726 where
727     Conn: RequestConnection + ?Sized,
728     A: Into<u32>,
729 {
730     let flags: u32 = flags.into();
731     let request0 = ModModeLineRequest {
732         screen,
733         hdisplay,
734         hsyncstart,
735         hsyncend,
736         htotal,
737         hskew,
738         vdisplay,
739         vsyncstart,
740         vsyncend,
741         vtotal,
742         flags,
743         private: Cow::Borrowed(private),
744     };
745     request0.send(conn)
746 }
747 
748 /// Opcode for the SwitchMode request
749 pub const SWITCH_MODE_REQUEST: u8 = 3;
750 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
751 pub struct SwitchModeRequest {
752     pub screen: u16,
753     pub zoom: u16,
754 }
755 impl SwitchModeRequest {
756     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,757     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
758     where
759         Conn: RequestConnection + ?Sized,
760     {
761         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
762             .ok_or(ConnectionError::UnsupportedExtension)?;
763         let length_so_far = 0;
764         let screen_bytes = self.screen.serialize();
765         let zoom_bytes = self.zoom.serialize();
766         let mut request0 = vec![
767             extension_information.major_opcode,
768             SWITCH_MODE_REQUEST,
769             0,
770             0,
771             screen_bytes[0],
772             screen_bytes[1],
773             zoom_bytes[0],
774             zoom_bytes[1],
775         ];
776         let length_so_far = length_so_far + request0.len();
777         assert_eq!(length_so_far % 4, 0);
778         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
779         request0[2..4].copy_from_slice(&length.to_ne_bytes());
780         Ok((vec![request0.into()], vec![]))
781     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,782     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
783     where
784         Conn: RequestConnection + ?Sized,
785     {
786         let (bytes, fds) = self.serialize(conn)?;
787         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
788         conn.send_request_without_reply(&slices, fds)
789     }
790     /// 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>791     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
792         if header.minor_opcode != SWITCH_MODE_REQUEST {
793             return Err(ParseError::InvalidValue);
794         }
795         let (screen, remaining) = u16::try_parse(value)?;
796         let (zoom, remaining) = u16::try_parse(remaining)?;
797         let _ = remaining;
798         Ok(SwitchModeRequest {
799             screen,
800             zoom,
801         })
802     }
803 }
804 impl Request for SwitchModeRequest {
805     type Reply = ();
806 }
switch_mode<Conn>(conn: &Conn, screen: u16, zoom: u16) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,807 pub fn switch_mode<Conn>(conn: &Conn, screen: u16, zoom: u16) -> Result<VoidCookie<'_, Conn>, ConnectionError>
808 where
809     Conn: RequestConnection + ?Sized,
810 {
811     let request0 = SwitchModeRequest {
812         screen,
813         zoom,
814     };
815     request0.send(conn)
816 }
817 
818 /// Opcode for the GetMonitor request
819 pub const GET_MONITOR_REQUEST: u8 = 4;
820 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
821 pub struct GetMonitorRequest {
822     pub screen: u16,
823 }
824 impl GetMonitorRequest {
825     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,826     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
827     where
828         Conn: RequestConnection + ?Sized,
829     {
830         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
831             .ok_or(ConnectionError::UnsupportedExtension)?;
832         let length_so_far = 0;
833         let screen_bytes = self.screen.serialize();
834         let mut request0 = vec![
835             extension_information.major_opcode,
836             GET_MONITOR_REQUEST,
837             0,
838             0,
839             screen_bytes[0],
840             screen_bytes[1],
841             0,
842             0,
843         ];
844         let length_so_far = length_so_far + request0.len();
845         assert_eq!(length_so_far % 4, 0);
846         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
847         request0[2..4].copy_from_slice(&length.to_ne_bytes());
848         Ok((vec![request0.into()], vec![]))
849     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetMonitorReply>, ConnectionError> where Conn: RequestConnection + ?Sized,850     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetMonitorReply>, ConnectionError>
851     where
852         Conn: RequestConnection + ?Sized,
853     {
854         let (bytes, fds) = self.serialize(conn)?;
855         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
856         conn.send_request_with_reply(&slices, fds)
857     }
858     /// 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>859     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
860         if header.minor_opcode != GET_MONITOR_REQUEST {
861             return Err(ParseError::InvalidValue);
862         }
863         let (screen, remaining) = u16::try_parse(value)?;
864         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
865         let _ = remaining;
866         Ok(GetMonitorRequest {
867             screen,
868         })
869     }
870 }
871 impl Request for GetMonitorRequest {
872     type Reply = GetMonitorReply;
873 }
get_monitor<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetMonitorReply>, ConnectionError> where Conn: RequestConnection + ?Sized,874 pub fn get_monitor<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetMonitorReply>, ConnectionError>
875 where
876     Conn: RequestConnection + ?Sized,
877 {
878     let request0 = GetMonitorRequest {
879         screen,
880     };
881     request0.send(conn)
882 }
883 
884 #[derive(Debug, Clone, PartialEq, Eq)]
885 pub struct GetMonitorReply {
886     pub sequence: u16,
887     pub length: u32,
888     pub hsync: Vec<Syncrange>,
889     pub vsync: Vec<Syncrange>,
890     pub vendor: Vec<u8>,
891     pub alignment_pad: Vec<u8>,
892     pub model: Vec<u8>,
893 }
894 impl TryParse for GetMonitorReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>895     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
896         let remaining = initial_value;
897         let (response_type, remaining) = u8::try_parse(remaining)?;
898         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
899         let (sequence, remaining) = u16::try_parse(remaining)?;
900         let (length, remaining) = u32::try_parse(remaining)?;
901         let (vendor_length, remaining) = u8::try_parse(remaining)?;
902         let (model_length, remaining) = u8::try_parse(remaining)?;
903         let (num_hsync, remaining) = u8::try_parse(remaining)?;
904         let (num_vsync, remaining) = u8::try_parse(remaining)?;
905         let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
906         let (hsync, remaining) = crate::x11_utils::parse_list::<Syncrange>(remaining, num_hsync.try_to_usize()?)?;
907         let (vsync, remaining) = crate::x11_utils::parse_list::<Syncrange>(remaining, num_vsync.try_to_usize()?)?;
908         let (vendor, remaining) = crate::x11_utils::parse_u8_list(remaining, vendor_length.try_to_usize()?)?;
909         let vendor = vendor.to_vec();
910         let (alignment_pad, remaining) = crate::x11_utils::parse_u8_list(remaining, (u32::from(vendor_length).checked_add(3u32).ok_or(ParseError::InvalidExpression)? & (!3u32)).checked_sub(u32::from(vendor_length)).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?;
911         let alignment_pad = alignment_pad.to_vec();
912         let (model, remaining) = crate::x11_utils::parse_u8_list(remaining, model_length.try_to_usize()?)?;
913         let model = model.to_vec();
914         if response_type != 1 {
915             return Err(ParseError::InvalidValue);
916         }
917         let result = GetMonitorReply { sequence, length, hsync, vsync, vendor, alignment_pad, model };
918         let _ = remaining;
919         let remaining = initial_value.get(32 + length as usize * 4..)
920             .ok_or(ParseError::InsufficientData)?;
921         Ok((result, remaining))
922     }
923 }
924 impl GetMonitorReply {
925     /// Get the value of the `vendor_length` field.
926     ///
927     /// The `vendor_length` field is used as the length field of the `vendor` field.
928     /// This function computes the field's value again based on the length of the list.
929     ///
930     /// # Panics
931     ///
932     /// Panics if the value cannot be represented in the target type. This
933     /// cannot happen with values of the struct received from the X11 server.
vendor_length(&self) -> u8934     pub fn vendor_length(&self) -> u8 {
935         self.vendor.len()
936             .try_into().unwrap()
937     }
938     /// Get the value of the `model_length` field.
939     ///
940     /// The `model_length` field is used as the length field of the `model` field.
941     /// This function computes the field's value again based on the length of the list.
942     ///
943     /// # Panics
944     ///
945     /// Panics if the value cannot be represented in the target type. This
946     /// cannot happen with values of the struct received from the X11 server.
model_length(&self) -> u8947     pub fn model_length(&self) -> u8 {
948         self.model.len()
949             .try_into().unwrap()
950     }
951     /// Get the value of the `num_hsync` field.
952     ///
953     /// The `num_hsync` field is used as the length field of the `hsync` field.
954     /// This function computes the field's value again based on the length of the list.
955     ///
956     /// # Panics
957     ///
958     /// Panics if the value cannot be represented in the target type. This
959     /// cannot happen with values of the struct received from the X11 server.
num_hsync(&self) -> u8960     pub fn num_hsync(&self) -> u8 {
961         self.hsync.len()
962             .try_into().unwrap()
963     }
964     /// Get the value of the `num_vsync` field.
965     ///
966     /// The `num_vsync` field is used as the length field of the `vsync` field.
967     /// This function computes the field's value again based on the length of the list.
968     ///
969     /// # Panics
970     ///
971     /// Panics if the value cannot be represented in the target type. This
972     /// cannot happen with values of the struct received from the X11 server.
num_vsync(&self) -> u8973     pub fn num_vsync(&self) -> u8 {
974         self.vsync.len()
975             .try_into().unwrap()
976     }
977 }
978 
979 /// Opcode for the LockModeSwitch request
980 pub const LOCK_MODE_SWITCH_REQUEST: u8 = 5;
981 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
982 pub struct LockModeSwitchRequest {
983     pub screen: u16,
984     pub lock: u16,
985 }
986 impl LockModeSwitchRequest {
987     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,988     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
989     where
990         Conn: RequestConnection + ?Sized,
991     {
992         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
993             .ok_or(ConnectionError::UnsupportedExtension)?;
994         let length_so_far = 0;
995         let screen_bytes = self.screen.serialize();
996         let lock_bytes = self.lock.serialize();
997         let mut request0 = vec![
998             extension_information.major_opcode,
999             LOCK_MODE_SWITCH_REQUEST,
1000             0,
1001             0,
1002             screen_bytes[0],
1003             screen_bytes[1],
1004             lock_bytes[0],
1005             lock_bytes[1],
1006         ];
1007         let length_so_far = length_so_far + request0.len();
1008         assert_eq!(length_so_far % 4, 0);
1009         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1010         request0[2..4].copy_from_slice(&length.to_ne_bytes());
1011         Ok((vec![request0.into()], vec![]))
1012     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,1013     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
1014     where
1015         Conn: RequestConnection + ?Sized,
1016     {
1017         let (bytes, fds) = self.serialize(conn)?;
1018         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
1019         conn.send_request_without_reply(&slices, fds)
1020     }
1021     /// 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>1022     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1023         if header.minor_opcode != LOCK_MODE_SWITCH_REQUEST {
1024             return Err(ParseError::InvalidValue);
1025         }
1026         let (screen, remaining) = u16::try_parse(value)?;
1027         let (lock, remaining) = u16::try_parse(remaining)?;
1028         let _ = remaining;
1029         Ok(LockModeSwitchRequest {
1030             screen,
1031             lock,
1032         })
1033     }
1034 }
1035 impl Request for LockModeSwitchRequest {
1036     type Reply = ();
1037 }
lock_mode_switch<Conn>(conn: &Conn, screen: u16, lock: u16) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,1038 pub fn lock_mode_switch<Conn>(conn: &Conn, screen: u16, lock: u16) -> Result<VoidCookie<'_, Conn>, ConnectionError>
1039 where
1040     Conn: RequestConnection + ?Sized,
1041 {
1042     let request0 = LockModeSwitchRequest {
1043         screen,
1044         lock,
1045     };
1046     request0.send(conn)
1047 }
1048 
1049 /// Opcode for the GetAllModeLines request
1050 pub const GET_ALL_MODE_LINES_REQUEST: u8 = 6;
1051 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
1052 pub struct GetAllModeLinesRequest {
1053     pub screen: u16,
1054 }
1055 impl GetAllModeLinesRequest {
1056     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,1057     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
1058     where
1059         Conn: RequestConnection + ?Sized,
1060     {
1061         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
1062             .ok_or(ConnectionError::UnsupportedExtension)?;
1063         let length_so_far = 0;
1064         let screen_bytes = self.screen.serialize();
1065         let mut request0 = vec![
1066             extension_information.major_opcode,
1067             GET_ALL_MODE_LINES_REQUEST,
1068             0,
1069             0,
1070             screen_bytes[0],
1071             screen_bytes[1],
1072             0,
1073             0,
1074         ];
1075         let length_so_far = length_so_far + request0.len();
1076         assert_eq!(length_so_far % 4, 0);
1077         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1078         request0[2..4].copy_from_slice(&length.to_ne_bytes());
1079         Ok((vec![request0.into()], vec![]))
1080     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetAllModeLinesReply>, ConnectionError> where Conn: RequestConnection + ?Sized,1081     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetAllModeLinesReply>, ConnectionError>
1082     where
1083         Conn: RequestConnection + ?Sized,
1084     {
1085         let (bytes, fds) = self.serialize(conn)?;
1086         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
1087         conn.send_request_with_reply(&slices, fds)
1088     }
1089     /// 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>1090     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1091         if header.minor_opcode != GET_ALL_MODE_LINES_REQUEST {
1092             return Err(ParseError::InvalidValue);
1093         }
1094         let (screen, remaining) = u16::try_parse(value)?;
1095         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
1096         let _ = remaining;
1097         Ok(GetAllModeLinesRequest {
1098             screen,
1099         })
1100     }
1101 }
1102 impl Request for GetAllModeLinesRequest {
1103     type Reply = GetAllModeLinesReply;
1104 }
get_all_mode_lines<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetAllModeLinesReply>, ConnectionError> where Conn: RequestConnection + ?Sized,1105 pub fn get_all_mode_lines<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetAllModeLinesReply>, ConnectionError>
1106 where
1107     Conn: RequestConnection + ?Sized,
1108 {
1109     let request0 = GetAllModeLinesRequest {
1110         screen,
1111     };
1112     request0.send(conn)
1113 }
1114 
1115 #[derive(Debug, Clone, PartialEq, Eq)]
1116 pub struct GetAllModeLinesReply {
1117     pub sequence: u16,
1118     pub length: u32,
1119     pub modeinfo: Vec<ModeInfo>,
1120 }
1121 impl TryParse for GetAllModeLinesReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>1122     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1123         let remaining = initial_value;
1124         let (response_type, remaining) = u8::try_parse(remaining)?;
1125         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1126         let (sequence, remaining) = u16::try_parse(remaining)?;
1127         let (length, remaining) = u32::try_parse(remaining)?;
1128         let (modecount, remaining) = u32::try_parse(remaining)?;
1129         let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
1130         let (modeinfo, remaining) = crate::x11_utils::parse_list::<ModeInfo>(remaining, modecount.try_to_usize()?)?;
1131         if response_type != 1 {
1132             return Err(ParseError::InvalidValue);
1133         }
1134         let result = GetAllModeLinesReply { sequence, length, modeinfo };
1135         let _ = remaining;
1136         let remaining = initial_value.get(32 + length as usize * 4..)
1137             .ok_or(ParseError::InsufficientData)?;
1138         Ok((result, remaining))
1139     }
1140 }
1141 impl GetAllModeLinesReply {
1142     /// Get the value of the `modecount` field.
1143     ///
1144     /// The `modecount` field is used as the length field of the `modeinfo` field.
1145     /// This function computes the field's value again based on the length of the list.
1146     ///
1147     /// # Panics
1148     ///
1149     /// Panics if the value cannot be represented in the target type. This
1150     /// cannot happen with values of the struct received from the X11 server.
modecount(&self) -> u321151     pub fn modecount(&self) -> u32 {
1152         self.modeinfo.len()
1153             .try_into().unwrap()
1154     }
1155 }
1156 
1157 /// Opcode for the AddModeLine request
1158 pub const ADD_MODE_LINE_REQUEST: u8 = 7;
1159 #[derive(Debug, Clone, PartialEq, Eq)]
1160 pub struct AddModeLineRequest<'input> {
1161     pub screen: u32,
1162     pub dotclock: Dotclock,
1163     pub hdisplay: u16,
1164     pub hsyncstart: u16,
1165     pub hsyncend: u16,
1166     pub htotal: u16,
1167     pub hskew: u16,
1168     pub vdisplay: u16,
1169     pub vsyncstart: u16,
1170     pub vsyncend: u16,
1171     pub vtotal: u16,
1172     pub flags: u32,
1173     pub after_dotclock: Dotclock,
1174     pub after_hdisplay: u16,
1175     pub after_hsyncstart: u16,
1176     pub after_hsyncend: u16,
1177     pub after_htotal: u16,
1178     pub after_hskew: u16,
1179     pub after_vdisplay: u16,
1180     pub after_vsyncstart: u16,
1181     pub after_vsyncend: u16,
1182     pub after_vtotal: u16,
1183     pub after_flags: u32,
1184     pub private: Cow<'input, [u8]>,
1185 }
1186 impl<'input> AddModeLineRequest<'input> {
1187     /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,1188     fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
1189     where
1190         Conn: RequestConnection + ?Sized,
1191     {
1192         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
1193             .ok_or(ConnectionError::UnsupportedExtension)?;
1194         let length_so_far = 0;
1195         let screen_bytes = self.screen.serialize();
1196         let dotclock_bytes = self.dotclock.serialize();
1197         let hdisplay_bytes = self.hdisplay.serialize();
1198         let hsyncstart_bytes = self.hsyncstart.serialize();
1199         let hsyncend_bytes = self.hsyncend.serialize();
1200         let htotal_bytes = self.htotal.serialize();
1201         let hskew_bytes = self.hskew.serialize();
1202         let vdisplay_bytes = self.vdisplay.serialize();
1203         let vsyncstart_bytes = self.vsyncstart.serialize();
1204         let vsyncend_bytes = self.vsyncend.serialize();
1205         let vtotal_bytes = self.vtotal.serialize();
1206         let flags_bytes = self.flags.serialize();
1207         let privsize = u32::try_from(self.private.len()).expect("`private` has too many elements");
1208         let privsize_bytes = privsize.serialize();
1209         let after_dotclock_bytes = self.after_dotclock.serialize();
1210         let after_hdisplay_bytes = self.after_hdisplay.serialize();
1211         let after_hsyncstart_bytes = self.after_hsyncstart.serialize();
1212         let after_hsyncend_bytes = self.after_hsyncend.serialize();
1213         let after_htotal_bytes = self.after_htotal.serialize();
1214         let after_hskew_bytes = self.after_hskew.serialize();
1215         let after_vdisplay_bytes = self.after_vdisplay.serialize();
1216         let after_vsyncstart_bytes = self.after_vsyncstart.serialize();
1217         let after_vsyncend_bytes = self.after_vsyncend.serialize();
1218         let after_vtotal_bytes = self.after_vtotal.serialize();
1219         let after_flags_bytes = self.after_flags.serialize();
1220         let mut request0 = vec![
1221             extension_information.major_opcode,
1222             ADD_MODE_LINE_REQUEST,
1223             0,
1224             0,
1225             screen_bytes[0],
1226             screen_bytes[1],
1227             screen_bytes[2],
1228             screen_bytes[3],
1229             dotclock_bytes[0],
1230             dotclock_bytes[1],
1231             dotclock_bytes[2],
1232             dotclock_bytes[3],
1233             hdisplay_bytes[0],
1234             hdisplay_bytes[1],
1235             hsyncstart_bytes[0],
1236             hsyncstart_bytes[1],
1237             hsyncend_bytes[0],
1238             hsyncend_bytes[1],
1239             htotal_bytes[0],
1240             htotal_bytes[1],
1241             hskew_bytes[0],
1242             hskew_bytes[1],
1243             vdisplay_bytes[0],
1244             vdisplay_bytes[1],
1245             vsyncstart_bytes[0],
1246             vsyncstart_bytes[1],
1247             vsyncend_bytes[0],
1248             vsyncend_bytes[1],
1249             vtotal_bytes[0],
1250             vtotal_bytes[1],
1251             0,
1252             0,
1253             flags_bytes[0],
1254             flags_bytes[1],
1255             flags_bytes[2],
1256             flags_bytes[3],
1257             0,
1258             0,
1259             0,
1260             0,
1261             0,
1262             0,
1263             0,
1264             0,
1265             0,
1266             0,
1267             0,
1268             0,
1269             privsize_bytes[0],
1270             privsize_bytes[1],
1271             privsize_bytes[2],
1272             privsize_bytes[3],
1273             after_dotclock_bytes[0],
1274             after_dotclock_bytes[1],
1275             after_dotclock_bytes[2],
1276             after_dotclock_bytes[3],
1277             after_hdisplay_bytes[0],
1278             after_hdisplay_bytes[1],
1279             after_hsyncstart_bytes[0],
1280             after_hsyncstart_bytes[1],
1281             after_hsyncend_bytes[0],
1282             after_hsyncend_bytes[1],
1283             after_htotal_bytes[0],
1284             after_htotal_bytes[1],
1285             after_hskew_bytes[0],
1286             after_hskew_bytes[1],
1287             after_vdisplay_bytes[0],
1288             after_vdisplay_bytes[1],
1289             after_vsyncstart_bytes[0],
1290             after_vsyncstart_bytes[1],
1291             after_vsyncend_bytes[0],
1292             after_vsyncend_bytes[1],
1293             after_vtotal_bytes[0],
1294             after_vtotal_bytes[1],
1295             0,
1296             0,
1297             after_flags_bytes[0],
1298             after_flags_bytes[1],
1299             after_flags_bytes[2],
1300             after_flags_bytes[3],
1301             0,
1302             0,
1303             0,
1304             0,
1305             0,
1306             0,
1307             0,
1308             0,
1309             0,
1310             0,
1311             0,
1312             0,
1313         ];
1314         let length_so_far = length_so_far + request0.len();
1315         let length_so_far = length_so_far + self.private.len();
1316         let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1317         let length_so_far = length_so_far + padding0.len();
1318         assert_eq!(length_so_far % 4, 0);
1319         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1320         request0[2..4].copy_from_slice(&length.to_ne_bytes());
1321         Ok((vec![request0.into(), self.private, padding0.into()], vec![]))
1322     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,1323     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
1324     where
1325         Conn: RequestConnection + ?Sized,
1326     {
1327         let (bytes, fds) = self.serialize(conn)?;
1328         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
1329         conn.send_request_without_reply(&slices, fds)
1330     }
1331     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError>1332     pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1333         if header.minor_opcode != ADD_MODE_LINE_REQUEST {
1334             return Err(ParseError::InvalidValue);
1335         }
1336         let (screen, remaining) = u32::try_parse(value)?;
1337         let (dotclock, remaining) = Dotclock::try_parse(remaining)?;
1338         let (hdisplay, remaining) = u16::try_parse(remaining)?;
1339         let (hsyncstart, remaining) = u16::try_parse(remaining)?;
1340         let (hsyncend, remaining) = u16::try_parse(remaining)?;
1341         let (htotal, remaining) = u16::try_parse(remaining)?;
1342         let (hskew, remaining) = u16::try_parse(remaining)?;
1343         let (vdisplay, remaining) = u16::try_parse(remaining)?;
1344         let (vsyncstart, remaining) = u16::try_parse(remaining)?;
1345         let (vsyncend, remaining) = u16::try_parse(remaining)?;
1346         let (vtotal, remaining) = u16::try_parse(remaining)?;
1347         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
1348         let (flags, remaining) = u32::try_parse(remaining)?;
1349         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
1350         let (privsize, remaining) = u32::try_parse(remaining)?;
1351         let (after_dotclock, remaining) = Dotclock::try_parse(remaining)?;
1352         let (after_hdisplay, remaining) = u16::try_parse(remaining)?;
1353         let (after_hsyncstart, remaining) = u16::try_parse(remaining)?;
1354         let (after_hsyncend, remaining) = u16::try_parse(remaining)?;
1355         let (after_htotal, remaining) = u16::try_parse(remaining)?;
1356         let (after_hskew, remaining) = u16::try_parse(remaining)?;
1357         let (after_vdisplay, remaining) = u16::try_parse(remaining)?;
1358         let (after_vsyncstart, remaining) = u16::try_parse(remaining)?;
1359         let (after_vsyncend, remaining) = u16::try_parse(remaining)?;
1360         let (after_vtotal, remaining) = u16::try_parse(remaining)?;
1361         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
1362         let (after_flags, remaining) = u32::try_parse(remaining)?;
1363         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
1364         let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?;
1365         let _ = remaining;
1366         Ok(AddModeLineRequest {
1367             screen,
1368             dotclock,
1369             hdisplay,
1370             hsyncstart,
1371             hsyncend,
1372             htotal,
1373             hskew,
1374             vdisplay,
1375             vsyncstart,
1376             vsyncend,
1377             vtotal,
1378             flags,
1379             after_dotclock,
1380             after_hdisplay,
1381             after_hsyncstart,
1382             after_hsyncend,
1383             after_htotal,
1384             after_hskew,
1385             after_vdisplay,
1386             after_vsyncstart,
1387             after_vsyncend,
1388             after_vtotal,
1389             after_flags,
1390             private: Cow::Borrowed(private),
1391         })
1392     }
1393     /// Clone all borrowed data in this AddModeLineRequest.
into_owned(self) -> AddModeLineRequest<'static>1394     pub fn into_owned(self) -> AddModeLineRequest<'static> {
1395         AddModeLineRequest {
1396             screen: self.screen,
1397             dotclock: self.dotclock,
1398             hdisplay: self.hdisplay,
1399             hsyncstart: self.hsyncstart,
1400             hsyncend: self.hsyncend,
1401             htotal: self.htotal,
1402             hskew: self.hskew,
1403             vdisplay: self.vdisplay,
1404             vsyncstart: self.vsyncstart,
1405             vsyncend: self.vsyncend,
1406             vtotal: self.vtotal,
1407             flags: self.flags,
1408             after_dotclock: self.after_dotclock,
1409             after_hdisplay: self.after_hdisplay,
1410             after_hsyncstart: self.after_hsyncstart,
1411             after_hsyncend: self.after_hsyncend,
1412             after_htotal: self.after_htotal,
1413             after_hskew: self.after_hskew,
1414             after_vdisplay: self.after_vdisplay,
1415             after_vsyncstart: self.after_vsyncstart,
1416             after_vsyncend: self.after_vsyncend,
1417             after_vtotal: self.after_vtotal,
1418             after_flags: self.after_flags,
1419             private: Cow::Owned(self.private.into_owned()),
1420         }
1421     }
1422 }
1423 impl<'input> Request for AddModeLineRequest<'input> {
1424     type Reply = ();
1425 }
add_mode_line<'c, 'input, Conn, A, B>(conn: &'c Conn, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, after_dotclock: Dotclock, after_hdisplay: u16, after_hsyncstart: u16, after_hsyncend: u16, after_htotal: u16, after_hskew: u16, after_vdisplay: u16, after_vsyncstart: u16, after_vsyncend: u16, after_vtotal: u16, after_flags: B, private: &'input [u8]) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u32>, B: Into<u32>,1426 pub fn add_mode_line<'c, 'input, Conn, A, B>(conn: &'c Conn, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, after_dotclock: Dotclock, after_hdisplay: u16, after_hsyncstart: u16, after_hsyncend: u16, after_htotal: u16, after_hskew: u16, after_vdisplay: u16, after_vsyncstart: u16, after_vsyncend: u16, after_vtotal: u16, after_flags: B, private: &'input [u8]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
1427 where
1428     Conn: RequestConnection + ?Sized,
1429     A: Into<u32>,
1430     B: Into<u32>,
1431 {
1432     let flags: u32 = flags.into();
1433     let after_flags: u32 = after_flags.into();
1434     let request0 = AddModeLineRequest {
1435         screen,
1436         dotclock,
1437         hdisplay,
1438         hsyncstart,
1439         hsyncend,
1440         htotal,
1441         hskew,
1442         vdisplay,
1443         vsyncstart,
1444         vsyncend,
1445         vtotal,
1446         flags,
1447         after_dotclock,
1448         after_hdisplay,
1449         after_hsyncstart,
1450         after_hsyncend,
1451         after_htotal,
1452         after_hskew,
1453         after_vdisplay,
1454         after_vsyncstart,
1455         after_vsyncend,
1456         after_vtotal,
1457         after_flags,
1458         private: Cow::Borrowed(private),
1459     };
1460     request0.send(conn)
1461 }
1462 
1463 /// Opcode for the DeleteModeLine request
1464 pub const DELETE_MODE_LINE_REQUEST: u8 = 8;
1465 #[derive(Debug, Clone, PartialEq, Eq)]
1466 pub struct DeleteModeLineRequest<'input> {
1467     pub screen: u32,
1468     pub dotclock: Dotclock,
1469     pub hdisplay: u16,
1470     pub hsyncstart: u16,
1471     pub hsyncend: u16,
1472     pub htotal: u16,
1473     pub hskew: u16,
1474     pub vdisplay: u16,
1475     pub vsyncstart: u16,
1476     pub vsyncend: u16,
1477     pub vtotal: u16,
1478     pub flags: u32,
1479     pub private: Cow<'input, [u8]>,
1480 }
1481 impl<'input> DeleteModeLineRequest<'input> {
1482     /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,1483     fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
1484     where
1485         Conn: RequestConnection + ?Sized,
1486     {
1487         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
1488             .ok_or(ConnectionError::UnsupportedExtension)?;
1489         let length_so_far = 0;
1490         let screen_bytes = self.screen.serialize();
1491         let dotclock_bytes = self.dotclock.serialize();
1492         let hdisplay_bytes = self.hdisplay.serialize();
1493         let hsyncstart_bytes = self.hsyncstart.serialize();
1494         let hsyncend_bytes = self.hsyncend.serialize();
1495         let htotal_bytes = self.htotal.serialize();
1496         let hskew_bytes = self.hskew.serialize();
1497         let vdisplay_bytes = self.vdisplay.serialize();
1498         let vsyncstart_bytes = self.vsyncstart.serialize();
1499         let vsyncend_bytes = self.vsyncend.serialize();
1500         let vtotal_bytes = self.vtotal.serialize();
1501         let flags_bytes = self.flags.serialize();
1502         let privsize = u32::try_from(self.private.len()).expect("`private` has too many elements");
1503         let privsize_bytes = privsize.serialize();
1504         let mut request0 = vec![
1505             extension_information.major_opcode,
1506             DELETE_MODE_LINE_REQUEST,
1507             0,
1508             0,
1509             screen_bytes[0],
1510             screen_bytes[1],
1511             screen_bytes[2],
1512             screen_bytes[3],
1513             dotclock_bytes[0],
1514             dotclock_bytes[1],
1515             dotclock_bytes[2],
1516             dotclock_bytes[3],
1517             hdisplay_bytes[0],
1518             hdisplay_bytes[1],
1519             hsyncstart_bytes[0],
1520             hsyncstart_bytes[1],
1521             hsyncend_bytes[0],
1522             hsyncend_bytes[1],
1523             htotal_bytes[0],
1524             htotal_bytes[1],
1525             hskew_bytes[0],
1526             hskew_bytes[1],
1527             vdisplay_bytes[0],
1528             vdisplay_bytes[1],
1529             vsyncstart_bytes[0],
1530             vsyncstart_bytes[1],
1531             vsyncend_bytes[0],
1532             vsyncend_bytes[1],
1533             vtotal_bytes[0],
1534             vtotal_bytes[1],
1535             0,
1536             0,
1537             flags_bytes[0],
1538             flags_bytes[1],
1539             flags_bytes[2],
1540             flags_bytes[3],
1541             0,
1542             0,
1543             0,
1544             0,
1545             0,
1546             0,
1547             0,
1548             0,
1549             0,
1550             0,
1551             0,
1552             0,
1553             privsize_bytes[0],
1554             privsize_bytes[1],
1555             privsize_bytes[2],
1556             privsize_bytes[3],
1557         ];
1558         let length_so_far = length_so_far + request0.len();
1559         let length_so_far = length_so_far + self.private.len();
1560         let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1561         let length_so_far = length_so_far + padding0.len();
1562         assert_eq!(length_so_far % 4, 0);
1563         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1564         request0[2..4].copy_from_slice(&length.to_ne_bytes());
1565         Ok((vec![request0.into(), self.private, padding0.into()], vec![]))
1566     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,1567     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
1568     where
1569         Conn: RequestConnection + ?Sized,
1570     {
1571         let (bytes, fds) = self.serialize(conn)?;
1572         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
1573         conn.send_request_without_reply(&slices, fds)
1574     }
1575     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError>1576     pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1577         if header.minor_opcode != DELETE_MODE_LINE_REQUEST {
1578             return Err(ParseError::InvalidValue);
1579         }
1580         let (screen, remaining) = u32::try_parse(value)?;
1581         let (dotclock, remaining) = Dotclock::try_parse(remaining)?;
1582         let (hdisplay, remaining) = u16::try_parse(remaining)?;
1583         let (hsyncstart, remaining) = u16::try_parse(remaining)?;
1584         let (hsyncend, remaining) = u16::try_parse(remaining)?;
1585         let (htotal, remaining) = u16::try_parse(remaining)?;
1586         let (hskew, remaining) = u16::try_parse(remaining)?;
1587         let (vdisplay, remaining) = u16::try_parse(remaining)?;
1588         let (vsyncstart, remaining) = u16::try_parse(remaining)?;
1589         let (vsyncend, remaining) = u16::try_parse(remaining)?;
1590         let (vtotal, remaining) = u16::try_parse(remaining)?;
1591         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
1592         let (flags, remaining) = u32::try_parse(remaining)?;
1593         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
1594         let (privsize, remaining) = u32::try_parse(remaining)?;
1595         let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?;
1596         let _ = remaining;
1597         Ok(DeleteModeLineRequest {
1598             screen,
1599             dotclock,
1600             hdisplay,
1601             hsyncstart,
1602             hsyncend,
1603             htotal,
1604             hskew,
1605             vdisplay,
1606             vsyncstart,
1607             vsyncend,
1608             vtotal,
1609             flags,
1610             private: Cow::Borrowed(private),
1611         })
1612     }
1613     /// Clone all borrowed data in this DeleteModeLineRequest.
into_owned(self) -> DeleteModeLineRequest<'static>1614     pub fn into_owned(self) -> DeleteModeLineRequest<'static> {
1615         DeleteModeLineRequest {
1616             screen: self.screen,
1617             dotclock: self.dotclock,
1618             hdisplay: self.hdisplay,
1619             hsyncstart: self.hsyncstart,
1620             hsyncend: self.hsyncend,
1621             htotal: self.htotal,
1622             hskew: self.hskew,
1623             vdisplay: self.vdisplay,
1624             vsyncstart: self.vsyncstart,
1625             vsyncend: self.vsyncend,
1626             vtotal: self.vtotal,
1627             flags: self.flags,
1628             private: Cow::Owned(self.private.into_owned()),
1629         }
1630     }
1631 }
1632 impl<'input> Request for DeleteModeLineRequest<'input> {
1633     type Reply = ();
1634 }
delete_mode_line<'c, 'input, Conn, A>(conn: &'c Conn, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u32>,1635 pub fn delete_mode_line<'c, 'input, Conn, A>(conn: &'c Conn, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
1636 where
1637     Conn: RequestConnection + ?Sized,
1638     A: Into<u32>,
1639 {
1640     let flags: u32 = flags.into();
1641     let request0 = DeleteModeLineRequest {
1642         screen,
1643         dotclock,
1644         hdisplay,
1645         hsyncstart,
1646         hsyncend,
1647         htotal,
1648         hskew,
1649         vdisplay,
1650         vsyncstart,
1651         vsyncend,
1652         vtotal,
1653         flags,
1654         private: Cow::Borrowed(private),
1655     };
1656     request0.send(conn)
1657 }
1658 
1659 /// Opcode for the ValidateModeLine request
1660 pub const VALIDATE_MODE_LINE_REQUEST: u8 = 9;
1661 #[derive(Debug, Clone, PartialEq, Eq)]
1662 pub struct ValidateModeLineRequest<'input> {
1663     pub screen: u32,
1664     pub dotclock: Dotclock,
1665     pub hdisplay: u16,
1666     pub hsyncstart: u16,
1667     pub hsyncend: u16,
1668     pub htotal: u16,
1669     pub hskew: u16,
1670     pub vdisplay: u16,
1671     pub vsyncstart: u16,
1672     pub vsyncend: u16,
1673     pub vtotal: u16,
1674     pub flags: u32,
1675     pub private: Cow<'input, [u8]>,
1676 }
1677 impl<'input> ValidateModeLineRequest<'input> {
1678     /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,1679     fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
1680     where
1681         Conn: RequestConnection + ?Sized,
1682     {
1683         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
1684             .ok_or(ConnectionError::UnsupportedExtension)?;
1685         let length_so_far = 0;
1686         let screen_bytes = self.screen.serialize();
1687         let dotclock_bytes = self.dotclock.serialize();
1688         let hdisplay_bytes = self.hdisplay.serialize();
1689         let hsyncstart_bytes = self.hsyncstart.serialize();
1690         let hsyncend_bytes = self.hsyncend.serialize();
1691         let htotal_bytes = self.htotal.serialize();
1692         let hskew_bytes = self.hskew.serialize();
1693         let vdisplay_bytes = self.vdisplay.serialize();
1694         let vsyncstart_bytes = self.vsyncstart.serialize();
1695         let vsyncend_bytes = self.vsyncend.serialize();
1696         let vtotal_bytes = self.vtotal.serialize();
1697         let flags_bytes = self.flags.serialize();
1698         let privsize = u32::try_from(self.private.len()).expect("`private` has too many elements");
1699         let privsize_bytes = privsize.serialize();
1700         let mut request0 = vec![
1701             extension_information.major_opcode,
1702             VALIDATE_MODE_LINE_REQUEST,
1703             0,
1704             0,
1705             screen_bytes[0],
1706             screen_bytes[1],
1707             screen_bytes[2],
1708             screen_bytes[3],
1709             dotclock_bytes[0],
1710             dotclock_bytes[1],
1711             dotclock_bytes[2],
1712             dotclock_bytes[3],
1713             hdisplay_bytes[0],
1714             hdisplay_bytes[1],
1715             hsyncstart_bytes[0],
1716             hsyncstart_bytes[1],
1717             hsyncend_bytes[0],
1718             hsyncend_bytes[1],
1719             htotal_bytes[0],
1720             htotal_bytes[1],
1721             hskew_bytes[0],
1722             hskew_bytes[1],
1723             vdisplay_bytes[0],
1724             vdisplay_bytes[1],
1725             vsyncstart_bytes[0],
1726             vsyncstart_bytes[1],
1727             vsyncend_bytes[0],
1728             vsyncend_bytes[1],
1729             vtotal_bytes[0],
1730             vtotal_bytes[1],
1731             0,
1732             0,
1733             flags_bytes[0],
1734             flags_bytes[1],
1735             flags_bytes[2],
1736             flags_bytes[3],
1737             0,
1738             0,
1739             0,
1740             0,
1741             0,
1742             0,
1743             0,
1744             0,
1745             0,
1746             0,
1747             0,
1748             0,
1749             privsize_bytes[0],
1750             privsize_bytes[1],
1751             privsize_bytes[2],
1752             privsize_bytes[3],
1753         ];
1754         let length_so_far = length_so_far + request0.len();
1755         let length_so_far = length_so_far + self.private.len();
1756         let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1757         let length_so_far = length_so_far + padding0.len();
1758         assert_eq!(length_so_far % 4, 0);
1759         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1760         request0[2..4].copy_from_slice(&length.to_ne_bytes());
1761         Ok((vec![request0.into(), self.private, padding0.into()], vec![]))
1762     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, ValidateModeLineReply>, ConnectionError> where Conn: RequestConnection + ?Sized,1763     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, ValidateModeLineReply>, ConnectionError>
1764     where
1765         Conn: RequestConnection + ?Sized,
1766     {
1767         let (bytes, fds) = self.serialize(conn)?;
1768         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
1769         conn.send_request_with_reply(&slices, fds)
1770     }
1771     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError>1772     pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1773         if header.minor_opcode != VALIDATE_MODE_LINE_REQUEST {
1774             return Err(ParseError::InvalidValue);
1775         }
1776         let (screen, remaining) = u32::try_parse(value)?;
1777         let (dotclock, remaining) = Dotclock::try_parse(remaining)?;
1778         let (hdisplay, remaining) = u16::try_parse(remaining)?;
1779         let (hsyncstart, remaining) = u16::try_parse(remaining)?;
1780         let (hsyncend, remaining) = u16::try_parse(remaining)?;
1781         let (htotal, remaining) = u16::try_parse(remaining)?;
1782         let (hskew, remaining) = u16::try_parse(remaining)?;
1783         let (vdisplay, remaining) = u16::try_parse(remaining)?;
1784         let (vsyncstart, remaining) = u16::try_parse(remaining)?;
1785         let (vsyncend, remaining) = u16::try_parse(remaining)?;
1786         let (vtotal, remaining) = u16::try_parse(remaining)?;
1787         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
1788         let (flags, remaining) = u32::try_parse(remaining)?;
1789         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
1790         let (privsize, remaining) = u32::try_parse(remaining)?;
1791         let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?;
1792         let _ = remaining;
1793         Ok(ValidateModeLineRequest {
1794             screen,
1795             dotclock,
1796             hdisplay,
1797             hsyncstart,
1798             hsyncend,
1799             htotal,
1800             hskew,
1801             vdisplay,
1802             vsyncstart,
1803             vsyncend,
1804             vtotal,
1805             flags,
1806             private: Cow::Borrowed(private),
1807         })
1808     }
1809     /// Clone all borrowed data in this ValidateModeLineRequest.
into_owned(self) -> ValidateModeLineRequest<'static>1810     pub fn into_owned(self) -> ValidateModeLineRequest<'static> {
1811         ValidateModeLineRequest {
1812             screen: self.screen,
1813             dotclock: self.dotclock,
1814             hdisplay: self.hdisplay,
1815             hsyncstart: self.hsyncstart,
1816             hsyncend: self.hsyncend,
1817             htotal: self.htotal,
1818             hskew: self.hskew,
1819             vdisplay: self.vdisplay,
1820             vsyncstart: self.vsyncstart,
1821             vsyncend: self.vsyncend,
1822             vtotal: self.vtotal,
1823             flags: self.flags,
1824             private: Cow::Owned(self.private.into_owned()),
1825         }
1826     }
1827 }
1828 impl<'input> Request for ValidateModeLineRequest<'input> {
1829     type Reply = ValidateModeLineReply;
1830 }
validate_mode_line<'c, 'input, Conn, A>(conn: &'c Conn, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<Cookie<'c, Conn, ValidateModeLineReply>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u32>,1831 pub fn validate_mode_line<'c, 'input, Conn, A>(conn: &'c Conn, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<Cookie<'c, Conn, ValidateModeLineReply>, ConnectionError>
1832 where
1833     Conn: RequestConnection + ?Sized,
1834     A: Into<u32>,
1835 {
1836     let flags: u32 = flags.into();
1837     let request0 = ValidateModeLineRequest {
1838         screen,
1839         dotclock,
1840         hdisplay,
1841         hsyncstart,
1842         hsyncend,
1843         htotal,
1844         hskew,
1845         vdisplay,
1846         vsyncstart,
1847         vsyncend,
1848         vtotal,
1849         flags,
1850         private: Cow::Borrowed(private),
1851     };
1852     request0.send(conn)
1853 }
1854 
1855 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
1856 pub struct ValidateModeLineReply {
1857     pub sequence: u16,
1858     pub length: u32,
1859     pub status: u32,
1860 }
1861 impl TryParse for ValidateModeLineReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>1862     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1863         let remaining = initial_value;
1864         let (response_type, remaining) = u8::try_parse(remaining)?;
1865         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1866         let (sequence, remaining) = u16::try_parse(remaining)?;
1867         let (length, remaining) = u32::try_parse(remaining)?;
1868         let (status, remaining) = u32::try_parse(remaining)?;
1869         let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
1870         if response_type != 1 {
1871             return Err(ParseError::InvalidValue);
1872         }
1873         let result = ValidateModeLineReply { sequence, length, status };
1874         let _ = remaining;
1875         let remaining = initial_value.get(32 + length as usize * 4..)
1876             .ok_or(ParseError::InsufficientData)?;
1877         Ok((result, remaining))
1878     }
1879 }
1880 
1881 /// Opcode for the SwitchToMode request
1882 pub const SWITCH_TO_MODE_REQUEST: u8 = 10;
1883 #[derive(Debug, Clone, PartialEq, Eq)]
1884 pub struct SwitchToModeRequest<'input> {
1885     pub screen: u32,
1886     pub dotclock: Dotclock,
1887     pub hdisplay: u16,
1888     pub hsyncstart: u16,
1889     pub hsyncend: u16,
1890     pub htotal: u16,
1891     pub hskew: u16,
1892     pub vdisplay: u16,
1893     pub vsyncstart: u16,
1894     pub vsyncend: u16,
1895     pub vtotal: u16,
1896     pub flags: u32,
1897     pub private: Cow<'input, [u8]>,
1898 }
1899 impl<'input> SwitchToModeRequest<'input> {
1900     /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,1901     fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
1902     where
1903         Conn: RequestConnection + ?Sized,
1904     {
1905         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
1906             .ok_or(ConnectionError::UnsupportedExtension)?;
1907         let length_so_far = 0;
1908         let screen_bytes = self.screen.serialize();
1909         let dotclock_bytes = self.dotclock.serialize();
1910         let hdisplay_bytes = self.hdisplay.serialize();
1911         let hsyncstart_bytes = self.hsyncstart.serialize();
1912         let hsyncend_bytes = self.hsyncend.serialize();
1913         let htotal_bytes = self.htotal.serialize();
1914         let hskew_bytes = self.hskew.serialize();
1915         let vdisplay_bytes = self.vdisplay.serialize();
1916         let vsyncstart_bytes = self.vsyncstart.serialize();
1917         let vsyncend_bytes = self.vsyncend.serialize();
1918         let vtotal_bytes = self.vtotal.serialize();
1919         let flags_bytes = self.flags.serialize();
1920         let privsize = u32::try_from(self.private.len()).expect("`private` has too many elements");
1921         let privsize_bytes = privsize.serialize();
1922         let mut request0 = vec![
1923             extension_information.major_opcode,
1924             SWITCH_TO_MODE_REQUEST,
1925             0,
1926             0,
1927             screen_bytes[0],
1928             screen_bytes[1],
1929             screen_bytes[2],
1930             screen_bytes[3],
1931             dotclock_bytes[0],
1932             dotclock_bytes[1],
1933             dotclock_bytes[2],
1934             dotclock_bytes[3],
1935             hdisplay_bytes[0],
1936             hdisplay_bytes[1],
1937             hsyncstart_bytes[0],
1938             hsyncstart_bytes[1],
1939             hsyncend_bytes[0],
1940             hsyncend_bytes[1],
1941             htotal_bytes[0],
1942             htotal_bytes[1],
1943             hskew_bytes[0],
1944             hskew_bytes[1],
1945             vdisplay_bytes[0],
1946             vdisplay_bytes[1],
1947             vsyncstart_bytes[0],
1948             vsyncstart_bytes[1],
1949             vsyncend_bytes[0],
1950             vsyncend_bytes[1],
1951             vtotal_bytes[0],
1952             vtotal_bytes[1],
1953             0,
1954             0,
1955             flags_bytes[0],
1956             flags_bytes[1],
1957             flags_bytes[2],
1958             flags_bytes[3],
1959             0,
1960             0,
1961             0,
1962             0,
1963             0,
1964             0,
1965             0,
1966             0,
1967             0,
1968             0,
1969             0,
1970             0,
1971             privsize_bytes[0],
1972             privsize_bytes[1],
1973             privsize_bytes[2],
1974             privsize_bytes[3],
1975         ];
1976         let length_so_far = length_so_far + request0.len();
1977         let length_so_far = length_so_far + self.private.len();
1978         let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1979         let length_so_far = length_so_far + padding0.len();
1980         assert_eq!(length_so_far % 4, 0);
1981         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1982         request0[2..4].copy_from_slice(&length.to_ne_bytes());
1983         Ok((vec![request0.into(), self.private, padding0.into()], vec![]))
1984     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,1985     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
1986     where
1987         Conn: RequestConnection + ?Sized,
1988     {
1989         let (bytes, fds) = self.serialize(conn)?;
1990         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
1991         conn.send_request_without_reply(&slices, fds)
1992     }
1993     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError>1994     pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1995         if header.minor_opcode != SWITCH_TO_MODE_REQUEST {
1996             return Err(ParseError::InvalidValue);
1997         }
1998         let (screen, remaining) = u32::try_parse(value)?;
1999         let (dotclock, remaining) = Dotclock::try_parse(remaining)?;
2000         let (hdisplay, remaining) = u16::try_parse(remaining)?;
2001         let (hsyncstart, remaining) = u16::try_parse(remaining)?;
2002         let (hsyncend, remaining) = u16::try_parse(remaining)?;
2003         let (htotal, remaining) = u16::try_parse(remaining)?;
2004         let (hskew, remaining) = u16::try_parse(remaining)?;
2005         let (vdisplay, remaining) = u16::try_parse(remaining)?;
2006         let (vsyncstart, remaining) = u16::try_parse(remaining)?;
2007         let (vsyncend, remaining) = u16::try_parse(remaining)?;
2008         let (vtotal, remaining) = u16::try_parse(remaining)?;
2009         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2010         let (flags, remaining) = u32::try_parse(remaining)?;
2011         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
2012         let (privsize, remaining) = u32::try_parse(remaining)?;
2013         let (private, remaining) = crate::x11_utils::parse_u8_list(remaining, privsize.try_to_usize()?)?;
2014         let _ = remaining;
2015         Ok(SwitchToModeRequest {
2016             screen,
2017             dotclock,
2018             hdisplay,
2019             hsyncstart,
2020             hsyncend,
2021             htotal,
2022             hskew,
2023             vdisplay,
2024             vsyncstart,
2025             vsyncend,
2026             vtotal,
2027             flags,
2028             private: Cow::Borrowed(private),
2029         })
2030     }
2031     /// Clone all borrowed data in this SwitchToModeRequest.
into_owned(self) -> SwitchToModeRequest<'static>2032     pub fn into_owned(self) -> SwitchToModeRequest<'static> {
2033         SwitchToModeRequest {
2034             screen: self.screen,
2035             dotclock: self.dotclock,
2036             hdisplay: self.hdisplay,
2037             hsyncstart: self.hsyncstart,
2038             hsyncend: self.hsyncend,
2039             htotal: self.htotal,
2040             hskew: self.hskew,
2041             vdisplay: self.vdisplay,
2042             vsyncstart: self.vsyncstart,
2043             vsyncend: self.vsyncend,
2044             vtotal: self.vtotal,
2045             flags: self.flags,
2046             private: Cow::Owned(self.private.into_owned()),
2047         }
2048     }
2049 }
2050 impl<'input> Request for SwitchToModeRequest<'input> {
2051     type Reply = ();
2052 }
switch_to_mode<'c, 'input, Conn, A>(conn: &'c Conn, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized, A: Into<u32>,2053 pub fn switch_to_mode<'c, 'input, Conn, A>(conn: &'c Conn, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
2054 where
2055     Conn: RequestConnection + ?Sized,
2056     A: Into<u32>,
2057 {
2058     let flags: u32 = flags.into();
2059     let request0 = SwitchToModeRequest {
2060         screen,
2061         dotclock,
2062         hdisplay,
2063         hsyncstart,
2064         hsyncend,
2065         htotal,
2066         hskew,
2067         vdisplay,
2068         vsyncstart,
2069         vsyncend,
2070         vtotal,
2071         flags,
2072         private: Cow::Borrowed(private),
2073     };
2074     request0.send(conn)
2075 }
2076 
2077 /// Opcode for the GetViewPort request
2078 pub const GET_VIEW_PORT_REQUEST: u8 = 11;
2079 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2080 pub struct GetViewPortRequest {
2081     pub screen: u16,
2082 }
2083 impl GetViewPortRequest {
2084     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,2085     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
2086     where
2087         Conn: RequestConnection + ?Sized,
2088     {
2089         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
2090             .ok_or(ConnectionError::UnsupportedExtension)?;
2091         let length_so_far = 0;
2092         let screen_bytes = self.screen.serialize();
2093         let mut request0 = vec![
2094             extension_information.major_opcode,
2095             GET_VIEW_PORT_REQUEST,
2096             0,
2097             0,
2098             screen_bytes[0],
2099             screen_bytes[1],
2100             0,
2101             0,
2102         ];
2103         let length_so_far = length_so_far + request0.len();
2104         assert_eq!(length_so_far % 4, 0);
2105         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2106         request0[2..4].copy_from_slice(&length.to_ne_bytes());
2107         Ok((vec![request0.into()], vec![]))
2108     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetViewPortReply>, ConnectionError> where Conn: RequestConnection + ?Sized,2109     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetViewPortReply>, ConnectionError>
2110     where
2111         Conn: RequestConnection + ?Sized,
2112     {
2113         let (bytes, fds) = self.serialize(conn)?;
2114         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
2115         conn.send_request_with_reply(&slices, fds)
2116     }
2117     /// 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>2118     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2119         if header.minor_opcode != GET_VIEW_PORT_REQUEST {
2120             return Err(ParseError::InvalidValue);
2121         }
2122         let (screen, remaining) = u16::try_parse(value)?;
2123         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2124         let _ = remaining;
2125         Ok(GetViewPortRequest {
2126             screen,
2127         })
2128     }
2129 }
2130 impl Request for GetViewPortRequest {
2131     type Reply = GetViewPortReply;
2132 }
get_view_port<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetViewPortReply>, ConnectionError> where Conn: RequestConnection + ?Sized,2133 pub fn get_view_port<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetViewPortReply>, ConnectionError>
2134 where
2135     Conn: RequestConnection + ?Sized,
2136 {
2137     let request0 = GetViewPortRequest {
2138         screen,
2139     };
2140     request0.send(conn)
2141 }
2142 
2143 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2144 pub struct GetViewPortReply {
2145     pub sequence: u16,
2146     pub length: u32,
2147     pub x: u32,
2148     pub y: u32,
2149 }
2150 impl TryParse for GetViewPortReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>2151     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2152         let remaining = initial_value;
2153         let (response_type, remaining) = u8::try_parse(remaining)?;
2154         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2155         let (sequence, remaining) = u16::try_parse(remaining)?;
2156         let (length, remaining) = u32::try_parse(remaining)?;
2157         let (x, remaining) = u32::try_parse(remaining)?;
2158         let (y, remaining) = u32::try_parse(remaining)?;
2159         let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
2160         if response_type != 1 {
2161             return Err(ParseError::InvalidValue);
2162         }
2163         let result = GetViewPortReply { sequence, length, x, y };
2164         let _ = remaining;
2165         let remaining = initial_value.get(32 + length as usize * 4..)
2166             .ok_or(ParseError::InsufficientData)?;
2167         Ok((result, remaining))
2168     }
2169 }
2170 
2171 /// Opcode for the SetViewPort request
2172 pub const SET_VIEW_PORT_REQUEST: u8 = 12;
2173 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2174 pub struct SetViewPortRequest {
2175     pub screen: u16,
2176     pub x: u32,
2177     pub y: u32,
2178 }
2179 impl SetViewPortRequest {
2180     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,2181     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
2182     where
2183         Conn: RequestConnection + ?Sized,
2184     {
2185         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
2186             .ok_or(ConnectionError::UnsupportedExtension)?;
2187         let length_so_far = 0;
2188         let screen_bytes = self.screen.serialize();
2189         let x_bytes = self.x.serialize();
2190         let y_bytes = self.y.serialize();
2191         let mut request0 = vec![
2192             extension_information.major_opcode,
2193             SET_VIEW_PORT_REQUEST,
2194             0,
2195             0,
2196             screen_bytes[0],
2197             screen_bytes[1],
2198             0,
2199             0,
2200             x_bytes[0],
2201             x_bytes[1],
2202             x_bytes[2],
2203             x_bytes[3],
2204             y_bytes[0],
2205             y_bytes[1],
2206             y_bytes[2],
2207             y_bytes[3],
2208         ];
2209         let length_so_far = length_so_far + request0.len();
2210         assert_eq!(length_so_far % 4, 0);
2211         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2212         request0[2..4].copy_from_slice(&length.to_ne_bytes());
2213         Ok((vec![request0.into()], vec![]))
2214     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,2215     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
2216     where
2217         Conn: RequestConnection + ?Sized,
2218     {
2219         let (bytes, fds) = self.serialize(conn)?;
2220         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
2221         conn.send_request_without_reply(&slices, fds)
2222     }
2223     /// 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>2224     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2225         if header.minor_opcode != SET_VIEW_PORT_REQUEST {
2226             return Err(ParseError::InvalidValue);
2227         }
2228         let (screen, remaining) = u16::try_parse(value)?;
2229         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2230         let (x, remaining) = u32::try_parse(remaining)?;
2231         let (y, remaining) = u32::try_parse(remaining)?;
2232         let _ = remaining;
2233         Ok(SetViewPortRequest {
2234             screen,
2235             x,
2236             y,
2237         })
2238     }
2239 }
2240 impl Request for SetViewPortRequest {
2241     type Reply = ();
2242 }
set_view_port<Conn>(conn: &Conn, screen: u16, x: u32, y: u32) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,2243 pub fn set_view_port<Conn>(conn: &Conn, screen: u16, x: u32, y: u32) -> Result<VoidCookie<'_, Conn>, ConnectionError>
2244 where
2245     Conn: RequestConnection + ?Sized,
2246 {
2247     let request0 = SetViewPortRequest {
2248         screen,
2249         x,
2250         y,
2251     };
2252     request0.send(conn)
2253 }
2254 
2255 /// Opcode for the GetDotClocks request
2256 pub const GET_DOT_CLOCKS_REQUEST: u8 = 13;
2257 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2258 pub struct GetDotClocksRequest {
2259     pub screen: u16,
2260 }
2261 impl GetDotClocksRequest {
2262     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,2263     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
2264     where
2265         Conn: RequestConnection + ?Sized,
2266     {
2267         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
2268             .ok_or(ConnectionError::UnsupportedExtension)?;
2269         let length_so_far = 0;
2270         let screen_bytes = self.screen.serialize();
2271         let mut request0 = vec![
2272             extension_information.major_opcode,
2273             GET_DOT_CLOCKS_REQUEST,
2274             0,
2275             0,
2276             screen_bytes[0],
2277             screen_bytes[1],
2278             0,
2279             0,
2280         ];
2281         let length_so_far = length_so_far + request0.len();
2282         assert_eq!(length_so_far % 4, 0);
2283         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2284         request0[2..4].copy_from_slice(&length.to_ne_bytes());
2285         Ok((vec![request0.into()], vec![]))
2286     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetDotClocksReply>, ConnectionError> where Conn: RequestConnection + ?Sized,2287     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetDotClocksReply>, ConnectionError>
2288     where
2289         Conn: RequestConnection + ?Sized,
2290     {
2291         let (bytes, fds) = self.serialize(conn)?;
2292         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
2293         conn.send_request_with_reply(&slices, fds)
2294     }
2295     /// 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>2296     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2297         if header.minor_opcode != GET_DOT_CLOCKS_REQUEST {
2298             return Err(ParseError::InvalidValue);
2299         }
2300         let (screen, remaining) = u16::try_parse(value)?;
2301         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2302         let _ = remaining;
2303         Ok(GetDotClocksRequest {
2304             screen,
2305         })
2306     }
2307 }
2308 impl Request for GetDotClocksRequest {
2309     type Reply = GetDotClocksReply;
2310 }
get_dot_clocks<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetDotClocksReply>, ConnectionError> where Conn: RequestConnection + ?Sized,2311 pub fn get_dot_clocks<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetDotClocksReply>, ConnectionError>
2312 where
2313     Conn: RequestConnection + ?Sized,
2314 {
2315     let request0 = GetDotClocksRequest {
2316         screen,
2317     };
2318     request0.send(conn)
2319 }
2320 
2321 #[derive(Debug, Clone, PartialEq, Eq)]
2322 pub struct GetDotClocksReply {
2323     pub sequence: u16,
2324     pub length: u32,
2325     pub flags: u32,
2326     pub clocks: u32,
2327     pub maxclocks: u32,
2328     pub clock: Vec<u32>,
2329 }
2330 impl TryParse for GetDotClocksReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>2331     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2332         let remaining = initial_value;
2333         let (response_type, remaining) = u8::try_parse(remaining)?;
2334         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2335         let (sequence, remaining) = u16::try_parse(remaining)?;
2336         let (length, remaining) = u32::try_parse(remaining)?;
2337         let (flags, remaining) = u32::try_parse(remaining)?;
2338         let (clocks, remaining) = u32::try_parse(remaining)?;
2339         let (maxclocks, remaining) = u32::try_parse(remaining)?;
2340         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
2341         let (clock, remaining) = crate::x11_utils::parse_list::<u32>(remaining, 1u32.checked_sub(flags & 1u32).ok_or(ParseError::InvalidExpression)?.checked_mul(clocks).ok_or(ParseError::InvalidExpression)?.try_to_usize()?)?;
2342         if response_type != 1 {
2343             return Err(ParseError::InvalidValue);
2344         }
2345         let result = GetDotClocksReply { sequence, length, flags, clocks, maxclocks, clock };
2346         let _ = remaining;
2347         let remaining = initial_value.get(32 + length as usize * 4..)
2348             .ok_or(ParseError::InsufficientData)?;
2349         Ok((result, remaining))
2350     }
2351 }
2352 
2353 /// Opcode for the SetClientVersion request
2354 pub const SET_CLIENT_VERSION_REQUEST: u8 = 14;
2355 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2356 pub struct SetClientVersionRequest {
2357     pub major: u16,
2358     pub minor: u16,
2359 }
2360 impl SetClientVersionRequest {
2361     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,2362     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
2363     where
2364         Conn: RequestConnection + ?Sized,
2365     {
2366         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
2367             .ok_or(ConnectionError::UnsupportedExtension)?;
2368         let length_so_far = 0;
2369         let major_bytes = self.major.serialize();
2370         let minor_bytes = self.minor.serialize();
2371         let mut request0 = vec![
2372             extension_information.major_opcode,
2373             SET_CLIENT_VERSION_REQUEST,
2374             0,
2375             0,
2376             major_bytes[0],
2377             major_bytes[1],
2378             minor_bytes[0],
2379             minor_bytes[1],
2380         ];
2381         let length_so_far = length_so_far + request0.len();
2382         assert_eq!(length_so_far % 4, 0);
2383         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2384         request0[2..4].copy_from_slice(&length.to_ne_bytes());
2385         Ok((vec![request0.into()], vec![]))
2386     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,2387     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
2388     where
2389         Conn: RequestConnection + ?Sized,
2390     {
2391         let (bytes, fds) = self.serialize(conn)?;
2392         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
2393         conn.send_request_without_reply(&slices, fds)
2394     }
2395     /// 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>2396     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2397         if header.minor_opcode != SET_CLIENT_VERSION_REQUEST {
2398             return Err(ParseError::InvalidValue);
2399         }
2400         let (major, remaining) = u16::try_parse(value)?;
2401         let (minor, remaining) = u16::try_parse(remaining)?;
2402         let _ = remaining;
2403         Ok(SetClientVersionRequest {
2404             major,
2405             minor,
2406         })
2407     }
2408 }
2409 impl Request for SetClientVersionRequest {
2410     type Reply = ();
2411 }
set_client_version<Conn>(conn: &Conn, major: u16, minor: u16) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,2412 pub fn set_client_version<Conn>(conn: &Conn, major: u16, minor: u16) -> Result<VoidCookie<'_, Conn>, ConnectionError>
2413 where
2414     Conn: RequestConnection + ?Sized,
2415 {
2416     let request0 = SetClientVersionRequest {
2417         major,
2418         minor,
2419     };
2420     request0.send(conn)
2421 }
2422 
2423 /// Opcode for the SetGamma request
2424 pub const SET_GAMMA_REQUEST: u8 = 15;
2425 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2426 pub struct SetGammaRequest {
2427     pub screen: u16,
2428     pub red: u32,
2429     pub green: u32,
2430     pub blue: u32,
2431 }
2432 impl SetGammaRequest {
2433     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,2434     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
2435     where
2436         Conn: RequestConnection + ?Sized,
2437     {
2438         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
2439             .ok_or(ConnectionError::UnsupportedExtension)?;
2440         let length_so_far = 0;
2441         let screen_bytes = self.screen.serialize();
2442         let red_bytes = self.red.serialize();
2443         let green_bytes = self.green.serialize();
2444         let blue_bytes = self.blue.serialize();
2445         let mut request0 = vec![
2446             extension_information.major_opcode,
2447             SET_GAMMA_REQUEST,
2448             0,
2449             0,
2450             screen_bytes[0],
2451             screen_bytes[1],
2452             0,
2453             0,
2454             red_bytes[0],
2455             red_bytes[1],
2456             red_bytes[2],
2457             red_bytes[3],
2458             green_bytes[0],
2459             green_bytes[1],
2460             green_bytes[2],
2461             green_bytes[3],
2462             blue_bytes[0],
2463             blue_bytes[1],
2464             blue_bytes[2],
2465             blue_bytes[3],
2466             0,
2467             0,
2468             0,
2469             0,
2470             0,
2471             0,
2472             0,
2473             0,
2474             0,
2475             0,
2476             0,
2477             0,
2478         ];
2479         let length_so_far = length_so_far + request0.len();
2480         assert_eq!(length_so_far % 4, 0);
2481         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2482         request0[2..4].copy_from_slice(&length.to_ne_bytes());
2483         Ok((vec![request0.into()], vec![]))
2484     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,2485     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
2486     where
2487         Conn: RequestConnection + ?Sized,
2488     {
2489         let (bytes, fds) = self.serialize(conn)?;
2490         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
2491         conn.send_request_without_reply(&slices, fds)
2492     }
2493     /// 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>2494     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2495         if header.minor_opcode != SET_GAMMA_REQUEST {
2496             return Err(ParseError::InvalidValue);
2497         }
2498         let (screen, remaining) = u16::try_parse(value)?;
2499         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2500         let (red, remaining) = u32::try_parse(remaining)?;
2501         let (green, remaining) = u32::try_parse(remaining)?;
2502         let (blue, remaining) = u32::try_parse(remaining)?;
2503         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
2504         let _ = remaining;
2505         Ok(SetGammaRequest {
2506             screen,
2507             red,
2508             green,
2509             blue,
2510         })
2511     }
2512 }
2513 impl Request for SetGammaRequest {
2514     type Reply = ();
2515 }
set_gamma<Conn>(conn: &Conn, screen: u16, red: u32, green: u32, blue: u32) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,2516 pub fn set_gamma<Conn>(conn: &Conn, screen: u16, red: u32, green: u32, blue: u32) -> Result<VoidCookie<'_, Conn>, ConnectionError>
2517 where
2518     Conn: RequestConnection + ?Sized,
2519 {
2520     let request0 = SetGammaRequest {
2521         screen,
2522         red,
2523         green,
2524         blue,
2525     };
2526     request0.send(conn)
2527 }
2528 
2529 /// Opcode for the GetGamma request
2530 pub const GET_GAMMA_REQUEST: u8 = 16;
2531 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2532 pub struct GetGammaRequest {
2533     pub screen: u16,
2534 }
2535 impl GetGammaRequest {
2536     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,2537     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
2538     where
2539         Conn: RequestConnection + ?Sized,
2540     {
2541         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
2542             .ok_or(ConnectionError::UnsupportedExtension)?;
2543         let length_so_far = 0;
2544         let screen_bytes = self.screen.serialize();
2545         let mut request0 = vec![
2546             extension_information.major_opcode,
2547             GET_GAMMA_REQUEST,
2548             0,
2549             0,
2550             screen_bytes[0],
2551             screen_bytes[1],
2552             0,
2553             0,
2554             0,
2555             0,
2556             0,
2557             0,
2558             0,
2559             0,
2560             0,
2561             0,
2562             0,
2563             0,
2564             0,
2565             0,
2566             0,
2567             0,
2568             0,
2569             0,
2570             0,
2571             0,
2572             0,
2573             0,
2574             0,
2575             0,
2576             0,
2577             0,
2578         ];
2579         let length_so_far = length_so_far + request0.len();
2580         assert_eq!(length_so_far % 4, 0);
2581         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2582         request0[2..4].copy_from_slice(&length.to_ne_bytes());
2583         Ok((vec![request0.into()], vec![]))
2584     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetGammaReply>, ConnectionError> where Conn: RequestConnection + ?Sized,2585     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetGammaReply>, ConnectionError>
2586     where
2587         Conn: RequestConnection + ?Sized,
2588     {
2589         let (bytes, fds) = self.serialize(conn)?;
2590         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
2591         conn.send_request_with_reply(&slices, fds)
2592     }
2593     /// 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>2594     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2595         if header.minor_opcode != GET_GAMMA_REQUEST {
2596             return Err(ParseError::InvalidValue);
2597         }
2598         let (screen, remaining) = u16::try_parse(value)?;
2599         let remaining = remaining.get(26..).ok_or(ParseError::InsufficientData)?;
2600         let _ = remaining;
2601         Ok(GetGammaRequest {
2602             screen,
2603         })
2604     }
2605 }
2606 impl Request for GetGammaRequest {
2607     type Reply = GetGammaReply;
2608 }
get_gamma<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetGammaReply>, ConnectionError> where Conn: RequestConnection + ?Sized,2609 pub fn get_gamma<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetGammaReply>, ConnectionError>
2610 where
2611     Conn: RequestConnection + ?Sized,
2612 {
2613     let request0 = GetGammaRequest {
2614         screen,
2615     };
2616     request0.send(conn)
2617 }
2618 
2619 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2620 pub struct GetGammaReply {
2621     pub sequence: u16,
2622     pub length: u32,
2623     pub red: u32,
2624     pub green: u32,
2625     pub blue: u32,
2626 }
2627 impl TryParse for GetGammaReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>2628     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2629         let remaining = initial_value;
2630         let (response_type, remaining) = u8::try_parse(remaining)?;
2631         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2632         let (sequence, remaining) = u16::try_parse(remaining)?;
2633         let (length, remaining) = u32::try_parse(remaining)?;
2634         let (red, remaining) = u32::try_parse(remaining)?;
2635         let (green, remaining) = u32::try_parse(remaining)?;
2636         let (blue, remaining) = u32::try_parse(remaining)?;
2637         let remaining = remaining.get(12..).ok_or(ParseError::InsufficientData)?;
2638         if response_type != 1 {
2639             return Err(ParseError::InvalidValue);
2640         }
2641         let result = GetGammaReply { sequence, length, red, green, blue };
2642         let _ = remaining;
2643         let remaining = initial_value.get(32 + length as usize * 4..)
2644             .ok_or(ParseError::InsufficientData)?;
2645         Ok((result, remaining))
2646     }
2647 }
2648 
2649 /// Opcode for the GetGammaRamp request
2650 pub const GET_GAMMA_RAMP_REQUEST: u8 = 17;
2651 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2652 pub struct GetGammaRampRequest {
2653     pub screen: u16,
2654     pub size: u16,
2655 }
2656 impl GetGammaRampRequest {
2657     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,2658     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
2659     where
2660         Conn: RequestConnection + ?Sized,
2661     {
2662         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
2663             .ok_or(ConnectionError::UnsupportedExtension)?;
2664         let length_so_far = 0;
2665         let screen_bytes = self.screen.serialize();
2666         let size_bytes = self.size.serialize();
2667         let mut request0 = vec![
2668             extension_information.major_opcode,
2669             GET_GAMMA_RAMP_REQUEST,
2670             0,
2671             0,
2672             screen_bytes[0],
2673             screen_bytes[1],
2674             size_bytes[0],
2675             size_bytes[1],
2676         ];
2677         let length_so_far = length_so_far + request0.len();
2678         assert_eq!(length_so_far % 4, 0);
2679         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2680         request0[2..4].copy_from_slice(&length.to_ne_bytes());
2681         Ok((vec![request0.into()], vec![]))
2682     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetGammaRampReply>, ConnectionError> where Conn: RequestConnection + ?Sized,2683     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetGammaRampReply>, ConnectionError>
2684     where
2685         Conn: RequestConnection + ?Sized,
2686     {
2687         let (bytes, fds) = self.serialize(conn)?;
2688         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
2689         conn.send_request_with_reply(&slices, fds)
2690     }
2691     /// 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>2692     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2693         if header.minor_opcode != GET_GAMMA_RAMP_REQUEST {
2694             return Err(ParseError::InvalidValue);
2695         }
2696         let (screen, remaining) = u16::try_parse(value)?;
2697         let (size, remaining) = u16::try_parse(remaining)?;
2698         let _ = remaining;
2699         Ok(GetGammaRampRequest {
2700             screen,
2701             size,
2702         })
2703     }
2704 }
2705 impl Request for GetGammaRampRequest {
2706     type Reply = GetGammaRampReply;
2707 }
get_gamma_ramp<Conn>(conn: &Conn, screen: u16, size: u16) -> Result<Cookie<'_, Conn, GetGammaRampReply>, ConnectionError> where Conn: RequestConnection + ?Sized,2708 pub fn get_gamma_ramp<Conn>(conn: &Conn, screen: u16, size: u16) -> Result<Cookie<'_, Conn, GetGammaRampReply>, ConnectionError>
2709 where
2710     Conn: RequestConnection + ?Sized,
2711 {
2712     let request0 = GetGammaRampRequest {
2713         screen,
2714         size,
2715     };
2716     request0.send(conn)
2717 }
2718 
2719 #[derive(Debug, Clone, PartialEq, Eq)]
2720 pub struct GetGammaRampReply {
2721     pub sequence: u16,
2722     pub length: u32,
2723     pub size: u16,
2724     pub red: Vec<u16>,
2725     pub green: Vec<u16>,
2726     pub blue: Vec<u16>,
2727 }
2728 impl TryParse for GetGammaRampReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>2729     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2730         let remaining = initial_value;
2731         let (response_type, remaining) = u8::try_parse(remaining)?;
2732         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2733         let (sequence, remaining) = u16::try_parse(remaining)?;
2734         let (length, remaining) = u32::try_parse(remaining)?;
2735         let (size, remaining) = u16::try_parse(remaining)?;
2736         let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?;
2737         let (red, remaining) = crate::x11_utils::parse_list::<u16>(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?;
2738         let (green, remaining) = crate::x11_utils::parse_list::<u16>(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?;
2739         let (blue, remaining) = crate::x11_utils::parse_list::<u16>(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?;
2740         if response_type != 1 {
2741             return Err(ParseError::InvalidValue);
2742         }
2743         let result = GetGammaRampReply { sequence, length, size, red, green, blue };
2744         let _ = remaining;
2745         let remaining = initial_value.get(32 + length as usize * 4..)
2746             .ok_or(ParseError::InsufficientData)?;
2747         Ok((result, remaining))
2748     }
2749 }
2750 
2751 /// Opcode for the SetGammaRamp request
2752 pub const SET_GAMMA_RAMP_REQUEST: u8 = 18;
2753 #[derive(Debug, Clone, PartialEq, Eq)]
2754 pub struct SetGammaRampRequest<'input> {
2755     pub screen: u16,
2756     pub size: u16,
2757     pub red: Cow<'input, [u16]>,
2758     pub green: Cow<'input, [u16]>,
2759     pub blue: Cow<'input, [u16]>,
2760 }
2761 impl<'input> SetGammaRampRequest<'input> {
2762     /// Serialize this request into bytes for the provided connection
serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,2763     fn serialize<Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
2764     where
2765         Conn: RequestConnection + ?Sized,
2766     {
2767         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
2768             .ok_or(ConnectionError::UnsupportedExtension)?;
2769         let length_so_far = 0;
2770         let screen_bytes = self.screen.serialize();
2771         let size_bytes = self.size.serialize();
2772         let mut request0 = vec![
2773             extension_information.major_opcode,
2774             SET_GAMMA_RAMP_REQUEST,
2775             0,
2776             0,
2777             screen_bytes[0],
2778             screen_bytes[1],
2779             size_bytes[0],
2780             size_bytes[1],
2781         ];
2782         let length_so_far = length_so_far + request0.len();
2783         assert_eq!(self.red.len(), usize::try_from(u32::from(self.size).checked_add(1u32).unwrap() & (!1u32)).unwrap(), "`red` has an incorrect length");
2784         let red_bytes = self.red.serialize();
2785         let length_so_far = length_so_far + red_bytes.len();
2786         assert_eq!(self.green.len(), usize::try_from(u32::from(self.size).checked_add(1u32).unwrap() & (!1u32)).unwrap(), "`green` has an incorrect length");
2787         let green_bytes = self.green.serialize();
2788         let length_so_far = length_so_far + green_bytes.len();
2789         assert_eq!(self.blue.len(), usize::try_from(u32::from(self.size).checked_add(1u32).unwrap() & (!1u32)).unwrap(), "`blue` has an incorrect length");
2790         let blue_bytes = self.blue.serialize();
2791         let length_so_far = length_so_far + blue_bytes.len();
2792         let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
2793         let length_so_far = length_so_far + padding0.len();
2794         assert_eq!(length_so_far % 4, 0);
2795         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2796         request0[2..4].copy_from_slice(&length.to_ne_bytes());
2797         Ok((vec![request0.into(), red_bytes.into(), green_bytes.into(), blue_bytes.into(), padding0.into()], vec![]))
2798     }
send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,2799     pub fn send<Conn>(self, conn: &Conn) -> Result<VoidCookie<'_, Conn>, ConnectionError>
2800     where
2801         Conn: RequestConnection + ?Sized,
2802     {
2803         let (bytes, fds) = self.serialize(conn)?;
2804         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
2805         conn.send_request_without_reply(&slices, fds)
2806     }
2807     /// Parse this request given its header, its body, and any fds that go along with it
try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError>2808     pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
2809         if header.minor_opcode != SET_GAMMA_RAMP_REQUEST {
2810             return Err(ParseError::InvalidValue);
2811         }
2812         let (screen, remaining) = u16::try_parse(value)?;
2813         let (size, remaining) = u16::try_parse(remaining)?;
2814         let (red, remaining) = crate::x11_utils::parse_list::<u16>(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?;
2815         let (green, remaining) = crate::x11_utils::parse_list::<u16>(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?;
2816         let (blue, remaining) = crate::x11_utils::parse_list::<u16>(remaining, (u32::from(size).checked_add(1u32).ok_or(ParseError::InvalidExpression)? & (!1u32)).try_to_usize()?)?;
2817         let _ = remaining;
2818         Ok(SetGammaRampRequest {
2819             screen,
2820             size,
2821             red: Cow::Owned(red),
2822             green: Cow::Owned(green),
2823             blue: Cow::Owned(blue),
2824         })
2825     }
2826     /// Clone all borrowed data in this SetGammaRampRequest.
into_owned(self) -> SetGammaRampRequest<'static>2827     pub fn into_owned(self) -> SetGammaRampRequest<'static> {
2828         SetGammaRampRequest {
2829             screen: self.screen,
2830             size: self.size,
2831             red: Cow::Owned(self.red.into_owned()),
2832             green: Cow::Owned(self.green.into_owned()),
2833             blue: Cow::Owned(self.blue.into_owned()),
2834         }
2835     }
2836 }
2837 impl<'input> Request for SetGammaRampRequest<'input> {
2838     type Reply = ();
2839 }
set_gamma_ramp<'c, 'input, Conn>(conn: &'c Conn, screen: u16, size: u16, red: &'input [u16], green: &'input [u16], blue: &'input [u16]) -> Result<VoidCookie<'c, Conn>, ConnectionError> where Conn: RequestConnection + ?Sized,2840 pub fn set_gamma_ramp<'c, 'input, Conn>(conn: &'c Conn, screen: u16, size: u16, red: &'input [u16], green: &'input [u16], blue: &'input [u16]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
2841 where
2842     Conn: RequestConnection + ?Sized,
2843 {
2844     let request0 = SetGammaRampRequest {
2845         screen,
2846         size,
2847         red: Cow::Borrowed(red),
2848         green: Cow::Borrowed(green),
2849         blue: Cow::Borrowed(blue),
2850     };
2851     request0.send(conn)
2852 }
2853 
2854 /// Opcode for the GetGammaRampSize request
2855 pub const GET_GAMMA_RAMP_SIZE_REQUEST: u8 = 19;
2856 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2857 pub struct GetGammaRampSizeRequest {
2858     pub screen: u16,
2859 }
2860 impl GetGammaRampSizeRequest {
2861     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,2862     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
2863     where
2864         Conn: RequestConnection + ?Sized,
2865     {
2866         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
2867             .ok_or(ConnectionError::UnsupportedExtension)?;
2868         let length_so_far = 0;
2869         let screen_bytes = self.screen.serialize();
2870         let mut request0 = vec![
2871             extension_information.major_opcode,
2872             GET_GAMMA_RAMP_SIZE_REQUEST,
2873             0,
2874             0,
2875             screen_bytes[0],
2876             screen_bytes[1],
2877             0,
2878             0,
2879         ];
2880         let length_so_far = length_so_far + request0.len();
2881         assert_eq!(length_so_far % 4, 0);
2882         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2883         request0[2..4].copy_from_slice(&length.to_ne_bytes());
2884         Ok((vec![request0.into()], vec![]))
2885     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetGammaRampSizeReply>, ConnectionError> where Conn: RequestConnection + ?Sized,2886     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetGammaRampSizeReply>, ConnectionError>
2887     where
2888         Conn: RequestConnection + ?Sized,
2889     {
2890         let (bytes, fds) = self.serialize(conn)?;
2891         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
2892         conn.send_request_with_reply(&slices, fds)
2893     }
2894     /// 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>2895     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2896         if header.minor_opcode != GET_GAMMA_RAMP_SIZE_REQUEST {
2897             return Err(ParseError::InvalidValue);
2898         }
2899         let (screen, remaining) = u16::try_parse(value)?;
2900         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2901         let _ = remaining;
2902         Ok(GetGammaRampSizeRequest {
2903             screen,
2904         })
2905     }
2906 }
2907 impl Request for GetGammaRampSizeRequest {
2908     type Reply = GetGammaRampSizeReply;
2909 }
get_gamma_ramp_size<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetGammaRampSizeReply>, ConnectionError> where Conn: RequestConnection + ?Sized,2910 pub fn get_gamma_ramp_size<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetGammaRampSizeReply>, ConnectionError>
2911 where
2912     Conn: RequestConnection + ?Sized,
2913 {
2914     let request0 = GetGammaRampSizeRequest {
2915         screen,
2916     };
2917     request0.send(conn)
2918 }
2919 
2920 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2921 pub struct GetGammaRampSizeReply {
2922     pub sequence: u16,
2923     pub length: u32,
2924     pub size: u16,
2925 }
2926 impl TryParse for GetGammaRampSizeReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>2927     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2928         let remaining = initial_value;
2929         let (response_type, remaining) = u8::try_parse(remaining)?;
2930         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2931         let (sequence, remaining) = u16::try_parse(remaining)?;
2932         let (length, remaining) = u32::try_parse(remaining)?;
2933         let (size, remaining) = u16::try_parse(remaining)?;
2934         let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?;
2935         if response_type != 1 {
2936             return Err(ParseError::InvalidValue);
2937         }
2938         let result = GetGammaRampSizeReply { sequence, length, size };
2939         let _ = remaining;
2940         let remaining = initial_value.get(32 + length as usize * 4..)
2941             .ok_or(ParseError::InsufficientData)?;
2942         Ok((result, remaining))
2943     }
2944 }
2945 
2946 /// Opcode for the GetPermissions request
2947 pub const GET_PERMISSIONS_REQUEST: u8 = 20;
2948 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
2949 pub struct GetPermissionsRequest {
2950     pub screen: u16,
2951 }
2952 impl GetPermissionsRequest {
2953     /// Serialize this request into bytes for the provided connection
serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError> where Conn: RequestConnection + ?Sized,2954     fn serialize<'input, Conn>(self, conn: &Conn) -> Result<BufWithFds<PiecewiseBuf<'input>>, ConnectionError>
2955     where
2956         Conn: RequestConnection + ?Sized,
2957     {
2958         let extension_information = conn.extension_information(X11_EXTENSION_NAME)?
2959             .ok_or(ConnectionError::UnsupportedExtension)?;
2960         let length_so_far = 0;
2961         let screen_bytes = self.screen.serialize();
2962         let mut request0 = vec![
2963             extension_information.major_opcode,
2964             GET_PERMISSIONS_REQUEST,
2965             0,
2966             0,
2967             screen_bytes[0],
2968             screen_bytes[1],
2969             0,
2970             0,
2971         ];
2972         let length_so_far = length_so_far + request0.len();
2973         assert_eq!(length_so_far % 4, 0);
2974         let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2975         request0[2..4].copy_from_slice(&length.to_ne_bytes());
2976         Ok((vec![request0.into()], vec![]))
2977     }
send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetPermissionsReply>, ConnectionError> where Conn: RequestConnection + ?Sized,2978     pub fn send<Conn>(self, conn: &Conn) -> Result<Cookie<'_, Conn, GetPermissionsReply>, ConnectionError>
2979     where
2980         Conn: RequestConnection + ?Sized,
2981     {
2982         let (bytes, fds) = self.serialize(conn)?;
2983         let slices = bytes.iter().map(|b| IoSlice::new(&*b)).collect::<Vec<_>>();
2984         conn.send_request_with_reply(&slices, fds)
2985     }
2986     /// 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>2987     pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2988         if header.minor_opcode != GET_PERMISSIONS_REQUEST {
2989             return Err(ParseError::InvalidValue);
2990         }
2991         let (screen, remaining) = u16::try_parse(value)?;
2992         let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
2993         let _ = remaining;
2994         Ok(GetPermissionsRequest {
2995             screen,
2996         })
2997     }
2998 }
2999 impl Request for GetPermissionsRequest {
3000     type Reply = GetPermissionsReply;
3001 }
get_permissions<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetPermissionsReply>, ConnectionError> where Conn: RequestConnection + ?Sized,3002 pub fn get_permissions<Conn>(conn: &Conn, screen: u16) -> Result<Cookie<'_, Conn, GetPermissionsReply>, ConnectionError>
3003 where
3004     Conn: RequestConnection + ?Sized,
3005 {
3006     let request0 = GetPermissionsRequest {
3007         screen,
3008     };
3009     request0.send(conn)
3010 }
3011 
3012 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
3013 pub struct GetPermissionsReply {
3014     pub sequence: u16,
3015     pub length: u32,
3016     pub permissions: u32,
3017 }
3018 impl TryParse for GetPermissionsReply {
try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError>3019     fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
3020         let remaining = initial_value;
3021         let (response_type, remaining) = u8::try_parse(remaining)?;
3022         let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
3023         let (sequence, remaining) = u16::try_parse(remaining)?;
3024         let (length, remaining) = u32::try_parse(remaining)?;
3025         let (permissions, remaining) = u32::try_parse(remaining)?;
3026         let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
3027         if response_type != 1 {
3028             return Err(ParseError::InvalidValue);
3029         }
3030         let result = GetPermissionsReply { sequence, length, permissions };
3031         let _ = remaining;
3032         let remaining = initial_value.get(32 + length as usize * 4..)
3033             .ok_or(ParseError::InsufficientData)?;
3034         Ok((result, remaining))
3035     }
3036 }
3037 
3038 /// Opcode for the BadClock error
3039 pub const BAD_CLOCK_ERROR: u8 = 0;
3040 
3041 /// Opcode for the BadHTimings error
3042 pub const BAD_H_TIMINGS_ERROR: u8 = 1;
3043 
3044 /// Opcode for the BadVTimings error
3045 pub const BAD_V_TIMINGS_ERROR: u8 = 2;
3046 
3047 /// Opcode for the ModeUnsuitable error
3048 pub const MODE_UNSUITABLE_ERROR: u8 = 3;
3049 
3050 /// Opcode for the ExtensionDisabled error
3051 pub const EXTENSION_DISABLED_ERROR: u8 = 4;
3052 
3053 /// Opcode for the ClientNotLocal error
3054 pub const CLIENT_NOT_LOCAL_ERROR: u8 = 5;
3055 
3056 /// Opcode for the ZoomLocked error
3057 pub const ZOOM_LOCKED_ERROR: u8 = 6;
3058 
3059 /// Extension trait defining the requests of this extension.
3060 pub trait ConnectionExt: RequestConnection {
xf86vidmode_query_version(&self) -> Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>3061     fn xf86vidmode_query_version(&self) -> Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>
3062     {
3063         query_version(self)
3064     }
xf86vidmode_get_mode_line(&self, screen: u16) -> Result<Cookie<'_, Self, GetModeLineReply>, ConnectionError>3065     fn xf86vidmode_get_mode_line(&self, screen: u16) -> Result<Cookie<'_, Self, GetModeLineReply>, ConnectionError>
3066     {
3067         get_mode_line(self, screen)
3068     }
xf86vidmode_mod_mode_line<'c, 'input, A>(&'c self, screen: u32, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Self>, ConnectionError> where A: Into<u32>,3069     fn xf86vidmode_mod_mode_line<'c, 'input, A>(&'c self, screen: u32, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Self>, ConnectionError>
3070     where
3071         A: Into<u32>,
3072     {
3073         mod_mode_line(self, screen, hdisplay, hsyncstart, hsyncend, htotal, hskew, vdisplay, vsyncstart, vsyncend, vtotal, flags, private)
3074     }
xf86vidmode_switch_mode(&self, screen: u16, zoom: u16) -> Result<VoidCookie<'_, Self>, ConnectionError>3075     fn xf86vidmode_switch_mode(&self, screen: u16, zoom: u16) -> Result<VoidCookie<'_, Self>, ConnectionError>
3076     {
3077         switch_mode(self, screen, zoom)
3078     }
xf86vidmode_get_monitor(&self, screen: u16) -> Result<Cookie<'_, Self, GetMonitorReply>, ConnectionError>3079     fn xf86vidmode_get_monitor(&self, screen: u16) -> Result<Cookie<'_, Self, GetMonitorReply>, ConnectionError>
3080     {
3081         get_monitor(self, screen)
3082     }
xf86vidmode_lock_mode_switch(&self, screen: u16, lock: u16) -> Result<VoidCookie<'_, Self>, ConnectionError>3083     fn xf86vidmode_lock_mode_switch(&self, screen: u16, lock: u16) -> Result<VoidCookie<'_, Self>, ConnectionError>
3084     {
3085         lock_mode_switch(self, screen, lock)
3086     }
xf86vidmode_get_all_mode_lines(&self, screen: u16) -> Result<Cookie<'_, Self, GetAllModeLinesReply>, ConnectionError>3087     fn xf86vidmode_get_all_mode_lines(&self, screen: u16) -> Result<Cookie<'_, Self, GetAllModeLinesReply>, ConnectionError>
3088     {
3089         get_all_mode_lines(self, screen)
3090     }
xf86vidmode_add_mode_line<'c, 'input, A, B>(&'c self, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, after_dotclock: Dotclock, after_hdisplay: u16, after_hsyncstart: u16, after_hsyncend: u16, after_htotal: u16, after_hskew: u16, after_vdisplay: u16, after_vsyncstart: u16, after_vsyncend: u16, after_vtotal: u16, after_flags: B, private: &'input [u8]) -> Result<VoidCookie<'c, Self>, ConnectionError> where A: Into<u32>, B: Into<u32>,3091     fn xf86vidmode_add_mode_line<'c, 'input, A, B>(&'c self, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, after_dotclock: Dotclock, after_hdisplay: u16, after_hsyncstart: u16, after_hsyncend: u16, after_htotal: u16, after_hskew: u16, after_vdisplay: u16, after_vsyncstart: u16, after_vsyncend: u16, after_vtotal: u16, after_flags: B, private: &'input [u8]) -> Result<VoidCookie<'c, Self>, ConnectionError>
3092     where
3093         A: Into<u32>,
3094         B: Into<u32>,
3095     {
3096         add_mode_line(self, screen, dotclock, hdisplay, hsyncstart, hsyncend, htotal, hskew, vdisplay, vsyncstart, vsyncend, vtotal, flags, after_dotclock, after_hdisplay, after_hsyncstart, after_hsyncend, after_htotal, after_hskew, after_vdisplay, after_vsyncstart, after_vsyncend, after_vtotal, after_flags, private)
3097     }
xf86vidmode_delete_mode_line<'c, 'input, A>(&'c self, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Self>, ConnectionError> where A: Into<u32>,3098     fn xf86vidmode_delete_mode_line<'c, 'input, A>(&'c self, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Self>, ConnectionError>
3099     where
3100         A: Into<u32>,
3101     {
3102         delete_mode_line(self, screen, dotclock, hdisplay, hsyncstart, hsyncend, htotal, hskew, vdisplay, vsyncstart, vsyncend, vtotal, flags, private)
3103     }
xf86vidmode_validate_mode_line<'c, 'input, A>(&'c self, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<Cookie<'c, Self, ValidateModeLineReply>, ConnectionError> where A: Into<u32>,3104     fn xf86vidmode_validate_mode_line<'c, 'input, A>(&'c self, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<Cookie<'c, Self, ValidateModeLineReply>, ConnectionError>
3105     where
3106         A: Into<u32>,
3107     {
3108         validate_mode_line(self, screen, dotclock, hdisplay, hsyncstart, hsyncend, htotal, hskew, vdisplay, vsyncstart, vsyncend, vtotal, flags, private)
3109     }
xf86vidmode_switch_to_mode<'c, 'input, A>(&'c self, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Self>, ConnectionError> where A: Into<u32>,3110     fn xf86vidmode_switch_to_mode<'c, 'input, A>(&'c self, screen: u32, dotclock: Dotclock, hdisplay: u16, hsyncstart: u16, hsyncend: u16, htotal: u16, hskew: u16, vdisplay: u16, vsyncstart: u16, vsyncend: u16, vtotal: u16, flags: A, private: &'input [u8]) -> Result<VoidCookie<'c, Self>, ConnectionError>
3111     where
3112         A: Into<u32>,
3113     {
3114         switch_to_mode(self, screen, dotclock, hdisplay, hsyncstart, hsyncend, htotal, hskew, vdisplay, vsyncstart, vsyncend, vtotal, flags, private)
3115     }
xf86vidmode_get_view_port(&self, screen: u16) -> Result<Cookie<'_, Self, GetViewPortReply>, ConnectionError>3116     fn xf86vidmode_get_view_port(&self, screen: u16) -> Result<Cookie<'_, Self, GetViewPortReply>, ConnectionError>
3117     {
3118         get_view_port(self, screen)
3119     }
xf86vidmode_set_view_port(&self, screen: u16, x: u32, y: u32) -> Result<VoidCookie<'_, Self>, ConnectionError>3120     fn xf86vidmode_set_view_port(&self, screen: u16, x: u32, y: u32) -> Result<VoidCookie<'_, Self>, ConnectionError>
3121     {
3122         set_view_port(self, screen, x, y)
3123     }
xf86vidmode_get_dot_clocks(&self, screen: u16) -> Result<Cookie<'_, Self, GetDotClocksReply>, ConnectionError>3124     fn xf86vidmode_get_dot_clocks(&self, screen: u16) -> Result<Cookie<'_, Self, GetDotClocksReply>, ConnectionError>
3125     {
3126         get_dot_clocks(self, screen)
3127     }
xf86vidmode_set_client_version(&self, major: u16, minor: u16) -> Result<VoidCookie<'_, Self>, ConnectionError>3128     fn xf86vidmode_set_client_version(&self, major: u16, minor: u16) -> Result<VoidCookie<'_, Self>, ConnectionError>
3129     {
3130         set_client_version(self, major, minor)
3131     }
xf86vidmode_set_gamma(&self, screen: u16, red: u32, green: u32, blue: u32) -> Result<VoidCookie<'_, Self>, ConnectionError>3132     fn xf86vidmode_set_gamma(&self, screen: u16, red: u32, green: u32, blue: u32) -> Result<VoidCookie<'_, Self>, ConnectionError>
3133     {
3134         set_gamma(self, screen, red, green, blue)
3135     }
xf86vidmode_get_gamma(&self, screen: u16) -> Result<Cookie<'_, Self, GetGammaReply>, ConnectionError>3136     fn xf86vidmode_get_gamma(&self, screen: u16) -> Result<Cookie<'_, Self, GetGammaReply>, ConnectionError>
3137     {
3138         get_gamma(self, screen)
3139     }
xf86vidmode_get_gamma_ramp(&self, screen: u16, size: u16) -> Result<Cookie<'_, Self, GetGammaRampReply>, ConnectionError>3140     fn xf86vidmode_get_gamma_ramp(&self, screen: u16, size: u16) -> Result<Cookie<'_, Self, GetGammaRampReply>, ConnectionError>
3141     {
3142         get_gamma_ramp(self, screen, size)
3143     }
xf86vidmode_set_gamma_ramp<'c, 'input>(&'c self, screen: u16, size: u16, red: &'input [u16], green: &'input [u16], blue: &'input [u16]) -> Result<VoidCookie<'c, Self>, ConnectionError>3144     fn xf86vidmode_set_gamma_ramp<'c, 'input>(&'c self, screen: u16, size: u16, red: &'input [u16], green: &'input [u16], blue: &'input [u16]) -> Result<VoidCookie<'c, Self>, ConnectionError>
3145     {
3146         set_gamma_ramp(self, screen, size, red, green, blue)
3147     }
xf86vidmode_get_gamma_ramp_size(&self, screen: u16) -> Result<Cookie<'_, Self, GetGammaRampSizeReply>, ConnectionError>3148     fn xf86vidmode_get_gamma_ramp_size(&self, screen: u16) -> Result<Cookie<'_, Self, GetGammaRampSizeReply>, ConnectionError>
3149     {
3150         get_gamma_ramp_size(self, screen)
3151     }
xf86vidmode_get_permissions(&self, screen: u16) -> Result<Cookie<'_, Self, GetPermissionsReply>, ConnectionError>3152     fn xf86vidmode_get_permissions(&self, screen: u16) -> Result<Cookie<'_, Self, GetPermissionsReply>, ConnectionError>
3153     {
3154         get_permissions(self, screen)
3155     }
3156 }
3157 
3158 impl<C: RequestConnection + ?Sized> ConnectionExt for C {}
3159