x11rb_protocol/protocol/
dbe.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `Dbe` 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 = "DOUBLE-BUFFER";
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
39pub type BackBuffer = xproto::Drawable;
40
41/// Specifies what to do with the front buffer after it is swapped with the back buffer.
42///
43/// # Fields
44///
45/// * `Undefined` - Discard the buffer. The buffer may be reallocated and end up with random VRAM content.
46/// * `Background` - Erase with window background.
47/// * `Untouched` - Leave untouched.
48/// * `Copied` - Copy the newly displayed front buffer.
49#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
50#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
51pub struct SwapAction(u8);
52impl SwapAction {
53    pub const UNDEFINED: Self = Self(0);
54    pub const BACKGROUND: Self = Self(1);
55    pub const UNTOUCHED: Self = Self(2);
56    pub const COPIED: Self = Self(3);
57}
58impl From<SwapAction> for u8 {
59    #[inline]
60    fn from(input: SwapAction) -> Self {
61        input.0
62    }
63}
64impl From<SwapAction> for Option<u8> {
65    #[inline]
66    fn from(input: SwapAction) -> Self {
67        Some(input.0)
68    }
69}
70impl From<SwapAction> for u16 {
71    #[inline]
72    fn from(input: SwapAction) -> Self {
73        u16::from(input.0)
74    }
75}
76impl From<SwapAction> for Option<u16> {
77    #[inline]
78    fn from(input: SwapAction) -> Self {
79        Some(u16::from(input.0))
80    }
81}
82impl From<SwapAction> for u32 {
83    #[inline]
84    fn from(input: SwapAction) -> Self {
85        u32::from(input.0)
86    }
87}
88impl From<SwapAction> for Option<u32> {
89    #[inline]
90    fn from(input: SwapAction) -> Self {
91        Some(u32::from(input.0))
92    }
93}
94impl From<u8> for SwapAction {
95    #[inline]
96    fn from(value: u8) -> Self {
97        Self(value)
98    }
99}
100impl core::fmt::Debug for SwapAction  {
101    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
102        let variants = [
103            (Self::UNDEFINED.0.into(), "UNDEFINED", "Undefined"),
104            (Self::BACKGROUND.0.into(), "BACKGROUND", "Background"),
105            (Self::UNTOUCHED.0.into(), "UNTOUCHED", "Untouched"),
106            (Self::COPIED.0.into(), "COPIED", "Copied"),
107        ];
108        pretty_print_enum(fmt, self.0.into(), &variants)
109    }
110}
111
112#[derive(Clone, Copy, Default)]
113#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
114#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
115pub struct SwapInfo {
116    pub window: xproto::Window,
117    pub swap_action: SwapAction,
118}
119impl_debug_if_no_extra_traits!(SwapInfo, "SwapInfo");
120impl TryParse for SwapInfo {
121    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
122        let (window, remaining) = xproto::Window::try_parse(remaining)?;
123        let (swap_action, remaining) = u8::try_parse(remaining)?;
124        let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
125        let swap_action = swap_action.into();
126        let result = SwapInfo { window, swap_action };
127        Ok((result, remaining))
128    }
129}
130impl Serialize for SwapInfo {
131    type Bytes = [u8; 8];
132    fn serialize(&self) -> [u8; 8] {
133        let window_bytes = self.window.serialize();
134        let swap_action_bytes = u8::from(self.swap_action).serialize();
135        [
136            window_bytes[0],
137            window_bytes[1],
138            window_bytes[2],
139            window_bytes[3],
140            swap_action_bytes[0],
141            0,
142            0,
143            0,
144        ]
145    }
146    fn serialize_into(&self, bytes: &mut Vec<u8>) {
147        bytes.reserve(8);
148        self.window.serialize_into(bytes);
149        u8::from(self.swap_action).serialize_into(bytes);
150        bytes.extend_from_slice(&[0; 3]);
151    }
152}
153
154#[derive(Clone, Copy, Default)]
155#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
156#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
157pub struct BufferAttributes {
158    pub window: xproto::Window,
159}
160impl_debug_if_no_extra_traits!(BufferAttributes, "BufferAttributes");
161impl TryParse for BufferAttributes {
162    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
163        let (window, remaining) = xproto::Window::try_parse(remaining)?;
164        let result = BufferAttributes { window };
165        Ok((result, remaining))
166    }
167}
168impl Serialize for BufferAttributes {
169    type Bytes = [u8; 4];
170    fn serialize(&self) -> [u8; 4] {
171        let window_bytes = self.window.serialize();
172        [
173            window_bytes[0],
174            window_bytes[1],
175            window_bytes[2],
176            window_bytes[3],
177        ]
178    }
179    fn serialize_into(&self, bytes: &mut Vec<u8>) {
180        bytes.reserve(4);
181        self.window.serialize_into(bytes);
182    }
183}
184
185#[derive(Clone, Copy, Default)]
186#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
187#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
188pub struct VisualInfo {
189    pub visual_id: xproto::Visualid,
190    pub depth: u8,
191    pub perf_level: u8,
192}
193impl_debug_if_no_extra_traits!(VisualInfo, "VisualInfo");
194impl TryParse for VisualInfo {
195    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
196        let (visual_id, remaining) = xproto::Visualid::try_parse(remaining)?;
197        let (depth, remaining) = u8::try_parse(remaining)?;
198        let (perf_level, remaining) = u8::try_parse(remaining)?;
199        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
200        let result = VisualInfo { visual_id, depth, perf_level };
201        Ok((result, remaining))
202    }
203}
204impl Serialize for VisualInfo {
205    type Bytes = [u8; 8];
206    fn serialize(&self) -> [u8; 8] {
207        let visual_id_bytes = self.visual_id.serialize();
208        let depth_bytes = self.depth.serialize();
209        let perf_level_bytes = self.perf_level.serialize();
210        [
211            visual_id_bytes[0],
212            visual_id_bytes[1],
213            visual_id_bytes[2],
214            visual_id_bytes[3],
215            depth_bytes[0],
216            perf_level_bytes[0],
217            0,
218            0,
219        ]
220    }
221    fn serialize_into(&self, bytes: &mut Vec<u8>) {
222        bytes.reserve(8);
223        self.visual_id.serialize_into(bytes);
224        self.depth.serialize_into(bytes);
225        self.perf_level.serialize_into(bytes);
226        bytes.extend_from_slice(&[0; 2]);
227    }
228}
229
230#[derive(Clone, Default)]
231#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
232#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
233pub struct VisualInfos {
234    pub infos: Vec<VisualInfo>,
235}
236impl_debug_if_no_extra_traits!(VisualInfos, "VisualInfos");
237impl TryParse for VisualInfos {
238    fn try_parse(remaining: &[u8]) -> Result<(Self, &[u8]), ParseError> {
239        let (n_infos, remaining) = u32::try_parse(remaining)?;
240        let (infos, remaining) = crate::x11_utils::parse_list::<VisualInfo>(remaining, n_infos.try_to_usize()?)?;
241        let result = VisualInfos { infos };
242        Ok((result, remaining))
243    }
244}
245impl Serialize for VisualInfos {
246    type Bytes = Vec<u8>;
247    fn serialize(&self) -> Vec<u8> {
248        let mut result = Vec::new();
249        self.serialize_into(&mut result);
250        result
251    }
252    fn serialize_into(&self, bytes: &mut Vec<u8>) {
253        let n_infos = u32::try_from(self.infos.len()).expect("`infos` has too many elements");
254        n_infos.serialize_into(bytes);
255        self.infos.serialize_into(bytes);
256    }
257}
258impl VisualInfos {
259    /// Get the value of the `n_infos` field.
260    ///
261    /// The `n_infos` field is used as the length field of the `infos` field.
262    /// This function computes the field's value again based on the length of the list.
263    ///
264    /// # Panics
265    ///
266    /// Panics if the value cannot be represented in the target type. This
267    /// cannot happen with values of the struct received from the X11 server.
268    pub fn n_infos(&self) -> u32 {
269        self.infos.len()
270            .try_into().unwrap()
271    }
272}
273
274/// Opcode for the BadBuffer error
275pub const BAD_BUFFER_ERROR: u8 = 0;
276
277/// Opcode for the QueryVersion request
278pub const QUERY_VERSION_REQUEST: u8 = 0;
279/// Queries the version of this extension.
280///
281/// Queries the version of this extension. You must do this before using any functionality it provides.
282///
283/// # Fields
284///
285/// * `major_version` - The major version of the extension. Check that it is compatible with the XCB_DBE_MAJOR_VERSION that your code is compiled with.
286/// * `minor_version` - The minor version of the extension. Check that it is compatible with the XCB_DBE_MINOR_VERSION that your code is compiled with.
287#[derive(Clone, Copy, Default)]
288#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
289#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
290pub struct QueryVersionRequest {
291    pub major_version: u8,
292    pub minor_version: u8,
293}
294impl_debug_if_no_extra_traits!(QueryVersionRequest, "QueryVersionRequest");
295impl QueryVersionRequest {
296    /// Serialize this request into bytes for the provided connection
297    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
298        let length_so_far = 0;
299        let major_version_bytes = self.major_version.serialize();
300        let minor_version_bytes = self.minor_version.serialize();
301        let mut request0 = vec![
302            major_opcode,
303            QUERY_VERSION_REQUEST,
304            0,
305            0,
306            major_version_bytes[0],
307            minor_version_bytes[0],
308            0,
309            0,
310        ];
311        let length_so_far = length_so_far + request0.len();
312        assert_eq!(length_so_far % 4, 0);
313        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
314        request0[2..4].copy_from_slice(&length.to_ne_bytes());
315        ([request0.into()], vec![])
316    }
317    /// Parse this request given its header, its body, and any fds that go along with it
318    #[cfg(feature = "request-parsing")]
319    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
320        if header.minor_opcode != QUERY_VERSION_REQUEST {
321            return Err(ParseError::InvalidValue);
322        }
323        let (major_version, remaining) = u8::try_parse(value)?;
324        let (minor_version, remaining) = u8::try_parse(remaining)?;
325        let remaining = remaining.get(2..).ok_or(ParseError::InsufficientData)?;
326        let _ = remaining;
327        Ok(QueryVersionRequest {
328            major_version,
329            minor_version,
330        })
331    }
332}
333impl Request for QueryVersionRequest {
334    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
335
336    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
337        let (bufs, fds) = self.serialize(major_opcode);
338        // Flatten the buffers into a single vector
339        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
340        (buf, fds)
341    }
342}
343impl crate::x11_utils::ReplyRequest for QueryVersionRequest {
344    type Reply = QueryVersionReply;
345}
346
347#[derive(Clone, Copy, 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 QueryVersionReply {
351    pub sequence: u16,
352    pub length: u32,
353    pub major_version: u8,
354    pub minor_version: u8,
355}
356impl_debug_if_no_extra_traits!(QueryVersionReply, "QueryVersionReply");
357impl TryParse for QueryVersionReply {
358    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
359        let remaining = initial_value;
360        let (response_type, remaining) = u8::try_parse(remaining)?;
361        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
362        let (sequence, remaining) = u16::try_parse(remaining)?;
363        let (length, remaining) = u32::try_parse(remaining)?;
364        let (major_version, remaining) = u8::try_parse(remaining)?;
365        let (minor_version, remaining) = u8::try_parse(remaining)?;
366        let remaining = remaining.get(22..).ok_or(ParseError::InsufficientData)?;
367        if response_type != 1 {
368            return Err(ParseError::InvalidValue);
369        }
370        let result = QueryVersionReply { sequence, length, major_version, minor_version };
371        let _ = remaining;
372        let remaining = initial_value.get(32 + length as usize * 4..)
373            .ok_or(ParseError::InsufficientData)?;
374        Ok((result, remaining))
375    }
376}
377impl Serialize for QueryVersionReply {
378    type Bytes = [u8; 32];
379    fn serialize(&self) -> [u8; 32] {
380        let response_type_bytes = &[1];
381        let sequence_bytes = self.sequence.serialize();
382        let length_bytes = self.length.serialize();
383        let major_version_bytes = self.major_version.serialize();
384        let minor_version_bytes = self.minor_version.serialize();
385        [
386            response_type_bytes[0],
387            0,
388            sequence_bytes[0],
389            sequence_bytes[1],
390            length_bytes[0],
391            length_bytes[1],
392            length_bytes[2],
393            length_bytes[3],
394            major_version_bytes[0],
395            minor_version_bytes[0],
396            0,
397            0,
398            0,
399            0,
400            0,
401            0,
402            0,
403            0,
404            0,
405            0,
406            0,
407            0,
408            0,
409            0,
410            0,
411            0,
412            0,
413            0,
414            0,
415            0,
416            0,
417            0,
418        ]
419    }
420    fn serialize_into(&self, bytes: &mut Vec<u8>) {
421        bytes.reserve(32);
422        let response_type_bytes = &[1];
423        bytes.push(response_type_bytes[0]);
424        bytes.extend_from_slice(&[0; 1]);
425        self.sequence.serialize_into(bytes);
426        self.length.serialize_into(bytes);
427        self.major_version.serialize_into(bytes);
428        self.minor_version.serialize_into(bytes);
429        bytes.extend_from_slice(&[0; 22]);
430    }
431}
432
433/// Opcode for the AllocateBackBuffer request
434pub const ALLOCATE_BACK_BUFFER_REQUEST: u8 = 1;
435/// Allocates a back buffer.
436///
437/// Associates `buffer` with the back buffer of `window`. Multiple ids may be associated with the back buffer, which is created by the first allocate call and destroyed by the last deallocate.
438///
439/// # Fields
440///
441/// * `window` - The window to which to add the back buffer.
442/// * `buffer` - The buffer id to associate with the back buffer.
443/// * `swap_action` - The swap action most likely to be used to present this back buffer. This is only a hint, and does not preclude the use of other swap actions.
444#[derive(Clone, Copy, Default)]
445#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
446#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
447pub struct AllocateBackBufferRequest {
448    pub window: xproto::Window,
449    pub buffer: BackBuffer,
450    pub swap_action: u8,
451}
452impl_debug_if_no_extra_traits!(AllocateBackBufferRequest, "AllocateBackBufferRequest");
453impl AllocateBackBufferRequest {
454    /// Serialize this request into bytes for the provided connection
455    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
456        let length_so_far = 0;
457        let window_bytes = self.window.serialize();
458        let buffer_bytes = self.buffer.serialize();
459        let swap_action_bytes = self.swap_action.serialize();
460        let mut request0 = vec![
461            major_opcode,
462            ALLOCATE_BACK_BUFFER_REQUEST,
463            0,
464            0,
465            window_bytes[0],
466            window_bytes[1],
467            window_bytes[2],
468            window_bytes[3],
469            buffer_bytes[0],
470            buffer_bytes[1],
471            buffer_bytes[2],
472            buffer_bytes[3],
473            swap_action_bytes[0],
474            0,
475            0,
476            0,
477        ];
478        let length_so_far = length_so_far + request0.len();
479        assert_eq!(length_so_far % 4, 0);
480        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
481        request0[2..4].copy_from_slice(&length.to_ne_bytes());
482        ([request0.into()], vec![])
483    }
484    /// Parse this request given its header, its body, and any fds that go along with it
485    #[cfg(feature = "request-parsing")]
486    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
487        if header.minor_opcode != ALLOCATE_BACK_BUFFER_REQUEST {
488            return Err(ParseError::InvalidValue);
489        }
490        let (window, remaining) = xproto::Window::try_parse(value)?;
491        let (buffer, remaining) = BackBuffer::try_parse(remaining)?;
492        let (swap_action, remaining) = u8::try_parse(remaining)?;
493        let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
494        let _ = remaining;
495        Ok(AllocateBackBufferRequest {
496            window,
497            buffer,
498            swap_action,
499        })
500    }
501}
502impl Request for AllocateBackBufferRequest {
503    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
504
505    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
506        let (bufs, fds) = self.serialize(major_opcode);
507        // Flatten the buffers into a single vector
508        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
509        (buf, fds)
510    }
511}
512impl crate::x11_utils::VoidRequest for AllocateBackBufferRequest {
513}
514
515/// Opcode for the DeallocateBackBuffer request
516pub const DEALLOCATE_BACK_BUFFER_REQUEST: u8 = 2;
517/// Deallocates a back buffer.
518///
519/// Deallocates the given `buffer`. If `buffer` is an invalid id, a `BadBuffer` error is returned. Because a window may have allocated multiple back buffer ids, the back buffer itself is not deleted until all these ids are deallocated by this call.
520///
521/// # Fields
522///
523/// * `buffer` - The back buffer to deallocate.
524#[derive(Clone, Copy, Default)]
525#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
526#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
527pub struct DeallocateBackBufferRequest {
528    pub buffer: BackBuffer,
529}
530impl_debug_if_no_extra_traits!(DeallocateBackBufferRequest, "DeallocateBackBufferRequest");
531impl DeallocateBackBufferRequest {
532    /// Serialize this request into bytes for the provided connection
533    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
534        let length_so_far = 0;
535        let buffer_bytes = self.buffer.serialize();
536        let mut request0 = vec![
537            major_opcode,
538            DEALLOCATE_BACK_BUFFER_REQUEST,
539            0,
540            0,
541            buffer_bytes[0],
542            buffer_bytes[1],
543            buffer_bytes[2],
544            buffer_bytes[3],
545        ];
546        let length_so_far = length_so_far + request0.len();
547        assert_eq!(length_so_far % 4, 0);
548        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
549        request0[2..4].copy_from_slice(&length.to_ne_bytes());
550        ([request0.into()], vec![])
551    }
552    /// Parse this request given its header, its body, and any fds that go along with it
553    #[cfg(feature = "request-parsing")]
554    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
555        if header.minor_opcode != DEALLOCATE_BACK_BUFFER_REQUEST {
556            return Err(ParseError::InvalidValue);
557        }
558        let (buffer, remaining) = BackBuffer::try_parse(value)?;
559        let _ = remaining;
560        Ok(DeallocateBackBufferRequest {
561            buffer,
562        })
563    }
564}
565impl Request for DeallocateBackBufferRequest {
566    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
567
568    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
569        let (bufs, fds) = self.serialize(major_opcode);
570        // Flatten the buffers into a single vector
571        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
572        (buf, fds)
573    }
574}
575impl crate::x11_utils::VoidRequest for DeallocateBackBufferRequest {
576}
577
578/// Opcode for the SwapBuffers request
579pub const SWAP_BUFFERS_REQUEST: u8 = 3;
580/// Swaps front and back buffers.
581///
582/// Swaps the front and back buffers on the specified windows. The front and back buffers retain their ids, so that the window id continues to refer to the front buffer, while the back buffer id created by this extension continues to refer to the back buffer. Back buffer contents is moved to the front buffer. Back buffer contents after the operation depends on the given swap action. The optimal swap action depends on how each frame is rendered. For example, if the buffer is cleared and fully overwritten on every frame, the "untouched" action, which throws away the buffer contents, would provide the best performance. To eliminate visual artifacts, the swap will occure during the monitor VSync, if the X server supports detecting it.
583///
584/// # Fields
585///
586/// * `actions` - List of windows on which to swap buffers.
587#[derive(Clone, Default)]
588#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
589#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
590pub struct SwapBuffersRequest<'input> {
591    pub actions: Cow<'input, [SwapInfo]>,
592}
593impl_debug_if_no_extra_traits!(SwapBuffersRequest<'_>, "SwapBuffersRequest");
594impl<'input> SwapBuffersRequest<'input> {
595    /// Serialize this request into bytes for the provided connection
596    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
597        let length_so_far = 0;
598        let n_actions = u32::try_from(self.actions.len()).expect("`actions` has too many elements");
599        let n_actions_bytes = n_actions.serialize();
600        let mut request0 = vec![
601            major_opcode,
602            SWAP_BUFFERS_REQUEST,
603            0,
604            0,
605            n_actions_bytes[0],
606            n_actions_bytes[1],
607            n_actions_bytes[2],
608            n_actions_bytes[3],
609        ];
610        let length_so_far = length_so_far + request0.len();
611        let actions_bytes = self.actions.serialize();
612        let length_so_far = length_so_far + actions_bytes.len();
613        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
614        let length_so_far = length_so_far + padding0.len();
615        assert_eq!(length_so_far % 4, 0);
616        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
617        request0[2..4].copy_from_slice(&length.to_ne_bytes());
618        ([request0.into(), actions_bytes.into(), padding0.into()], vec![])
619    }
620    /// Parse this request given its header, its body, and any fds that go along with it
621    #[cfg(feature = "request-parsing")]
622    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
623        if header.minor_opcode != SWAP_BUFFERS_REQUEST {
624            return Err(ParseError::InvalidValue);
625        }
626        let (n_actions, remaining) = u32::try_parse(value)?;
627        let (actions, remaining) = crate::x11_utils::parse_list::<SwapInfo>(remaining, n_actions.try_to_usize()?)?;
628        let _ = remaining;
629        Ok(SwapBuffersRequest {
630            actions: Cow::Owned(actions),
631        })
632    }
633    /// Clone all borrowed data in this SwapBuffersRequest.
634    pub fn into_owned(self) -> SwapBuffersRequest<'static> {
635        SwapBuffersRequest {
636            actions: Cow::Owned(self.actions.into_owned()),
637        }
638    }
639}
640impl<'input> Request for SwapBuffersRequest<'input> {
641    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
642
643    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
644        let (bufs, fds) = self.serialize(major_opcode);
645        // Flatten the buffers into a single vector
646        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
647        (buf, fds)
648    }
649}
650impl<'input> crate::x11_utils::VoidRequest for SwapBuffersRequest<'input> {
651}
652
653/// Opcode for the BeginIdiom request
654pub const BEGIN_IDIOM_REQUEST: u8 = 4;
655/// Begins a logical swap block.
656///
657/// Creates a block of operations intended to occur together. This may be needed if window presentation requires changing buffers unknown to this extension, such as depth or stencil buffers.
658#[derive(Clone, Copy, Default)]
659#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
660#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
661pub struct BeginIdiomRequest;
662impl_debug_if_no_extra_traits!(BeginIdiomRequest, "BeginIdiomRequest");
663impl BeginIdiomRequest {
664    /// Serialize this request into bytes for the provided connection
665    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
666        let length_so_far = 0;
667        let mut request0 = vec![
668            major_opcode,
669            BEGIN_IDIOM_REQUEST,
670            0,
671            0,
672        ];
673        let length_so_far = length_so_far + request0.len();
674        assert_eq!(length_so_far % 4, 0);
675        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
676        request0[2..4].copy_from_slice(&length.to_ne_bytes());
677        ([request0.into()], vec![])
678    }
679    /// Parse this request given its header, its body, and any fds that go along with it
680    #[cfg(feature = "request-parsing")]
681    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
682        if header.minor_opcode != BEGIN_IDIOM_REQUEST {
683            return Err(ParseError::InvalidValue);
684        }
685        let _ = value;
686        Ok(BeginIdiomRequest
687        )
688    }
689}
690impl Request for BeginIdiomRequest {
691    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
692
693    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
694        let (bufs, fds) = self.serialize(major_opcode);
695        // Flatten the buffers into a single vector
696        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
697        (buf, fds)
698    }
699}
700impl crate::x11_utils::VoidRequest for BeginIdiomRequest {
701}
702
703/// Opcode for the EndIdiom request
704pub const END_IDIOM_REQUEST: u8 = 5;
705/// Ends a logical swap block.
706#[derive(Clone, Copy, Default)]
707#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
708#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
709pub struct EndIdiomRequest;
710impl_debug_if_no_extra_traits!(EndIdiomRequest, "EndIdiomRequest");
711impl EndIdiomRequest {
712    /// Serialize this request into bytes for the provided connection
713    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
714        let length_so_far = 0;
715        let mut request0 = vec![
716            major_opcode,
717            END_IDIOM_REQUEST,
718            0,
719            0,
720        ];
721        let length_so_far = length_so_far + request0.len();
722        assert_eq!(length_so_far % 4, 0);
723        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
724        request0[2..4].copy_from_slice(&length.to_ne_bytes());
725        ([request0.into()], vec![])
726    }
727    /// Parse this request given its header, its body, and any fds that go along with it
728    #[cfg(feature = "request-parsing")]
729    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
730        if header.minor_opcode != END_IDIOM_REQUEST {
731            return Err(ParseError::InvalidValue);
732        }
733        let _ = value;
734        Ok(EndIdiomRequest
735        )
736    }
737}
738impl Request for EndIdiomRequest {
739    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
740
741    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
742        let (bufs, fds) = self.serialize(major_opcode);
743        // Flatten the buffers into a single vector
744        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
745        (buf, fds)
746    }
747}
748impl crate::x11_utils::VoidRequest for EndIdiomRequest {
749}
750
751/// Opcode for the GetVisualInfo request
752pub const GET_VISUAL_INFO_REQUEST: u8 = 6;
753/// Requests visuals that support double buffering.
754#[derive(Clone, Default)]
755#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
756#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
757pub struct GetVisualInfoRequest<'input> {
758    pub drawables: Cow<'input, [xproto::Drawable]>,
759}
760impl_debug_if_no_extra_traits!(GetVisualInfoRequest<'_>, "GetVisualInfoRequest");
761impl<'input> GetVisualInfoRequest<'input> {
762    /// Serialize this request into bytes for the provided connection
763    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'input, [u8]>; 3]> {
764        let length_so_far = 0;
765        let n_drawables = u32::try_from(self.drawables.len()).expect("`drawables` has too many elements");
766        let n_drawables_bytes = n_drawables.serialize();
767        let mut request0 = vec![
768            major_opcode,
769            GET_VISUAL_INFO_REQUEST,
770            0,
771            0,
772            n_drawables_bytes[0],
773            n_drawables_bytes[1],
774            n_drawables_bytes[2],
775            n_drawables_bytes[3],
776        ];
777        let length_so_far = length_so_far + request0.len();
778        let drawables_bytes = self.drawables.serialize();
779        let length_so_far = length_so_far + drawables_bytes.len();
780        let padding0 = &[0; 3][..(4 - (length_so_far % 4)) % 4];
781        let length_so_far = length_so_far + padding0.len();
782        assert_eq!(length_so_far % 4, 0);
783        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
784        request0[2..4].copy_from_slice(&length.to_ne_bytes());
785        ([request0.into(), drawables_bytes.into(), padding0.into()], vec![])
786    }
787    /// Parse this request given its header, its body, and any fds that go along with it
788    #[cfg(feature = "request-parsing")]
789    pub fn try_parse_request(header: RequestHeader, value: &'input [u8]) -> Result<Self, ParseError> {
790        if header.minor_opcode != GET_VISUAL_INFO_REQUEST {
791            return Err(ParseError::InvalidValue);
792        }
793        let (n_drawables, remaining) = u32::try_parse(value)?;
794        let (drawables, remaining) = crate::x11_utils::parse_list::<xproto::Drawable>(remaining, n_drawables.try_to_usize()?)?;
795        let _ = remaining;
796        Ok(GetVisualInfoRequest {
797            drawables: Cow::Owned(drawables),
798        })
799    }
800    /// Clone all borrowed data in this GetVisualInfoRequest.
801    pub fn into_owned(self) -> GetVisualInfoRequest<'static> {
802        GetVisualInfoRequest {
803            drawables: Cow::Owned(self.drawables.into_owned()),
804        }
805    }
806}
807impl<'input> Request for GetVisualInfoRequest<'input> {
808    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
809
810    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
811        let (bufs, fds) = self.serialize(major_opcode);
812        // Flatten the buffers into a single vector
813        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
814        (buf, fds)
815    }
816}
817impl<'input> crate::x11_utils::ReplyRequest for GetVisualInfoRequest<'input> {
818    type Reply = GetVisualInfoReply;
819}
820
821#[derive(Clone, Default)]
822#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
823#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
824pub struct GetVisualInfoReply {
825    pub sequence: u16,
826    pub length: u32,
827    pub supported_visuals: Vec<VisualInfos>,
828}
829impl_debug_if_no_extra_traits!(GetVisualInfoReply, "GetVisualInfoReply");
830impl TryParse for GetVisualInfoReply {
831    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
832        let remaining = initial_value;
833        let (response_type, remaining) = u8::try_parse(remaining)?;
834        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
835        let (sequence, remaining) = u16::try_parse(remaining)?;
836        let (length, remaining) = u32::try_parse(remaining)?;
837        let (n_supported_visuals, remaining) = u32::try_parse(remaining)?;
838        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
839        let (supported_visuals, remaining) = crate::x11_utils::parse_list::<VisualInfos>(remaining, n_supported_visuals.try_to_usize()?)?;
840        if response_type != 1 {
841            return Err(ParseError::InvalidValue);
842        }
843        let result = GetVisualInfoReply { sequence, length, supported_visuals };
844        let _ = remaining;
845        let remaining = initial_value.get(32 + length as usize * 4..)
846            .ok_or(ParseError::InsufficientData)?;
847        Ok((result, remaining))
848    }
849}
850impl Serialize for GetVisualInfoReply {
851    type Bytes = Vec<u8>;
852    fn serialize(&self) -> Vec<u8> {
853        let mut result = Vec::new();
854        self.serialize_into(&mut result);
855        result
856    }
857    fn serialize_into(&self, bytes: &mut Vec<u8>) {
858        bytes.reserve(32);
859        let response_type_bytes = &[1];
860        bytes.push(response_type_bytes[0]);
861        bytes.extend_from_slice(&[0; 1]);
862        self.sequence.serialize_into(bytes);
863        self.length.serialize_into(bytes);
864        let n_supported_visuals = u32::try_from(self.supported_visuals.len()).expect("`supported_visuals` has too many elements");
865        n_supported_visuals.serialize_into(bytes);
866        bytes.extend_from_slice(&[0; 20]);
867        self.supported_visuals.serialize_into(bytes);
868    }
869}
870impl GetVisualInfoReply {
871    /// Get the value of the `n_supported_visuals` field.
872    ///
873    /// The `n_supported_visuals` field is used as the length field of the `supported_visuals` field.
874    /// This function computes the field's value again based on the length of the list.
875    ///
876    /// # Panics
877    ///
878    /// Panics if the value cannot be represented in the target type. This
879    /// cannot happen with values of the struct received from the X11 server.
880    pub fn n_supported_visuals(&self) -> u32 {
881        self.supported_visuals.len()
882            .try_into().unwrap()
883    }
884}
885
886/// Opcode for the GetBackBufferAttributes request
887pub const GET_BACK_BUFFER_ATTRIBUTES_REQUEST: u8 = 7;
888/// Gets back buffer attributes.
889///
890/// Returns the attributes of the specified `buffer`.
891///
892/// # Fields
893///
894/// * `buffer` - The back buffer to query.
895/// * `attributes` - The attributes of `buffer`.
896#[derive(Clone, Copy, Default)]
897#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
898#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
899pub struct GetBackBufferAttributesRequest {
900    pub buffer: BackBuffer,
901}
902impl_debug_if_no_extra_traits!(GetBackBufferAttributesRequest, "GetBackBufferAttributesRequest");
903impl GetBackBufferAttributesRequest {
904    /// Serialize this request into bytes for the provided connection
905    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
906        let length_so_far = 0;
907        let buffer_bytes = self.buffer.serialize();
908        let mut request0 = vec![
909            major_opcode,
910            GET_BACK_BUFFER_ATTRIBUTES_REQUEST,
911            0,
912            0,
913            buffer_bytes[0],
914            buffer_bytes[1],
915            buffer_bytes[2],
916            buffer_bytes[3],
917        ];
918        let length_so_far = length_so_far + request0.len();
919        assert_eq!(length_so_far % 4, 0);
920        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
921        request0[2..4].copy_from_slice(&length.to_ne_bytes());
922        ([request0.into()], vec![])
923    }
924    /// Parse this request given its header, its body, and any fds that go along with it
925    #[cfg(feature = "request-parsing")]
926    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
927        if header.minor_opcode != GET_BACK_BUFFER_ATTRIBUTES_REQUEST {
928            return Err(ParseError::InvalidValue);
929        }
930        let (buffer, remaining) = BackBuffer::try_parse(value)?;
931        let _ = remaining;
932        Ok(GetBackBufferAttributesRequest {
933            buffer,
934        })
935    }
936}
937impl Request for GetBackBufferAttributesRequest {
938    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
939
940    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
941        let (bufs, fds) = self.serialize(major_opcode);
942        // Flatten the buffers into a single vector
943        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
944        (buf, fds)
945    }
946}
947impl crate::x11_utils::ReplyRequest for GetBackBufferAttributesRequest {
948    type Reply = GetBackBufferAttributesReply;
949}
950
951#[derive(Clone, Copy, Default)]
952#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
953#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
954pub struct GetBackBufferAttributesReply {
955    pub sequence: u16,
956    pub length: u32,
957    pub attributes: BufferAttributes,
958}
959impl_debug_if_no_extra_traits!(GetBackBufferAttributesReply, "GetBackBufferAttributesReply");
960impl TryParse for GetBackBufferAttributesReply {
961    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
962        let remaining = initial_value;
963        let (response_type, remaining) = u8::try_parse(remaining)?;
964        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
965        let (sequence, remaining) = u16::try_parse(remaining)?;
966        let (length, remaining) = u32::try_parse(remaining)?;
967        let (attributes, remaining) = BufferAttributes::try_parse(remaining)?;
968        let remaining = remaining.get(20..).ok_or(ParseError::InsufficientData)?;
969        if response_type != 1 {
970            return Err(ParseError::InvalidValue);
971        }
972        let result = GetBackBufferAttributesReply { sequence, length, attributes };
973        let _ = remaining;
974        let remaining = initial_value.get(32 + length as usize * 4..)
975            .ok_or(ParseError::InsufficientData)?;
976        Ok((result, remaining))
977    }
978}
979impl Serialize for GetBackBufferAttributesReply {
980    type Bytes = [u8; 32];
981    fn serialize(&self) -> [u8; 32] {
982        let response_type_bytes = &[1];
983        let sequence_bytes = self.sequence.serialize();
984        let length_bytes = self.length.serialize();
985        let attributes_bytes = self.attributes.serialize();
986        [
987            response_type_bytes[0],
988            0,
989            sequence_bytes[0],
990            sequence_bytes[1],
991            length_bytes[0],
992            length_bytes[1],
993            length_bytes[2],
994            length_bytes[3],
995            attributes_bytes[0],
996            attributes_bytes[1],
997            attributes_bytes[2],
998            attributes_bytes[3],
999            0,
1000            0,
1001            0,
1002            0,
1003            0,
1004            0,
1005            0,
1006            0,
1007            0,
1008            0,
1009            0,
1010            0,
1011            0,
1012            0,
1013            0,
1014            0,
1015            0,
1016            0,
1017            0,
1018            0,
1019        ]
1020    }
1021    fn serialize_into(&self, bytes: &mut Vec<u8>) {
1022        bytes.reserve(32);
1023        let response_type_bytes = &[1];
1024        bytes.push(response_type_bytes[0]);
1025        bytes.extend_from_slice(&[0; 1]);
1026        self.sequence.serialize_into(bytes);
1027        self.length.serialize_into(bytes);
1028        self.attributes.serialize_into(bytes);
1029        bytes.extend_from_slice(&[0; 20]);
1030    }
1031}
1032