x11rb_protocol/protocol/
xselinux.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `SELinux` X11 extension.
5
6#![allow(clippy::too_many_arguments)]
7// The code generator is simpler if it can always use conversions
8#![allow(clippy::useless_conversion)]
9
10#[allow(unused_imports)]
11use alloc::borrow::Cow;
12#[allow(unused_imports)]
13use core::convert::TryInto;
14use alloc::vec;
15use alloc::vec::Vec;
16use core::convert::TryFrom;
17use crate::errors::ParseError;
18#[allow(unused_imports)]
19use crate::x11_utils::TryIntoUSize;
20use crate::BufWithFds;
21#[allow(unused_imports)]
22use crate::utils::{RawFdContainer, pretty_print_bitmask, pretty_print_enum};
23#[allow(unused_imports)]
24use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd};
25#[allow(unused_imports)]
26use super::xproto;
27
28/// The X11 name of the extension for QueryExtension
29pub const X11_EXTENSION_NAME: &str = "SELinux";
30
31/// The version number of this extension that this client library supports.
32///
33/// This constant contains the version number of this extension that is supported
34/// by this build of x11rb. For most things, it does not make sense to use this
35/// information. If you need to send a `QueryVersion`, it is recommended to instead
36/// send the maximum version of the extension that you need.
37pub const X11_XML_VERSION: (u32, u32) = (1, 0);
38
39/// Opcode for the QueryVersion request
40pub const QUERY_VERSION_REQUEST: u8 = 0;
41#[derive(Clone, Copy, Default)]
42#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
43#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
44pub struct QueryVersionRequest {
45    pub client_major: u8,
46    pub client_minor: u8,
47}
48impl_debug_if_no_extra_traits!(QueryVersionRequest, "QueryVersionRequest");
49impl QueryVersionRequest {
50    /// Serialize this request into bytes for the provided connection
51    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
52        let length_so_far = 0;
53        let client_major_bytes = self.client_major.serialize();
54        let client_minor_bytes = self.client_minor.serialize();
55        let mut request0 = vec![
56            major_opcode,
57            QUERY_VERSION_REQUEST,
58            0,
59            0,
60            client_major_bytes[0],
61            client_minor_bytes[0],
62            0,
63            0,
64        ];
65        let length_so_far = length_so_far + request0.len();
66        assert_eq!(length_so_far % 4, 0);
67        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
68        request0[2..4].copy_from_slice(&length.to_ne_bytes());
69        ([request0.into()], vec![])
70    }
71    /// Parse this request given its header, its body, and any fds that go along with it
72    #[cfg(feature = "request-parsing")]
73    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
74        if header.minor_opcode != QUERY_VERSION_REQUEST {
75            return Err(ParseError::InvalidValue);
76        }
77        let (client_major, remaining) = u8::try_parse(value)?;
78        let (client_minor, remaining) = u8::try_parse(remaining)?;
79        let _ = remaining;
80        Ok(QueryVersionRequest {
81            client_major,
82            client_minor,
83        })
84    }
85}
86impl Request for QueryVersionRequest {
87    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
88
89    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
90        let (bufs, fds) = self.serialize(major_opcode);
91        // Flatten the buffers into a single vector
92        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
93        (buf, fds)
94    }
95}
96impl crate::x11_utils::ReplyRequest for QueryVersionRequest {
97    type Reply = QueryVersionReply;
98}
99
100#[derive(Clone, Copy, Default)]
101#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
102#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
103pub struct QueryVersionReply {
104    pub sequence: u16,
105    pub length: u32,
106    pub server_major: u16,
107    pub server_minor: u16,
108}
109impl_debug_if_no_extra_traits!(QueryVersionReply, "QueryVersionReply");
110impl TryParse for QueryVersionReply {
111    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
112        let remaining = initial_value;
113        let (response_type, remaining) = u8::try_parse(remaining)?;
114        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
115        let (sequence, remaining) = u16::try_parse(remaining)?;
116        let (length, remaining) = u32::try_parse(remaining)?;
117        let (server_major, remaining) = u16::try_parse(remaining)?;
118        let (server_minor, remaining) = u16::try_parse(remaining)?;
119        if response_type != 1 {
120            return Err(ParseError::InvalidValue);
121        }
122        let result = QueryVersionReply { sequence, length, server_major, server_minor };
123        let _ = remaining;
124        let remaining = initial_value.get(32 + length as usize * 4..)
125            .ok_or(ParseError::InsufficientData)?;
126        Ok((result, remaining))
127    }
128}
129impl Serialize for QueryVersionReply {
130    type Bytes = [u8; 12];
131    fn serialize(&self) -> [u8; 12] {
132        let response_type_bytes = &[1];
133        let sequence_bytes = self.sequence.serialize();
134        let length_bytes = self.length.serialize();
135        let server_major_bytes = self.server_major.serialize();
136        let server_minor_bytes = self.server_minor.serialize();
137        [
138            response_type_bytes[0],
139            0,
140            sequence_bytes[0],
141            sequence_bytes[1],
142            length_bytes[0],
143            length_bytes[1],
144            length_bytes[2],
145            length_bytes[3],
146            server_major_bytes[0],
147            server_major_bytes[1],
148            server_minor_bytes[0],
149            server_minor_bytes[1],
150        ]
151    }
152    fn serialize_into(&self, bytes: &mut Vec<u8>) {
153        bytes.reserve(12);
154        let response_type_bytes = &[1];
155        bytes.push(response_type_bytes[0]);
156        bytes.extend_from_slice(&[0; 1]);
157        self.sequence.serialize_into(bytes);
158        self.length.serialize_into(bytes);
159        self.server_major.serialize_into(bytes);
160        self.server_minor.serialize_into(bytes);
161    }
162}
163
164/// Opcode for the SetDeviceCreateContext request
165pub const SET_DEVICE_CREATE_CONTEXT_REQUEST: u8 = 1;
166#[derive(Clone, Default)]
167#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
168#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
169pub struct SetDeviceCreateContextRequest<'input> {
170    pub context: Cow<'input, [u8]>,
171}
172impl_debug_if_no_extra_traits!(SetDeviceCreateContextRequest<'_>, "SetDeviceCreateContextRequest");
173impl<'input> SetDeviceCreateContextRequest<'input> {
174    /// Serialize this request into bytes for the provided connection
175    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
176        let length_so_far = 0;
177        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
178        let context_len_bytes = context_len.serialize();
179        let mut request0 = vec![
180            major_opcode,
181            SET_DEVICE_CREATE_CONTEXT_REQUEST,
182            0,
183            0,
184            context_len_bytes[0],
185            context_len_bytes[1],
186            context_len_bytes[2],
187            context_len_bytes[3],
188        ];
189        let length_so_far = length_so_far + request0.len();
190        let length_so_far = length_so_far + self.context.len();
191        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
192        let length_so_far = length_so_far + padding0.len();
193        assert_eq!(length_so_far % 4, 0);
194        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
195        request0[2..4].copy_from_slice(&length.to_ne_bytes());
196        ([request0.into(), self.context, padding0.into()], vec![])
197    }
198    /// Parse this request given its header, its body, and any fds that go along with it
199    #[cfg(feature = "request-parsing")]
200    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
201        if header.minor_opcode != SET_DEVICE_CREATE_CONTEXT_REQUEST {
202            return Err(ParseError::InvalidValue);
203        }
204        let (context_len, remaining) = u32::try_parse(value)?;
205        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
206        let _ = remaining;
207        Ok(SetDeviceCreateContextRequest {
208            context: Cow::Borrowed(context),
209        })
210    }
211    /// Clone all borrowed data in this SetDeviceCreateContextRequest.
212    pub fn into_owned(self) -> SetDeviceCreateContextRequest<'static> {
213        SetDeviceCreateContextRequest {
214            context: Cow::Owned(self.context.into_owned()),
215        }
216    }
217}
218impl<'input> Request for SetDeviceCreateContextRequest<'input> {
219    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
220
221    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
222        let (bufs, fds) = self.serialize(major_opcode);
223        // Flatten the buffers into a single vector
224        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
225        (buf, fds)
226    }
227}
228impl<'input> crate::x11_utils::VoidRequest for SetDeviceCreateContextRequest<'input> {
229}
230
231/// Opcode for the GetDeviceCreateContext request
232pub const GET_DEVICE_CREATE_CONTEXT_REQUEST: u8 = 2;
233#[derive(Clone, Copy, Default)]
234#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
235#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
236pub struct GetDeviceCreateContextRequest;
237impl_debug_if_no_extra_traits!(GetDeviceCreateContextRequest, "GetDeviceCreateContextRequest");
238impl GetDeviceCreateContextRequest {
239    /// Serialize this request into bytes for the provided connection
240    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
241        let length_so_far = 0;
242        let mut request0 = vec![
243            major_opcode,
244            GET_DEVICE_CREATE_CONTEXT_REQUEST,
245            0,
246            0,
247        ];
248        let length_so_far = length_so_far + request0.len();
249        assert_eq!(length_so_far % 4, 0);
250        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
251        request0[2..4].copy_from_slice(&length.to_ne_bytes());
252        ([request0.into()], vec![])
253    }
254    /// Parse this request given its header, its body, and any fds that go along with it
255    #[cfg(feature = "request-parsing")]
256    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
257        if header.minor_opcode != GET_DEVICE_CREATE_CONTEXT_REQUEST {
258            return Err(ParseError::InvalidValue);
259        }
260        let _ = value;
261        Ok(GetDeviceCreateContextRequest
262        )
263    }
264}
265impl Request for GetDeviceCreateContextRequest {
266    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
267
268    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
269        let (bufs, fds) = self.serialize(major_opcode);
270        // Flatten the buffers into a single vector
271        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
272        (buf, fds)
273    }
274}
275impl crate::x11_utils::ReplyRequest for GetDeviceCreateContextRequest {
276    type Reply = GetDeviceCreateContextReply;
277}
278
279#[derive(Clone, Default)]
280#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
281#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
282pub struct GetDeviceCreateContextReply {
283    pub sequence: u16,
284    pub length: u32,
285    pub context: Vec<u8>,
286}
287impl_debug_if_no_extra_traits!(GetDeviceCreateContextReply, "GetDeviceCreateContextReply");
288impl TryParse for GetDeviceCreateContextReply {
289    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
290        let remaining = initial_value;
291        let (response_type, remaining) = u8::try_parse(remaining)?;
292        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
293        let (sequence, remaining) = u16::try_parse(remaining)?;
294        let (length, remaining) = u32::try_parse(remaining)?;
295        let (context_len, remaining) = u32::try_parse(remaining)?;
296        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
297        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
298        let context = context.to_vec();
299        if response_type != 1 {
300            return Err(ParseError::InvalidValue);
301        }
302        let result = GetDeviceCreateContextReply { sequence, length, context };
303        let _ = remaining;
304        let remaining = initial_value.get(32 + length as usize * 4..)
305            .ok_or(ParseError::InsufficientData)?;
306        Ok((result, remaining))
307    }
308}
309impl Serialize for GetDeviceCreateContextReply {
310    type Bytes = Vec<u8>;
311    fn serialize(&self) -> Vec<u8> {
312        let mut result = Vec::new();
313        self.serialize_into(&mut result);
314        result
315    }
316    fn serialize_into(&self, bytes: &mut Vec<u8>) {
317        bytes.reserve(32);
318        let response_type_bytes = &[1];
319        bytes.push(response_type_bytes[0]);
320        bytes.extend_from_slice(&[0; 1]);
321        self.sequence.serialize_into(bytes);
322        self.length.serialize_into(bytes);
323        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
324        context_len.serialize_into(bytes);
325        bytes.extend_from_slice(&[0; 20]);
326        bytes.extend_from_slice(&self.context);
327    }
328}
329impl GetDeviceCreateContextReply {
330    /// Get the value of the `context_len` field.
331    ///
332    /// The `context_len` field is used as the length field of the `context` field.
333    /// This function computes the field's value again based on the length of the list.
334    ///
335    /// # Panics
336    ///
337    /// Panics if the value cannot be represented in the target type. This
338    /// cannot happen with values of the struct received from the X11 server.
339    pub fn context_len(&self) -> u32 {
340        self.context.len()
341            .try_into().unwrap()
342    }
343}
344
345/// Opcode for the SetDeviceContext request
346pub const SET_DEVICE_CONTEXT_REQUEST: u8 = 3;
347#[derive(Clone, Default)]
348#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
349#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
350pub struct SetDeviceContextRequest<'input> {
351    pub device: u32,
352    pub context: Cow<'input, [u8]>,
353}
354impl_debug_if_no_extra_traits!(SetDeviceContextRequest<'_>, "SetDeviceContextRequest");
355impl<'input> SetDeviceContextRequest<'input> {
356    /// Serialize this request into bytes for the provided connection
357    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
358        let length_so_far = 0;
359        let device_bytes = self.device.serialize();
360        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
361        let context_len_bytes = context_len.serialize();
362        let mut request0 = vec![
363            major_opcode,
364            SET_DEVICE_CONTEXT_REQUEST,
365            0,
366            0,
367            device_bytes[0],
368            device_bytes[1],
369            device_bytes[2],
370            device_bytes[3],
371            context_len_bytes[0],
372            context_len_bytes[1],
373            context_len_bytes[2],
374            context_len_bytes[3],
375        ];
376        let length_so_far = length_so_far + request0.len();
377        let length_so_far = length_so_far + self.context.len();
378        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
379        let length_so_far = length_so_far + padding0.len();
380        assert_eq!(length_so_far % 4, 0);
381        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
382        request0[2..4].copy_from_slice(&length.to_ne_bytes());
383        ([request0.into(), self.context, padding0.into()], vec![])
384    }
385    /// Parse this request given its header, its body, and any fds that go along with it
386    #[cfg(feature = "request-parsing")]
387    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
388        if header.minor_opcode != SET_DEVICE_CONTEXT_REQUEST {
389            return Err(ParseError::InvalidValue);
390        }
391        let (device, remaining) = u32::try_parse(value)?;
392        let (context_len, remaining) = u32::try_parse(remaining)?;
393        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
394        let _ = remaining;
395        Ok(SetDeviceContextRequest {
396            device,
397            context: Cow::Borrowed(context),
398        })
399    }
400    /// Clone all borrowed data in this SetDeviceContextRequest.
401    pub fn into_owned(self) -> SetDeviceContextRequest<'static> {
402        SetDeviceContextRequest {
403            device: self.device,
404            context: Cow::Owned(self.context.into_owned()),
405        }
406    }
407}
408impl<'input> Request for SetDeviceContextRequest<'input> {
409    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
410
411    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
412        let (bufs, fds) = self.serialize(major_opcode);
413        // Flatten the buffers into a single vector
414        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
415        (buf, fds)
416    }
417}
418impl<'input> crate::x11_utils::VoidRequest for SetDeviceContextRequest<'input> {
419}
420
421/// Opcode for the GetDeviceContext request
422pub const GET_DEVICE_CONTEXT_REQUEST: u8 = 4;
423#[derive(Clone, Copy, Default)]
424#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
425#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
426pub struct GetDeviceContextRequest {
427    pub device: u32,
428}
429impl_debug_if_no_extra_traits!(GetDeviceContextRequest, "GetDeviceContextRequest");
430impl GetDeviceContextRequest {
431    /// Serialize this request into bytes for the provided connection
432    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
433        let length_so_far = 0;
434        let device_bytes = self.device.serialize();
435        let mut request0 = vec![
436            major_opcode,
437            GET_DEVICE_CONTEXT_REQUEST,
438            0,
439            0,
440            device_bytes[0],
441            device_bytes[1],
442            device_bytes[2],
443            device_bytes[3],
444        ];
445        let length_so_far = length_so_far + request0.len();
446        assert_eq!(length_so_far % 4, 0);
447        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
448        request0[2..4].copy_from_slice(&length.to_ne_bytes());
449        ([request0.into()], vec![])
450    }
451    /// Parse this request given its header, its body, and any fds that go along with it
452    #[cfg(feature = "request-parsing")]
453    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
454        if header.minor_opcode != GET_DEVICE_CONTEXT_REQUEST {
455            return Err(ParseError::InvalidValue);
456        }
457        let (device, remaining) = u32::try_parse(value)?;
458        let _ = remaining;
459        Ok(GetDeviceContextRequest {
460            device,
461        })
462    }
463}
464impl Request for GetDeviceContextRequest {
465    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
466
467    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
468        let (bufs, fds) = self.serialize(major_opcode);
469        // Flatten the buffers into a single vector
470        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
471        (buf, fds)
472    }
473}
474impl crate::x11_utils::ReplyRequest for GetDeviceContextRequest {
475    type Reply = GetDeviceContextReply;
476}
477
478#[derive(Clone, Default)]
479#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
480#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
481pub struct GetDeviceContextReply {
482    pub sequence: u16,
483    pub length: u32,
484    pub context: Vec<u8>,
485}
486impl_debug_if_no_extra_traits!(GetDeviceContextReply, "GetDeviceContextReply");
487impl TryParse for GetDeviceContextReply {
488    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
489        let remaining = initial_value;
490        let (response_type, remaining) = u8::try_parse(remaining)?;
491        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
492        let (sequence, remaining) = u16::try_parse(remaining)?;
493        let (length, remaining) = u32::try_parse(remaining)?;
494        let (context_len, remaining) = u32::try_parse(remaining)?;
495        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
496        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
497        let context = context.to_vec();
498        if response_type != 1 {
499            return Err(ParseError::InvalidValue);
500        }
501        let result = GetDeviceContextReply { sequence, length, context };
502        let _ = remaining;
503        let remaining = initial_value.get(32 + length as usize * 4..)
504            .ok_or(ParseError::InsufficientData)?;
505        Ok((result, remaining))
506    }
507}
508impl Serialize for GetDeviceContextReply {
509    type Bytes = Vec<u8>;
510    fn serialize(&self) -> Vec<u8> {
511        let mut result = Vec::new();
512        self.serialize_into(&mut result);
513        result
514    }
515    fn serialize_into(&self, bytes: &mut Vec<u8>) {
516        bytes.reserve(32);
517        let response_type_bytes = &[1];
518        bytes.push(response_type_bytes[0]);
519        bytes.extend_from_slice(&[0; 1]);
520        self.sequence.serialize_into(bytes);
521        self.length.serialize_into(bytes);
522        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
523        context_len.serialize_into(bytes);
524        bytes.extend_from_slice(&[0; 20]);
525        bytes.extend_from_slice(&self.context);
526    }
527}
528impl GetDeviceContextReply {
529    /// Get the value of the `context_len` field.
530    ///
531    /// The `context_len` field is used as the length field of the `context` field.
532    /// This function computes the field's value again based on the length of the list.
533    ///
534    /// # Panics
535    ///
536    /// Panics if the value cannot be represented in the target type. This
537    /// cannot happen with values of the struct received from the X11 server.
538    pub fn context_len(&self) -> u32 {
539        self.context.len()
540            .try_into().unwrap()
541    }
542}
543
544/// Opcode for the SetWindowCreateContext request
545pub const SET_WINDOW_CREATE_CONTEXT_REQUEST: u8 = 5;
546#[derive(Clone, Default)]
547#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
548#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
549pub struct SetWindowCreateContextRequest<'input> {
550    pub context: Cow<'input, [u8]>,
551}
552impl_debug_if_no_extra_traits!(SetWindowCreateContextRequest<'_>, "SetWindowCreateContextRequest");
553impl<'input> SetWindowCreateContextRequest<'input> {
554    /// Serialize this request into bytes for the provided connection
555    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
556        let length_so_far = 0;
557        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
558        let context_len_bytes = context_len.serialize();
559        let mut request0 = vec![
560            major_opcode,
561            SET_WINDOW_CREATE_CONTEXT_REQUEST,
562            0,
563            0,
564            context_len_bytes[0],
565            context_len_bytes[1],
566            context_len_bytes[2],
567            context_len_bytes[3],
568        ];
569        let length_so_far = length_so_far + request0.len();
570        let length_so_far = length_so_far + self.context.len();
571        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
572        let length_so_far = length_so_far + padding0.len();
573        assert_eq!(length_so_far % 4, 0);
574        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
575        request0[2..4].copy_from_slice(&length.to_ne_bytes());
576        ([request0.into(), self.context, padding0.into()], vec![])
577    }
578    /// Parse this request given its header, its body, and any fds that go along with it
579    #[cfg(feature = "request-parsing")]
580    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
581        if header.minor_opcode != SET_WINDOW_CREATE_CONTEXT_REQUEST {
582            return Err(ParseError::InvalidValue);
583        }
584        let (context_len, remaining) = u32::try_parse(value)?;
585        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
586        let _ = remaining;
587        Ok(SetWindowCreateContextRequest {
588            context: Cow::Borrowed(context),
589        })
590    }
591    /// Clone all borrowed data in this SetWindowCreateContextRequest.
592    pub fn into_owned(self) -> SetWindowCreateContextRequest<'static> {
593        SetWindowCreateContextRequest {
594            context: Cow::Owned(self.context.into_owned()),
595        }
596    }
597}
598impl<'input> Request for SetWindowCreateContextRequest<'input> {
599    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
600
601    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
602        let (bufs, fds) = self.serialize(major_opcode);
603        // Flatten the buffers into a single vector
604        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
605        (buf, fds)
606    }
607}
608impl<'input> crate::x11_utils::VoidRequest for SetWindowCreateContextRequest<'input> {
609}
610
611/// Opcode for the GetWindowCreateContext request
612pub const GET_WINDOW_CREATE_CONTEXT_REQUEST: u8 = 6;
613#[derive(Clone, Copy, Default)]
614#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
615#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
616pub struct GetWindowCreateContextRequest;
617impl_debug_if_no_extra_traits!(GetWindowCreateContextRequest, "GetWindowCreateContextRequest");
618impl GetWindowCreateContextRequest {
619    /// Serialize this request into bytes for the provided connection
620    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
621        let length_so_far = 0;
622        let mut request0 = vec![
623            major_opcode,
624            GET_WINDOW_CREATE_CONTEXT_REQUEST,
625            0,
626            0,
627        ];
628        let length_so_far = length_so_far + request0.len();
629        assert_eq!(length_so_far % 4, 0);
630        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
631        request0[2..4].copy_from_slice(&length.to_ne_bytes());
632        ([request0.into()], vec![])
633    }
634    /// Parse this request given its header, its body, and any fds that go along with it
635    #[cfg(feature = "request-parsing")]
636    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
637        if header.minor_opcode != GET_WINDOW_CREATE_CONTEXT_REQUEST {
638            return Err(ParseError::InvalidValue);
639        }
640        let _ = value;
641        Ok(GetWindowCreateContextRequest
642        )
643    }
644}
645impl Request for GetWindowCreateContextRequest {
646    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
647
648    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
649        let (bufs, fds) = self.serialize(major_opcode);
650        // Flatten the buffers into a single vector
651        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
652        (buf, fds)
653    }
654}
655impl crate::x11_utils::ReplyRequest for GetWindowCreateContextRequest {
656    type Reply = GetWindowCreateContextReply;
657}
658
659#[derive(Clone, Default)]
660#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
661#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
662pub struct GetWindowCreateContextReply {
663    pub sequence: u16,
664    pub length: u32,
665    pub context: Vec<u8>,
666}
667impl_debug_if_no_extra_traits!(GetWindowCreateContextReply, "GetWindowCreateContextReply");
668impl TryParse for GetWindowCreateContextReply {
669    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
670        let remaining = initial_value;
671        let (response_type, remaining) = u8::try_parse(remaining)?;
672        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
673        let (sequence, remaining) = u16::try_parse(remaining)?;
674        let (length, remaining) = u32::try_parse(remaining)?;
675        let (context_len, remaining) = u32::try_parse(remaining)?;
676        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
677        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
678        let context = context.to_vec();
679        if response_type != 1 {
680            return Err(ParseError::InvalidValue);
681        }
682        let result = GetWindowCreateContextReply { sequence, length, context };
683        let _ = remaining;
684        let remaining = initial_value.get(32 + length as usize * 4..)
685            .ok_or(ParseError::InsufficientData)?;
686        Ok((result, remaining))
687    }
688}
689impl Serialize for GetWindowCreateContextReply {
690    type Bytes = Vec<u8>;
691    fn serialize(&self) -> Vec<u8> {
692        let mut result = Vec::new();
693        self.serialize_into(&mut result);
694        result
695    }
696    fn serialize_into(&self, bytes: &mut Vec<u8>) {
697        bytes.reserve(32);
698        let response_type_bytes = &[1];
699        bytes.push(response_type_bytes[0]);
700        bytes.extend_from_slice(&[0; 1]);
701        self.sequence.serialize_into(bytes);
702        self.length.serialize_into(bytes);
703        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
704        context_len.serialize_into(bytes);
705        bytes.extend_from_slice(&[0; 20]);
706        bytes.extend_from_slice(&self.context);
707    }
708}
709impl GetWindowCreateContextReply {
710    /// Get the value of the `context_len` field.
711    ///
712    /// The `context_len` field is used as the length field of the `context` field.
713    /// This function computes the field's value again based on the length of the list.
714    ///
715    /// # Panics
716    ///
717    /// Panics if the value cannot be represented in the target type. This
718    /// cannot happen with values of the struct received from the X11 server.
719    pub fn context_len(&self) -> u32 {
720        self.context.len()
721            .try_into().unwrap()
722    }
723}
724
725/// Opcode for the GetWindowContext request
726pub const GET_WINDOW_CONTEXT_REQUEST: u8 = 7;
727#[derive(Clone, Copy, Default)]
728#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
729#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
730pub struct GetWindowContextRequest {
731    pub window: xproto::Window,
732}
733impl_debug_if_no_extra_traits!(GetWindowContextRequest, "GetWindowContextRequest");
734impl GetWindowContextRequest {
735    /// Serialize this request into bytes for the provided connection
736    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
737        let length_so_far = 0;
738        let window_bytes = self.window.serialize();
739        let mut request0 = vec![
740            major_opcode,
741            GET_WINDOW_CONTEXT_REQUEST,
742            0,
743            0,
744            window_bytes[0],
745            window_bytes[1],
746            window_bytes[2],
747            window_bytes[3],
748        ];
749        let length_so_far = length_so_far + request0.len();
750        assert_eq!(length_so_far % 4, 0);
751        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
752        request0[2..4].copy_from_slice(&length.to_ne_bytes());
753        ([request0.into()], vec![])
754    }
755    /// Parse this request given its header, its body, and any fds that go along with it
756    #[cfg(feature = "request-parsing")]
757    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
758        if header.minor_opcode != GET_WINDOW_CONTEXT_REQUEST {
759            return Err(ParseError::InvalidValue);
760        }
761        let (window, remaining) = xproto::Window::try_parse(value)?;
762        let _ = remaining;
763        Ok(GetWindowContextRequest {
764            window,
765        })
766    }
767}
768impl Request for GetWindowContextRequest {
769    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
770
771    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
772        let (bufs, fds) = self.serialize(major_opcode);
773        // Flatten the buffers into a single vector
774        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
775        (buf, fds)
776    }
777}
778impl crate::x11_utils::ReplyRequest for GetWindowContextRequest {
779    type Reply = GetWindowContextReply;
780}
781
782#[derive(Clone, Default)]
783#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
784#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
785pub struct GetWindowContextReply {
786    pub sequence: u16,
787    pub length: u32,
788    pub context: Vec<u8>,
789}
790impl_debug_if_no_extra_traits!(GetWindowContextReply, "GetWindowContextReply");
791impl TryParse for GetWindowContextReply {
792    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
793        let remaining = initial_value;
794        let (response_type, remaining) = u8::try_parse(remaining)?;
795        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
796        let (sequence, remaining) = u16::try_parse(remaining)?;
797        let (length, remaining) = u32::try_parse(remaining)?;
798        let (context_len, remaining) = u32::try_parse(remaining)?;
799        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
800        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
801        let context = context.to_vec();
802        if response_type != 1 {
803            return Err(ParseError::InvalidValue);
804        }
805        let result = GetWindowContextReply { sequence, length, context };
806        let _ = remaining;
807        let remaining = initial_value.get(32 + length as usize * 4..)
808            .ok_or(ParseError::InsufficientData)?;
809        Ok((result, remaining))
810    }
811}
812impl Serialize for GetWindowContextReply {
813    type Bytes = Vec<u8>;
814    fn serialize(&self) -> Vec<u8> {
815        let mut result = Vec::new();
816        self.serialize_into(&mut result);
817        result
818    }
819    fn serialize_into(&self, bytes: &mut Vec<u8>) {
820        bytes.reserve(32);
821        let response_type_bytes = &[1];
822        bytes.push(response_type_bytes[0]);
823        bytes.extend_from_slice(&[0; 1]);
824        self.sequence.serialize_into(bytes);
825        self.length.serialize_into(bytes);
826        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
827        context_len.serialize_into(bytes);
828        bytes.extend_from_slice(&[0; 20]);
829        bytes.extend_from_slice(&self.context);
830    }
831}
832impl GetWindowContextReply {
833    /// Get the value of the `context_len` field.
834    ///
835    /// The `context_len` field is used as the length field of the `context` field.
836    /// This function computes the field's value again based on the length of the list.
837    ///
838    /// # Panics
839    ///
840    /// Panics if the value cannot be represented in the target type. This
841    /// cannot happen with values of the struct received from the X11 server.
842    pub fn context_len(&self) -> u32 {
843        self.context.len()
844            .try_into().unwrap()
845    }
846}
847
848#[derive(Clone, Default)]
849#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
850#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
851pub struct ListItem {
852    pub name: xproto::Atom,
853    pub object_context: Vec<u8>,
854    pub data_context: Vec<u8>,
855}
856impl_debug_if_no_extra_traits!(ListItem, "ListItem");
857impl TryParse for ListItem {
858    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
859        let value = remaining;
860        let (name, remaining) = xproto::Atom::try_parse(remaining)?;
861        let (object_context_len, remaining) = u32::try_parse(remaining)?;
862        let (data_context_len, remaining) = u32::try_parse(remaining)?;
863        let (object_context, remaining) = crate::x11_utils::parse_u8_list(remaining, object_context_len.try_to_usize()?)?;
864        let object_context = object_context.to_vec();
865        // Align offset to multiple of 4
866        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
867        let misalignment = (4 - (offset % 4)) % 4;
868        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
869        let (data_context, remaining) = crate::x11_utils::parse_u8_list(remaining, data_context_len.try_to_usize()?)?;
870        let data_context = data_context.to_vec();
871        // Align offset to multiple of 4
872        let offset = remaining.as_ptr() as usize - value.as_ptr() as usize;
873        let misalignment = (4 - (offset % 4)) % 4;
874        let remaining = remaining.get(misalignment..).ok_or(ParseError::InsufficientData)?;
875        let result = ListItem { name, object_context, data_context };
876        Ok((result, remaining))
877    }
878}
879impl Serialize for ListItem {
880    type Bytes = Vec<u8>;
881    fn serialize(&self) -> Vec<u8> {
882        let mut result = Vec::new();
883        self.serialize_into(&mut result);
884        result
885    }
886    fn serialize_into(&self, bytes: &mut Vec<u8>) {
887        bytes.reserve(12);
888        self.name.serialize_into(bytes);
889        let object_context_len = u32::try_from(self.object_context.len()).expect("`object_context` has too many elements");
890        object_context_len.serialize_into(bytes);
891        let data_context_len = u32::try_from(self.data_context.len()).expect("`data_context` has too many elements");
892        data_context_len.serialize_into(bytes);
893        bytes.extend_from_slice(&self.object_context);
894        bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]);
895        bytes.extend_from_slice(&self.data_context);
896        bytes.extend_from_slice(&[0; 3][..(4 - (bytes.len() % 4)) % 4]);
897    }
898}
899impl ListItem {
900    /// Get the value of the `object_context_len` field.
901    ///
902    /// The `object_context_len` field is used as the length field of the `object_context` field.
903    /// This function computes the field's value again based on the length of the list.
904    ///
905    /// # Panics
906    ///
907    /// Panics if the value cannot be represented in the target type. This
908    /// cannot happen with values of the struct received from the X11 server.
909    pub fn object_context_len(&self) -> u32 {
910        self.object_context.len()
911            .try_into().unwrap()
912    }
913    /// Get the value of the `data_context_len` field.
914    ///
915    /// The `data_context_len` field is used as the length field of the `data_context` field.
916    /// This function computes the field's value again based on the length of the list.
917    ///
918    /// # Panics
919    ///
920    /// Panics if the value cannot be represented in the target type. This
921    /// cannot happen with values of the struct received from the X11 server.
922    pub fn data_context_len(&self) -> u32 {
923        self.data_context.len()
924            .try_into().unwrap()
925    }
926}
927
928/// Opcode for the SetPropertyCreateContext request
929pub const SET_PROPERTY_CREATE_CONTEXT_REQUEST: u8 = 8;
930#[derive(Clone, Default)]
931#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
932#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
933pub struct SetPropertyCreateContextRequest<'input> {
934    pub context: Cow<'input, [u8]>,
935}
936impl_debug_if_no_extra_traits!(SetPropertyCreateContextRequest<'_>, "SetPropertyCreateContextRequest");
937impl<'input> SetPropertyCreateContextRequest<'input> {
938    /// Serialize this request into bytes for the provided connection
939    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
940        let length_so_far = 0;
941        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
942        let context_len_bytes = context_len.serialize();
943        let mut request0 = vec![
944            major_opcode,
945            SET_PROPERTY_CREATE_CONTEXT_REQUEST,
946            0,
947            0,
948            context_len_bytes[0],
949            context_len_bytes[1],
950            context_len_bytes[2],
951            context_len_bytes[3],
952        ];
953        let length_so_far = length_so_far + request0.len();
954        let length_so_far = length_so_far + self.context.len();
955        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
956        let length_so_far = length_so_far + padding0.len();
957        assert_eq!(length_so_far % 4, 0);
958        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
959        request0[2..4].copy_from_slice(&length.to_ne_bytes());
960        ([request0.into(), self.context, padding0.into()], vec![])
961    }
962    /// Parse this request given its header, its body, and any fds that go along with it
963    #[cfg(feature = "request-parsing")]
964    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
965        if header.minor_opcode != SET_PROPERTY_CREATE_CONTEXT_REQUEST {
966            return Err(ParseError::InvalidValue);
967        }
968        let (context_len, remaining) = u32::try_parse(value)?;
969        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
970        let _ = remaining;
971        Ok(SetPropertyCreateContextRequest {
972            context: Cow::Borrowed(context),
973        })
974    }
975    /// Clone all borrowed data in this SetPropertyCreateContextRequest.
976    pub fn into_owned(self) -> SetPropertyCreateContextRequest<'static> {
977        SetPropertyCreateContextRequest {
978            context: Cow::Owned(self.context.into_owned()),
979        }
980    }
981}
982impl<'input> Request for SetPropertyCreateContextRequest<'input> {
983    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
984
985    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
986        let (bufs, fds) = self.serialize(major_opcode);
987        // Flatten the buffers into a single vector
988        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
989        (buf, fds)
990    }
991}
992impl<'input> crate::x11_utils::VoidRequest for SetPropertyCreateContextRequest<'input> {
993}
994
995/// Opcode for the GetPropertyCreateContext request
996pub const GET_PROPERTY_CREATE_CONTEXT_REQUEST: u8 = 9;
997#[derive(Clone, Copy, Default)]
998#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
999#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1000pub struct GetPropertyCreateContextRequest;
1001impl_debug_if_no_extra_traits!(GetPropertyCreateContextRequest, "GetPropertyCreateContextRequest");
1002impl GetPropertyCreateContextRequest {
1003    /// Serialize this request into bytes for the provided connection
1004    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1005        let length_so_far = 0;
1006        let mut request0 = vec![
1007            major_opcode,
1008            GET_PROPERTY_CREATE_CONTEXT_REQUEST,
1009            0,
1010            0,
1011        ];
1012        let length_so_far = length_so_far + request0.len();
1013        assert_eq!(length_so_far % 4, 0);
1014        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1015        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1016        ([request0.into()], vec![])
1017    }
1018    /// Parse this request given its header, its body, and any fds that go along with it
1019    #[cfg(feature = "request-parsing")]
1020    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1021        if header.minor_opcode != GET_PROPERTY_CREATE_CONTEXT_REQUEST {
1022            return Err(ParseError::InvalidValue);
1023        }
1024        let _ = value;
1025        Ok(GetPropertyCreateContextRequest
1026        )
1027    }
1028}
1029impl Request for GetPropertyCreateContextRequest {
1030    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1031
1032    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1033        let (bufs, fds) = self.serialize(major_opcode);
1034        // Flatten the buffers into a single vector
1035        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1036        (buf, fds)
1037    }
1038}
1039impl crate::x11_utils::ReplyRequest for GetPropertyCreateContextRequest {
1040    type Reply = GetPropertyCreateContextReply;
1041}
1042
1043#[derive(Clone, Default)]
1044#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1045#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1046pub struct GetPropertyCreateContextReply {
1047    pub sequence: u16,
1048    pub length: u32,
1049    pub context: Vec<u8>,
1050}
1051impl_debug_if_no_extra_traits!(GetPropertyCreateContextReply, "GetPropertyCreateContextReply");
1052impl TryParse for GetPropertyCreateContextReply {
1053    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1054        let remaining = initial_value;
1055        let (response_type, remaining) = u8::try_parse(remaining)?;
1056        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1057        let (sequence, remaining) = u16::try_parse(remaining)?;
1058        let (length, remaining) = u32::try_parse(remaining)?;
1059        let (context_len, remaining) = u32::try_parse(remaining)?;
1060        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
1061        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
1062        let context = context.to_vec();
1063        if response_type != 1 {
1064            return Err(ParseError::InvalidValue);
1065        }
1066        let result = GetPropertyCreateContextReply { sequence, length, context };
1067        let _ = remaining;
1068        let remaining = initial_value.get(32 + length as usize * 4..)
1069            .ok_or(ParseError::InsufficientData)?;
1070        Ok((result, remaining))
1071    }
1072}
1073impl Serialize for GetPropertyCreateContextReply {
1074    type Bytes = Vec<u8>;
1075    fn serialize(&self) -> Vec<u8> {
1076        let mut result = Vec::new();
1077        self.serialize_into(&mut result);
1078        result
1079    }
1080    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1081        bytes.reserve(32);
1082        let response_type_bytes = &[1];
1083        bytes.push(response_type_bytes[0]);
1084        bytes.extend_from_slice(&[0; 1]);
1085        self.sequence.serialize_into(bytes);
1086        self.length.serialize_into(bytes);
1087        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
1088        context_len.serialize_into(bytes);
1089        bytes.extend_from_slice(&[0; 20]);
1090        bytes.extend_from_slice(&self.context);
1091    }
1092}
1093impl GetPropertyCreateContextReply {
1094    /// Get the value of the `context_len` field.
1095    ///
1096    /// The `context_len` field is used as the length field of the `context` field.
1097    /// This function computes the field's value again based on the length of the list.
1098    ///
1099    /// # Panics
1100    ///
1101    /// Panics if the value cannot be represented in the target type. This
1102    /// cannot happen with values of the struct received from the X11 server.
1103    pub fn context_len(&self) -> u32 {
1104        self.context.len()
1105            .try_into().unwrap()
1106    }
1107}
1108
1109/// Opcode for the SetPropertyUseContext request
1110pub const SET_PROPERTY_USE_CONTEXT_REQUEST: u8 = 10;
1111#[derive(Clone, Default)]
1112#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1113#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1114pub struct SetPropertyUseContextRequest<'input> {
1115    pub context: Cow<'input, [u8]>,
1116}
1117impl_debug_if_no_extra_traits!(SetPropertyUseContextRequest<'_>, "SetPropertyUseContextRequest");
1118impl<'input> SetPropertyUseContextRequest<'input> {
1119    /// Serialize this request into bytes for the provided connection
1120    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
1121        let length_so_far = 0;
1122        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
1123        let context_len_bytes = context_len.serialize();
1124        let mut request0 = vec![
1125            major_opcode,
1126            SET_PROPERTY_USE_CONTEXT_REQUEST,
1127            0,
1128            0,
1129            context_len_bytes[0],
1130            context_len_bytes[1],
1131            context_len_bytes[2],
1132            context_len_bytes[3],
1133        ];
1134        let length_so_far = length_so_far + request0.len();
1135        let length_so_far = length_so_far + self.context.len();
1136        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1137        let length_so_far = length_so_far + padding0.len();
1138        assert_eq!(length_so_far % 4, 0);
1139        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1140        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1141        ([request0.into(), self.context, padding0.into()], vec![])
1142    }
1143    /// Parse this request given its header, its body, and any fds that go along with it
1144    #[cfg(feature = "request-parsing")]
1145    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1146        if header.minor_opcode != SET_PROPERTY_USE_CONTEXT_REQUEST {
1147            return Err(ParseError::InvalidValue);
1148        }
1149        let (context_len, remaining) = u32::try_parse(value)?;
1150        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
1151        let _ = remaining;
1152        Ok(SetPropertyUseContextRequest {
1153            context: Cow::Borrowed(context),
1154        })
1155    }
1156    /// Clone all borrowed data in this SetPropertyUseContextRequest.
1157    pub fn into_owned(self) -> SetPropertyUseContextRequest<'static> {
1158        SetPropertyUseContextRequest {
1159            context: Cow::Owned(self.context.into_owned()),
1160        }
1161    }
1162}
1163impl<'input> Request for SetPropertyUseContextRequest<'input> {
1164    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1165
1166    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1167        let (bufs, fds) = self.serialize(major_opcode);
1168        // Flatten the buffers into a single vector
1169        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1170        (buf, fds)
1171    }
1172}
1173impl<'input> crate::x11_utils::VoidRequest for SetPropertyUseContextRequest<'input> {
1174}
1175
1176/// Opcode for the GetPropertyUseContext request
1177pub const GET_PROPERTY_USE_CONTEXT_REQUEST: u8 = 11;
1178#[derive(Clone, Copy, Default)]
1179#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1180#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1181pub struct GetPropertyUseContextRequest;
1182impl_debug_if_no_extra_traits!(GetPropertyUseContextRequest, "GetPropertyUseContextRequest");
1183impl GetPropertyUseContextRequest {
1184    /// Serialize this request into bytes for the provided connection
1185    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1186        let length_so_far = 0;
1187        let mut request0 = vec![
1188            major_opcode,
1189            GET_PROPERTY_USE_CONTEXT_REQUEST,
1190            0,
1191            0,
1192        ];
1193        let length_so_far = length_so_far + request0.len();
1194        assert_eq!(length_so_far % 4, 0);
1195        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1196        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1197        ([request0.into()], vec![])
1198    }
1199    /// Parse this request given its header, its body, and any fds that go along with it
1200    #[cfg(feature = "request-parsing")]
1201    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1202        if header.minor_opcode != GET_PROPERTY_USE_CONTEXT_REQUEST {
1203            return Err(ParseError::InvalidValue);
1204        }
1205        let _ = value;
1206        Ok(GetPropertyUseContextRequest
1207        )
1208    }
1209}
1210impl Request for GetPropertyUseContextRequest {
1211    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1212
1213    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1214        let (bufs, fds) = self.serialize(major_opcode);
1215        // Flatten the buffers into a single vector
1216        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1217        (buf, fds)
1218    }
1219}
1220impl crate::x11_utils::ReplyRequest for GetPropertyUseContextRequest {
1221    type Reply = GetPropertyUseContextReply;
1222}
1223
1224#[derive(Clone, Default)]
1225#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1226#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1227pub struct GetPropertyUseContextReply {
1228    pub sequence: u16,
1229    pub length: u32,
1230    pub context: Vec<u8>,
1231}
1232impl_debug_if_no_extra_traits!(GetPropertyUseContextReply, "GetPropertyUseContextReply");
1233impl TryParse for GetPropertyUseContextReply {
1234    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1235        let remaining = initial_value;
1236        let (response_type, remaining) = u8::try_parse(remaining)?;
1237        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1238        let (sequence, remaining) = u16::try_parse(remaining)?;
1239        let (length, remaining) = u32::try_parse(remaining)?;
1240        let (context_len, remaining) = u32::try_parse(remaining)?;
1241        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
1242        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
1243        let context = context.to_vec();
1244        if response_type != 1 {
1245            return Err(ParseError::InvalidValue);
1246        }
1247        let result = GetPropertyUseContextReply { sequence, length, context };
1248        let _ = remaining;
1249        let remaining = initial_value.get(32 + length as usize * 4..)
1250            .ok_or(ParseError::InsufficientData)?;
1251        Ok((result, remaining))
1252    }
1253}
1254impl Serialize for GetPropertyUseContextReply {
1255    type Bytes = Vec<u8>;
1256    fn serialize(&self) -> Vec<u8> {
1257        let mut result = Vec::new();
1258        self.serialize_into(&mut result);
1259        result
1260    }
1261    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1262        bytes.reserve(32);
1263        let response_type_bytes = &[1];
1264        bytes.push(response_type_bytes[0]);
1265        bytes.extend_from_slice(&[0; 1]);
1266        self.sequence.serialize_into(bytes);
1267        self.length.serialize_into(bytes);
1268        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
1269        context_len.serialize_into(bytes);
1270        bytes.extend_from_slice(&[0; 20]);
1271        bytes.extend_from_slice(&self.context);
1272    }
1273}
1274impl GetPropertyUseContextReply {
1275    /// Get the value of the `context_len` field.
1276    ///
1277    /// The `context_len` field is used as the length field of the `context` field.
1278    /// This function computes the field's value again based on the length of the list.
1279    ///
1280    /// # Panics
1281    ///
1282    /// Panics if the value cannot be represented in the target type. This
1283    /// cannot happen with values of the struct received from the X11 server.
1284    pub fn context_len(&self) -> u32 {
1285        self.context.len()
1286            .try_into().unwrap()
1287    }
1288}
1289
1290/// Opcode for the GetPropertyContext request
1291pub const GET_PROPERTY_CONTEXT_REQUEST: u8 = 12;
1292#[derive(Clone, Copy, Default)]
1293#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1294#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1295pub struct GetPropertyContextRequest {
1296    pub window: xproto::Window,
1297    pub property: xproto::Atom,
1298}
1299impl_debug_if_no_extra_traits!(GetPropertyContextRequest, "GetPropertyContextRequest");
1300impl GetPropertyContextRequest {
1301    /// Serialize this request into bytes for the provided connection
1302    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1303        let length_so_far = 0;
1304        let window_bytes = self.window.serialize();
1305        let property_bytes = self.property.serialize();
1306        let mut request0 = vec![
1307            major_opcode,
1308            GET_PROPERTY_CONTEXT_REQUEST,
1309            0,
1310            0,
1311            window_bytes[0],
1312            window_bytes[1],
1313            window_bytes[2],
1314            window_bytes[3],
1315            property_bytes[0],
1316            property_bytes[1],
1317            property_bytes[2],
1318            property_bytes[3],
1319        ];
1320        let length_so_far = length_so_far + request0.len();
1321        assert_eq!(length_so_far % 4, 0);
1322        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1323        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1324        ([request0.into()], vec![])
1325    }
1326    /// Parse this request given its header, its body, and any fds that go along with it
1327    #[cfg(feature = "request-parsing")]
1328    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1329        if header.minor_opcode != GET_PROPERTY_CONTEXT_REQUEST {
1330            return Err(ParseError::InvalidValue);
1331        }
1332        let (window, remaining) = xproto::Window::try_parse(value)?;
1333        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
1334        let _ = remaining;
1335        Ok(GetPropertyContextRequest {
1336            window,
1337            property,
1338        })
1339    }
1340}
1341impl Request for GetPropertyContextRequest {
1342    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1343
1344    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1345        let (bufs, fds) = self.serialize(major_opcode);
1346        // Flatten the buffers into a single vector
1347        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1348        (buf, fds)
1349    }
1350}
1351impl crate::x11_utils::ReplyRequest for GetPropertyContextRequest {
1352    type Reply = GetPropertyContextReply;
1353}
1354
1355#[derive(Clone, Default)]
1356#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1357#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1358pub struct GetPropertyContextReply {
1359    pub sequence: u16,
1360    pub length: u32,
1361    pub context: Vec<u8>,
1362}
1363impl_debug_if_no_extra_traits!(GetPropertyContextReply, "GetPropertyContextReply");
1364impl TryParse for GetPropertyContextReply {
1365    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1366        let remaining = initial_value;
1367        let (response_type, remaining) = u8::try_parse(remaining)?;
1368        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1369        let (sequence, remaining) = u16::try_parse(remaining)?;
1370        let (length, remaining) = u32::try_parse(remaining)?;
1371        let (context_len, remaining) = u32::try_parse(remaining)?;
1372        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
1373        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
1374        let context = context.to_vec();
1375        if response_type != 1 {
1376            return Err(ParseError::InvalidValue);
1377        }
1378        let result = GetPropertyContextReply { sequence, length, context };
1379        let _ = remaining;
1380        let remaining = initial_value.get(32 + length as usize * 4..)
1381            .ok_or(ParseError::InsufficientData)?;
1382        Ok((result, remaining))
1383    }
1384}
1385impl Serialize for GetPropertyContextReply {
1386    type Bytes = Vec<u8>;
1387    fn serialize(&self) -> Vec<u8> {
1388        let mut result = Vec::new();
1389        self.serialize_into(&mut result);
1390        result
1391    }
1392    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1393        bytes.reserve(32);
1394        let response_type_bytes = &[1];
1395        bytes.push(response_type_bytes[0]);
1396        bytes.extend_from_slice(&[0; 1]);
1397        self.sequence.serialize_into(bytes);
1398        self.length.serialize_into(bytes);
1399        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
1400        context_len.serialize_into(bytes);
1401        bytes.extend_from_slice(&[0; 20]);
1402        bytes.extend_from_slice(&self.context);
1403    }
1404}
1405impl GetPropertyContextReply {
1406    /// Get the value of the `context_len` field.
1407    ///
1408    /// The `context_len` field is used as the length field of the `context` field.
1409    /// This function computes the field's value again based on the length of the list.
1410    ///
1411    /// # Panics
1412    ///
1413    /// Panics if the value cannot be represented in the target type. This
1414    /// cannot happen with values of the struct received from the X11 server.
1415    pub fn context_len(&self) -> u32 {
1416        self.context.len()
1417            .try_into().unwrap()
1418    }
1419}
1420
1421/// Opcode for the GetPropertyDataContext request
1422pub const GET_PROPERTY_DATA_CONTEXT_REQUEST: u8 = 13;
1423#[derive(Clone, Copy, Default)]
1424#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1425#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1426pub struct GetPropertyDataContextRequest {
1427    pub window: xproto::Window,
1428    pub property: xproto::Atom,
1429}
1430impl_debug_if_no_extra_traits!(GetPropertyDataContextRequest, "GetPropertyDataContextRequest");
1431impl GetPropertyDataContextRequest {
1432    /// Serialize this request into bytes for the provided connection
1433    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1434        let length_so_far = 0;
1435        let window_bytes = self.window.serialize();
1436        let property_bytes = self.property.serialize();
1437        let mut request0 = vec![
1438            major_opcode,
1439            GET_PROPERTY_DATA_CONTEXT_REQUEST,
1440            0,
1441            0,
1442            window_bytes[0],
1443            window_bytes[1],
1444            window_bytes[2],
1445            window_bytes[3],
1446            property_bytes[0],
1447            property_bytes[1],
1448            property_bytes[2],
1449            property_bytes[3],
1450        ];
1451        let length_so_far = length_so_far + request0.len();
1452        assert_eq!(length_so_far % 4, 0);
1453        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1454        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1455        ([request0.into()], vec![])
1456    }
1457    /// Parse this request given its header, its body, and any fds that go along with it
1458    #[cfg(feature = "request-parsing")]
1459    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1460        if header.minor_opcode != GET_PROPERTY_DATA_CONTEXT_REQUEST {
1461            return Err(ParseError::InvalidValue);
1462        }
1463        let (window, remaining) = xproto::Window::try_parse(value)?;
1464        let (property, remaining) = xproto::Atom::try_parse(remaining)?;
1465        let _ = remaining;
1466        Ok(GetPropertyDataContextRequest {
1467            window,
1468            property,
1469        })
1470    }
1471}
1472impl Request for GetPropertyDataContextRequest {
1473    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1474
1475    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1476        let (bufs, fds) = self.serialize(major_opcode);
1477        // Flatten the buffers into a single vector
1478        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1479        (buf, fds)
1480    }
1481}
1482impl crate::x11_utils::ReplyRequest for GetPropertyDataContextRequest {
1483    type Reply = GetPropertyDataContextReply;
1484}
1485
1486#[derive(Clone, Default)]
1487#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1488#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1489pub struct GetPropertyDataContextReply {
1490    pub sequence: u16,
1491    pub length: u32,
1492    pub context: Vec<u8>,
1493}
1494impl_debug_if_no_extra_traits!(GetPropertyDataContextReply, "GetPropertyDataContextReply");
1495impl TryParse for GetPropertyDataContextReply {
1496    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1497        let remaining = initial_value;
1498        let (response_type, remaining) = u8::try_parse(remaining)?;
1499        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1500        let (sequence, remaining) = u16::try_parse(remaining)?;
1501        let (length, remaining) = u32::try_parse(remaining)?;
1502        let (context_len, remaining) = u32::try_parse(remaining)?;
1503        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
1504        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
1505        let context = context.to_vec();
1506        if response_type != 1 {
1507            return Err(ParseError::InvalidValue);
1508        }
1509        let result = GetPropertyDataContextReply { sequence, length, context };
1510        let _ = remaining;
1511        let remaining = initial_value.get(32 + length as usize * 4..)
1512            .ok_or(ParseError::InsufficientData)?;
1513        Ok((result, remaining))
1514    }
1515}
1516impl Serialize for GetPropertyDataContextReply {
1517    type Bytes = Vec<u8>;
1518    fn serialize(&self) -> Vec<u8> {
1519        let mut result = Vec::new();
1520        self.serialize_into(&mut result);
1521        result
1522    }
1523    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1524        bytes.reserve(32);
1525        let response_type_bytes = &[1];
1526        bytes.push(response_type_bytes[0]);
1527        bytes.extend_from_slice(&[0; 1]);
1528        self.sequence.serialize_into(bytes);
1529        self.length.serialize_into(bytes);
1530        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
1531        context_len.serialize_into(bytes);
1532        bytes.extend_from_slice(&[0; 20]);
1533        bytes.extend_from_slice(&self.context);
1534    }
1535}
1536impl GetPropertyDataContextReply {
1537    /// Get the value of the `context_len` field.
1538    ///
1539    /// The `context_len` field is used as the length field of the `context` field.
1540    /// This function computes the field's value again based on the length of the list.
1541    ///
1542    /// # Panics
1543    ///
1544    /// Panics if the value cannot be represented in the target type. This
1545    /// cannot happen with values of the struct received from the X11 server.
1546    pub fn context_len(&self) -> u32 {
1547        self.context.len()
1548            .try_into().unwrap()
1549    }
1550}
1551
1552/// Opcode for the ListProperties request
1553pub const LIST_PROPERTIES_REQUEST: u8 = 14;
1554#[derive(Clone, Copy, Default)]
1555#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1556#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1557pub struct ListPropertiesRequest {
1558    pub window: xproto::Window,
1559}
1560impl_debug_if_no_extra_traits!(ListPropertiesRequest, "ListPropertiesRequest");
1561impl ListPropertiesRequest {
1562    /// Serialize this request into bytes for the provided connection
1563    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1564        let length_so_far = 0;
1565        let window_bytes = self.window.serialize();
1566        let mut request0 = vec![
1567            major_opcode,
1568            LIST_PROPERTIES_REQUEST,
1569            0,
1570            0,
1571            window_bytes[0],
1572            window_bytes[1],
1573            window_bytes[2],
1574            window_bytes[3],
1575        ];
1576        let length_so_far = length_so_far + request0.len();
1577        assert_eq!(length_so_far % 4, 0);
1578        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1579        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1580        ([request0.into()], vec![])
1581    }
1582    /// Parse this request given its header, its body, and any fds that go along with it
1583    #[cfg(feature = "request-parsing")]
1584    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1585        if header.minor_opcode != LIST_PROPERTIES_REQUEST {
1586            return Err(ParseError::InvalidValue);
1587        }
1588        let (window, remaining) = xproto::Window::try_parse(value)?;
1589        let _ = remaining;
1590        Ok(ListPropertiesRequest {
1591            window,
1592        })
1593    }
1594}
1595impl Request for ListPropertiesRequest {
1596    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1597
1598    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1599        let (bufs, fds) = self.serialize(major_opcode);
1600        // Flatten the buffers into a single vector
1601        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1602        (buf, fds)
1603    }
1604}
1605impl crate::x11_utils::ReplyRequest for ListPropertiesRequest {
1606    type Reply = ListPropertiesReply;
1607}
1608
1609#[derive(Clone, Default)]
1610#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1611#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1612pub struct ListPropertiesReply {
1613    pub sequence: u16,
1614    pub length: u32,
1615    pub properties: Vec<ListItem>,
1616}
1617impl_debug_if_no_extra_traits!(ListPropertiesReply, "ListPropertiesReply");
1618impl TryParse for ListPropertiesReply {
1619    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1620        let remaining = initial_value;
1621        let (response_type, remaining) = u8::try_parse(remaining)?;
1622        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1623        let (sequence, remaining) = u16::try_parse(remaining)?;
1624        let (length, remaining) = u32::try_parse(remaining)?;
1625        let (properties_len, remaining) = u32::try_parse(remaining)?;
1626        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
1627        let (properties, remaining) = crate::x11_utils::parse_list::<ListItem>(remaining, properties_len.try_to_usize()?)?;
1628        if response_type != 1 {
1629            return Err(ParseError::InvalidValue);
1630        }
1631        let result = ListPropertiesReply { sequence, length, properties };
1632        let _ = remaining;
1633        let remaining = initial_value.get(32 + length as usize * 4..)
1634            .ok_or(ParseError::InsufficientData)?;
1635        Ok((result, remaining))
1636    }
1637}
1638impl Serialize for ListPropertiesReply {
1639    type Bytes = Vec<u8>;
1640    fn serialize(&self) -> Vec<u8> {
1641        let mut result = Vec::new();
1642        self.serialize_into(&mut result);
1643        result
1644    }
1645    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1646        bytes.reserve(32);
1647        let response_type_bytes = &[1];
1648        bytes.push(response_type_bytes[0]);
1649        bytes.extend_from_slice(&[0; 1]);
1650        self.sequence.serialize_into(bytes);
1651        self.length.serialize_into(bytes);
1652        let properties_len = u32::try_from(self.properties.len()).expect("`properties` has too many elements");
1653        properties_len.serialize_into(bytes);
1654        bytes.extend_from_slice(&[0; 20]);
1655        self.properties.serialize_into(bytes);
1656    }
1657}
1658impl ListPropertiesReply {
1659    /// Get the value of the `properties_len` field.
1660    ///
1661    /// The `properties_len` field is used as the length field of the `properties` field.
1662    /// This function computes the field's value again based on the length of the list.
1663    ///
1664    /// # Panics
1665    ///
1666    /// Panics if the value cannot be represented in the target type. This
1667    /// cannot happen with values of the struct received from the X11 server.
1668    pub fn properties_len(&self) -> u32 {
1669        self.properties.len()
1670            .try_into().unwrap()
1671    }
1672}
1673
1674/// Opcode for the SetSelectionCreateContext request
1675pub const SET_SELECTION_CREATE_CONTEXT_REQUEST: u8 = 15;
1676#[derive(Clone, Default)]
1677#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1678#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1679pub struct SetSelectionCreateContextRequest<'input> {
1680    pub context: Cow<'input, [u8]>,
1681}
1682impl_debug_if_no_extra_traits!(SetSelectionCreateContextRequest<'_>, "SetSelectionCreateContextRequest");
1683impl<'input> SetSelectionCreateContextRequest<'input> {
1684    /// Serialize this request into bytes for the provided connection
1685    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
1686        let length_so_far = 0;
1687        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
1688        let context_len_bytes = context_len.serialize();
1689        let mut request0 = vec![
1690            major_opcode,
1691            SET_SELECTION_CREATE_CONTEXT_REQUEST,
1692            0,
1693            0,
1694            context_len_bytes[0],
1695            context_len_bytes[1],
1696            context_len_bytes[2],
1697            context_len_bytes[3],
1698        ];
1699        let length_so_far = length_so_far + request0.len();
1700        let length_so_far = length_so_far + self.context.len();
1701        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1702        let length_so_far = length_so_far + padding0.len();
1703        assert_eq!(length_so_far % 4, 0);
1704        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1705        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1706        ([request0.into(), self.context, padding0.into()], vec![])
1707    }
1708    /// Parse this request given its header, its body, and any fds that go along with it
1709    #[cfg(feature = "request-parsing")]
1710    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1711        if header.minor_opcode != SET_SELECTION_CREATE_CONTEXT_REQUEST {
1712            return Err(ParseError::InvalidValue);
1713        }
1714        let (context_len, remaining) = u32::try_parse(value)?;
1715        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
1716        let _ = remaining;
1717        Ok(SetSelectionCreateContextRequest {
1718            context: Cow::Borrowed(context),
1719        })
1720    }
1721    /// Clone all borrowed data in this SetSelectionCreateContextRequest.
1722    pub fn into_owned(self) -> SetSelectionCreateContextRequest<'static> {
1723        SetSelectionCreateContextRequest {
1724            context: Cow::Owned(self.context.into_owned()),
1725        }
1726    }
1727}
1728impl<'input> Request for SetSelectionCreateContextRequest<'input> {
1729    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1730
1731    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1732        let (bufs, fds) = self.serialize(major_opcode);
1733        // Flatten the buffers into a single vector
1734        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1735        (buf, fds)
1736    }
1737}
1738impl<'input> crate::x11_utils::VoidRequest for SetSelectionCreateContextRequest<'input> {
1739}
1740
1741/// Opcode for the GetSelectionCreateContext request
1742pub const GET_SELECTION_CREATE_CONTEXT_REQUEST: u8 = 16;
1743#[derive(Clone, Copy, Default)]
1744#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1745#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1746pub struct GetSelectionCreateContextRequest;
1747impl_debug_if_no_extra_traits!(GetSelectionCreateContextRequest, "GetSelectionCreateContextRequest");
1748impl GetSelectionCreateContextRequest {
1749    /// Serialize this request into bytes for the provided connection
1750    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1751        let length_so_far = 0;
1752        let mut request0 = vec![
1753            major_opcode,
1754            GET_SELECTION_CREATE_CONTEXT_REQUEST,
1755            0,
1756            0,
1757        ];
1758        let length_so_far = length_so_far + request0.len();
1759        assert_eq!(length_so_far % 4, 0);
1760        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1761        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1762        ([request0.into()], vec![])
1763    }
1764    /// Parse this request given its header, its body, and any fds that go along with it
1765    #[cfg(feature = "request-parsing")]
1766    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1767        if header.minor_opcode != GET_SELECTION_CREATE_CONTEXT_REQUEST {
1768            return Err(ParseError::InvalidValue);
1769        }
1770        let _ = value;
1771        Ok(GetSelectionCreateContextRequest
1772        )
1773    }
1774}
1775impl Request for GetSelectionCreateContextRequest {
1776    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1777
1778    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1779        let (bufs, fds) = self.serialize(major_opcode);
1780        // Flatten the buffers into a single vector
1781        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1782        (buf, fds)
1783    }
1784}
1785impl crate::x11_utils::ReplyRequest for GetSelectionCreateContextRequest {
1786    type Reply = GetSelectionCreateContextReply;
1787}
1788
1789#[derive(Clone, Default)]
1790#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1791#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1792pub struct GetSelectionCreateContextReply {
1793    pub sequence: u16,
1794    pub length: u32,
1795    pub context: Vec<u8>,
1796}
1797impl_debug_if_no_extra_traits!(GetSelectionCreateContextReply, "GetSelectionCreateContextReply");
1798impl TryParse for GetSelectionCreateContextReply {
1799    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1800        let remaining = initial_value;
1801        let (response_type, remaining) = u8::try_parse(remaining)?;
1802        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1803        let (sequence, remaining) = u16::try_parse(remaining)?;
1804        let (length, remaining) = u32::try_parse(remaining)?;
1805        let (context_len, remaining) = u32::try_parse(remaining)?;
1806        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
1807        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
1808        let context = context.to_vec();
1809        if response_type != 1 {
1810            return Err(ParseError::InvalidValue);
1811        }
1812        let result = GetSelectionCreateContextReply { sequence, length, context };
1813        let _ = remaining;
1814        let remaining = initial_value.get(32 + length as usize * 4..)
1815            .ok_or(ParseError::InsufficientData)?;
1816        Ok((result, remaining))
1817    }
1818}
1819impl Serialize for GetSelectionCreateContextReply {
1820    type Bytes = Vec<u8>;
1821    fn serialize(&self) -> Vec<u8> {
1822        let mut result = Vec::new();
1823        self.serialize_into(&mut result);
1824        result
1825    }
1826    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1827        bytes.reserve(32);
1828        let response_type_bytes = &[1];
1829        bytes.push(response_type_bytes[0]);
1830        bytes.extend_from_slice(&[0; 1]);
1831        self.sequence.serialize_into(bytes);
1832        self.length.serialize_into(bytes);
1833        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
1834        context_len.serialize_into(bytes);
1835        bytes.extend_from_slice(&[0; 20]);
1836        bytes.extend_from_slice(&self.context);
1837    }
1838}
1839impl GetSelectionCreateContextReply {
1840    /// Get the value of the `context_len` field.
1841    ///
1842    /// The `context_len` field is used as the length field of the `context` field.
1843    /// This function computes the field's value again based on the length of the list.
1844    ///
1845    /// # Panics
1846    ///
1847    /// Panics if the value cannot be represented in the target type. This
1848    /// cannot happen with values of the struct received from the X11 server.
1849    pub fn context_len(&self) -> u32 {
1850        self.context.len()
1851            .try_into().unwrap()
1852    }
1853}
1854
1855/// Opcode for the SetSelectionUseContext request
1856pub const SET_SELECTION_USE_CONTEXT_REQUEST: u8 = 17;
1857#[derive(Clone, Default)]
1858#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1859#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1860pub struct SetSelectionUseContextRequest<'input> {
1861    pub context: Cow<'input, [u8]>,
1862}
1863impl_debug_if_no_extra_traits!(SetSelectionUseContextRequest<'_>, "SetSelectionUseContextRequest");
1864impl<'input> SetSelectionUseContextRequest<'input> {
1865    /// Serialize this request into bytes for the provided connection
1866    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
1867        let length_so_far = 0;
1868        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
1869        let context_len_bytes = context_len.serialize();
1870        let mut request0 = vec![
1871            major_opcode,
1872            SET_SELECTION_USE_CONTEXT_REQUEST,
1873            0,
1874            0,
1875            context_len_bytes[0],
1876            context_len_bytes[1],
1877            context_len_bytes[2],
1878            context_len_bytes[3],
1879        ];
1880        let length_so_far = length_so_far + request0.len();
1881        let length_so_far = length_so_far + self.context.len();
1882        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
1883        let length_so_far = length_so_far + padding0.len();
1884        assert_eq!(length_so_far % 4, 0);
1885        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1886        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1887        ([request0.into(), self.context, padding0.into()], vec![])
1888    }
1889    /// Parse this request given its header, its body, and any fds that go along with it
1890    #[cfg(feature = "request-parsing")]
1891    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
1892        if header.minor_opcode != SET_SELECTION_USE_CONTEXT_REQUEST {
1893            return Err(ParseError::InvalidValue);
1894        }
1895        let (context_len, remaining) = u32::try_parse(value)?;
1896        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
1897        let _ = remaining;
1898        Ok(SetSelectionUseContextRequest {
1899            context: Cow::Borrowed(context),
1900        })
1901    }
1902    /// Clone all borrowed data in this SetSelectionUseContextRequest.
1903    pub fn into_owned(self) -> SetSelectionUseContextRequest<'static> {
1904        SetSelectionUseContextRequest {
1905            context: Cow::Owned(self.context.into_owned()),
1906        }
1907    }
1908}
1909impl<'input> Request for SetSelectionUseContextRequest<'input> {
1910    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1911
1912    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1913        let (bufs, fds) = self.serialize(major_opcode);
1914        // Flatten the buffers into a single vector
1915        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1916        (buf, fds)
1917    }
1918}
1919impl<'input> crate::x11_utils::VoidRequest for SetSelectionUseContextRequest<'input> {
1920}
1921
1922/// Opcode for the GetSelectionUseContext request
1923pub const GET_SELECTION_USE_CONTEXT_REQUEST: u8 = 18;
1924#[derive(Clone, Copy, Default)]
1925#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1926#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1927pub struct GetSelectionUseContextRequest;
1928impl_debug_if_no_extra_traits!(GetSelectionUseContextRequest, "GetSelectionUseContextRequest");
1929impl GetSelectionUseContextRequest {
1930    /// Serialize this request into bytes for the provided connection
1931    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
1932        let length_so_far = 0;
1933        let mut request0 = vec![
1934            major_opcode,
1935            GET_SELECTION_USE_CONTEXT_REQUEST,
1936            0,
1937            0,
1938        ];
1939        let length_so_far = length_so_far + request0.len();
1940        assert_eq!(length_so_far % 4, 0);
1941        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
1942        request0[2..4].copy_from_slice(&length.to_ne_bytes());
1943        ([request0.into()], vec![])
1944    }
1945    /// Parse this request given its header, its body, and any fds that go along with it
1946    #[cfg(feature = "request-parsing")]
1947    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
1948        if header.minor_opcode != GET_SELECTION_USE_CONTEXT_REQUEST {
1949            return Err(ParseError::InvalidValue);
1950        }
1951        let _ = value;
1952        Ok(GetSelectionUseContextRequest
1953        )
1954    }
1955}
1956impl Request for GetSelectionUseContextRequest {
1957    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
1958
1959    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
1960        let (bufs, fds) = self.serialize(major_opcode);
1961        // Flatten the buffers into a single vector
1962        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
1963        (buf, fds)
1964    }
1965}
1966impl crate::x11_utils::ReplyRequest for GetSelectionUseContextRequest {
1967    type Reply = GetSelectionUseContextReply;
1968}
1969
1970#[derive(Clone, Default)]
1971#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
1972#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
1973pub struct GetSelectionUseContextReply {
1974    pub sequence: u16,
1975    pub length: u32,
1976    pub context: Vec<u8>,
1977}
1978impl_debug_if_no_extra_traits!(GetSelectionUseContextReply, "GetSelectionUseContextReply");
1979impl TryParse for GetSelectionUseContextReply {
1980    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
1981        let remaining = initial_value;
1982        let (response_type, remaining) = u8::try_parse(remaining)?;
1983        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
1984        let (sequence, remaining) = u16::try_parse(remaining)?;
1985        let (length, remaining) = u32::try_parse(remaining)?;
1986        let (context_len, remaining) = u32::try_parse(remaining)?;
1987        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
1988        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
1989        let context = context.to_vec();
1990        if response_type != 1 {
1991            return Err(ParseError::InvalidValue);
1992        }
1993        let result = GetSelectionUseContextReply { sequence, length, context };
1994        let _ = remaining;
1995        let remaining = initial_value.get(32 + length as usize * 4..)
1996            .ok_or(ParseError::InsufficientData)?;
1997        Ok((result, remaining))
1998    }
1999}
2000impl Serialize for GetSelectionUseContextReply {
2001    type Bytes = Vec<u8>;
2002    fn serialize(&self) -> Vec<u8> {
2003        let mut result = Vec::new();
2004        self.serialize_into(&mut result);
2005        result
2006    }
2007    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2008        bytes.reserve(32);
2009        let response_type_bytes = &[1];
2010        bytes.push(response_type_bytes[0]);
2011        bytes.extend_from_slice(&[0; 1]);
2012        self.sequence.serialize_into(bytes);
2013        self.length.serialize_into(bytes);
2014        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
2015        context_len.serialize_into(bytes);
2016        bytes.extend_from_slice(&[0; 20]);
2017        bytes.extend_from_slice(&self.context);
2018    }
2019}
2020impl GetSelectionUseContextReply {
2021    /// Get the value of the `context_len` field.
2022    ///
2023    /// The `context_len` field is used as the length field of the `context` field.
2024    /// This function computes the field's value again based on the length of the list.
2025    ///
2026    /// # Panics
2027    ///
2028    /// Panics if the value cannot be represented in the target type. This
2029    /// cannot happen with values of the struct received from the X11 server.
2030    pub fn context_len(&self) -> u32 {
2031        self.context.len()
2032            .try_into().unwrap()
2033    }
2034}
2035
2036/// Opcode for the GetSelectionContext request
2037pub const GET_SELECTION_CONTEXT_REQUEST: u8 = 19;
2038#[derive(Clone, Copy, Default)]
2039#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2040#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2041pub struct GetSelectionContextRequest {
2042    pub selection: xproto::Atom,
2043}
2044impl_debug_if_no_extra_traits!(GetSelectionContextRequest, "GetSelectionContextRequest");
2045impl GetSelectionContextRequest {
2046    /// Serialize this request into bytes for the provided connection
2047    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2048        let length_so_far = 0;
2049        let selection_bytes = self.selection.serialize();
2050        let mut request0 = vec![
2051            major_opcode,
2052            GET_SELECTION_CONTEXT_REQUEST,
2053            0,
2054            0,
2055            selection_bytes[0],
2056            selection_bytes[1],
2057            selection_bytes[2],
2058            selection_bytes[3],
2059        ];
2060        let length_so_far = length_so_far + request0.len();
2061        assert_eq!(length_so_far % 4, 0);
2062        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2063        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2064        ([request0.into()], vec![])
2065    }
2066    /// Parse this request given its header, its body, and any fds that go along with it
2067    #[cfg(feature = "request-parsing")]
2068    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2069        if header.minor_opcode != GET_SELECTION_CONTEXT_REQUEST {
2070            return Err(ParseError::InvalidValue);
2071        }
2072        let (selection, remaining) = xproto::Atom::try_parse(value)?;
2073        let _ = remaining;
2074        Ok(GetSelectionContextRequest {
2075            selection,
2076        })
2077    }
2078}
2079impl Request for GetSelectionContextRequest {
2080    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2081
2082    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2083        let (bufs, fds) = self.serialize(major_opcode);
2084        // Flatten the buffers into a single vector
2085        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2086        (buf, fds)
2087    }
2088}
2089impl crate::x11_utils::ReplyRequest for GetSelectionContextRequest {
2090    type Reply = GetSelectionContextReply;
2091}
2092
2093#[derive(Clone, Default)]
2094#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2095#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2096pub struct GetSelectionContextReply {
2097    pub sequence: u16,
2098    pub length: u32,
2099    pub context: Vec<u8>,
2100}
2101impl_debug_if_no_extra_traits!(GetSelectionContextReply, "GetSelectionContextReply");
2102impl TryParse for GetSelectionContextReply {
2103    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2104        let remaining = initial_value;
2105        let (response_type, remaining) = u8::try_parse(remaining)?;
2106        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2107        let (sequence, remaining) = u16::try_parse(remaining)?;
2108        let (length, remaining) = u32::try_parse(remaining)?;
2109        let (context_len, remaining) = u32::try_parse(remaining)?;
2110        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
2111        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
2112        let context = context.to_vec();
2113        if response_type != 1 {
2114            return Err(ParseError::InvalidValue);
2115        }
2116        let result = GetSelectionContextReply { sequence, length, context };
2117        let _ = remaining;
2118        let remaining = initial_value.get(32 + length as usize * 4..)
2119            .ok_or(ParseError::InsufficientData)?;
2120        Ok((result, remaining))
2121    }
2122}
2123impl Serialize for GetSelectionContextReply {
2124    type Bytes = Vec<u8>;
2125    fn serialize(&self) -> Vec<u8> {
2126        let mut result = Vec::new();
2127        self.serialize_into(&mut result);
2128        result
2129    }
2130    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2131        bytes.reserve(32);
2132        let response_type_bytes = &[1];
2133        bytes.push(response_type_bytes[0]);
2134        bytes.extend_from_slice(&[0; 1]);
2135        self.sequence.serialize_into(bytes);
2136        self.length.serialize_into(bytes);
2137        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
2138        context_len.serialize_into(bytes);
2139        bytes.extend_from_slice(&[0; 20]);
2140        bytes.extend_from_slice(&self.context);
2141    }
2142}
2143impl GetSelectionContextReply {
2144    /// Get the value of the `context_len` field.
2145    ///
2146    /// The `context_len` field is used as the length field of the `context` field.
2147    /// This function computes the field's value again based on the length of the list.
2148    ///
2149    /// # Panics
2150    ///
2151    /// Panics if the value cannot be represented in the target type. This
2152    /// cannot happen with values of the struct received from the X11 server.
2153    pub fn context_len(&self) -> u32 {
2154        self.context.len()
2155            .try_into().unwrap()
2156    }
2157}
2158
2159/// Opcode for the GetSelectionDataContext request
2160pub const GET_SELECTION_DATA_CONTEXT_REQUEST: u8 = 20;
2161#[derive(Clone, Copy, Default)]
2162#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2163#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2164pub struct GetSelectionDataContextRequest {
2165    pub selection: xproto::Atom,
2166}
2167impl_debug_if_no_extra_traits!(GetSelectionDataContextRequest, "GetSelectionDataContextRequest");
2168impl GetSelectionDataContextRequest {
2169    /// Serialize this request into bytes for the provided connection
2170    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2171        let length_so_far = 0;
2172        let selection_bytes = self.selection.serialize();
2173        let mut request0 = vec![
2174            major_opcode,
2175            GET_SELECTION_DATA_CONTEXT_REQUEST,
2176            0,
2177            0,
2178            selection_bytes[0],
2179            selection_bytes[1],
2180            selection_bytes[2],
2181            selection_bytes[3],
2182        ];
2183        let length_so_far = length_so_far + request0.len();
2184        assert_eq!(length_so_far % 4, 0);
2185        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2186        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2187        ([request0.into()], vec![])
2188    }
2189    /// Parse this request given its header, its body, and any fds that go along with it
2190    #[cfg(feature = "request-parsing")]
2191    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2192        if header.minor_opcode != GET_SELECTION_DATA_CONTEXT_REQUEST {
2193            return Err(ParseError::InvalidValue);
2194        }
2195        let (selection, remaining) = xproto::Atom::try_parse(value)?;
2196        let _ = remaining;
2197        Ok(GetSelectionDataContextRequest {
2198            selection,
2199        })
2200    }
2201}
2202impl Request for GetSelectionDataContextRequest {
2203    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2204
2205    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2206        let (bufs, fds) = self.serialize(major_opcode);
2207        // Flatten the buffers into a single vector
2208        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2209        (buf, fds)
2210    }
2211}
2212impl crate::x11_utils::ReplyRequest for GetSelectionDataContextRequest {
2213    type Reply = GetSelectionDataContextReply;
2214}
2215
2216#[derive(Clone, Default)]
2217#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2218#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2219pub struct GetSelectionDataContextReply {
2220    pub sequence: u16,
2221    pub length: u32,
2222    pub context: Vec<u8>,
2223}
2224impl_debug_if_no_extra_traits!(GetSelectionDataContextReply, "GetSelectionDataContextReply");
2225impl TryParse for GetSelectionDataContextReply {
2226    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2227        let remaining = initial_value;
2228        let (response_type, remaining) = u8::try_parse(remaining)?;
2229        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2230        let (sequence, remaining) = u16::try_parse(remaining)?;
2231        let (length, remaining) = u32::try_parse(remaining)?;
2232        let (context_len, remaining) = u32::try_parse(remaining)?;
2233        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
2234        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
2235        let context = context.to_vec();
2236        if response_type != 1 {
2237            return Err(ParseError::InvalidValue);
2238        }
2239        let result = GetSelectionDataContextReply { sequence, length, context };
2240        let _ = remaining;
2241        let remaining = initial_value.get(32 + length as usize * 4..)
2242            .ok_or(ParseError::InsufficientData)?;
2243        Ok((result, remaining))
2244    }
2245}
2246impl Serialize for GetSelectionDataContextReply {
2247    type Bytes = Vec<u8>;
2248    fn serialize(&self) -> Vec<u8> {
2249        let mut result = Vec::new();
2250        self.serialize_into(&mut result);
2251        result
2252    }
2253    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2254        bytes.reserve(32);
2255        let response_type_bytes = &[1];
2256        bytes.push(response_type_bytes[0]);
2257        bytes.extend_from_slice(&[0; 1]);
2258        self.sequence.serialize_into(bytes);
2259        self.length.serialize_into(bytes);
2260        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
2261        context_len.serialize_into(bytes);
2262        bytes.extend_from_slice(&[0; 20]);
2263        bytes.extend_from_slice(&self.context);
2264    }
2265}
2266impl GetSelectionDataContextReply {
2267    /// Get the value of the `context_len` field.
2268    ///
2269    /// The `context_len` field is used as the length field of the `context` field.
2270    /// This function computes the field's value again based on the length of the list.
2271    ///
2272    /// # Panics
2273    ///
2274    /// Panics if the value cannot be represented in the target type. This
2275    /// cannot happen with values of the struct received from the X11 server.
2276    pub fn context_len(&self) -> u32 {
2277        self.context.len()
2278            .try_into().unwrap()
2279    }
2280}
2281
2282/// Opcode for the ListSelections request
2283pub const LIST_SELECTIONS_REQUEST: u8 = 21;
2284#[derive(Clone, Copy, Default)]
2285#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2286#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2287pub struct ListSelectionsRequest;
2288impl_debug_if_no_extra_traits!(ListSelectionsRequest, "ListSelectionsRequest");
2289impl ListSelectionsRequest {
2290    /// Serialize this request into bytes for the provided connection
2291    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2292        let length_so_far = 0;
2293        let mut request0 = vec![
2294            major_opcode,
2295            LIST_SELECTIONS_REQUEST,
2296            0,
2297            0,
2298        ];
2299        let length_so_far = length_so_far + request0.len();
2300        assert_eq!(length_so_far % 4, 0);
2301        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2302        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2303        ([request0.into()], vec![])
2304    }
2305    /// Parse this request given its header, its body, and any fds that go along with it
2306    #[cfg(feature = "request-parsing")]
2307    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2308        if header.minor_opcode != LIST_SELECTIONS_REQUEST {
2309            return Err(ParseError::InvalidValue);
2310        }
2311        let _ = value;
2312        Ok(ListSelectionsRequest
2313        )
2314    }
2315}
2316impl Request for ListSelectionsRequest {
2317    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2318
2319    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2320        let (bufs, fds) = self.serialize(major_opcode);
2321        // Flatten the buffers into a single vector
2322        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2323        (buf, fds)
2324    }
2325}
2326impl crate::x11_utils::ReplyRequest for ListSelectionsRequest {
2327    type Reply = ListSelectionsReply;
2328}
2329
2330#[derive(Clone, Default)]
2331#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2332#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2333pub struct ListSelectionsReply {
2334    pub sequence: u16,
2335    pub length: u32,
2336    pub selections: Vec<ListItem>,
2337}
2338impl_debug_if_no_extra_traits!(ListSelectionsReply, "ListSelectionsReply");
2339impl TryParse for ListSelectionsReply {
2340    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2341        let remaining = initial_value;
2342        let (response_type, remaining) = u8::try_parse(remaining)?;
2343        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2344        let (sequence, remaining) = u16::try_parse(remaining)?;
2345        let (length, remaining) = u32::try_parse(remaining)?;
2346        let (selections_len, remaining) = u32::try_parse(remaining)?;
2347        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
2348        let (selections, remaining) = crate::x11_utils::parse_list::<ListItem>(remaining, selections_len.try_to_usize()?)?;
2349        if response_type != 1 {
2350            return Err(ParseError::InvalidValue);
2351        }
2352        let result = ListSelectionsReply { sequence, length, selections };
2353        let _ = remaining;
2354        let remaining = initial_value.get(32 + length as usize * 4..)
2355            .ok_or(ParseError::InsufficientData)?;
2356        Ok((result, remaining))
2357    }
2358}
2359impl Serialize for ListSelectionsReply {
2360    type Bytes = Vec<u8>;
2361    fn serialize(&self) -> Vec<u8> {
2362        let mut result = Vec::new();
2363        self.serialize_into(&mut result);
2364        result
2365    }
2366    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2367        bytes.reserve(32);
2368        let response_type_bytes = &[1];
2369        bytes.push(response_type_bytes[0]);
2370        bytes.extend_from_slice(&[0; 1]);
2371        self.sequence.serialize_into(bytes);
2372        self.length.serialize_into(bytes);
2373        let selections_len = u32::try_from(self.selections.len()).expect("`selections` has too many elements");
2374        selections_len.serialize_into(bytes);
2375        bytes.extend_from_slice(&[0; 20]);
2376        self.selections.serialize_into(bytes);
2377    }
2378}
2379impl ListSelectionsReply {
2380    /// Get the value of the `selections_len` field.
2381    ///
2382    /// The `selections_len` field is used as the length field of the `selections` field.
2383    /// This function computes the field's value again based on the length of the list.
2384    ///
2385    /// # Panics
2386    ///
2387    /// Panics if the value cannot be represented in the target type. This
2388    /// cannot happen with values of the struct received from the X11 server.
2389    pub fn selections_len(&self) -> u32 {
2390        self.selections.len()
2391            .try_into().unwrap()
2392    }
2393}
2394
2395/// Opcode for the GetClientContext request
2396pub const GET_CLIENT_CONTEXT_REQUEST: u8 = 22;
2397#[derive(Clone, Copy, Default)]
2398#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2399#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2400pub struct GetClientContextRequest {
2401    pub resource: u32,
2402}
2403impl_debug_if_no_extra_traits!(GetClientContextRequest, "GetClientContextRequest");
2404impl GetClientContextRequest {
2405    /// Serialize this request into bytes for the provided connection
2406    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
2407        let length_so_far = 0;
2408        let resource_bytes = self.resource.serialize();
2409        let mut request0 = vec![
2410            major_opcode,
2411            GET_CLIENT_CONTEXT_REQUEST,
2412            0,
2413            0,
2414            resource_bytes[0],
2415            resource_bytes[1],
2416            resource_bytes[2],
2417            resource_bytes[3],
2418        ];
2419        let length_so_far = length_so_far + request0.len();
2420        assert_eq!(length_so_far % 4, 0);
2421        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
2422        request0[2..4].copy_from_slice(&length.to_ne_bytes());
2423        ([request0.into()], vec![])
2424    }
2425    /// Parse this request given its header, its body, and any fds that go along with it
2426    #[cfg(feature = "request-parsing")]
2427    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
2428        if header.minor_opcode != GET_CLIENT_CONTEXT_REQUEST {
2429            return Err(ParseError::InvalidValue);
2430        }
2431        let (resource, remaining) = u32::try_parse(value)?;
2432        let _ = remaining;
2433        Ok(GetClientContextRequest {
2434            resource,
2435        })
2436    }
2437}
2438impl Request for GetClientContextRequest {
2439    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
2440
2441    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
2442        let (bufs, fds) = self.serialize(major_opcode);
2443        // Flatten the buffers into a single vector
2444        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
2445        (buf, fds)
2446    }
2447}
2448impl crate::x11_utils::ReplyRequest for GetClientContextRequest {
2449    type Reply = GetClientContextReply;
2450}
2451
2452#[derive(Clone, Default)]
2453#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
2454#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2455pub struct GetClientContextReply {
2456    pub sequence: u16,
2457    pub length: u32,
2458    pub context: Vec<u8>,
2459}
2460impl_debug_if_no_extra_traits!(GetClientContextReply, "GetClientContextReply");
2461impl TryParse for GetClientContextReply {
2462    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
2463        let remaining = initial_value;
2464        let (response_type, remaining) = u8::try_parse(remaining)?;
2465        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
2466        let (sequence, remaining) = u16::try_parse(remaining)?;
2467        let (length, remaining) = u32::try_parse(remaining)?;
2468        let (context_len, remaining) = u32::try_parse(remaining)?;
2469        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
2470        let (context, remaining) = crate::x11_utils::parse_u8_list(remaining, context_len.try_to_usize()?)?;
2471        let context = context.to_vec();
2472        if response_type != 1 {
2473            return Err(ParseError::InvalidValue);
2474        }
2475        let result = GetClientContextReply { sequence, length, context };
2476        let _ = remaining;
2477        let remaining = initial_value.get(32 + length as usize * 4..)
2478            .ok_or(ParseError::InsufficientData)?;
2479        Ok((result, remaining))
2480    }
2481}
2482impl Serialize for GetClientContextReply {
2483    type Bytes = Vec<u8>;
2484    fn serialize(&self) -> Vec<u8> {
2485        let mut result = Vec::new();
2486        self.serialize_into(&mut result);
2487        result
2488    }
2489    fn serialize_into(&self, bytes: &mut Vec<u8>) {
2490        bytes.reserve(32);
2491        let response_type_bytes = &[1];
2492        bytes.push(response_type_bytes[0]);
2493        bytes.extend_from_slice(&[0; 1]);
2494        self.sequence.serialize_into(bytes);
2495        self.length.serialize_into(bytes);
2496        let context_len = u32::try_from(self.context.len()).expect("`context` has too many elements");
2497        context_len.serialize_into(bytes);
2498        bytes.extend_from_slice(&[0; 20]);
2499        bytes.extend_from_slice(&self.context);
2500    }
2501}
2502impl GetClientContextReply {
2503    /// Get the value of the `context_len` field.
2504    ///
2505    /// The `context_len` field is used as the length field of the `context` field.
2506    /// This function computes the field's value again based on the length of the list.
2507    ///
2508    /// # Panics
2509    ///
2510    /// Panics if the value cannot be represented in the target type. This
2511    /// cannot happen with values of the struct received from the X11 server.
2512    pub fn context_len(&self) -> u32 {
2513        self.context.len()
2514            .try_into().unwrap()
2515    }
2516}
2517