x11rb_protocol/protocol/
damage.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `Damage` 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::xfixes;
27#[allow(unused_imports)]
28use super::xproto;
29
30/// The X11 name of the extension for QueryExtension
31pub const X11_EXTENSION_NAME: &str = "DAMAGE";
32
33/// The version number of this extension that this client library supports.
34///
35/// This constant contains the version number of this extension that is supported
36/// by this build of x11rb. For most things, it does not make sense to use this
37/// information. If you need to send a `QueryVersion`, it is recommended to instead
38/// send the maximum version of the extension that you need.
39pub const X11_XML_VERSION: (u32, u32) = (1, 1);
40
41pub type Damage = u32;
42
43#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
44#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
45pub struct ReportLevel(u8);
46impl ReportLevel {
47    pub const RAW_RECTANGLES: Self = Self(0);
48    pub const DELTA_RECTANGLES: Self = Self(1);
49    pub const BOUNDING_BOX: Self = Self(2);
50    pub const NON_EMPTY: Self = Self(3);
51}
52impl From<ReportLevel> for u8 {
53    #[inline]
54    fn from(input: ReportLevel) -> Self {
55        input.0
56    }
57}
58impl From<ReportLevel> for Option<u8> {
59    #[inline]
60    fn from(input: ReportLevel) -> Self {
61        Some(input.0)
62    }
63}
64impl From<ReportLevel> for u16 {
65    #[inline]
66    fn from(input: ReportLevel) -> Self {
67        u16::from(input.0)
68    }
69}
70impl From<ReportLevel> for Option<u16> {
71    #[inline]
72    fn from(input: ReportLevel) -> Self {
73        Some(u16::from(input.0))
74    }
75}
76impl From<ReportLevel> for u32 {
77    #[inline]
78    fn from(input: ReportLevel) -> Self {
79        u32::from(input.0)
80    }
81}
82impl From<ReportLevel> for Option<u32> {
83    #[inline]
84    fn from(input: ReportLevel) -> Self {
85        Some(u32::from(input.0))
86    }
87}
88impl From<u8> for ReportLevel {
89    #[inline]
90    fn from(value: u8) -> Self {
91        Self(value)
92    }
93}
94impl core::fmt::Debug for ReportLevel  {
95    fn fmt(&self, fmt: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
96        let variants = [
97            (Self::RAW_RECTANGLES.0.into(), "RAW_RECTANGLES", "RawRectangles"),
98            (Self::DELTA_RECTANGLES.0.into(), "DELTA_RECTANGLES", "DeltaRectangles"),
99            (Self::BOUNDING_BOX.0.into(), "BOUNDING_BOX", "BoundingBox"),
100            (Self::NON_EMPTY.0.into(), "NON_EMPTY", "NonEmpty"),
101        ];
102        pretty_print_enum(fmt, self.0.into(), &variants)
103    }
104}
105
106/// Opcode for the BadDamage error
107pub const BAD_DAMAGE_ERROR: u8 = 0;
108
109/// Opcode for the QueryVersion request
110pub const QUERY_VERSION_REQUEST: u8 = 0;
111/// Negotiate the version of the DAMAGE extension.
112///
113/// This negotiates the version of the DAMAGE extension.  It must precede any other
114/// request using the DAMAGE extension.  Failure to do so will cause a BadRequest
115/// error for those requests.
116///
117/// # Fields
118///
119/// * `client_major_version` - The major version supported by the client.
120/// * `client_minor_version` - The minor version supported by the client.
121#[derive(Clone, Copy, Default)]
122#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
123#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
124pub struct QueryVersionRequest {
125    pub client_major_version: u32,
126    pub client_minor_version: u32,
127}
128impl_debug_if_no_extra_traits!(QueryVersionRequest, "QueryVersionRequest");
129impl QueryVersionRequest {
130    /// Serialize this request into bytes for the provided connection
131    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
132        let length_so_far = 0;
133        let client_major_version_bytes = self.client_major_version.serialize();
134        let client_minor_version_bytes = self.client_minor_version.serialize();
135        let mut request0 = vec![
136            major_opcode,
137            QUERY_VERSION_REQUEST,
138            0,
139            0,
140            client_major_version_bytes[0],
141            client_major_version_bytes[1],
142            client_major_version_bytes[2],
143            client_major_version_bytes[3],
144            client_minor_version_bytes[0],
145            client_minor_version_bytes[1],
146            client_minor_version_bytes[2],
147            client_minor_version_bytes[3],
148        ];
149        let length_so_far = length_so_far + request0.len();
150        assert_eq!(length_so_far % 4, 0);
151        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
152        request0[2..4].copy_from_slice(&length.to_ne_bytes());
153        ([request0.into()], vec![])
154    }
155    /// Parse this request given its header, its body, and any fds that go along with it
156    #[cfg(feature = "request-parsing")]
157    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
158        if header.minor_opcode != QUERY_VERSION_REQUEST {
159            return Err(ParseError::InvalidValue);
160        }
161        let (client_major_version, remaining) = u32::try_parse(value)?;
162        let (client_minor_version, remaining) = u32::try_parse(remaining)?;
163        let _ = remaining;
164        Ok(QueryVersionRequest {
165            client_major_version,
166            client_minor_version,
167        })
168    }
169}
170impl Request for QueryVersionRequest {
171    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
172
173    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
174        let (bufs, fds) = self.serialize(major_opcode);
175        // Flatten the buffers into a single vector
176        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
177        (buf, fds)
178    }
179}
180impl crate::x11_utils::ReplyRequest for QueryVersionRequest {
181    type Reply = QueryVersionReply;
182}
183
184/// The negotiated version of the DAMAGE extension.
185///
186/// This indicates the version of the DAMAGE extension chosen by the server.
187/// It will always be less than or equal to the version offered by the client.
188///
189/// # Fields
190///
191/// * `major_version` - The major version chosen by the server.
192/// * `minor_version` - The minor version chosen by the server.
193#[derive(Clone, Copy, Default)]
194#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
195#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
196pub struct QueryVersionReply {
197    pub sequence: u16,
198    pub length: u32,
199    pub major_version: u32,
200    pub minor_version: u32,
201}
202impl_debug_if_no_extra_traits!(QueryVersionReply, "QueryVersionReply");
203impl TryParse for QueryVersionReply {
204    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
205        let remaining = initial_value;
206        let (response_type, remaining) = u8::try_parse(remaining)?;
207        let remaining = remaining.get(1..).ok_or(ParseError::InsufficientData)?;
208        let (sequence, remaining) = u16::try_parse(remaining)?;
209        let (length, remaining) = u32::try_parse(remaining)?;
210        let (major_version, remaining) = u32::try_parse(remaining)?;
211        let (minor_version, remaining) = u32::try_parse(remaining)?;
212        let remaining = remaining.get(16..).ok_or(ParseError::InsufficientData)?;
213        if response_type != 1 {
214            return Err(ParseError::InvalidValue);
215        }
216        let result = QueryVersionReply { sequence, length, major_version, minor_version };
217        let _ = remaining;
218        let remaining = initial_value.get(32 + length as usize * 4..)
219            .ok_or(ParseError::InsufficientData)?;
220        Ok((result, remaining))
221    }
222}
223impl Serialize for QueryVersionReply {
224    type Bytes = [u8; 32];
225    fn serialize(&self) -> [u8; 32] {
226        let response_type_bytes = &[1];
227        let sequence_bytes = self.sequence.serialize();
228        let length_bytes = self.length.serialize();
229        let major_version_bytes = self.major_version.serialize();
230        let minor_version_bytes = self.minor_version.serialize();
231        [
232            response_type_bytes[0],
233            0,
234            sequence_bytes[0],
235            sequence_bytes[1],
236            length_bytes[0],
237            length_bytes[1],
238            length_bytes[2],
239            length_bytes[3],
240            major_version_bytes[0],
241            major_version_bytes[1],
242            major_version_bytes[2],
243            major_version_bytes[3],
244            minor_version_bytes[0],
245            minor_version_bytes[1],
246            minor_version_bytes[2],
247            minor_version_bytes[3],
248            0,
249            0,
250            0,
251            0,
252            0,
253            0,
254            0,
255            0,
256            0,
257            0,
258            0,
259            0,
260            0,
261            0,
262            0,
263            0,
264        ]
265    }
266    fn serialize_into(&self, bytes: &mut Vec<u8>) {
267        bytes.reserve(32);
268        let response_type_bytes = &[1];
269        bytes.push(response_type_bytes[0]);
270        bytes.extend_from_slice(&[0; 1]);
271        self.sequence.serialize_into(bytes);
272        self.length.serialize_into(bytes);
273        self.major_version.serialize_into(bytes);
274        self.minor_version.serialize_into(bytes);
275        bytes.extend_from_slice(&[0; 16]);
276    }
277}
278
279/// Opcode for the Create request
280pub const CREATE_REQUEST: u8 = 1;
281/// Creates a Damage object to monitor changes to a drawable..
282///
283/// This creates a Damage object to monitor changes to a drawable, and specifies
284/// the level of detail to be reported for changes.
285///
286/// We call changes made to pixel contents of windows and pixmaps 'damage'
287/// throughout this extension.
288///
289/// Damage accumulates as drawing occurs in the drawable.  Each drawing operation
290/// 'damages' one or more rectangular areas within the drawable.  The rectangles
291/// are guaranteed to include the set of pixels modified by each operation, but
292/// may include significantly more than just those pixels.  The desire is for
293/// the damage to strike a balance between the number of rectangles reported and
294/// the extraneous area included.  A reasonable goal is for each primitive
295/// object drawn (line, string, rectangle) to be represented as a single
296/// rectangle and for the damage area of the operation to be the union of these
297/// rectangles.
298///
299/// The DAMAGE extension allows applications to either receive the raw
300/// rectangles as a stream of events, or to have them partially processed within
301/// the X server to reduce the amount of data transmitted as well as reduce the
302/// processing latency once the repaint operation has started.
303///
304/// The Damage object holds any accumulated damage region and reflects the
305/// relationship between the drawable selected for damage notification and the
306/// drawable for which damage is tracked.
307///
308/// # Fields
309///
310/// * `damage` - The ID with which you will refer to the new Damage object, created by
311/// `xcb_generate_id`.
312/// * `drawable` - The ID of the drawable to be monitored.
313/// * `level` - The level of detail to be provided in Damage events.
314#[derive(Clone, Copy, Default)]
315#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
316#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
317pub struct CreateRequest {
318    pub damage: Damage,
319    pub drawable: xproto::Drawable,
320    pub level: ReportLevel,
321}
322impl_debug_if_no_extra_traits!(CreateRequest, "CreateRequest");
323impl CreateRequest {
324    /// Serialize this request into bytes for the provided connection
325    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
326        let length_so_far = 0;
327        let damage_bytes = self.damage.serialize();
328        let drawable_bytes = self.drawable.serialize();
329        let level_bytes = u8::from(self.level).serialize();
330        let mut request0 = vec![
331            major_opcode,
332            CREATE_REQUEST,
333            0,
334            0,
335            damage_bytes[0],
336            damage_bytes[1],
337            damage_bytes[2],
338            damage_bytes[3],
339            drawable_bytes[0],
340            drawable_bytes[1],
341            drawable_bytes[2],
342            drawable_bytes[3],
343            level_bytes[0],
344            0,
345            0,
346            0,
347        ];
348        let length_so_far = length_so_far + request0.len();
349        assert_eq!(length_so_far % 4, 0);
350        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
351        request0[2..4].copy_from_slice(&length.to_ne_bytes());
352        ([request0.into()], vec![])
353    }
354    /// Parse this request given its header, its body, and any fds that go along with it
355    #[cfg(feature = "request-parsing")]
356    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
357        if header.minor_opcode != CREATE_REQUEST {
358            return Err(ParseError::InvalidValue);
359        }
360        let (damage, remaining) = Damage::try_parse(value)?;
361        let (drawable, remaining) = xproto::Drawable::try_parse(remaining)?;
362        let (level, remaining) = u8::try_parse(remaining)?;
363        let level = level.into();
364        let remaining = remaining.get(3..).ok_or(ParseError::InsufficientData)?;
365        let _ = remaining;
366        Ok(CreateRequest {
367            damage,
368            drawable,
369            level,
370        })
371    }
372}
373impl Request for CreateRequest {
374    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
375
376    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
377        let (bufs, fds) = self.serialize(major_opcode);
378        // Flatten the buffers into a single vector
379        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
380        (buf, fds)
381    }
382}
383impl crate::x11_utils::VoidRequest for CreateRequest {
384}
385
386/// Opcode for the Destroy request
387pub const DESTROY_REQUEST: u8 = 2;
388/// Destroys a previously created Damage object..
389///
390/// This destroys a Damage object and requests the X server stop reporting
391/// the changes it was tracking.
392///
393/// # Fields
394///
395/// * `damage` - The ID you provided to `xcb_create_damage`.
396#[derive(Clone, Copy, Default)]
397#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
398#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
399pub struct DestroyRequest {
400    pub damage: Damage,
401}
402impl_debug_if_no_extra_traits!(DestroyRequest, "DestroyRequest");
403impl DestroyRequest {
404    /// Serialize this request into bytes for the provided connection
405    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
406        let length_so_far = 0;
407        let damage_bytes = self.damage.serialize();
408        let mut request0 = vec![
409            major_opcode,
410            DESTROY_REQUEST,
411            0,
412            0,
413            damage_bytes[0],
414            damage_bytes[1],
415            damage_bytes[2],
416            damage_bytes[3],
417        ];
418        let length_so_far = length_so_far + request0.len();
419        assert_eq!(length_so_far % 4, 0);
420        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
421        request0[2..4].copy_from_slice(&length.to_ne_bytes());
422        ([request0.into()], vec![])
423    }
424    /// Parse this request given its header, its body, and any fds that go along with it
425    #[cfg(feature = "request-parsing")]
426    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
427        if header.minor_opcode != DESTROY_REQUEST {
428            return Err(ParseError::InvalidValue);
429        }
430        let (damage, remaining) = Damage::try_parse(value)?;
431        let _ = remaining;
432        Ok(DestroyRequest {
433            damage,
434        })
435    }
436}
437impl Request for DestroyRequest {
438    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
439
440    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
441        let (bufs, fds) = self.serialize(major_opcode);
442        // Flatten the buffers into a single vector
443        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
444        (buf, fds)
445    }
446}
447impl crate::x11_utils::VoidRequest for DestroyRequest {
448}
449
450/// Opcode for the Subtract request
451pub const SUBTRACT_REQUEST: u8 = 3;
452/// Remove regions from a previously created Damage object..
453///
454/// This updates the regions of damage recorded in a a Damage object.
455/// See <https://www.x.org/releases/current/doc/damageproto/damageproto.txt>
456/// for details.
457///
458/// # Fields
459///
460/// * `damage` - The ID you provided to `xcb_create_damage`.
461#[derive(Clone, Copy, Default)]
462#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
463#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
464pub struct SubtractRequest {
465    pub damage: Damage,
466    pub repair: xfixes::Region,
467    pub parts: xfixes::Region,
468}
469impl_debug_if_no_extra_traits!(SubtractRequest, "SubtractRequest");
470impl SubtractRequest {
471    /// Serialize this request into bytes for the provided connection
472    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
473        let length_so_far = 0;
474        let damage_bytes = self.damage.serialize();
475        let repair_bytes = self.repair.serialize();
476        let parts_bytes = self.parts.serialize();
477        let mut request0 = vec![
478            major_opcode,
479            SUBTRACT_REQUEST,
480            0,
481            0,
482            damage_bytes[0],
483            damage_bytes[1],
484            damage_bytes[2],
485            damage_bytes[3],
486            repair_bytes[0],
487            repair_bytes[1],
488            repair_bytes[2],
489            repair_bytes[3],
490            parts_bytes[0],
491            parts_bytes[1],
492            parts_bytes[2],
493            parts_bytes[3],
494        ];
495        let length_so_far = length_so_far + request0.len();
496        assert_eq!(length_so_far % 4, 0);
497        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
498        request0[2..4].copy_from_slice(&length.to_ne_bytes());
499        ([request0.into()], vec![])
500    }
501    /// Parse this request given its header, its body, and any fds that go along with it
502    #[cfg(feature = "request-parsing")]
503    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
504        if header.minor_opcode != SUBTRACT_REQUEST {
505            return Err(ParseError::InvalidValue);
506        }
507        let (damage, remaining) = Damage::try_parse(value)?;
508        let (repair, remaining) = xfixes::Region::try_parse(remaining)?;
509        let (parts, remaining) = xfixes::Region::try_parse(remaining)?;
510        let _ = remaining;
511        Ok(SubtractRequest {
512            damage,
513            repair,
514            parts,
515        })
516    }
517}
518impl Request for SubtractRequest {
519    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
520
521    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
522        let (bufs, fds) = self.serialize(major_opcode);
523        // Flatten the buffers into a single vector
524        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
525        (buf, fds)
526    }
527}
528impl crate::x11_utils::VoidRequest for SubtractRequest {
529}
530
531/// Opcode for the Add request
532pub const ADD_REQUEST: u8 = 4;
533/// Add a region to a previously created Damage object..
534///
535/// This updates the regions of damage recorded in a a Damage object.
536/// See <https://www.x.org/releases/current/doc/damageproto/damageproto.txt>
537/// for details.
538///
539/// # Fields
540///
541/// * `damage` - The ID you provided to `xcb_create_damage`.
542#[derive(Clone, Copy, Default)]
543#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
544#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
545pub struct AddRequest {
546    pub drawable: xproto::Drawable,
547    pub region: xfixes::Region,
548}
549impl_debug_if_no_extra_traits!(AddRequest, "AddRequest");
550impl AddRequest {
551    /// Serialize this request into bytes for the provided connection
552    pub fn serialize(self, major_opcode: u8) -> BufWithFds<[Cow<'static, [u8]>; 1]> {
553        let length_so_far = 0;
554        let drawable_bytes = self.drawable.serialize();
555        let region_bytes = self.region.serialize();
556        let mut request0 = vec![
557            major_opcode,
558            ADD_REQUEST,
559            0,
560            0,
561            drawable_bytes[0],
562            drawable_bytes[1],
563            drawable_bytes[2],
564            drawable_bytes[3],
565            region_bytes[0],
566            region_bytes[1],
567            region_bytes[2],
568            region_bytes[3],
569        ];
570        let length_so_far = length_so_far + request0.len();
571        assert_eq!(length_so_far % 4, 0);
572        let length = u16::try_from(length_so_far / 4).unwrap_or(0);
573        request0[2..4].copy_from_slice(&length.to_ne_bytes());
574        ([request0.into()], vec![])
575    }
576    /// Parse this request given its header, its body, and any fds that go along with it
577    #[cfg(feature = "request-parsing")]
578    pub fn try_parse_request(header: RequestHeader, value: &[u8]) -> Result<Self, ParseError> {
579        if header.minor_opcode != ADD_REQUEST {
580            return Err(ParseError::InvalidValue);
581        }
582        let (drawable, remaining) = xproto::Drawable::try_parse(value)?;
583        let (region, remaining) = xfixes::Region::try_parse(remaining)?;
584        let _ = remaining;
585        Ok(AddRequest {
586            drawable,
587            region,
588        })
589    }
590}
591impl Request for AddRequest {
592    const EXTENSION_NAME: Option<&'static str> = Some(X11_EXTENSION_NAME);
593
594    fn serialize(self, major_opcode: u8) -> BufWithFds<Vec<u8>> {
595        let (bufs, fds) = self.serialize(major_opcode);
596        // Flatten the buffers into a single vector
597        let buf = bufs.iter().flat_map(|buf| buf.iter().copied()).collect();
598        (buf, fds)
599    }
600}
601impl crate::x11_utils::VoidRequest for AddRequest {
602}
603
604/// Opcode for the Notify event
605pub const NOTIFY_EVENT: u8 = 0;
606/// the contents of the monitored drawable have changed.
607///
608/// # Fields
609///
610/// * `level` - The level of the damage being reported.
611/// If the 0x80 bit is set, indicates there are subsequent Damage events
612/// being delivered immediately as part of a larger Damage region.
613/// * `drawable` - The drawable for which damage is being reported.
614/// * `damage` - The Damage object being used to track the damage.
615/// * `timestamp` - Time when the event was generated (in milliseconds).
616/// * `area` - Damaged area of the drawable.
617/// * `geometry` - Total area of the drawable.
618///
619/// # See
620///
621/// * `Create`: request
622#[derive(Clone, Copy, Default)]
623#[cfg_attr(feature = "extra-traits", derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash))]
624#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
625pub struct NotifyEvent {
626    pub response_type: u8,
627    pub level: ReportLevel,
628    pub sequence: u16,
629    pub drawable: xproto::Drawable,
630    pub damage: Damage,
631    pub timestamp: xproto::Timestamp,
632    pub area: xproto::Rectangle,
633    pub geometry: xproto::Rectangle,
634}
635impl_debug_if_no_extra_traits!(NotifyEvent, "NotifyEvent");
636impl TryParse for NotifyEvent {
637    fn try_parse(initial_value: &[u8]) -> Result<(Self, &[u8]), ParseError> {
638        let remaining = initial_value;
639        let (response_type, remaining) = u8::try_parse(remaining)?;
640        let (level, remaining) = u8::try_parse(remaining)?;
641        let (sequence, remaining) = u16::try_parse(remaining)?;
642        let (drawable, remaining) = xproto::Drawable::try_parse(remaining)?;
643        let (damage, remaining) = Damage::try_parse(remaining)?;
644        let (timestamp, remaining) = xproto::Timestamp::try_parse(remaining)?;
645        let (area, remaining) = xproto::Rectangle::try_parse(remaining)?;
646        let (geometry, remaining) = xproto::Rectangle::try_parse(remaining)?;
647        let level = level.into();
648        let result = NotifyEvent { response_type, level, sequence, drawable, damage, timestamp, area, geometry };
649        let _ = remaining;
650        let remaining = initial_value.get(32..)
651            .ok_or(ParseError::InsufficientData)?;
652        Ok((result, remaining))
653    }
654}
655impl Serialize for NotifyEvent {
656    type Bytes = [u8; 32];
657    fn serialize(&self) -> [u8; 32] {
658        let response_type_bytes = self.response_type.serialize();
659        let level_bytes = u8::from(self.level).serialize();
660        let sequence_bytes = self.sequence.serialize();
661        let drawable_bytes = self.drawable.serialize();
662        let damage_bytes = self.damage.serialize();
663        let timestamp_bytes = self.timestamp.serialize();
664        let area_bytes = self.area.serialize();
665        let geometry_bytes = self.geometry.serialize();
666        [
667            response_type_bytes[0],
668            level_bytes[0],
669            sequence_bytes[0],
670            sequence_bytes[1],
671            drawable_bytes[0],
672            drawable_bytes[1],
673            drawable_bytes[2],
674            drawable_bytes[3],
675            damage_bytes[0],
676            damage_bytes[1],
677            damage_bytes[2],
678            damage_bytes[3],
679            timestamp_bytes[0],
680            timestamp_bytes[1],
681            timestamp_bytes[2],
682            timestamp_bytes[3],
683            area_bytes[0],
684            area_bytes[1],
685            area_bytes[2],
686            area_bytes[3],
687            area_bytes[4],
688            area_bytes[5],
689            area_bytes[6],
690            area_bytes[7],
691            geometry_bytes[0],
692            geometry_bytes[1],
693            geometry_bytes[2],
694            geometry_bytes[3],
695            geometry_bytes[4],
696            geometry_bytes[5],
697            geometry_bytes[6],
698            geometry_bytes[7],
699        ]
700    }
701    fn serialize_into(&self, bytes: &mut Vec<u8>) {
702        bytes.reserve(32);
703        self.response_type.serialize_into(bytes);
704        u8::from(self.level).serialize_into(bytes);
705        self.sequence.serialize_into(bytes);
706        self.drawable.serialize_into(bytes);
707        self.damage.serialize_into(bytes);
708        self.timestamp.serialize_into(bytes);
709        self.area.serialize_into(bytes);
710        self.geometry.serialize_into(bytes);
711    }
712}
713impl From<&NotifyEvent> for [u8; 32] {
714    fn from(input: &NotifyEvent) -> Self {
715        let response_type_bytes = input.response_type.serialize();
716        let level_bytes = u8::from(input.level).serialize();
717        let sequence_bytes = input.sequence.serialize();
718        let drawable_bytes = input.drawable.serialize();
719        let damage_bytes = input.damage.serialize();
720        let timestamp_bytes = input.timestamp.serialize();
721        let area_bytes = input.area.serialize();
722        let geometry_bytes = input.geometry.serialize();
723        [
724            response_type_bytes[0],
725            level_bytes[0],
726            sequence_bytes[0],
727            sequence_bytes[1],
728            drawable_bytes[0],
729            drawable_bytes[1],
730            drawable_bytes[2],
731            drawable_bytes[3],
732            damage_bytes[0],
733            damage_bytes[1],
734            damage_bytes[2],
735            damage_bytes[3],
736            timestamp_bytes[0],
737            timestamp_bytes[1],
738            timestamp_bytes[2],
739            timestamp_bytes[3],
740            area_bytes[0],
741            area_bytes[1],
742            area_bytes[2],
743            area_bytes[3],
744            area_bytes[4],
745            area_bytes[5],
746            area_bytes[6],
747            area_bytes[7],
748            geometry_bytes[0],
749            geometry_bytes[1],
750            geometry_bytes[2],
751            geometry_bytes[3],
752            geometry_bytes[4],
753            geometry_bytes[5],
754            geometry_bytes[6],
755            geometry_bytes[7],
756        ]
757    }
758}
759impl From<NotifyEvent> for [u8; 32] {
760    fn from(input: NotifyEvent) -> Self {
761        Self::from(&input)
762    }
763}
764