wayland_client_protocol/
wayland_client_protocol.rs

1// GENERATED FILE -- DO NOT EDIT
2//
3// Copyright © 2008-2011 Kristian Høgsberg
4// Copyright © 2010-2011 Intel Corporation
5// Copyright © 2012-2013 Collabora, Ltd.
6// 
7// Permission is hereby granted, free of charge, to any person
8// obtaining a copy of this software and associated documentation files
9// (the "Software"), to deal in the Software without restriction,
10// including without limitation the rights to use, copy, modify, merge,
11// publish, distribute, sublicense, and/or sell copies of the Software,
12// and to permit persons to whom the Software is furnished to do so,
13// subject to the following conditions:
14// 
15// The above copyright notice and this permission notice (including the
16// next paragraph) shall be included in all copies or substantial
17// portions of the Software.
18// 
19// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22// NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
23// BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
24// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26// SOFTWARE.
27
28#![allow(warnings)]
29#![allow(clippy::all)]
30use anyhow;
31#[allow(unused_imports)]
32use fuchsia_wayland_core::{Array, Enum, Fixed, NewId, NewObject};
33use fuchsia_wayland_core::{ArgKind, Arg, FromArgs, IntoMessage, Message,
34                            MessageGroupSpec, MessageHeader, MessageSpec, MessageType,
35                            ObjectId, EncodeError, DecodeError, Interface};
36pub mod wl_display {
37use super::*;
38
39/// core global object
40///
41/// The core global object.  This is a special singleton object.  It
42/// is used for internal Wayland protocol features.
43#[derive(Debug)]
44pub struct WlDisplay;
45
46impl Interface for WlDisplay {
47    const NAME: &'static str = "wl_display";
48    const VERSION: u32 = 1;
49    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
50        // sync
51        MessageSpec(&[
52            ArgKind::NewId,
53        ]),
54        // get_registry
55        MessageSpec(&[
56            ArgKind::NewId,
57        ]),
58    ]);
59    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
60        // error
61        MessageSpec(&[
62            ArgKind::Object,
63            ArgKind::Uint,
64            ArgKind::String,
65        ]),
66        // delete_id
67        MessageSpec(&[
68            ArgKind::Uint,
69        ]),
70    ]);
71    type Incoming = Event;
72    type Outgoing = Request;
73}
74
75#[derive(Debug)]
76pub enum Request {
77
78    /// asynchronous roundtrip
79    ///
80    /// The sync request asks the server to emit the 'done' event
81    /// on the returned wl_callback object.  Since requests are
82    /// handled in-order and events are delivered in-order, this can
83    /// be used as a barrier to ensure all previous requests and the
84    /// resulting events have been handled.
85    /// 
86    /// The object returned by this request will be destroyed by the
87    /// compositor after the callback is fired and as such the client must not
88    /// attempt to use it after that point.
89    /// 
90    /// The callback_data passed in the callback is the event serial.
91    Sync {
92        /// callback object for the sync request
93        callback: NewId,
94    },
95
96    /// get global registry object
97    ///
98    /// This request creates a registry object that allows the client
99    /// to list and bind the global objects available from the
100    /// compositor.
101    /// 
102    /// It should be noted that the server side resources consumed in
103    /// response to a get_registry request can only be released when the
104    /// client disconnects, not when the client side proxy is destroyed.
105    /// Therefore, clients should invoke get_registry as infrequently as
106    /// possible to avoid wasting memory.
107    GetRegistry {
108        /// global registry object
109        registry: NewId,
110    },
111}
112
113impl MessageType for Request {
114    fn log(&self, this: ObjectId) -> String {
115        match *self {
116            Request::Sync {
117                ref callback,
118            } => {
119                format!("wl_display@{:?}::sync(callback: {:?})", this, callback)
120            }
121            Request::GetRegistry {
122                ref registry,
123            } => {
124                format!("wl_display@{:?}::get_registry(registry: {:?})", this, registry)
125            }
126        }
127    }
128    fn message_name(&self) -> &'static std::ffi::CStr{
129        match *self {
130            Request::Sync { .. } => c"wl_display::sync",
131            Request::GetRegistry { .. } => c"wl_display::get_registry",
132        }
133    }
134}
135#[derive(Debug)]
136pub enum Event {
137
138    /// fatal error event
139    ///
140    /// The error event is sent out when a fatal (non-recoverable)
141    /// error has occurred.  The object_id argument is the object
142    /// where the error occurred, most often in response to a request
143    /// to that object.  The code identifies the error and is defined
144    /// by the object interface.  As such, each interface defines its
145    /// own set of error codes.  The message is a brief description
146    /// of the error, for (debugging) convenience.
147    Error {
148        /// object where the error occurred
149        object_id: ObjectId,
150        /// error code
151        code: u32,
152        /// error description
153        message: String,
154    },
155
156    /// acknowledge object ID deletion
157    ///
158    /// This event is used internally by the object ID management
159    /// logic. When a client deletes an object that it had created,
160    /// the server will send this event to acknowledge that it has
161    /// seen the delete request. When the client receives this event,
162    /// it will know that it can safely reuse the object ID.
163    DeleteId {
164        /// deleted object ID
165        id: u32,
166    },
167}
168
169impl MessageType for Event {
170    fn log(&self, this: ObjectId) -> String {
171        match *self {
172            Event::Error {
173                ref object_id,
174                ref code,
175                ref message,
176            } => {
177                format!("wl_display@{:?}::error(object_id: {:?}, code: {:?}, message: {:?})", this, object_id, code, message)
178            }
179            Event::DeleteId {
180                ref id,
181            } => {
182                format!("wl_display@{:?}::delete_id(id: {:?})", this, id)
183            }
184        }
185    }
186    fn message_name(&self) -> &'static std::ffi::CStr{
187        match *self {
188            Event::Error { .. } => c"wl_display::error",
189            Event::DeleteId { .. } => c"wl_display::delete_id",
190        }
191    }
192}
193impl IntoMessage for Request {
194    type Error = EncodeError;
195    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
196        let mut header = MessageHeader {
197            sender: id,
198            opcode: 0,
199            length: 0,
200        };
201        let mut msg = Message::new();
202        msg.write_header(&header)?;
203        match self {
204        Request::Sync {
205            callback,
206        } => {
207            msg.write_arg(Arg::NewId(callback))?;
208            header.opcode = 0;
209        },
210        Request::GetRegistry {
211            registry,
212        } => {
213            msg.write_arg(Arg::NewId(registry))?;
214            header.opcode = 1;
215        },
216        }
217        header.length = msg.bytes().len() as u16;
218        msg.rewind();
219        msg.write_header(&header)?;
220        Ok(msg)
221    }
222}
223impl FromArgs for Event {
224    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
225        match op {
226        0 /* error */ => {
227            let mut iter = args.into_iter();
228            Ok(Event::Error {
229                object_id: iter.next()
230                                             .ok_or(DecodeError::InsufficientArgs)?
231                                             .as_object()?,
232                code: iter.next()
233                                             .ok_or(DecodeError::InsufficientArgs)?
234                                             .as_uint()?,
235                message: iter.next()
236                                             .ok_or(DecodeError::InsufficientArgs)?
237                                             .as_string()?,
238
239            })
240        },
241        1 /* delete_id */ => {
242            let mut iter = args.into_iter();
243            Ok(Event::DeleteId {
244                id: iter.next()
245                                             .ok_or(DecodeError::InsufficientArgs)?
246                                             .as_uint()?,
247
248            })
249        },
250        _ => {
251            Err(DecodeError::InvalidOpcode(op).into())
252        },
253        }
254    }
255}
256
257/// global error values
258///
259/// These errors are global and can be emitted in response to any
260/// server request.
261#[derive(Copy, Clone, Debug, Eq, PartialEq)]
262#[repr(u32)]
263pub enum Error {
264    /// server couldn't find object,
265    InvalidObject = 0,
266    /// method doesn't exist on the specified interface or malformed request,
267    InvalidMethod = 1,
268    /// server is out of memory,
269    NoMemory = 2,
270    /// implementation error in compositor,
271    Implementation = 3,
272}
273
274impl Error {
275    pub fn from_bits(v: u32) -> Option<Self> {
276        match v {
277        0 => Some(Error::InvalidObject),
278        1 => Some(Error::InvalidMethod),
279        2 => Some(Error::NoMemory),
280        3 => Some(Error::Implementation),
281        _ => None,
282        }
283    }
284
285    pub fn bits(&self) -> u32 {
286        *self as u32
287    }
288}
289impl Into<Arg> for Error {
290    fn into(self) -> Arg {
291        Arg::Uint(self.bits())
292    }
293}
294} // mod wl_display
295
296pub use crate::wl_display::WlDisplay;
297pub use crate::wl_display::Request as WlDisplayRequest;
298pub use crate::wl_display::Event as WlDisplayEvent;
299pub mod wl_registry {
300use super::*;
301
302/// global registry object
303///
304/// The singleton global registry object.  The server has a number of
305/// global objects that are available to all clients.  These objects
306/// typically represent an actual object in the server (for example,
307/// an input device) or they are singleton objects that provide
308/// extension functionality.
309/// 
310/// When a client creates a registry object, the registry object
311/// will emit a global event for each global currently in the
312/// registry.  Globals come and go as a result of device or
313/// monitor hotplugs, reconfiguration or other events, and the
314/// registry will send out global and global_remove events to
315/// keep the client up to date with the changes.  To mark the end
316/// of the initial burst of events, the client can use the
317/// wl_display.sync request immediately after calling
318/// wl_display.get_registry.
319/// 
320/// A client can bind to a global object by using the bind
321/// request.  This creates a client-side handle that lets the object
322/// emit events to the client and lets the client invoke requests on
323/// the object.
324#[derive(Debug)]
325pub struct WlRegistry;
326
327impl Interface for WlRegistry {
328    const NAME: &'static str = "wl_registry";
329    const VERSION: u32 = 1;
330    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
331        // bind
332        MessageSpec(&[
333            ArgKind::Uint,
334            ArgKind::String,
335            ArgKind::Uint,
336            ArgKind::NewId,
337        ]),
338    ]);
339    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
340        // global
341        MessageSpec(&[
342            ArgKind::Uint,
343            ArgKind::String,
344            ArgKind::Uint,
345        ]),
346        // global_remove
347        MessageSpec(&[
348            ArgKind::Uint,
349        ]),
350    ]);
351    type Incoming = Event;
352    type Outgoing = Request;
353}
354
355#[derive(Debug)]
356pub enum Request {
357
358    /// bind an object to the display
359    ///
360    /// Binds a new, client-created object to the server using the
361    /// specified name as the identifier.
362    Bind {
363        /// unique numeric name of the object
364        name: u32,
365        id_interface_name: String,
366        id_interface_version: u32,
367        /// bounded object
368        id: NewId,
369    },
370}
371
372impl MessageType for Request {
373    fn log(&self, this: ObjectId) -> String {
374        match *self {
375            Request::Bind {
376                ref name,
377                ref id_interface_name,
378                ref id_interface_version,
379                ref id,
380            } => {
381                format!("wl_registry@{:?}::bind(name: {:?}, id_interface_name: {:?}, id_interface_version: {:?}, id: {:?})", this, name, id_interface_name, id_interface_version, id)
382            }
383        }
384    }
385    fn message_name(&self) -> &'static std::ffi::CStr{
386        match *self {
387            Request::Bind { .. } => c"wl_registry::bind",
388        }
389    }
390}
391#[derive(Debug)]
392pub enum Event {
393
394    /// announce global object
395    ///
396    /// Notify the client of global objects.
397    /// 
398    /// The event notifies the client that a global object with
399    /// the given name is now available, and it implements the
400    /// given version of the given interface.
401    Global {
402        /// numeric name of the global object
403        name: u32,
404        /// interface implemented by the object
405        interface: String,
406        /// interface version
407        version: u32,
408    },
409
410    /// announce removal of global object
411    ///
412    /// Notify the client of removed global objects.
413    /// 
414    /// This event notifies the client that the global identified
415    /// by name is no longer available.  If the client bound to
416    /// the global using the bind request, the client should now
417    /// destroy that object.
418    /// 
419    /// The object remains valid and requests to the object will be
420    /// ignored until the client destroys it, to avoid races between
421    /// the global going away and a client sending a request to it.
422    GlobalRemove {
423        /// numeric name of the global object
424        name: u32,
425    },
426}
427
428impl MessageType for Event {
429    fn log(&self, this: ObjectId) -> String {
430        match *self {
431            Event::Global {
432                ref name,
433                ref interface,
434                ref version,
435            } => {
436                format!("wl_registry@{:?}::global(name: {:?}, interface: {:?}, version: {:?})", this, name, interface, version)
437            }
438            Event::GlobalRemove {
439                ref name,
440            } => {
441                format!("wl_registry@{:?}::global_remove(name: {:?})", this, name)
442            }
443        }
444    }
445    fn message_name(&self) -> &'static std::ffi::CStr{
446        match *self {
447            Event::Global { .. } => c"wl_registry::global",
448            Event::GlobalRemove { .. } => c"wl_registry::global_remove",
449        }
450    }
451}
452impl IntoMessage for Request {
453    type Error = EncodeError;
454    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
455        let mut header = MessageHeader {
456            sender: id,
457            opcode: 0,
458            length: 0,
459        };
460        let mut msg = Message::new();
461        msg.write_header(&header)?;
462        match self {
463        Request::Bind {
464            name,
465            id_interface_name,
466            id_interface_version,
467            id,
468        } => {
469            msg.write_arg(Arg::Uint(name))?;
470            msg.write_arg(Arg::String(id_interface_name))?;
471            msg.write_arg(Arg::Uint(id_interface_version))?;
472            msg.write_arg(Arg::NewId(id))?;
473            header.opcode = 0;
474        },
475        }
476        header.length = msg.bytes().len() as u16;
477        msg.rewind();
478        msg.write_header(&header)?;
479        Ok(msg)
480    }
481}
482impl FromArgs for Event {
483    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
484        match op {
485        0 /* global */ => {
486            let mut iter = args.into_iter();
487            Ok(Event::Global {
488                name: iter.next()
489                                             .ok_or(DecodeError::InsufficientArgs)?
490                                             .as_uint()?,
491                interface: iter.next()
492                                             .ok_or(DecodeError::InsufficientArgs)?
493                                             .as_string()?,
494                version: iter.next()
495                                             .ok_or(DecodeError::InsufficientArgs)?
496                                             .as_uint()?,
497
498            })
499        },
500        1 /* global_remove */ => {
501            let mut iter = args.into_iter();
502            Ok(Event::GlobalRemove {
503                name: iter.next()
504                                             .ok_or(DecodeError::InsufficientArgs)?
505                                             .as_uint()?,
506
507            })
508        },
509        _ => {
510            Err(DecodeError::InvalidOpcode(op).into())
511        },
512        }
513    }
514}
515} // mod wl_registry
516
517pub use crate::wl_registry::WlRegistry;
518pub use crate::wl_registry::Request as WlRegistryRequest;
519pub use crate::wl_registry::Event as WlRegistryEvent;
520pub mod wl_callback {
521use super::*;
522
523/// callback object
524///
525/// Clients can handle the 'done' event to get notified when
526/// the related request is done.
527#[derive(Debug)]
528pub struct WlCallback;
529
530impl Interface for WlCallback {
531    const NAME: &'static str = "wl_callback";
532    const VERSION: u32 = 1;
533    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
534    ]);
535    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
536        // done
537        MessageSpec(&[
538            ArgKind::Uint,
539        ]),
540    ]);
541    type Incoming = Event;
542    type Outgoing = Request;
543}
544
545#[derive(Debug)]
546pub enum Request {
547}
548
549impl MessageType for Request {
550    fn log(&self, this: ObjectId) -> String {
551        match *self {
552        }
553    }
554    fn message_name(&self) -> &'static std::ffi::CStr{
555        match *self {
556        }
557    }
558}
559#[derive(Debug)]
560pub enum Event {
561
562    /// done event
563    ///
564    /// Notify the client when the related request is done.
565    Done {
566        /// request-specific data for the callback
567        callback_data: u32,
568    },
569}
570
571impl MessageType for Event {
572    fn log(&self, this: ObjectId) -> String {
573        match *self {
574            Event::Done {
575                ref callback_data,
576            } => {
577                format!("wl_callback@{:?}::done(callback_data: {:?})", this, callback_data)
578            }
579        }
580    }
581    fn message_name(&self) -> &'static std::ffi::CStr{
582        match *self {
583            Event::Done { .. } => c"wl_callback::done",
584        }
585    }
586}
587impl IntoMessage for Request {
588    type Error = EncodeError;
589    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
590        let mut header = MessageHeader {
591            sender: id,
592            opcode: 0,
593            length: 0,
594        };
595        let mut msg = Message::new();
596        msg.write_header(&header)?;
597        match self {
598        }
599        header.length = msg.bytes().len() as u16;
600        msg.rewind();
601        msg.write_header(&header)?;
602        Ok(msg)
603    }
604}
605impl FromArgs for Event {
606    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
607        match op {
608        0 /* done */ => {
609            let mut iter = args.into_iter();
610            Ok(Event::Done {
611                callback_data: iter.next()
612                                             .ok_or(DecodeError::InsufficientArgs)?
613                                             .as_uint()?,
614
615            })
616        },
617        _ => {
618            Err(DecodeError::InvalidOpcode(op).into())
619        },
620        }
621    }
622}
623} // mod wl_callback
624
625pub use crate::wl_callback::WlCallback;
626pub use crate::wl_callback::Request as WlCallbackRequest;
627pub use crate::wl_callback::Event as WlCallbackEvent;
628pub mod wl_compositor {
629use super::*;
630
631/// the compositor singleton
632///
633/// A compositor.  This object is a singleton global.  The
634/// compositor is in charge of combining the contents of multiple
635/// surfaces into one displayable output.
636#[derive(Debug)]
637pub struct WlCompositor;
638
639impl Interface for WlCompositor {
640    const NAME: &'static str = "wl_compositor";
641    const VERSION: u32 = 4;
642    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
643        // create_surface
644        MessageSpec(&[
645            ArgKind::NewId,
646        ]),
647        // create_region
648        MessageSpec(&[
649            ArgKind::NewId,
650        ]),
651    ]);
652    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
653    ]);
654    type Incoming = Event;
655    type Outgoing = Request;
656}
657
658#[derive(Debug)]
659pub enum Request {
660
661    /// create new surface
662    ///
663    /// Ask the compositor to create a new surface.
664    CreateSurface {
665        /// the new surface
666        id: NewId,
667    },
668
669    /// create new region
670    ///
671    /// Ask the compositor to create a new region.
672    CreateRegion {
673        /// the new region
674        id: NewId,
675    },
676}
677
678impl MessageType for Request {
679    fn log(&self, this: ObjectId) -> String {
680        match *self {
681            Request::CreateSurface {
682                ref id,
683            } => {
684                format!("wl_compositor@{:?}::create_surface(id: {:?})", this, id)
685            }
686            Request::CreateRegion {
687                ref id,
688            } => {
689                format!("wl_compositor@{:?}::create_region(id: {:?})", this, id)
690            }
691        }
692    }
693    fn message_name(&self) -> &'static std::ffi::CStr{
694        match *self {
695            Request::CreateSurface { .. } => c"wl_compositor::create_surface",
696            Request::CreateRegion { .. } => c"wl_compositor::create_region",
697        }
698    }
699}
700#[derive(Debug)]
701pub enum Event {
702}
703
704impl MessageType for Event {
705    fn log(&self, this: ObjectId) -> String {
706        match *self {
707        }
708    }
709    fn message_name(&self) -> &'static std::ffi::CStr{
710        match *self {
711        }
712    }
713}
714impl IntoMessage for Request {
715    type Error = EncodeError;
716    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
717        let mut header = MessageHeader {
718            sender: id,
719            opcode: 0,
720            length: 0,
721        };
722        let mut msg = Message::new();
723        msg.write_header(&header)?;
724        match self {
725        Request::CreateSurface {
726            id,
727        } => {
728            msg.write_arg(Arg::NewId(id))?;
729            header.opcode = 0;
730        },
731        Request::CreateRegion {
732            id,
733        } => {
734            msg.write_arg(Arg::NewId(id))?;
735            header.opcode = 1;
736        },
737        }
738        header.length = msg.bytes().len() as u16;
739        msg.rewind();
740        msg.write_header(&header)?;
741        Ok(msg)
742    }
743}
744impl FromArgs for Event {
745    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
746        match op {
747        _ => {
748            Err(DecodeError::InvalidOpcode(op).into())
749        },
750        }
751    }
752}
753} // mod wl_compositor
754
755pub use crate::wl_compositor::WlCompositor;
756pub use crate::wl_compositor::Request as WlCompositorRequest;
757pub use crate::wl_compositor::Event as WlCompositorEvent;
758pub mod wl_shm_pool {
759use super::*;
760
761/// a shared memory pool
762///
763/// The wl_shm_pool object encapsulates a piece of memory shared
764/// between the compositor and client.  Through the wl_shm_pool
765/// object, the client can allocate shared memory wl_buffer objects.
766/// All objects created through the same pool share the same
767/// underlying mapped memory. Reusing the mapped memory avoids the
768/// setup/teardown overhead and is useful when interactively resizing
769/// a surface or for many small buffers.
770#[derive(Debug)]
771pub struct WlShmPool;
772
773impl Interface for WlShmPool {
774    const NAME: &'static str = "wl_shm_pool";
775    const VERSION: u32 = 1;
776    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
777        // create_buffer
778        MessageSpec(&[
779            ArgKind::NewId,
780            ArgKind::Int,
781            ArgKind::Int,
782            ArgKind::Int,
783            ArgKind::Int,
784            ArgKind::Uint,
785        ]),
786        // destroy
787        MessageSpec(&[
788        ]),
789        // resize
790        MessageSpec(&[
791            ArgKind::Int,
792        ]),
793    ]);
794    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
795    ]);
796    type Incoming = Event;
797    type Outgoing = Request;
798}
799
800#[derive(Debug)]
801pub enum Request {
802
803    /// create a buffer from the pool
804    ///
805    /// Create a wl_buffer object from the pool.
806    /// 
807    /// The buffer is created offset bytes into the pool and has
808    /// width and height as specified.  The stride argument specifies
809    /// the number of bytes from the beginning of one row to the beginning
810    /// of the next.  The format is the pixel format of the buffer and
811    /// must be one of those advertised through the wl_shm.format event.
812    /// 
813    /// A buffer will keep a reference to the pool it was created from
814    /// so it is valid to destroy the pool immediately after creating
815    /// a buffer from it.
816    CreateBuffer {
817        /// buffer to create
818        id: NewId,
819        /// buffer byte offset within the pool
820        offset: i32,
821        /// buffer width, in pixels
822        width: i32,
823        /// buffer height, in pixels
824        height: i32,
825        /// number of bytes from the beginning of one row to the beginning of the next row
826        stride: i32,
827        /// buffer pixel format
828        format: crate::wl_shm::Format,
829    },
830
831    /// destroy the pool
832    ///
833    /// Destroy the shared memory pool.
834    /// 
835    /// The mmapped memory will be released when all
836    /// buffers that have been created from this pool
837    /// are gone.
838    Destroy,
839
840    /// change the size of the pool mapping
841    ///
842    /// This request will cause the server to remap the backing memory
843    /// for the pool from the file descriptor passed when the pool was
844    /// created, but using the new size.  This request can only be
845    /// used to make the pool bigger.
846    Resize {
847        /// new size of the pool, in bytes
848        size: i32,
849    },
850}
851
852impl MessageType for Request {
853    fn log(&self, this: ObjectId) -> String {
854        match *self {
855            Request::CreateBuffer {
856                ref id,
857                ref offset,
858                ref width,
859                ref height,
860                ref stride,
861                ref format,
862            } => {
863                format!("wl_shm_pool@{:?}::create_buffer(id: {:?}, offset: {:?}, width: {:?}, height: {:?}, stride: {:?}, format: {:?})", this, id, offset, width, height, stride, format)
864            }
865            Request::Destroy {
866            } => {
867                format!("wl_shm_pool@{:?}::destroy()", this)
868            }
869            Request::Resize {
870                ref size,
871            } => {
872                format!("wl_shm_pool@{:?}::resize(size: {:?})", this, size)
873            }
874        }
875    }
876    fn message_name(&self) -> &'static std::ffi::CStr{
877        match *self {
878            Request::CreateBuffer { .. } => c"wl_shm_pool::create_buffer",
879            Request::Destroy { .. } => c"wl_shm_pool::destroy",
880            Request::Resize { .. } => c"wl_shm_pool::resize",
881        }
882    }
883}
884#[derive(Debug)]
885pub enum Event {
886}
887
888impl MessageType for Event {
889    fn log(&self, this: ObjectId) -> String {
890        match *self {
891        }
892    }
893    fn message_name(&self) -> &'static std::ffi::CStr{
894        match *self {
895        }
896    }
897}
898impl IntoMessage for Request {
899    type Error = EncodeError;
900    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
901        let mut header = MessageHeader {
902            sender: id,
903            opcode: 0,
904            length: 0,
905        };
906        let mut msg = Message::new();
907        msg.write_header(&header)?;
908        match self {
909        Request::CreateBuffer {
910            id,
911            offset,
912            width,
913            height,
914            stride,
915            format,
916        } => {
917            msg.write_arg(Arg::NewId(id))?;
918            msg.write_arg(Arg::Int(offset))?;
919            msg.write_arg(Arg::Int(width))?;
920            msg.write_arg(Arg::Int(height))?;
921            msg.write_arg(Arg::Int(stride))?;
922            msg.write_arg(Arg::Uint(format.bits()))?;
923            header.opcode = 0;
924        },
925        Request::Destroy {
926        } => {
927            header.opcode = 1;
928        },
929        Request::Resize {
930            size,
931        } => {
932            msg.write_arg(Arg::Int(size))?;
933            header.opcode = 2;
934        },
935        }
936        header.length = msg.bytes().len() as u16;
937        msg.rewind();
938        msg.write_header(&header)?;
939        Ok(msg)
940    }
941}
942impl FromArgs for Event {
943    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
944        match op {
945        _ => {
946            Err(DecodeError::InvalidOpcode(op).into())
947        },
948        }
949    }
950}
951} // mod wl_shm_pool
952
953pub use crate::wl_shm_pool::WlShmPool;
954pub use crate::wl_shm_pool::Request as WlShmPoolRequest;
955pub use crate::wl_shm_pool::Event as WlShmPoolEvent;
956pub mod wl_shm {
957use super::*;
958
959/// shared memory support
960///
961/// A singleton global object that provides support for shared
962/// memory.
963/// 
964/// Clients can create wl_shm_pool objects using the create_pool
965/// request.
966/// 
967/// At connection setup time, the wl_shm object emits one or more
968/// format events to inform clients about the valid pixel formats
969/// that can be used for buffers.
970#[derive(Debug)]
971pub struct WlShm;
972
973impl Interface for WlShm {
974    const NAME: &'static str = "wl_shm";
975    const VERSION: u32 = 1;
976    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
977        // create_pool
978        MessageSpec(&[
979            ArgKind::NewId,
980            ArgKind::Handle,
981            ArgKind::Int,
982        ]),
983    ]);
984    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
985        // format
986        MessageSpec(&[
987            ArgKind::Uint,
988        ]),
989    ]);
990    type Incoming = Event;
991    type Outgoing = Request;
992}
993
994#[derive(Debug)]
995pub enum Request {
996
997    /// create a shm pool
998    ///
999    /// Create a new wl_shm_pool object.
1000    /// 
1001    /// The pool can be used to create shared memory based buffer
1002    /// objects.  The server will mmap size bytes of the passed file
1003    /// descriptor, to use as backing memory for the pool.
1004    CreatePool {
1005        /// pool to create
1006        id: NewId,
1007        /// file descriptor for the pool
1008        fd: zx::Handle,
1009        /// pool size, in bytes
1010        size: i32,
1011    },
1012}
1013
1014impl MessageType for Request {
1015    fn log(&self, this: ObjectId) -> String {
1016        match *self {
1017            Request::CreatePool {
1018                ref id,
1019                ref fd,
1020                ref size,
1021            } => {
1022                format!("wl_shm@{:?}::create_pool(id: {:?}, fd: <handle>, size: {:?})", this, id, size)
1023            }
1024        }
1025    }
1026    fn message_name(&self) -> &'static std::ffi::CStr{
1027        match *self {
1028            Request::CreatePool { .. } => c"wl_shm::create_pool",
1029        }
1030    }
1031}
1032#[derive(Debug)]
1033pub enum Event {
1034
1035    /// pixel format description
1036    ///
1037    /// Informs the client about a valid pixel format that
1038    /// can be used for buffers. Known formats include
1039    /// argb8888 and xrgb8888.
1040    Format {
1041        /// buffer pixel format
1042        format: Enum<Format>,
1043    },
1044}
1045
1046impl MessageType for Event {
1047    fn log(&self, this: ObjectId) -> String {
1048        match *self {
1049            Event::Format {
1050                ref format,
1051            } => {
1052                format!("wl_shm@{:?}::format(format: {:?})", this, format)
1053            }
1054        }
1055    }
1056    fn message_name(&self) -> &'static std::ffi::CStr{
1057        match *self {
1058            Event::Format { .. } => c"wl_shm::format",
1059        }
1060    }
1061}
1062impl IntoMessage for Request {
1063    type Error = EncodeError;
1064    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
1065        let mut header = MessageHeader {
1066            sender: id,
1067            opcode: 0,
1068            length: 0,
1069        };
1070        let mut msg = Message::new();
1071        msg.write_header(&header)?;
1072        match self {
1073        Request::CreatePool {
1074            id,
1075            fd,
1076            size,
1077        } => {
1078            msg.write_arg(Arg::NewId(id))?;
1079            msg.write_arg(Arg::Handle(fd))?;
1080            msg.write_arg(Arg::Int(size))?;
1081            header.opcode = 0;
1082        },
1083        }
1084        header.length = msg.bytes().len() as u16;
1085        msg.rewind();
1086        msg.write_header(&header)?;
1087        Ok(msg)
1088    }
1089}
1090impl FromArgs for Event {
1091    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
1092        match op {
1093        0 /* format */ => {
1094            let mut iter = args.into_iter();
1095            Ok(Event::Format {
1096                format: iter.next()
1097                                             .ok_or(DecodeError::InsufficientArgs)?
1098                                             .as_uint().map(|i| match Format::from_bits(i) {
1099                                      Some(e) => Enum::Recognized(e),
1100                                      None => Enum::Unrecognized(i),
1101                                 })?,
1102
1103            })
1104        },
1105        _ => {
1106            Err(DecodeError::InvalidOpcode(op).into())
1107        },
1108        }
1109    }
1110}
1111
1112/// wl_shm error values
1113///
1114/// These errors can be emitted in response to wl_shm requests.
1115#[derive(Copy, Clone, Debug, Eq, PartialEq)]
1116#[repr(u32)]
1117pub enum Error {
1118    /// buffer format is not known,
1119    InvalidFormat = 0,
1120    /// invalid size or stride during pool or buffer creation,
1121    InvalidStride = 1,
1122    /// mmapping the file descriptor failed,
1123    InvalidFd = 2,
1124}
1125
1126impl Error {
1127    pub fn from_bits(v: u32) -> Option<Self> {
1128        match v {
1129        0 => Some(Error::InvalidFormat),
1130        1 => Some(Error::InvalidStride),
1131        2 => Some(Error::InvalidFd),
1132        _ => None,
1133        }
1134    }
1135
1136    pub fn bits(&self) -> u32 {
1137        *self as u32
1138    }
1139}
1140impl Into<Arg> for Error {
1141    fn into(self) -> Arg {
1142        Arg::Uint(self.bits())
1143    }
1144}
1145
1146/// pixel formats
1147///
1148/// This describes the memory layout of an individual pixel.
1149/// 
1150/// All renderers should support argb8888 and xrgb8888 but any other
1151/// formats are optional and may not be supported by the particular
1152/// renderer in use.
1153/// 
1154/// The drm format codes match the macros defined in drm_fourcc.h, except
1155/// argb8888 and xrgb8888. The formats actually supported by the compositor
1156/// will be reported by the format event.
1157#[derive(Copy, Clone, Debug, Eq, PartialEq)]
1158#[repr(u32)]
1159pub enum Format {
1160    /// 32-bit ARGB format, [31:0] A:R:G:B 8:8:8:8 little endian,
1161    Argb8888 = 0,
1162    /// 32-bit RGB format, [31:0] x:R:G:B 8:8:8:8 little endian,
1163    Xrgb8888 = 1,
1164    /// 8-bit color index format, [7:0] C,
1165    C8 = 538982467,
1166    /// 8-bit RGB format, [7:0] R:G:B 3:3:2,
1167    Rgb332 = 943867730,
1168    /// 8-bit BGR format, [7:0] B:G:R 2:3:3,
1169    Bgr233 = 944916290,
1170    /// 16-bit xRGB format, [15:0] x:R:G:B 4:4:4:4 little endian,
1171    Xrgb4444 = 842093144,
1172    /// 16-bit xBGR format, [15:0] x:B:G:R 4:4:4:4 little endian,
1173    Xbgr4444 = 842089048,
1174    /// 16-bit RGBx format, [15:0] R:G:B:x 4:4:4:4 little endian,
1175    Rgbx4444 = 842094674,
1176    /// 16-bit BGRx format, [15:0] B:G:R:x 4:4:4:4 little endian,
1177    Bgrx4444 = 842094658,
1178    /// 16-bit ARGB format, [15:0] A:R:G:B 4:4:4:4 little endian,
1179    Argb4444 = 842093121,
1180    /// 16-bit ABGR format, [15:0] A:B:G:R 4:4:4:4 little endian,
1181    Abgr4444 = 842089025,
1182    /// 16-bit RBGA format, [15:0] R:G:B:A 4:4:4:4 little endian,
1183    Rgba4444 = 842088786,
1184    /// 16-bit BGRA format, [15:0] B:G:R:A 4:4:4:4 little endian,
1185    Bgra4444 = 842088770,
1186    /// 16-bit xRGB format, [15:0] x:R:G:B 1:5:5:5 little endian,
1187    Xrgb1555 = 892424792,
1188    /// 16-bit xBGR 1555 format, [15:0] x:B:G:R 1:5:5:5 little endian,
1189    Xbgr1555 = 892420696,
1190    /// 16-bit RGBx 5551 format, [15:0] R:G:B:x 5:5:5:1 little endian,
1191    Rgbx5551 = 892426322,
1192    /// 16-bit BGRx 5551 format, [15:0] B:G:R:x 5:5:5:1 little endian,
1193    Bgrx5551 = 892426306,
1194    /// 16-bit ARGB 1555 format, [15:0] A:R:G:B 1:5:5:5 little endian,
1195    Argb1555 = 892424769,
1196    /// 16-bit ABGR 1555 format, [15:0] A:B:G:R 1:5:5:5 little endian,
1197    Abgr1555 = 892420673,
1198    /// 16-bit RGBA 5551 format, [15:0] R:G:B:A 5:5:5:1 little endian,
1199    Rgba5551 = 892420434,
1200    /// 16-bit BGRA 5551 format, [15:0] B:G:R:A 5:5:5:1 little endian,
1201    Bgra5551 = 892420418,
1202    /// 16-bit RGB 565 format, [15:0] R:G:B 5:6:5 little endian,
1203    Rgb565 = 909199186,
1204    /// 16-bit BGR 565 format, [15:0] B:G:R 5:6:5 little endian,
1205    Bgr565 = 909199170,
1206    /// 24-bit RGB format, [23:0] R:G:B little endian,
1207    Rgb888 = 875710290,
1208    /// 24-bit BGR format, [23:0] B:G:R little endian,
1209    Bgr888 = 875710274,
1210    /// 32-bit xBGR format, [31:0] x:B:G:R 8:8:8:8 little endian,
1211    Xbgr8888 = 875709016,
1212    /// 32-bit RGBx format, [31:0] R:G:B:x 8:8:8:8 little endian,
1213    Rgbx8888 = 875714642,
1214    /// 32-bit BGRx format, [31:0] B:G:R:x 8:8:8:8 little endian,
1215    Bgrx8888 = 875714626,
1216    /// 32-bit ABGR format, [31:0] A:B:G:R 8:8:8:8 little endian,
1217    Abgr8888 = 875708993,
1218    /// 32-bit RGBA format, [31:0] R:G:B:A 8:8:8:8 little endian,
1219    Rgba8888 = 875708754,
1220    /// 32-bit BGRA format, [31:0] B:G:R:A 8:8:8:8 little endian,
1221    Bgra8888 = 875708738,
1222    /// 32-bit xRGB format, [31:0] x:R:G:B 2:10:10:10 little endian,
1223    Xrgb2101010 = 808669784,
1224    /// 32-bit xBGR format, [31:0] x:B:G:R 2:10:10:10 little endian,
1225    Xbgr2101010 = 808665688,
1226    /// 32-bit RGBx format, [31:0] R:G:B:x 10:10:10:2 little endian,
1227    Rgbx1010102 = 808671314,
1228    /// 32-bit BGRx format, [31:0] B:G:R:x 10:10:10:2 little endian,
1229    Bgrx1010102 = 808671298,
1230    /// 32-bit ARGB format, [31:0] A:R:G:B 2:10:10:10 little endian,
1231    Argb2101010 = 808669761,
1232    /// 32-bit ABGR format, [31:0] A:B:G:R 2:10:10:10 little endian,
1233    Abgr2101010 = 808665665,
1234    /// 32-bit RGBA format, [31:0] R:G:B:A 10:10:10:2 little endian,
1235    Rgba1010102 = 808665426,
1236    /// 32-bit BGRA format, [31:0] B:G:R:A 10:10:10:2 little endian,
1237    Bgra1010102 = 808665410,
1238    /// packed YCbCr format, [31:0] Cr0:Y1:Cb0:Y0 8:8:8:8 little endian,
1239    Yuyv = 1448695129,
1240    /// packed YCbCr format, [31:0] Cb0:Y1:Cr0:Y0 8:8:8:8 little endian,
1241    Yvyu = 1431918169,
1242    /// packed YCbCr format, [31:0] Y1:Cr0:Y0:Cb0 8:8:8:8 little endian,
1243    Uyvy = 1498831189,
1244    /// packed YCbCr format, [31:0] Y1:Cb0:Y0:Cr0 8:8:8:8 little endian,
1245    Vyuy = 1498765654,
1246    /// packed AYCbCr format, [31:0] A:Y:Cb:Cr 8:8:8:8 little endian,
1247    Ayuv = 1448433985,
1248    /// 2 plane YCbCr Cr:Cb format, 2x2 subsampled Cr:Cb plane,
1249    Nv12 = 842094158,
1250    /// 2 plane YCbCr Cb:Cr format, 2x2 subsampled Cb:Cr plane,
1251    Nv21 = 825382478,
1252    /// 2 plane YCbCr Cr:Cb format, 2x1 subsampled Cr:Cb plane,
1253    Nv16 = 909203022,
1254    /// 2 plane YCbCr Cb:Cr format, 2x1 subsampled Cb:Cr plane,
1255    Nv61 = 825644622,
1256    /// 3 plane YCbCr format, 4x4 subsampled Cb (1) and Cr (2) planes,
1257    Yuv410 = 961959257,
1258    /// 3 plane YCbCr format, 4x4 subsampled Cr (1) and Cb (2) planes,
1259    Yvu410 = 961893977,
1260    /// 3 plane YCbCr format, 4x1 subsampled Cb (1) and Cr (2) planes,
1261    Yuv411 = 825316697,
1262    /// 3 plane YCbCr format, 4x1 subsampled Cr (1) and Cb (2) planes,
1263    Yvu411 = 825316953,
1264    /// 3 plane YCbCr format, 2x2 subsampled Cb (1) and Cr (2) planes,
1265    Yuv420 = 842093913,
1266    /// 3 plane YCbCr format, 2x2 subsampled Cr (1) and Cb (2) planes,
1267    Yvu420 = 842094169,
1268    /// 3 plane YCbCr format, 2x1 subsampled Cb (1) and Cr (2) planes,
1269    Yuv422 = 909202777,
1270    /// 3 plane YCbCr format, 2x1 subsampled Cr (1) and Cb (2) planes,
1271    Yvu422 = 909203033,
1272    /// 3 plane YCbCr format, non-subsampled Cb (1) and Cr (2) planes,
1273    Yuv444 = 875713881,
1274    /// 3 plane YCbCr format, non-subsampled Cr (1) and Cb (2) planes,
1275    Yvu444 = 875714137,
1276    /// [7:0] R,
1277    R8 = 538982482,
1278    /// [15:0] R little endian,
1279    R16 = 540422482,
1280    /// [15:0] R:G 8:8 little endian,
1281    Rg88 = 943212370,
1282    /// [15:0] G:R 8:8 little endian,
1283    Gr88 = 943215175,
1284    /// [31:0] R:G 16:16 little endian,
1285    Rg1616 = 842221394,
1286    /// [31:0] G:R 16:16 little endian,
1287    Gr1616 = 842224199,
1288    /// [63:0] x:R:G:B 16:16:16:16 little endian,
1289    Xrgb16161616f = 1211388504,
1290    /// [63:0] x:B:G:R 16:16:16:16 little endian,
1291    Xbgr16161616f = 1211384408,
1292    /// [63:0] A:R:G:B 16:16:16:16 little endian,
1293    Argb16161616f = 1211388481,
1294    /// [63:0] A:B:G:R 16:16:16:16 little endian,
1295    Abgr16161616f = 1211384385,
1296    /// [31:0] X:Y:Cb:Cr 8:8:8:8 little endian,
1297    Xyuv8888 = 1448434008,
1298    /// [23:0] Cr:Cb:Y 8:8:8 little endian,
1299    Vuy888 = 875713878,
1300    /// Y followed by U then V, 10:10:10. Non-linear modifier only,
1301    Vuy101010 = 808670550,
1302    /// [63:0] Cr0:0:Y1:0:Cb0:0:Y0:0 10:6:10:6:10:6:10:6 little endian per 2 Y pixels,
1303    Y210 = 808530521,
1304    /// [63:0] Cr0:0:Y1:0:Cb0:0:Y0:0 12:4:12:4:12:4:12:4 little endian per 2 Y pixels,
1305    Y212 = 842084953,
1306    /// [63:0] Cr0:Y1:Cb0:Y0 16:16:16:16 little endian per 2 Y pixels,
1307    Y216 = 909193817,
1308    /// [31:0] A:Cr:Y:Cb 2:10:10:10 little endian,
1309    Y410 = 808531033,
1310    /// [63:0] A:0:Cr:0:Y:0:Cb:0 12:4:12:4:12:4:12:4 little endian,
1311    Y412 = 842085465,
1312    /// [63:0] A:Cr:Y:Cb 16:16:16:16 little endian,
1313    Y416 = 909194329,
1314    /// [31:0] X:Cr:Y:Cb 2:10:10:10 little endian,
1315    Xvyu2101010 = 808670808,
1316    /// [63:0] X:0:Cr:0:Y:0:Cb:0 12:4:12:4:12:4:12:4 little endian,
1317    Xvyu1216161616 = 909334104,
1318    /// [63:0] X:Cr:Y:Cb 16:16:16:16 little endian,
1319    Xvyu16161616 = 942954072,
1320    /// [63:0]   A3:A2:Y3:0:Cr0:0:Y2:0:A1:A0:Y1:0:Cb0:0:Y0:0  1:1:8:2:8:2:8:2:1:1:8:2:8:2:8:2 little endian,
1321    Y0l0 = 810299481,
1322    /// [63:0]   X3:X2:Y3:0:Cr0:0:Y2:0:X1:X0:Y1:0:Cb0:0:Y0:0  1:1:8:2:8:2:8:2:1:1:8:2:8:2:8:2 little endian,
1323    X0l0 = 810299480,
1324    /// [63:0]   A3:A2:Y3:Cr0:Y2:A1:A0:Y1:Cb0:Y0  1:1:10:10:10:1:1:10:10:10 little endian,
1325    Y0l2 = 843853913,
1326    /// [63:0]   X3:X2:Y3:Cr0:Y2:X1:X0:Y1:Cb0:Y0  1:1:10:10:10:1:1:10:10:10 little endian,
1327    X0l2 = 843853912,
1328    Yuv4208bit = 942691673,
1329    Yuv42010bit = 808539481,
1330    Xrgb8888A8 = 943805016,
1331    Xbgr8888A8 = 943800920,
1332    Rgbx8888A8 = 943806546,
1333    Bgrx8888A8 = 943806530,
1334    Rgb888A8 = 943798354,
1335    Bgr888A8 = 943798338,
1336    Rgb565A8 = 943797586,
1337    Bgr565A8 = 943797570,
1338    /// non-subsampled Cr:Cb plane,
1339    Nv24 = 875714126,
1340    /// non-subsampled Cb:Cr plane,
1341    Nv42 = 842290766,
1342    /// 2x1 subsampled Cr:Cb plane, 10 bit per channel,
1343    P210 = 808530512,
1344    /// 2x2 subsampled Cr:Cb plane 10 bits per channel,
1345    P010 = 808530000,
1346    /// 2x2 subsampled Cr:Cb plane 12 bits per channel,
1347    P012 = 842084432,
1348    /// 2x2 subsampled Cr:Cb plane 16 bits per channel,
1349    P016 = 909193296,
1350}
1351
1352impl Format {
1353    pub fn from_bits(v: u32) -> Option<Self> {
1354        match v {
1355        0 => Some(Format::Argb8888),
1356        1 => Some(Format::Xrgb8888),
1357        538982467 => Some(Format::C8),
1358        943867730 => Some(Format::Rgb332),
1359        944916290 => Some(Format::Bgr233),
1360        842093144 => Some(Format::Xrgb4444),
1361        842089048 => Some(Format::Xbgr4444),
1362        842094674 => Some(Format::Rgbx4444),
1363        842094658 => Some(Format::Bgrx4444),
1364        842093121 => Some(Format::Argb4444),
1365        842089025 => Some(Format::Abgr4444),
1366        842088786 => Some(Format::Rgba4444),
1367        842088770 => Some(Format::Bgra4444),
1368        892424792 => Some(Format::Xrgb1555),
1369        892420696 => Some(Format::Xbgr1555),
1370        892426322 => Some(Format::Rgbx5551),
1371        892426306 => Some(Format::Bgrx5551),
1372        892424769 => Some(Format::Argb1555),
1373        892420673 => Some(Format::Abgr1555),
1374        892420434 => Some(Format::Rgba5551),
1375        892420418 => Some(Format::Bgra5551),
1376        909199186 => Some(Format::Rgb565),
1377        909199170 => Some(Format::Bgr565),
1378        875710290 => Some(Format::Rgb888),
1379        875710274 => Some(Format::Bgr888),
1380        875709016 => Some(Format::Xbgr8888),
1381        875714642 => Some(Format::Rgbx8888),
1382        875714626 => Some(Format::Bgrx8888),
1383        875708993 => Some(Format::Abgr8888),
1384        875708754 => Some(Format::Rgba8888),
1385        875708738 => Some(Format::Bgra8888),
1386        808669784 => Some(Format::Xrgb2101010),
1387        808665688 => Some(Format::Xbgr2101010),
1388        808671314 => Some(Format::Rgbx1010102),
1389        808671298 => Some(Format::Bgrx1010102),
1390        808669761 => Some(Format::Argb2101010),
1391        808665665 => Some(Format::Abgr2101010),
1392        808665426 => Some(Format::Rgba1010102),
1393        808665410 => Some(Format::Bgra1010102),
1394        1448695129 => Some(Format::Yuyv),
1395        1431918169 => Some(Format::Yvyu),
1396        1498831189 => Some(Format::Uyvy),
1397        1498765654 => Some(Format::Vyuy),
1398        1448433985 => Some(Format::Ayuv),
1399        842094158 => Some(Format::Nv12),
1400        825382478 => Some(Format::Nv21),
1401        909203022 => Some(Format::Nv16),
1402        825644622 => Some(Format::Nv61),
1403        961959257 => Some(Format::Yuv410),
1404        961893977 => Some(Format::Yvu410),
1405        825316697 => Some(Format::Yuv411),
1406        825316953 => Some(Format::Yvu411),
1407        842093913 => Some(Format::Yuv420),
1408        842094169 => Some(Format::Yvu420),
1409        909202777 => Some(Format::Yuv422),
1410        909203033 => Some(Format::Yvu422),
1411        875713881 => Some(Format::Yuv444),
1412        875714137 => Some(Format::Yvu444),
1413        538982482 => Some(Format::R8),
1414        540422482 => Some(Format::R16),
1415        943212370 => Some(Format::Rg88),
1416        943215175 => Some(Format::Gr88),
1417        842221394 => Some(Format::Rg1616),
1418        842224199 => Some(Format::Gr1616),
1419        1211388504 => Some(Format::Xrgb16161616f),
1420        1211384408 => Some(Format::Xbgr16161616f),
1421        1211388481 => Some(Format::Argb16161616f),
1422        1211384385 => Some(Format::Abgr16161616f),
1423        1448434008 => Some(Format::Xyuv8888),
1424        875713878 => Some(Format::Vuy888),
1425        808670550 => Some(Format::Vuy101010),
1426        808530521 => Some(Format::Y210),
1427        842084953 => Some(Format::Y212),
1428        909193817 => Some(Format::Y216),
1429        808531033 => Some(Format::Y410),
1430        842085465 => Some(Format::Y412),
1431        909194329 => Some(Format::Y416),
1432        808670808 => Some(Format::Xvyu2101010),
1433        909334104 => Some(Format::Xvyu1216161616),
1434        942954072 => Some(Format::Xvyu16161616),
1435        810299481 => Some(Format::Y0l0),
1436        810299480 => Some(Format::X0l0),
1437        843853913 => Some(Format::Y0l2),
1438        843853912 => Some(Format::X0l2),
1439        942691673 => Some(Format::Yuv4208bit),
1440        808539481 => Some(Format::Yuv42010bit),
1441        943805016 => Some(Format::Xrgb8888A8),
1442        943800920 => Some(Format::Xbgr8888A8),
1443        943806546 => Some(Format::Rgbx8888A8),
1444        943806530 => Some(Format::Bgrx8888A8),
1445        943798354 => Some(Format::Rgb888A8),
1446        943798338 => Some(Format::Bgr888A8),
1447        943797586 => Some(Format::Rgb565A8),
1448        943797570 => Some(Format::Bgr565A8),
1449        875714126 => Some(Format::Nv24),
1450        842290766 => Some(Format::Nv42),
1451        808530512 => Some(Format::P210),
1452        808530000 => Some(Format::P010),
1453        842084432 => Some(Format::P012),
1454        909193296 => Some(Format::P016),
1455        _ => None,
1456        }
1457    }
1458
1459    pub fn bits(&self) -> u32 {
1460        *self as u32
1461    }
1462}
1463impl Into<Arg> for Format {
1464    fn into(self) -> Arg {
1465        Arg::Uint(self.bits())
1466    }
1467}
1468} // mod wl_shm
1469
1470pub use crate::wl_shm::WlShm;
1471pub use crate::wl_shm::Request as WlShmRequest;
1472pub use crate::wl_shm::Event as WlShmEvent;
1473pub mod wl_buffer {
1474use super::*;
1475
1476/// content for a wl_surface
1477///
1478/// A buffer provides the content for a wl_surface. Buffers are
1479/// created through factory interfaces such as wl_drm, wl_shm or
1480/// similar. It has a width and a height and can be attached to a
1481/// wl_surface, but the mechanism by which a client provides and
1482/// updates the contents is defined by the buffer factory interface.
1483#[derive(Debug)]
1484pub struct WlBuffer;
1485
1486impl Interface for WlBuffer {
1487    const NAME: &'static str = "wl_buffer";
1488    const VERSION: u32 = 1;
1489    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
1490        // destroy
1491        MessageSpec(&[
1492        ]),
1493    ]);
1494    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
1495        // release
1496        MessageSpec(&[
1497        ]),
1498    ]);
1499    type Incoming = Event;
1500    type Outgoing = Request;
1501}
1502
1503#[derive(Debug)]
1504pub enum Request {
1505
1506    /// destroy a buffer
1507    ///
1508    /// Destroy a buffer. If and how you need to release the backing
1509    /// storage is defined by the buffer factory interface.
1510    /// 
1511    /// For possible side-effects to a surface, see wl_surface.attach.
1512    Destroy,
1513}
1514
1515impl MessageType for Request {
1516    fn log(&self, this: ObjectId) -> String {
1517        match *self {
1518            Request::Destroy {
1519            } => {
1520                format!("wl_buffer@{:?}::destroy()", this)
1521            }
1522        }
1523    }
1524    fn message_name(&self) -> &'static std::ffi::CStr{
1525        match *self {
1526            Request::Destroy { .. } => c"wl_buffer::destroy",
1527        }
1528    }
1529}
1530#[derive(Debug)]
1531pub enum Event {
1532
1533    /// compositor releases buffer
1534    ///
1535    /// Sent when this wl_buffer is no longer used by the compositor.
1536    /// The client is now free to reuse or destroy this buffer and its
1537    /// backing storage.
1538    /// 
1539    /// If a client receives a release event before the frame callback
1540    /// requested in the same wl_surface.commit that attaches this
1541    /// wl_buffer to a surface, then the client is immediately free to
1542    /// reuse the buffer and its backing storage, and does not need a
1543    /// second buffer for the next surface content update. Typically
1544    /// this is possible, when the compositor maintains a copy of the
1545    /// wl_surface contents, e.g. as a GL texture. This is an important
1546    /// optimization for GL(ES) compositors with wl_shm clients.
1547    Release,
1548}
1549
1550impl MessageType for Event {
1551    fn log(&self, this: ObjectId) -> String {
1552        match *self {
1553            Event::Release {
1554            } => {
1555                format!("wl_buffer@{:?}::release()", this)
1556            }
1557        }
1558    }
1559    fn message_name(&self) -> &'static std::ffi::CStr{
1560        match *self {
1561            Event::Release { .. } => c"wl_buffer::release",
1562        }
1563    }
1564}
1565impl IntoMessage for Request {
1566    type Error = EncodeError;
1567    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
1568        let mut header = MessageHeader {
1569            sender: id,
1570            opcode: 0,
1571            length: 0,
1572        };
1573        let mut msg = Message::new();
1574        msg.write_header(&header)?;
1575        match self {
1576        Request::Destroy {
1577        } => {
1578            header.opcode = 0;
1579        },
1580        }
1581        header.length = msg.bytes().len() as u16;
1582        msg.rewind();
1583        msg.write_header(&header)?;
1584        Ok(msg)
1585    }
1586}
1587impl FromArgs for Event {
1588    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
1589        match op {
1590        0 /* release */ => {
1591            let mut iter = args.into_iter();
1592            Ok(Event::Release {
1593
1594            })
1595        },
1596        _ => {
1597            Err(DecodeError::InvalidOpcode(op).into())
1598        },
1599        }
1600    }
1601}
1602} // mod wl_buffer
1603
1604pub use crate::wl_buffer::WlBuffer;
1605pub use crate::wl_buffer::Request as WlBufferRequest;
1606pub use crate::wl_buffer::Event as WlBufferEvent;
1607pub mod wl_data_offer {
1608use super::*;
1609
1610/// offer to transfer data
1611///
1612/// A wl_data_offer represents a piece of data offered for transfer
1613/// by another client (the source client).  It is used by the
1614/// copy-and-paste and drag-and-drop mechanisms.  The offer
1615/// describes the different mime types that the data can be
1616/// converted to and provides the mechanism for transferring the
1617/// data directly from the source client.
1618#[derive(Debug)]
1619pub struct WlDataOffer;
1620
1621impl Interface for WlDataOffer {
1622    const NAME: &'static str = "wl_data_offer";
1623    const VERSION: u32 = 3;
1624    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
1625        // accept
1626        MessageSpec(&[
1627            ArgKind::Uint,
1628            ArgKind::String,
1629        ]),
1630        // receive
1631        MessageSpec(&[
1632            ArgKind::String,
1633            ArgKind::Handle,
1634        ]),
1635        // destroy
1636        MessageSpec(&[
1637        ]),
1638        // finish
1639        MessageSpec(&[
1640        ]),
1641        // set_actions
1642        MessageSpec(&[
1643            ArgKind::Uint,
1644            ArgKind::Uint,
1645        ]),
1646    ]);
1647    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
1648        // offer
1649        MessageSpec(&[
1650            ArgKind::String,
1651        ]),
1652        // source_actions
1653        MessageSpec(&[
1654            ArgKind::Uint,
1655        ]),
1656        // action
1657        MessageSpec(&[
1658            ArgKind::Uint,
1659        ]),
1660    ]);
1661    type Incoming = Event;
1662    type Outgoing = Request;
1663}
1664
1665#[derive(Debug)]
1666pub enum Request {
1667
1668    /// accept one of the offered mime types
1669    ///
1670    /// Indicate that the client can accept the given mime type, or
1671    /// NULL for not accepted.
1672    /// 
1673    /// For objects of version 2 or older, this request is used by the
1674    /// client to give feedback whether the client can receive the given
1675    /// mime type, or NULL if none is accepted; the feedback does not
1676    /// determine whether the drag-and-drop operation succeeds or not.
1677    /// 
1678    /// For objects of version 3 or newer, this request determines the
1679    /// final result of the drag-and-drop operation. If the end result
1680    /// is that no mime types were accepted, the drag-and-drop operation
1681    /// will be cancelled and the corresponding drag source will receive
1682    /// wl_data_source.cancelled. Clients may still use this event in
1683    /// conjunction with wl_data_source.action for feedback.
1684    Accept {
1685        /// serial number of the accept request
1686        serial: u32,
1687        /// mime type accepted by the client
1688        mime_type: String,
1689    },
1690
1691    /// request that the data is transferred
1692    ///
1693    /// To transfer the offered data, the client issues this request
1694    /// and indicates the mime type it wants to receive.  The transfer
1695    /// happens through the passed file descriptor (typically created
1696    /// with the pipe system call).  The source client writes the data
1697    /// in the mime type representation requested and then closes the
1698    /// file descriptor.
1699    /// 
1700    /// The receiving client reads from the read end of the pipe until
1701    /// EOF and then closes its end, at which point the transfer is
1702    /// complete.
1703    /// 
1704    /// This request may happen multiple times for different mime types,
1705    /// both before and after wl_data_device.drop. Drag-and-drop destination
1706    /// clients may preemptively fetch data or examine it more closely to
1707    /// determine acceptance.
1708    Receive {
1709        /// mime type desired by receiver
1710        mime_type: String,
1711        /// file descriptor for data transfer
1712        fd: zx::Handle,
1713    },
1714
1715    /// destroy data offer
1716    ///
1717    /// Destroy the data offer.
1718    Destroy,
1719
1720    /// the offer will no longer be used
1721    ///
1722    /// Notifies the compositor that the drag destination successfully
1723    /// finished the drag-and-drop operation.
1724    /// 
1725    /// Upon receiving this request, the compositor will emit
1726    /// wl_data_source.dnd_finished on the drag source client.
1727    /// 
1728    /// It is a client error to perform other requests than
1729    /// wl_data_offer.destroy after this one. It is also an error to perform
1730    /// this request after a NULL mime type has been set in
1731    /// wl_data_offer.accept or no action was received through
1732    /// wl_data_offer.action.
1733    /// 
1734    /// If wl_data_offer.finish request is received for a non drag and drop
1735    /// operation, the invalid_finish protocol error is raised.
1736    Finish,
1737
1738    /// set the available/preferred drag-and-drop actions
1739    ///
1740    /// Sets the actions that the destination side client supports for
1741    /// this operation. This request may trigger the emission of
1742    /// wl_data_source.action and wl_data_offer.action events if the compositor
1743    /// needs to change the selected action.
1744    /// 
1745    /// This request can be called multiple times throughout the
1746    /// drag-and-drop operation, typically in response to wl_data_device.enter
1747    /// or wl_data_device.motion events.
1748    /// 
1749    /// This request determines the final result of the drag-and-drop
1750    /// operation. If the end result is that no action is accepted,
1751    /// the drag source will receive wl_data_source.cancelled.
1752    /// 
1753    /// The dnd_actions argument must contain only values expressed in the
1754    /// wl_data_device_manager.dnd_actions enum, and the preferred_action
1755    /// argument must only contain one of those values set, otherwise it
1756    /// will result in a protocol error.
1757    /// 
1758    /// While managing an "ask" action, the destination drag-and-drop client
1759    /// may perform further wl_data_offer.receive requests, and is expected
1760    /// to perform one last wl_data_offer.set_actions request with a preferred
1761    /// action other than "ask" (and optionally wl_data_offer.accept) before
1762    /// requesting wl_data_offer.finish, in order to convey the action selected
1763    /// by the user. If the preferred action is not in the
1764    /// wl_data_offer.source_actions mask, an error will be raised.
1765    /// 
1766    /// If the "ask" action is dismissed (e.g. user cancellation), the client
1767    /// is expected to perform wl_data_offer.destroy right away.
1768    /// 
1769    /// This request can only be made on drag-and-drop offers, a protocol error
1770    /// will be raised otherwise.
1771    SetActions {
1772        /// actions supported by the destination client
1773        dnd_actions: crate::wl_data_device_manager::DndAction,
1774        /// action preferred by the destination client
1775        preferred_action: crate::wl_data_device_manager::DndAction,
1776    },
1777}
1778
1779impl MessageType for Request {
1780    fn log(&self, this: ObjectId) -> String {
1781        match *self {
1782            Request::Accept {
1783                ref serial,
1784                ref mime_type,
1785            } => {
1786                format!("wl_data_offer@{:?}::accept(serial: {:?}, mime_type: {:?})", this, serial, mime_type)
1787            }
1788            Request::Receive {
1789                ref mime_type,
1790                ref fd,
1791            } => {
1792                format!("wl_data_offer@{:?}::receive(mime_type: {:?}, fd: <handle>)", this, mime_type)
1793            }
1794            Request::Destroy {
1795            } => {
1796                format!("wl_data_offer@{:?}::destroy()", this)
1797            }
1798            Request::Finish {
1799            } => {
1800                format!("wl_data_offer@{:?}::finish()", this)
1801            }
1802            Request::SetActions {
1803                ref dnd_actions,
1804                ref preferred_action,
1805            } => {
1806                format!("wl_data_offer@{:?}::set_actions(dnd_actions: {:?}, preferred_action: {:?})", this, dnd_actions, preferred_action)
1807            }
1808        }
1809    }
1810    fn message_name(&self) -> &'static std::ffi::CStr{
1811        match *self {
1812            Request::Accept { .. } => c"wl_data_offer::accept",
1813            Request::Receive { .. } => c"wl_data_offer::receive",
1814            Request::Destroy { .. } => c"wl_data_offer::destroy",
1815            Request::Finish { .. } => c"wl_data_offer::finish",
1816            Request::SetActions { .. } => c"wl_data_offer::set_actions",
1817        }
1818    }
1819}
1820#[derive(Debug)]
1821pub enum Event {
1822
1823    /// advertise offered mime type
1824    ///
1825    /// Sent immediately after creating the wl_data_offer object.  One
1826    /// event per offered mime type.
1827    Offer {
1828        /// offered mime type
1829        mime_type: String,
1830    },
1831
1832    /// notify the source-side available actions
1833    ///
1834    /// This event indicates the actions offered by the data source. It
1835    /// will be sent right after wl_data_device.enter, or anytime the source
1836    /// side changes its offered actions through wl_data_source.set_actions.
1837    SourceActions {
1838        /// actions offered by the data source
1839        source_actions: Enum<crate::wl_data_device_manager::DndAction>,
1840    },
1841
1842    /// notify the selected action
1843    ///
1844    /// This event indicates the action selected by the compositor after
1845    /// matching the source/destination side actions. Only one action (or
1846    /// none) will be offered here.
1847    /// 
1848    /// This event can be emitted multiple times during the drag-and-drop
1849    /// operation in response to destination side action changes through
1850    /// wl_data_offer.set_actions.
1851    /// 
1852    /// This event will no longer be emitted after wl_data_device.drop
1853    /// happened on the drag-and-drop destination, the client must
1854    /// honor the last action received, or the last preferred one set
1855    /// through wl_data_offer.set_actions when handling an "ask" action.
1856    /// 
1857    /// Compositors may also change the selected action on the fly, mainly
1858    /// in response to keyboard modifier changes during the drag-and-drop
1859    /// operation.
1860    /// 
1861    /// The most recent action received is always the valid one. Prior to
1862    /// receiving wl_data_device.drop, the chosen action may change (e.g.
1863    /// due to keyboard modifiers being pressed). At the time of receiving
1864    /// wl_data_device.drop the drag-and-drop destination must honor the
1865    /// last action received.
1866    /// 
1867    /// Action changes may still happen after wl_data_device.drop,
1868    /// especially on "ask" actions, where the drag-and-drop destination
1869    /// may choose another action afterwards. Action changes happening
1870    /// at this stage are always the result of inter-client negotiation, the
1871    /// compositor shall no longer be able to induce a different action.
1872    /// 
1873    /// Upon "ask" actions, it is expected that the drag-and-drop destination
1874    /// may potentially choose a different action and/or mime type,
1875    /// based on wl_data_offer.source_actions and finally chosen by the
1876    /// user (e.g. popping up a menu with the available options). The
1877    /// final wl_data_offer.set_actions and wl_data_offer.accept requests
1878    /// must happen before the call to wl_data_offer.finish.
1879    Action {
1880        /// action selected by the compositor
1881        dnd_action: Enum<crate::wl_data_device_manager::DndAction>,
1882    },
1883}
1884
1885impl MessageType for Event {
1886    fn log(&self, this: ObjectId) -> String {
1887        match *self {
1888            Event::Offer {
1889                ref mime_type,
1890            } => {
1891                format!("wl_data_offer@{:?}::offer(mime_type: {:?})", this, mime_type)
1892            }
1893            Event::SourceActions {
1894                ref source_actions,
1895            } => {
1896                format!("wl_data_offer@{:?}::source_actions(source_actions: {:?})", this, source_actions)
1897            }
1898            Event::Action {
1899                ref dnd_action,
1900            } => {
1901                format!("wl_data_offer@{:?}::action(dnd_action: {:?})", this, dnd_action)
1902            }
1903        }
1904    }
1905    fn message_name(&self) -> &'static std::ffi::CStr{
1906        match *self {
1907            Event::Offer { .. } => c"wl_data_offer::offer",
1908            Event::SourceActions { .. } => c"wl_data_offer::source_actions",
1909            Event::Action { .. } => c"wl_data_offer::action",
1910        }
1911    }
1912}
1913impl IntoMessage for Request {
1914    type Error = EncodeError;
1915    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
1916        let mut header = MessageHeader {
1917            sender: id,
1918            opcode: 0,
1919            length: 0,
1920        };
1921        let mut msg = Message::new();
1922        msg.write_header(&header)?;
1923        match self {
1924        Request::Accept {
1925            serial,
1926            mime_type,
1927        } => {
1928            msg.write_arg(Arg::Uint(serial))?;
1929            msg.write_arg(Arg::String(mime_type))?;
1930            header.opcode = 0;
1931        },
1932        Request::Receive {
1933            mime_type,
1934            fd,
1935        } => {
1936            msg.write_arg(Arg::String(mime_type))?;
1937            msg.write_arg(Arg::Handle(fd))?;
1938            header.opcode = 1;
1939        },
1940        Request::Destroy {
1941        } => {
1942            header.opcode = 2;
1943        },
1944        Request::Finish {
1945        } => {
1946            header.opcode = 3;
1947        },
1948        Request::SetActions {
1949            dnd_actions,
1950            preferred_action,
1951        } => {
1952            msg.write_arg(Arg::Uint(dnd_actions.bits()))?;
1953            msg.write_arg(Arg::Uint(preferred_action.bits()))?;
1954            header.opcode = 4;
1955        },
1956        }
1957        header.length = msg.bytes().len() as u16;
1958        msg.rewind();
1959        msg.write_header(&header)?;
1960        Ok(msg)
1961    }
1962}
1963impl FromArgs for Event {
1964    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
1965        match op {
1966        0 /* offer */ => {
1967            let mut iter = args.into_iter();
1968            Ok(Event::Offer {
1969                mime_type: iter.next()
1970                                             .ok_or(DecodeError::InsufficientArgs)?
1971                                             .as_string()?,
1972
1973            })
1974        },
1975        1 /* source_actions */ => {
1976            let mut iter = args.into_iter();
1977            Ok(Event::SourceActions {
1978                source_actions: iter.next()
1979                                             .ok_or(DecodeError::InsufficientArgs)?
1980                                             .as_uint().map(|i| match crate::wl_data_device_manager::DndAction::from_bits(i) {
1981                                      Some(e) => Enum::Recognized(e),
1982                                      None => Enum::Unrecognized(i),
1983                                 })?,
1984
1985            })
1986        },
1987        2 /* action */ => {
1988            let mut iter = args.into_iter();
1989            Ok(Event::Action {
1990                dnd_action: iter.next()
1991                                             .ok_or(DecodeError::InsufficientArgs)?
1992                                             .as_uint().map(|i| match crate::wl_data_device_manager::DndAction::from_bits(i) {
1993                                      Some(e) => Enum::Recognized(e),
1994                                      None => Enum::Unrecognized(i),
1995                                 })?,
1996
1997            })
1998        },
1999        _ => {
2000            Err(DecodeError::InvalidOpcode(op).into())
2001        },
2002        }
2003    }
2004}
2005#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2006#[repr(u32)]
2007pub enum Error {
2008    /// finish request was called untimely,
2009    InvalidFinish = 0,
2010    /// action mask contains invalid values,
2011    InvalidActionMask = 1,
2012    /// action argument has an invalid value,
2013    InvalidAction = 2,
2014    /// offer doesn't accept this request,
2015    InvalidOffer = 3,
2016}
2017
2018impl Error {
2019    pub fn from_bits(v: u32) -> Option<Self> {
2020        match v {
2021        0 => Some(Error::InvalidFinish),
2022        1 => Some(Error::InvalidActionMask),
2023        2 => Some(Error::InvalidAction),
2024        3 => Some(Error::InvalidOffer),
2025        _ => None,
2026        }
2027    }
2028
2029    pub fn bits(&self) -> u32 {
2030        *self as u32
2031    }
2032}
2033impl Into<Arg> for Error {
2034    fn into(self) -> Arg {
2035        Arg::Uint(self.bits())
2036    }
2037}
2038} // mod wl_data_offer
2039
2040pub use crate::wl_data_offer::WlDataOffer;
2041pub use crate::wl_data_offer::Request as WlDataOfferRequest;
2042pub use crate::wl_data_offer::Event as WlDataOfferEvent;
2043pub mod wl_data_source {
2044use super::*;
2045
2046/// offer to transfer data
2047///
2048/// The wl_data_source object is the source side of a wl_data_offer.
2049/// It is created by the source client in a data transfer and
2050/// provides a way to describe the offered data and a way to respond
2051/// to requests to transfer the data.
2052#[derive(Debug)]
2053pub struct WlDataSource;
2054
2055impl Interface for WlDataSource {
2056    const NAME: &'static str = "wl_data_source";
2057    const VERSION: u32 = 3;
2058    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
2059        // offer
2060        MessageSpec(&[
2061            ArgKind::String,
2062        ]),
2063        // destroy
2064        MessageSpec(&[
2065        ]),
2066        // set_actions
2067        MessageSpec(&[
2068            ArgKind::Uint,
2069        ]),
2070    ]);
2071    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
2072        // target
2073        MessageSpec(&[
2074            ArgKind::String,
2075        ]),
2076        // send
2077        MessageSpec(&[
2078            ArgKind::String,
2079            ArgKind::Handle,
2080        ]),
2081        // cancelled
2082        MessageSpec(&[
2083        ]),
2084        // dnd_drop_performed
2085        MessageSpec(&[
2086        ]),
2087        // dnd_finished
2088        MessageSpec(&[
2089        ]),
2090        // action
2091        MessageSpec(&[
2092            ArgKind::Uint,
2093        ]),
2094    ]);
2095    type Incoming = Event;
2096    type Outgoing = Request;
2097}
2098
2099#[derive(Debug)]
2100pub enum Request {
2101
2102    /// add an offered mime type
2103    ///
2104    /// This request adds a mime type to the set of mime types
2105    /// advertised to targets.  Can be called several times to offer
2106    /// multiple types.
2107    Offer {
2108        /// mime type offered by the data source
2109        mime_type: String,
2110    },
2111
2112    /// destroy the data source
2113    ///
2114    /// Destroy the data source.
2115    Destroy,
2116
2117    /// set the available drag-and-drop actions
2118    ///
2119    /// Sets the actions that the source side client supports for this
2120    /// operation. This request may trigger wl_data_source.action and
2121    /// wl_data_offer.action events if the compositor needs to change the
2122    /// selected action.
2123    /// 
2124    /// The dnd_actions argument must contain only values expressed in the
2125    /// wl_data_device_manager.dnd_actions enum, otherwise it will result
2126    /// in a protocol error.
2127    /// 
2128    /// This request must be made once only, and can only be made on sources
2129    /// used in drag-and-drop, so it must be performed before
2130    /// wl_data_device.start_drag. Attempting to use the source other than
2131    /// for drag-and-drop will raise a protocol error.
2132    SetActions {
2133        /// actions supported by the data source
2134        dnd_actions: crate::wl_data_device_manager::DndAction,
2135    },
2136}
2137
2138impl MessageType for Request {
2139    fn log(&self, this: ObjectId) -> String {
2140        match *self {
2141            Request::Offer {
2142                ref mime_type,
2143            } => {
2144                format!("wl_data_source@{:?}::offer(mime_type: {:?})", this, mime_type)
2145            }
2146            Request::Destroy {
2147            } => {
2148                format!("wl_data_source@{:?}::destroy()", this)
2149            }
2150            Request::SetActions {
2151                ref dnd_actions,
2152            } => {
2153                format!("wl_data_source@{:?}::set_actions(dnd_actions: {:?})", this, dnd_actions)
2154            }
2155        }
2156    }
2157    fn message_name(&self) -> &'static std::ffi::CStr{
2158        match *self {
2159            Request::Offer { .. } => c"wl_data_source::offer",
2160            Request::Destroy { .. } => c"wl_data_source::destroy",
2161            Request::SetActions { .. } => c"wl_data_source::set_actions",
2162        }
2163    }
2164}
2165#[derive(Debug)]
2166pub enum Event {
2167
2168    /// a target accepts an offered mime type
2169    ///
2170    /// Sent when a target accepts pointer_focus or motion events.  If
2171    /// a target does not accept any of the offered types, type is NULL.
2172    /// 
2173    /// Used for feedback during drag-and-drop.
2174    Target {
2175        /// mime type accepted by the target
2176        mime_type: String,
2177    },
2178
2179    /// send the data
2180    ///
2181    /// Request for data from the client.  Send the data as the
2182    /// specified mime type over the passed file descriptor, then
2183    /// close it.
2184    Send {
2185        /// mime type for the data
2186        mime_type: String,
2187        /// file descriptor for the data
2188        fd: zx::Handle,
2189    },
2190
2191    /// selection was cancelled
2192    ///
2193    /// This data source is no longer valid. There are several reasons why
2194    /// this could happen:
2195    /// 
2196    /// - The data source has been replaced by another data source.
2197    /// - The drag-and-drop operation was performed, but the drop destination
2198    /// did not accept any of the mime types offered through
2199    /// wl_data_source.target.
2200    /// - The drag-and-drop operation was performed, but the drop destination
2201    /// did not select any of the actions present in the mask offered through
2202    /// wl_data_source.action.
2203    /// - The drag-and-drop operation was performed but didn't happen over a
2204    /// surface.
2205    /// - The compositor cancelled the drag-and-drop operation (e.g. compositor
2206    /// dependent timeouts to avoid stale drag-and-drop transfers).
2207    /// 
2208    /// The client should clean up and destroy this data source.
2209    /// 
2210    /// For objects of version 2 or older, wl_data_source.cancelled will
2211    /// only be emitted if the data source was replaced by another data
2212    /// source.
2213    Cancelled,
2214
2215    /// the drag-and-drop operation physically finished
2216    ///
2217    /// The user performed the drop action. This event does not indicate
2218    /// acceptance, wl_data_source.cancelled may still be emitted afterwards
2219    /// if the drop destination does not accept any mime type.
2220    /// 
2221    /// However, this event might however not be received if the compositor
2222    /// cancelled the drag-and-drop operation before this event could happen.
2223    /// 
2224    /// Note that the data_source may still be used in the future and should
2225    /// not be destroyed here.
2226    DndDropPerformed,
2227
2228    /// the drag-and-drop operation concluded
2229    ///
2230    /// The drop destination finished interoperating with this data
2231    /// source, so the client is now free to destroy this data source and
2232    /// free all associated data.
2233    /// 
2234    /// If the action used to perform the operation was "move", the
2235    /// source can now delete the transferred data.
2236    DndFinished,
2237
2238    /// notify the selected action
2239    ///
2240    /// This event indicates the action selected by the compositor after
2241    /// matching the source/destination side actions. Only one action (or
2242    /// none) will be offered here.
2243    /// 
2244    /// This event can be emitted multiple times during the drag-and-drop
2245    /// operation, mainly in response to destination side changes through
2246    /// wl_data_offer.set_actions, and as the data device enters/leaves
2247    /// surfaces.
2248    /// 
2249    /// It is only possible to receive this event after
2250    /// wl_data_source.dnd_drop_performed if the drag-and-drop operation
2251    /// ended in an "ask" action, in which case the final wl_data_source.action
2252    /// event will happen immediately before wl_data_source.dnd_finished.
2253    /// 
2254    /// Compositors may also change the selected action on the fly, mainly
2255    /// in response to keyboard modifier changes during the drag-and-drop
2256    /// operation.
2257    /// 
2258    /// The most recent action received is always the valid one. The chosen
2259    /// action may change alongside negotiation (e.g. an "ask" action can turn
2260    /// into a "move" operation), so the effects of the final action must
2261    /// always be applied in wl_data_offer.dnd_finished.
2262    /// 
2263    /// Clients can trigger cursor surface changes from this point, so
2264    /// they reflect the current action.
2265    Action {
2266        /// action selected by the compositor
2267        dnd_action: Enum<crate::wl_data_device_manager::DndAction>,
2268    },
2269}
2270
2271impl MessageType for Event {
2272    fn log(&self, this: ObjectId) -> String {
2273        match *self {
2274            Event::Target {
2275                ref mime_type,
2276            } => {
2277                format!("wl_data_source@{:?}::target(mime_type: {:?})", this, mime_type)
2278            }
2279            Event::Send {
2280                ref mime_type,
2281                ref fd,
2282            } => {
2283                format!("wl_data_source@{:?}::send(mime_type: {:?}, fd: <handle>)", this, mime_type)
2284            }
2285            Event::Cancelled {
2286            } => {
2287                format!("wl_data_source@{:?}::cancelled()", this)
2288            }
2289            Event::DndDropPerformed {
2290            } => {
2291                format!("wl_data_source@{:?}::dnd_drop_performed()", this)
2292            }
2293            Event::DndFinished {
2294            } => {
2295                format!("wl_data_source@{:?}::dnd_finished()", this)
2296            }
2297            Event::Action {
2298                ref dnd_action,
2299            } => {
2300                format!("wl_data_source@{:?}::action(dnd_action: {:?})", this, dnd_action)
2301            }
2302        }
2303    }
2304    fn message_name(&self) -> &'static std::ffi::CStr{
2305        match *self {
2306            Event::Target { .. } => c"wl_data_source::target",
2307            Event::Send { .. } => c"wl_data_source::send",
2308            Event::Cancelled { .. } => c"wl_data_source::cancelled",
2309            Event::DndDropPerformed { .. } => c"wl_data_source::dnd_drop_performed",
2310            Event::DndFinished { .. } => c"wl_data_source::dnd_finished",
2311            Event::Action { .. } => c"wl_data_source::action",
2312        }
2313    }
2314}
2315impl IntoMessage for Request {
2316    type Error = EncodeError;
2317    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
2318        let mut header = MessageHeader {
2319            sender: id,
2320            opcode: 0,
2321            length: 0,
2322        };
2323        let mut msg = Message::new();
2324        msg.write_header(&header)?;
2325        match self {
2326        Request::Offer {
2327            mime_type,
2328        } => {
2329            msg.write_arg(Arg::String(mime_type))?;
2330            header.opcode = 0;
2331        },
2332        Request::Destroy {
2333        } => {
2334            header.opcode = 1;
2335        },
2336        Request::SetActions {
2337            dnd_actions,
2338        } => {
2339            msg.write_arg(Arg::Uint(dnd_actions.bits()))?;
2340            header.opcode = 2;
2341        },
2342        }
2343        header.length = msg.bytes().len() as u16;
2344        msg.rewind();
2345        msg.write_header(&header)?;
2346        Ok(msg)
2347    }
2348}
2349impl FromArgs for Event {
2350    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
2351        match op {
2352        0 /* target */ => {
2353            let mut iter = args.into_iter();
2354            Ok(Event::Target {
2355                mime_type: iter.next()
2356                                             .ok_or(DecodeError::InsufficientArgs)?
2357                                             .as_string()?,
2358
2359            })
2360        },
2361        1 /* send */ => {
2362            let mut iter = args.into_iter();
2363            Ok(Event::Send {
2364                mime_type: iter.next()
2365                                             .ok_or(DecodeError::InsufficientArgs)?
2366                                             .as_string()?,
2367                fd: iter.next()
2368                                             .ok_or(DecodeError::InsufficientArgs)?
2369                                             .as_handle()?,
2370
2371            })
2372        },
2373        2 /* cancelled */ => {
2374            let mut iter = args.into_iter();
2375            Ok(Event::Cancelled {
2376
2377            })
2378        },
2379        3 /* dnd_drop_performed */ => {
2380            let mut iter = args.into_iter();
2381            Ok(Event::DndDropPerformed {
2382
2383            })
2384        },
2385        4 /* dnd_finished */ => {
2386            let mut iter = args.into_iter();
2387            Ok(Event::DndFinished {
2388
2389            })
2390        },
2391        5 /* action */ => {
2392            let mut iter = args.into_iter();
2393            Ok(Event::Action {
2394                dnd_action: iter.next()
2395                                             .ok_or(DecodeError::InsufficientArgs)?
2396                                             .as_uint().map(|i| match crate::wl_data_device_manager::DndAction::from_bits(i) {
2397                                      Some(e) => Enum::Recognized(e),
2398                                      None => Enum::Unrecognized(i),
2399                                 })?,
2400
2401            })
2402        },
2403        _ => {
2404            Err(DecodeError::InvalidOpcode(op).into())
2405        },
2406        }
2407    }
2408}
2409#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2410#[repr(u32)]
2411pub enum Error {
2412    /// action mask contains invalid values,
2413    InvalidActionMask = 0,
2414    /// source doesn't accept this request,
2415    InvalidSource = 1,
2416}
2417
2418impl Error {
2419    pub fn from_bits(v: u32) -> Option<Self> {
2420        match v {
2421        0 => Some(Error::InvalidActionMask),
2422        1 => Some(Error::InvalidSource),
2423        _ => None,
2424        }
2425    }
2426
2427    pub fn bits(&self) -> u32 {
2428        *self as u32
2429    }
2430}
2431impl Into<Arg> for Error {
2432    fn into(self) -> Arg {
2433        Arg::Uint(self.bits())
2434    }
2435}
2436} // mod wl_data_source
2437
2438pub use crate::wl_data_source::WlDataSource;
2439pub use crate::wl_data_source::Request as WlDataSourceRequest;
2440pub use crate::wl_data_source::Event as WlDataSourceEvent;
2441pub mod wl_data_device {
2442use super::*;
2443
2444/// data transfer device
2445///
2446/// There is one wl_data_device per seat which can be obtained
2447/// from the global wl_data_device_manager singleton.
2448/// 
2449/// A wl_data_device provides access to inter-client data transfer
2450/// mechanisms such as copy-and-paste and drag-and-drop.
2451#[derive(Debug)]
2452pub struct WlDataDevice;
2453
2454impl Interface for WlDataDevice {
2455    const NAME: &'static str = "wl_data_device";
2456    const VERSION: u32 = 3;
2457    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
2458        // start_drag
2459        MessageSpec(&[
2460            ArgKind::Object,
2461            ArgKind::Object,
2462            ArgKind::Object,
2463            ArgKind::Uint,
2464        ]),
2465        // set_selection
2466        MessageSpec(&[
2467            ArgKind::Object,
2468            ArgKind::Uint,
2469        ]),
2470        // release
2471        MessageSpec(&[
2472        ]),
2473    ]);
2474    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
2475        // data_offer
2476        MessageSpec(&[
2477            ArgKind::NewId,
2478        ]),
2479        // enter
2480        MessageSpec(&[
2481            ArgKind::Uint,
2482            ArgKind::Object,
2483            ArgKind::Fixed,
2484            ArgKind::Fixed,
2485            ArgKind::Object,
2486        ]),
2487        // leave
2488        MessageSpec(&[
2489        ]),
2490        // motion
2491        MessageSpec(&[
2492            ArgKind::Uint,
2493            ArgKind::Fixed,
2494            ArgKind::Fixed,
2495        ]),
2496        // drop
2497        MessageSpec(&[
2498        ]),
2499        // selection
2500        MessageSpec(&[
2501            ArgKind::Object,
2502        ]),
2503    ]);
2504    type Incoming = Event;
2505    type Outgoing = Request;
2506}
2507
2508#[derive(Debug)]
2509pub enum Request {
2510
2511    /// start drag-and-drop operation
2512    ///
2513    /// This request asks the compositor to start a drag-and-drop
2514    /// operation on behalf of the client.
2515    /// 
2516    /// The source argument is the data source that provides the data
2517    /// for the eventual data transfer. If source is NULL, enter, leave
2518    /// and motion events are sent only to the client that initiated the
2519    /// drag and the client is expected to handle the data passing
2520    /// internally.
2521    /// 
2522    /// The origin surface is the surface where the drag originates and
2523    /// the client must have an active implicit grab that matches the
2524    /// serial.
2525    /// 
2526    /// The icon surface is an optional (can be NULL) surface that
2527    /// provides an icon to be moved around with the cursor.  Initially,
2528    /// the top-left corner of the icon surface is placed at the cursor
2529    /// hotspot, but subsequent wl_surface.attach request can move the
2530    /// relative position. Attach requests must be confirmed with
2531    /// wl_surface.commit as usual. The icon surface is given the role of
2532    /// a drag-and-drop icon. If the icon surface already has another role,
2533    /// it raises a protocol error.
2534    /// 
2535    /// The current and pending input regions of the icon wl_surface are
2536    /// cleared, and wl_surface.set_input_region is ignored until the
2537    /// wl_surface is no longer used as the icon surface. When the use
2538    /// as an icon ends, the current and pending input regions become
2539    /// undefined, and the wl_surface is unmapped.
2540    StartDrag {
2541        /// data source for the eventual transfer
2542        source: ObjectId,
2543        /// surface where the drag originates
2544        origin: ObjectId,
2545        /// drag-and-drop icon surface
2546        icon: ObjectId,
2547        /// serial number of the implicit grab on the origin
2548        serial: u32,
2549    },
2550
2551    /// copy data to the selection
2552    ///
2553    /// This request asks the compositor to set the selection
2554    /// to the data from the source on behalf of the client.
2555    /// 
2556    /// To unset the selection, set the source to NULL.
2557    SetSelection {
2558        /// data source for the selection
2559        source: ObjectId,
2560        /// serial number of the event that triggered this request
2561        serial: u32,
2562    },
2563
2564    /// destroy data device
2565    ///
2566    /// This request destroys the data device.
2567    Release,
2568}
2569
2570impl MessageType for Request {
2571    fn log(&self, this: ObjectId) -> String {
2572        match *self {
2573            Request::StartDrag {
2574                ref source,
2575                ref origin,
2576                ref icon,
2577                ref serial,
2578            } => {
2579                format!("wl_data_device@{:?}::start_drag(source: {:?}, origin: {:?}, icon: {:?}, serial: {:?})", this, source, origin, icon, serial)
2580            }
2581            Request::SetSelection {
2582                ref source,
2583                ref serial,
2584            } => {
2585                format!("wl_data_device@{:?}::set_selection(source: {:?}, serial: {:?})", this, source, serial)
2586            }
2587            Request::Release {
2588            } => {
2589                format!("wl_data_device@{:?}::release()", this)
2590            }
2591        }
2592    }
2593    fn message_name(&self) -> &'static std::ffi::CStr{
2594        match *self {
2595            Request::StartDrag { .. } => c"wl_data_device::start_drag",
2596            Request::SetSelection { .. } => c"wl_data_device::set_selection",
2597            Request::Release { .. } => c"wl_data_device::release",
2598        }
2599    }
2600}
2601#[derive(Debug)]
2602pub enum Event {
2603
2604    /// introduce a new wl_data_offer
2605    ///
2606    /// The data_offer event introduces a new wl_data_offer object,
2607    /// which will subsequently be used in either the
2608    /// data_device.enter event (for drag-and-drop) or the
2609    /// data_device.selection event (for selections).  Immediately
2610    /// following the data_device_data_offer event, the new data_offer
2611    /// object will send out data_offer.offer events to describe the
2612    /// mime types it offers.
2613    DataOffer {
2614        /// the new data_offer object
2615        id: NewObject<WlDataOffer>,
2616    },
2617
2618    /// initiate drag-and-drop session
2619    ///
2620    /// This event is sent when an active drag-and-drop pointer enters
2621    /// a surface owned by the client.  The position of the pointer at
2622    /// enter time is provided by the x and y arguments, in surface-local
2623    /// coordinates.
2624    Enter {
2625        /// serial number of the enter event
2626        serial: u32,
2627        /// client surface entered
2628        surface: ObjectId,
2629        /// surface-local x coordinate
2630        x: Fixed,
2631        /// surface-local y coordinate
2632        y: Fixed,
2633        /// source data_offer object
2634        id: ObjectId,
2635    },
2636
2637    /// end drag-and-drop session
2638    ///
2639    /// This event is sent when the drag-and-drop pointer leaves the
2640    /// surface and the session ends.  The client must destroy the
2641    /// wl_data_offer introduced at enter time at this point.
2642    Leave,
2643
2644    /// drag-and-drop session motion
2645    ///
2646    /// This event is sent when the drag-and-drop pointer moves within
2647    /// the currently focused surface. The new position of the pointer
2648    /// is provided by the x and y arguments, in surface-local
2649    /// coordinates.
2650    Motion {
2651        /// timestamp with millisecond granularity
2652        time: u32,
2653        /// surface-local x coordinate
2654        x: Fixed,
2655        /// surface-local y coordinate
2656        y: Fixed,
2657    },
2658
2659    /// end drag-and-drop session successfully
2660    ///
2661    /// The event is sent when a drag-and-drop operation is ended
2662    /// because the implicit grab is removed.
2663    /// 
2664    /// The drag-and-drop destination is expected to honor the last action
2665    /// received through wl_data_offer.action, if the resulting action is
2666    /// "copy" or "move", the destination can still perform
2667    /// wl_data_offer.receive requests, and is expected to end all
2668    /// transfers with a wl_data_offer.finish request.
2669    /// 
2670    /// If the resulting action is "ask", the action will not be considered
2671    /// final. The drag-and-drop destination is expected to perform one last
2672    /// wl_data_offer.set_actions request, or wl_data_offer.destroy in order
2673    /// to cancel the operation.
2674    Drop,
2675
2676    /// advertise new selection
2677    ///
2678    /// The selection event is sent out to notify the client of a new
2679    /// wl_data_offer for the selection for this device.  The
2680    /// data_device.data_offer and the data_offer.offer events are
2681    /// sent out immediately before this event to introduce the data
2682    /// offer object.  The selection event is sent to a client
2683    /// immediately before receiving keyboard focus and when a new
2684    /// selection is set while the client has keyboard focus.  The
2685    /// data_offer is valid until a new data_offer or NULL is received
2686    /// or until the client loses keyboard focus.  The client must
2687    /// destroy the previous selection data_offer, if any, upon receiving
2688    /// this event.
2689    Selection {
2690        /// selection data_offer object
2691        id: ObjectId,
2692    },
2693}
2694
2695impl MessageType for Event {
2696    fn log(&self, this: ObjectId) -> String {
2697        match *self {
2698            Event::DataOffer {
2699                ref id,
2700            } => {
2701                format!("wl_data_device@{:?}::data_offer(id: {:?})", this, id)
2702            }
2703            Event::Enter {
2704                ref serial,
2705                ref surface,
2706                ref x,
2707                ref y,
2708                ref id,
2709            } => {
2710                format!("wl_data_device@{:?}::enter(serial: {:?}, surface: {:?}, x: {:?}, y: {:?}, id: {:?})", this, serial, surface, x, y, id)
2711            }
2712            Event::Leave {
2713            } => {
2714                format!("wl_data_device@{:?}::leave()", this)
2715            }
2716            Event::Motion {
2717                ref time,
2718                ref x,
2719                ref y,
2720            } => {
2721                format!("wl_data_device@{:?}::motion(time: {:?}, x: {:?}, y: {:?})", this, time, x, y)
2722            }
2723            Event::Drop {
2724            } => {
2725                format!("wl_data_device@{:?}::drop()", this)
2726            }
2727            Event::Selection {
2728                ref id,
2729            } => {
2730                format!("wl_data_device@{:?}::selection(id: {:?})", this, id)
2731            }
2732        }
2733    }
2734    fn message_name(&self) -> &'static std::ffi::CStr{
2735        match *self {
2736            Event::DataOffer { .. } => c"wl_data_device::data_offer",
2737            Event::Enter { .. } => c"wl_data_device::enter",
2738            Event::Leave { .. } => c"wl_data_device::leave",
2739            Event::Motion { .. } => c"wl_data_device::motion",
2740            Event::Drop { .. } => c"wl_data_device::drop",
2741            Event::Selection { .. } => c"wl_data_device::selection",
2742        }
2743    }
2744}
2745impl IntoMessage for Request {
2746    type Error = EncodeError;
2747    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
2748        let mut header = MessageHeader {
2749            sender: id,
2750            opcode: 0,
2751            length: 0,
2752        };
2753        let mut msg = Message::new();
2754        msg.write_header(&header)?;
2755        match self {
2756        Request::StartDrag {
2757            source,
2758            origin,
2759            icon,
2760            serial,
2761        } => {
2762            msg.write_arg(Arg::Object(source))?;
2763            msg.write_arg(Arg::Object(origin))?;
2764            msg.write_arg(Arg::Object(icon))?;
2765            msg.write_arg(Arg::Uint(serial))?;
2766            header.opcode = 0;
2767        },
2768        Request::SetSelection {
2769            source,
2770            serial,
2771        } => {
2772            msg.write_arg(Arg::Object(source))?;
2773            msg.write_arg(Arg::Uint(serial))?;
2774            header.opcode = 1;
2775        },
2776        Request::Release {
2777        } => {
2778            header.opcode = 2;
2779        },
2780        }
2781        header.length = msg.bytes().len() as u16;
2782        msg.rewind();
2783        msg.write_header(&header)?;
2784        Ok(msg)
2785    }
2786}
2787impl FromArgs for Event {
2788    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
2789        match op {
2790        0 /* data_offer */ => {
2791            let mut iter = args.into_iter();
2792            Ok(Event::DataOffer {
2793                id: iter.next()
2794                                             .ok_or(DecodeError::InsufficientArgs)?
2795                                             .as_new_id()?.into(),
2796
2797            })
2798        },
2799        1 /* enter */ => {
2800            let mut iter = args.into_iter();
2801            Ok(Event::Enter {
2802                serial: iter.next()
2803                                             .ok_or(DecodeError::InsufficientArgs)?
2804                                             .as_uint()?,
2805                surface: iter.next()
2806                                             .ok_or(DecodeError::InsufficientArgs)?
2807                                             .as_object()?,
2808                x: iter.next()
2809                                             .ok_or(DecodeError::InsufficientArgs)?
2810                                             .as_fixed()?.into(),
2811                y: iter.next()
2812                                             .ok_or(DecodeError::InsufficientArgs)?
2813                                             .as_fixed()?.into(),
2814                id: iter.next()
2815                                             .ok_or(DecodeError::InsufficientArgs)?
2816                                             .as_object()?,
2817
2818            })
2819        },
2820        2 /* leave */ => {
2821            let mut iter = args.into_iter();
2822            Ok(Event::Leave {
2823
2824            })
2825        },
2826        3 /* motion */ => {
2827            let mut iter = args.into_iter();
2828            Ok(Event::Motion {
2829                time: iter.next()
2830                                             .ok_or(DecodeError::InsufficientArgs)?
2831                                             .as_uint()?,
2832                x: iter.next()
2833                                             .ok_or(DecodeError::InsufficientArgs)?
2834                                             .as_fixed()?.into(),
2835                y: iter.next()
2836                                             .ok_or(DecodeError::InsufficientArgs)?
2837                                             .as_fixed()?.into(),
2838
2839            })
2840        },
2841        4 /* drop */ => {
2842            let mut iter = args.into_iter();
2843            Ok(Event::Drop {
2844
2845            })
2846        },
2847        5 /* selection */ => {
2848            let mut iter = args.into_iter();
2849            Ok(Event::Selection {
2850                id: iter.next()
2851                                             .ok_or(DecodeError::InsufficientArgs)?
2852                                             .as_object()?,
2853
2854            })
2855        },
2856        _ => {
2857            Err(DecodeError::InvalidOpcode(op).into())
2858        },
2859        }
2860    }
2861}
2862#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2863#[repr(u32)]
2864pub enum Error {
2865    /// given wl_surface has another role,
2866    Role = 0,
2867}
2868
2869impl Error {
2870    pub fn from_bits(v: u32) -> Option<Self> {
2871        match v {
2872        0 => Some(Error::Role),
2873        _ => None,
2874        }
2875    }
2876
2877    pub fn bits(&self) -> u32 {
2878        *self as u32
2879    }
2880}
2881impl Into<Arg> for Error {
2882    fn into(self) -> Arg {
2883        Arg::Uint(self.bits())
2884    }
2885}
2886} // mod wl_data_device
2887
2888pub use crate::wl_data_device::WlDataDevice;
2889pub use crate::wl_data_device::Request as WlDataDeviceRequest;
2890pub use crate::wl_data_device::Event as WlDataDeviceEvent;
2891pub mod wl_data_device_manager {
2892use super::*;
2893
2894/// data transfer interface
2895///
2896/// The wl_data_device_manager is a singleton global object that
2897/// provides access to inter-client data transfer mechanisms such as
2898/// copy-and-paste and drag-and-drop.  These mechanisms are tied to
2899/// a wl_seat and this interface lets a client get a wl_data_device
2900/// corresponding to a wl_seat.
2901/// 
2902/// Depending on the version bound, the objects created from the bound
2903/// wl_data_device_manager object will have different requirements for
2904/// functioning properly. See wl_data_source.set_actions,
2905/// wl_data_offer.accept and wl_data_offer.finish for details.
2906#[derive(Debug)]
2907pub struct WlDataDeviceManager;
2908
2909impl Interface for WlDataDeviceManager {
2910    const NAME: &'static str = "wl_data_device_manager";
2911    const VERSION: u32 = 3;
2912    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
2913        // create_data_source
2914        MessageSpec(&[
2915            ArgKind::NewId,
2916        ]),
2917        // get_data_device
2918        MessageSpec(&[
2919            ArgKind::NewId,
2920            ArgKind::Object,
2921        ]),
2922    ]);
2923    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
2924    ]);
2925    type Incoming = Event;
2926    type Outgoing = Request;
2927}
2928
2929#[derive(Debug)]
2930pub enum Request {
2931
2932    /// create a new data source
2933    ///
2934    /// Create a new data source.
2935    CreateDataSource {
2936        /// data source to create
2937        id: NewId,
2938    },
2939
2940    /// create a new data device
2941    ///
2942    /// Create a new data device for a given seat.
2943    GetDataDevice {
2944        /// data device to create
2945        id: NewId,
2946        /// seat associated with the data device
2947        seat: ObjectId,
2948    },
2949}
2950
2951impl MessageType for Request {
2952    fn log(&self, this: ObjectId) -> String {
2953        match *self {
2954            Request::CreateDataSource {
2955                ref id,
2956            } => {
2957                format!("wl_data_device_manager@{:?}::create_data_source(id: {:?})", this, id)
2958            }
2959            Request::GetDataDevice {
2960                ref id,
2961                ref seat,
2962            } => {
2963                format!("wl_data_device_manager@{:?}::get_data_device(id: {:?}, seat: {:?})", this, id, seat)
2964            }
2965        }
2966    }
2967    fn message_name(&self) -> &'static std::ffi::CStr{
2968        match *self {
2969            Request::CreateDataSource { .. } => c"wl_data_device_manager::create_data_source",
2970            Request::GetDataDevice { .. } => c"wl_data_device_manager::get_data_device",
2971        }
2972    }
2973}
2974#[derive(Debug)]
2975pub enum Event {
2976}
2977
2978impl MessageType for Event {
2979    fn log(&self, this: ObjectId) -> String {
2980        match *self {
2981        }
2982    }
2983    fn message_name(&self) -> &'static std::ffi::CStr{
2984        match *self {
2985        }
2986    }
2987}
2988impl IntoMessage for Request {
2989    type Error = EncodeError;
2990    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
2991        let mut header = MessageHeader {
2992            sender: id,
2993            opcode: 0,
2994            length: 0,
2995        };
2996        let mut msg = Message::new();
2997        msg.write_header(&header)?;
2998        match self {
2999        Request::CreateDataSource {
3000            id,
3001        } => {
3002            msg.write_arg(Arg::NewId(id))?;
3003            header.opcode = 0;
3004        },
3005        Request::GetDataDevice {
3006            id,
3007            seat,
3008        } => {
3009            msg.write_arg(Arg::NewId(id))?;
3010            msg.write_arg(Arg::Object(seat))?;
3011            header.opcode = 1;
3012        },
3013        }
3014        header.length = msg.bytes().len() as u16;
3015        msg.rewind();
3016        msg.write_header(&header)?;
3017        Ok(msg)
3018    }
3019}
3020impl FromArgs for Event {
3021    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
3022        match op {
3023        _ => {
3024            Err(DecodeError::InvalidOpcode(op).into())
3025        },
3026        }
3027    }
3028}
3029::bitflags::bitflags! {
3030
3031    /// drag and drop actions
3032    ///
3033    /// This is a bitmask of the available/preferred actions in a
3034    /// drag-and-drop operation.
3035    /// 
3036    /// In the compositor, the selected action is a result of matching the
3037    /// actions offered by the source and destination sides.  "action" events
3038    /// with a "none" action will be sent to both source and destination if
3039    /// there is no match. All further checks will effectively happen on
3040    /// (source actions ∩ destination actions).
3041    /// 
3042    /// In addition, compositors may also pick different actions in
3043    /// reaction to key modifiers being pressed. One common design that
3044    /// is used in major toolkits (and the behavior recommended for
3045    /// compositors) is:
3046    /// 
3047    /// - If no modifiers are pressed, the first match (in bit order)
3048    /// will be used.
3049    /// - Pressing Shift selects "move", if enabled in the mask.
3050    /// - Pressing Control selects "copy", if enabled in the mask.
3051    /// 
3052    /// Behavior beyond that is considered implementation-dependent.
3053    /// Compositors may for example bind other modifiers (like Alt/Meta)
3054    /// or drags initiated with other buttons than BTN_LEFT to specific
3055    /// actions (e.g. "ask").
3056    #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
3057    pub struct DndAction: u32 {
3058        /// no action,
3059        const None = 0;
3060        /// copy action,
3061        const Copy = 1;
3062        /// move action,
3063        const Move = 2;
3064        /// ask action,
3065        const Ask = 4;
3066    }
3067}
3068impl Into<Arg> for DndAction {
3069    fn into(self) -> Arg {
3070        Arg::Uint(self.bits())
3071    }
3072}
3073} // mod wl_data_device_manager
3074
3075pub use crate::wl_data_device_manager::WlDataDeviceManager;
3076pub use crate::wl_data_device_manager::Request as WlDataDeviceManagerRequest;
3077pub use crate::wl_data_device_manager::Event as WlDataDeviceManagerEvent;
3078pub mod wl_shell {
3079use super::*;
3080
3081/// create desktop-style surfaces
3082///
3083/// This interface is implemented by servers that provide
3084/// desktop-style user interfaces.
3085/// 
3086/// It allows clients to associate a wl_shell_surface with
3087/// a basic surface.
3088/// 
3089/// Note! This protocol is deprecated and not intended for production use.
3090/// For desktop-style user interfaces, use xdg_shell.
3091#[derive(Debug)]
3092pub struct WlShell;
3093
3094impl Interface for WlShell {
3095    const NAME: &'static str = "wl_shell";
3096    const VERSION: u32 = 1;
3097    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
3098        // get_shell_surface
3099        MessageSpec(&[
3100            ArgKind::NewId,
3101            ArgKind::Object,
3102        ]),
3103    ]);
3104    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
3105    ]);
3106    type Incoming = Event;
3107    type Outgoing = Request;
3108}
3109
3110#[derive(Debug)]
3111pub enum Request {
3112
3113    /// create a shell surface from a surface
3114    ///
3115    /// Create a shell surface for an existing surface. This gives
3116    /// the wl_surface the role of a shell surface. If the wl_surface
3117    /// already has another role, it raises a protocol error.
3118    /// 
3119    /// Only one shell surface can be associated with a given surface.
3120    GetShellSurface {
3121        /// shell surface to create
3122        id: NewId,
3123        /// surface to be given the shell surface role
3124        surface: ObjectId,
3125    },
3126}
3127
3128impl MessageType for Request {
3129    fn log(&self, this: ObjectId) -> String {
3130        match *self {
3131            Request::GetShellSurface {
3132                ref id,
3133                ref surface,
3134            } => {
3135                format!("wl_shell@{:?}::get_shell_surface(id: {:?}, surface: {:?})", this, id, surface)
3136            }
3137        }
3138    }
3139    fn message_name(&self) -> &'static std::ffi::CStr{
3140        match *self {
3141            Request::GetShellSurface { .. } => c"wl_shell::get_shell_surface",
3142        }
3143    }
3144}
3145#[derive(Debug)]
3146pub enum Event {
3147}
3148
3149impl MessageType for Event {
3150    fn log(&self, this: ObjectId) -> String {
3151        match *self {
3152        }
3153    }
3154    fn message_name(&self) -> &'static std::ffi::CStr{
3155        match *self {
3156        }
3157    }
3158}
3159impl IntoMessage for Request {
3160    type Error = EncodeError;
3161    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
3162        let mut header = MessageHeader {
3163            sender: id,
3164            opcode: 0,
3165            length: 0,
3166        };
3167        let mut msg = Message::new();
3168        msg.write_header(&header)?;
3169        match self {
3170        Request::GetShellSurface {
3171            id,
3172            surface,
3173        } => {
3174            msg.write_arg(Arg::NewId(id))?;
3175            msg.write_arg(Arg::Object(surface))?;
3176            header.opcode = 0;
3177        },
3178        }
3179        header.length = msg.bytes().len() as u16;
3180        msg.rewind();
3181        msg.write_header(&header)?;
3182        Ok(msg)
3183    }
3184}
3185impl FromArgs for Event {
3186    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
3187        match op {
3188        _ => {
3189            Err(DecodeError::InvalidOpcode(op).into())
3190        },
3191        }
3192    }
3193}
3194#[derive(Copy, Clone, Debug, Eq, PartialEq)]
3195#[repr(u32)]
3196pub enum Error {
3197    /// given wl_surface has another role,
3198    Role = 0,
3199}
3200
3201impl Error {
3202    pub fn from_bits(v: u32) -> Option<Self> {
3203        match v {
3204        0 => Some(Error::Role),
3205        _ => None,
3206        }
3207    }
3208
3209    pub fn bits(&self) -> u32 {
3210        *self as u32
3211    }
3212}
3213impl Into<Arg> for Error {
3214    fn into(self) -> Arg {
3215        Arg::Uint(self.bits())
3216    }
3217}
3218} // mod wl_shell
3219
3220pub use crate::wl_shell::WlShell;
3221pub use crate::wl_shell::Request as WlShellRequest;
3222pub use crate::wl_shell::Event as WlShellEvent;
3223pub mod wl_shell_surface {
3224use super::*;
3225
3226/// desktop-style metadata interface
3227///
3228/// An interface that may be implemented by a wl_surface, for
3229/// implementations that provide a desktop-style user interface.
3230/// 
3231/// It provides requests to treat surfaces like toplevel, fullscreen
3232/// or popup windows, move, resize or maximize them, associate
3233/// metadata like title and class, etc.
3234/// 
3235/// On the server side the object is automatically destroyed when
3236/// the related wl_surface is destroyed. On the client side,
3237/// wl_shell_surface_destroy() must be called before destroying
3238/// the wl_surface object.
3239#[derive(Debug)]
3240pub struct WlShellSurface;
3241
3242impl Interface for WlShellSurface {
3243    const NAME: &'static str = "wl_shell_surface";
3244    const VERSION: u32 = 1;
3245    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
3246        // pong
3247        MessageSpec(&[
3248            ArgKind::Uint,
3249        ]),
3250        // move
3251        MessageSpec(&[
3252            ArgKind::Object,
3253            ArgKind::Uint,
3254        ]),
3255        // resize
3256        MessageSpec(&[
3257            ArgKind::Object,
3258            ArgKind::Uint,
3259            ArgKind::Uint,
3260        ]),
3261        // set_toplevel
3262        MessageSpec(&[
3263        ]),
3264        // set_transient
3265        MessageSpec(&[
3266            ArgKind::Object,
3267            ArgKind::Int,
3268            ArgKind::Int,
3269            ArgKind::Uint,
3270        ]),
3271        // set_fullscreen
3272        MessageSpec(&[
3273            ArgKind::Uint,
3274            ArgKind::Uint,
3275            ArgKind::Object,
3276        ]),
3277        // set_popup
3278        MessageSpec(&[
3279            ArgKind::Object,
3280            ArgKind::Uint,
3281            ArgKind::Object,
3282            ArgKind::Int,
3283            ArgKind::Int,
3284            ArgKind::Uint,
3285        ]),
3286        // set_maximized
3287        MessageSpec(&[
3288            ArgKind::Object,
3289        ]),
3290        // set_title
3291        MessageSpec(&[
3292            ArgKind::String,
3293        ]),
3294        // set_class
3295        MessageSpec(&[
3296            ArgKind::String,
3297        ]),
3298    ]);
3299    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
3300        // ping
3301        MessageSpec(&[
3302            ArgKind::Uint,
3303        ]),
3304        // configure
3305        MessageSpec(&[
3306            ArgKind::Uint,
3307            ArgKind::Int,
3308            ArgKind::Int,
3309        ]),
3310        // popup_done
3311        MessageSpec(&[
3312        ]),
3313    ]);
3314    type Incoming = Event;
3315    type Outgoing = Request;
3316}
3317
3318#[derive(Debug)]
3319pub enum Request {
3320
3321    /// respond to a ping event
3322    ///
3323    /// A client must respond to a ping event with a pong request or
3324    /// the client may be deemed unresponsive.
3325    Pong {
3326        /// serial number of the ping event
3327        serial: u32,
3328    },
3329
3330    /// start an interactive move
3331    ///
3332    /// Start a pointer-driven move of the surface.
3333    /// 
3334    /// This request must be used in response to a button press event.
3335    /// The server may ignore move requests depending on the state of
3336    /// the surface (e.g. fullscreen or maximized).
3337    Move {
3338        /// seat whose pointer is used
3339        seat: ObjectId,
3340        /// serial number of the implicit grab on the pointer
3341        serial: u32,
3342    },
3343
3344    /// start an interactive resize
3345    ///
3346    /// Start a pointer-driven resizing of the surface.
3347    /// 
3348    /// This request must be used in response to a button press event.
3349    /// The server may ignore resize requests depending on the state of
3350    /// the surface (e.g. fullscreen or maximized).
3351    Resize {
3352        /// seat whose pointer is used
3353        seat: ObjectId,
3354        /// serial number of the implicit grab on the pointer
3355        serial: u32,
3356        /// which edge or corner is being dragged
3357        edges: Resize,
3358    },
3359
3360    /// make the surface a toplevel surface
3361    ///
3362    /// Map the surface as a toplevel surface.
3363    /// 
3364    /// A toplevel surface is not fullscreen, maximized or transient.
3365    SetToplevel,
3366
3367    /// make the surface a transient surface
3368    ///
3369    /// Map the surface relative to an existing surface.
3370    /// 
3371    /// The x and y arguments specify the location of the upper left
3372    /// corner of the surface relative to the upper left corner of the
3373    /// parent surface, in surface-local coordinates.
3374    /// 
3375    /// The flags argument controls details of the transient behaviour.
3376    SetTransient {
3377        /// parent surface
3378        parent: ObjectId,
3379        /// surface-local x coordinate
3380        x: i32,
3381        /// surface-local y coordinate
3382        y: i32,
3383        /// transient surface behavior
3384        flags: Transient,
3385    },
3386
3387    /// make the surface a fullscreen surface
3388    ///
3389    /// Map the surface as a fullscreen surface.
3390    /// 
3391    /// If an output parameter is given then the surface will be made
3392    /// fullscreen on that output. If the client does not specify the
3393    /// output then the compositor will apply its policy - usually
3394    /// choosing the output on which the surface has the biggest surface
3395    /// area.
3396    /// 
3397    /// The client may specify a method to resolve a size conflict
3398    /// between the output size and the surface size - this is provided
3399    /// through the method parameter.
3400    /// 
3401    /// The framerate parameter is used only when the method is set
3402    /// to "driver", to indicate the preferred framerate. A value of 0
3403    /// indicates that the client does not care about framerate.  The
3404    /// framerate is specified in mHz, that is framerate of 60000 is 60Hz.
3405    /// 
3406    /// A method of "scale" or "driver" implies a scaling operation of
3407    /// the surface, either via a direct scaling operation or a change of
3408    /// the output mode. This will override any kind of output scaling, so
3409    /// that mapping a surface with a buffer size equal to the mode can
3410    /// fill the screen independent of buffer_scale.
3411    /// 
3412    /// A method of "fill" means we don't scale up the buffer, however
3413    /// any output scale is applied. This means that you may run into
3414    /// an edge case where the application maps a buffer with the same
3415    /// size of the output mode but buffer_scale 1 (thus making a
3416    /// surface larger than the output). In this case it is allowed to
3417    /// downscale the results to fit the screen.
3418    /// 
3419    /// The compositor must reply to this request with a configure event
3420    /// with the dimensions for the output on which the surface will
3421    /// be made fullscreen.
3422    SetFullscreen {
3423        /// method for resolving size conflict
3424        method: FullscreenMethod,
3425        /// framerate in mHz
3426        framerate: u32,
3427        /// output on which the surface is to be fullscreen
3428        output: ObjectId,
3429    },
3430
3431    /// make the surface a popup surface
3432    ///
3433    /// Map the surface as a popup.
3434    /// 
3435    /// A popup surface is a transient surface with an added pointer
3436    /// grab.
3437    /// 
3438    /// An existing implicit grab will be changed to owner-events mode,
3439    /// and the popup grab will continue after the implicit grab ends
3440    /// (i.e. releasing the mouse button does not cause the popup to
3441    /// be unmapped).
3442    /// 
3443    /// The popup grab continues until the window is destroyed or a
3444    /// mouse button is pressed in any other client's window. A click
3445    /// in any of the client's surfaces is reported as normal, however,
3446    /// clicks in other clients' surfaces will be discarded and trigger
3447    /// the callback.
3448    /// 
3449    /// The x and y arguments specify the location of the upper left
3450    /// corner of the surface relative to the upper left corner of the
3451    /// parent surface, in surface-local coordinates.
3452    SetPopup {
3453        /// seat whose pointer is used
3454        seat: ObjectId,
3455        /// serial number of the implicit grab on the pointer
3456        serial: u32,
3457        /// parent surface
3458        parent: ObjectId,
3459        /// surface-local x coordinate
3460        x: i32,
3461        /// surface-local y coordinate
3462        y: i32,
3463        /// transient surface behavior
3464        flags: Transient,
3465    },
3466
3467    /// make the surface a maximized surface
3468    ///
3469    /// Map the surface as a maximized surface.
3470    /// 
3471    /// If an output parameter is given then the surface will be
3472    /// maximized on that output. If the client does not specify the
3473    /// output then the compositor will apply its policy - usually
3474    /// choosing the output on which the surface has the biggest surface
3475    /// area.
3476    /// 
3477    /// The compositor will reply with a configure event telling
3478    /// the expected new surface size. The operation is completed
3479    /// on the next buffer attach to this surface.
3480    /// 
3481    /// A maximized surface typically fills the entire output it is
3482    /// bound to, except for desktop elements such as panels. This is
3483    /// the main difference between a maximized shell surface and a
3484    /// fullscreen shell surface.
3485    /// 
3486    /// The details depend on the compositor implementation.
3487    SetMaximized {
3488        /// output on which the surface is to be maximized
3489        output: ObjectId,
3490    },
3491
3492    /// set surface title
3493    ///
3494    /// Set a short title for the surface.
3495    /// 
3496    /// This string may be used to identify the surface in a task bar,
3497    /// window list, or other user interface elements provided by the
3498    /// compositor.
3499    /// 
3500    /// The string must be encoded in UTF-8.
3501    SetTitle {
3502        /// surface title
3503        title: String,
3504    },
3505
3506    /// set surface class
3507    ///
3508    /// Set a class for the surface.
3509    /// 
3510    /// The surface class identifies the general class of applications
3511    /// to which the surface belongs. A common convention is to use the
3512    /// file name (or the full path if it is a non-standard location) of
3513    /// the application's .desktop file as the class.
3514    SetClass {
3515        /// surface class
3516        class_: String,
3517    },
3518}
3519
3520impl MessageType for Request {
3521    fn log(&self, this: ObjectId) -> String {
3522        match *self {
3523            Request::Pong {
3524                ref serial,
3525            } => {
3526                format!("wl_shell_surface@{:?}::pong(serial: {:?})", this, serial)
3527            }
3528            Request::Move {
3529                ref seat,
3530                ref serial,
3531            } => {
3532                format!("wl_shell_surface@{:?}::move(seat: {:?}, serial: {:?})", this, seat, serial)
3533            }
3534            Request::Resize {
3535                ref seat,
3536                ref serial,
3537                ref edges,
3538            } => {
3539                format!("wl_shell_surface@{:?}::resize(seat: {:?}, serial: {:?}, edges: {:?})", this, seat, serial, edges)
3540            }
3541            Request::SetToplevel {
3542            } => {
3543                format!("wl_shell_surface@{:?}::set_toplevel()", this)
3544            }
3545            Request::SetTransient {
3546                ref parent,
3547                ref x,
3548                ref y,
3549                ref flags,
3550            } => {
3551                format!("wl_shell_surface@{:?}::set_transient(parent: {:?}, x: {:?}, y: {:?}, flags: {:?})", this, parent, x, y, flags)
3552            }
3553            Request::SetFullscreen {
3554                ref method,
3555                ref framerate,
3556                ref output,
3557            } => {
3558                format!("wl_shell_surface@{:?}::set_fullscreen(method: {:?}, framerate: {:?}, output: {:?})", this, method, framerate, output)
3559            }
3560            Request::SetPopup {
3561                ref seat,
3562                ref serial,
3563                ref parent,
3564                ref x,
3565                ref y,
3566                ref flags,
3567            } => {
3568                format!("wl_shell_surface@{:?}::set_popup(seat: {:?}, serial: {:?}, parent: {:?}, x: {:?}, y: {:?}, flags: {:?})", this, seat, serial, parent, x, y, flags)
3569            }
3570            Request::SetMaximized {
3571                ref output,
3572            } => {
3573                format!("wl_shell_surface@{:?}::set_maximized(output: {:?})", this, output)
3574            }
3575            Request::SetTitle {
3576                ref title,
3577            } => {
3578                format!("wl_shell_surface@{:?}::set_title(title: {:?})", this, title)
3579            }
3580            Request::SetClass {
3581                ref class_,
3582            } => {
3583                format!("wl_shell_surface@{:?}::set_class(class_: {:?})", this, class_)
3584            }
3585        }
3586    }
3587    fn message_name(&self) -> &'static std::ffi::CStr{
3588        match *self {
3589            Request::Pong { .. } => c"wl_shell_surface::pong",
3590            Request::Move { .. } => c"wl_shell_surface::move",
3591            Request::Resize { .. } => c"wl_shell_surface::resize",
3592            Request::SetToplevel { .. } => c"wl_shell_surface::set_toplevel",
3593            Request::SetTransient { .. } => c"wl_shell_surface::set_transient",
3594            Request::SetFullscreen { .. } => c"wl_shell_surface::set_fullscreen",
3595            Request::SetPopup { .. } => c"wl_shell_surface::set_popup",
3596            Request::SetMaximized { .. } => c"wl_shell_surface::set_maximized",
3597            Request::SetTitle { .. } => c"wl_shell_surface::set_title",
3598            Request::SetClass { .. } => c"wl_shell_surface::set_class",
3599        }
3600    }
3601}
3602#[derive(Debug)]
3603pub enum Event {
3604
3605    /// ping client
3606    ///
3607    /// Ping a client to check if it is receiving events and sending
3608    /// requests. A client is expected to reply with a pong request.
3609    Ping {
3610        /// serial number of the ping
3611        serial: u32,
3612    },
3613
3614    /// suggest resize
3615    ///
3616    /// The configure event asks the client to resize its surface.
3617    /// 
3618    /// The size is a hint, in the sense that the client is free to
3619    /// ignore it if it doesn't resize, pick a smaller size (to
3620    /// satisfy aspect ratio or resize in steps of NxM pixels).
3621    /// 
3622    /// The edges parameter provides a hint about how the surface
3623    /// was resized. The client may use this information to decide
3624    /// how to adjust its content to the new size (e.g. a scrolling
3625    /// area might adjust its content position to leave the viewable
3626    /// content unmoved).
3627    /// 
3628    /// The client is free to dismiss all but the last configure
3629    /// event it received.
3630    /// 
3631    /// The width and height arguments specify the size of the window
3632    /// in surface-local coordinates.
3633    Configure {
3634        /// how the surface was resized
3635        edges: Enum<Resize>,
3636        /// new width of the surface
3637        width: i32,
3638        /// new height of the surface
3639        height: i32,
3640    },
3641
3642    /// popup interaction is done
3643    ///
3644    /// The popup_done event is sent out when a popup grab is broken,
3645    /// that is, when the user clicks a surface that doesn't belong
3646    /// to the client owning the popup surface.
3647    PopupDone,
3648}
3649
3650impl MessageType for Event {
3651    fn log(&self, this: ObjectId) -> String {
3652        match *self {
3653            Event::Ping {
3654                ref serial,
3655            } => {
3656                format!("wl_shell_surface@{:?}::ping(serial: {:?})", this, serial)
3657            }
3658            Event::Configure {
3659                ref edges,
3660                ref width,
3661                ref height,
3662            } => {
3663                format!("wl_shell_surface@{:?}::configure(edges: {:?}, width: {:?}, height: {:?})", this, edges, width, height)
3664            }
3665            Event::PopupDone {
3666            } => {
3667                format!("wl_shell_surface@{:?}::popup_done()", this)
3668            }
3669        }
3670    }
3671    fn message_name(&self) -> &'static std::ffi::CStr{
3672        match *self {
3673            Event::Ping { .. } => c"wl_shell_surface::ping",
3674            Event::Configure { .. } => c"wl_shell_surface::configure",
3675            Event::PopupDone { .. } => c"wl_shell_surface::popup_done",
3676        }
3677    }
3678}
3679impl IntoMessage for Request {
3680    type Error = EncodeError;
3681    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
3682        let mut header = MessageHeader {
3683            sender: id,
3684            opcode: 0,
3685            length: 0,
3686        };
3687        let mut msg = Message::new();
3688        msg.write_header(&header)?;
3689        match self {
3690        Request::Pong {
3691            serial,
3692        } => {
3693            msg.write_arg(Arg::Uint(serial))?;
3694            header.opcode = 0;
3695        },
3696        Request::Move {
3697            seat,
3698            serial,
3699        } => {
3700            msg.write_arg(Arg::Object(seat))?;
3701            msg.write_arg(Arg::Uint(serial))?;
3702            header.opcode = 1;
3703        },
3704        Request::Resize {
3705            seat,
3706            serial,
3707            edges,
3708        } => {
3709            msg.write_arg(Arg::Object(seat))?;
3710            msg.write_arg(Arg::Uint(serial))?;
3711            msg.write_arg(Arg::Uint(edges.bits()))?;
3712            header.opcode = 2;
3713        },
3714        Request::SetToplevel {
3715        } => {
3716            header.opcode = 3;
3717        },
3718        Request::SetTransient {
3719            parent,
3720            x,
3721            y,
3722            flags,
3723        } => {
3724            msg.write_arg(Arg::Object(parent))?;
3725            msg.write_arg(Arg::Int(x))?;
3726            msg.write_arg(Arg::Int(y))?;
3727            msg.write_arg(Arg::Uint(flags.bits()))?;
3728            header.opcode = 4;
3729        },
3730        Request::SetFullscreen {
3731            method,
3732            framerate,
3733            output,
3734        } => {
3735            msg.write_arg(Arg::Uint(method.bits()))?;
3736            msg.write_arg(Arg::Uint(framerate))?;
3737            msg.write_arg(Arg::Object(output))?;
3738            header.opcode = 5;
3739        },
3740        Request::SetPopup {
3741            seat,
3742            serial,
3743            parent,
3744            x,
3745            y,
3746            flags,
3747        } => {
3748            msg.write_arg(Arg::Object(seat))?;
3749            msg.write_arg(Arg::Uint(serial))?;
3750            msg.write_arg(Arg::Object(parent))?;
3751            msg.write_arg(Arg::Int(x))?;
3752            msg.write_arg(Arg::Int(y))?;
3753            msg.write_arg(Arg::Uint(flags.bits()))?;
3754            header.opcode = 6;
3755        },
3756        Request::SetMaximized {
3757            output,
3758        } => {
3759            msg.write_arg(Arg::Object(output))?;
3760            header.opcode = 7;
3761        },
3762        Request::SetTitle {
3763            title,
3764        } => {
3765            msg.write_arg(Arg::String(title))?;
3766            header.opcode = 8;
3767        },
3768        Request::SetClass {
3769            class_,
3770        } => {
3771            msg.write_arg(Arg::String(class_))?;
3772            header.opcode = 9;
3773        },
3774        }
3775        header.length = msg.bytes().len() as u16;
3776        msg.rewind();
3777        msg.write_header(&header)?;
3778        Ok(msg)
3779    }
3780}
3781impl FromArgs for Event {
3782    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
3783        match op {
3784        0 /* ping */ => {
3785            let mut iter = args.into_iter();
3786            Ok(Event::Ping {
3787                serial: iter.next()
3788                                             .ok_or(DecodeError::InsufficientArgs)?
3789                                             .as_uint()?,
3790
3791            })
3792        },
3793        1 /* configure */ => {
3794            let mut iter = args.into_iter();
3795            Ok(Event::Configure {
3796                edges: iter.next()
3797                                             .ok_or(DecodeError::InsufficientArgs)?
3798                                             .as_uint().map(|i| match Resize::from_bits(i) {
3799                                      Some(e) => Enum::Recognized(e),
3800                                      None => Enum::Unrecognized(i),
3801                                 })?,
3802                width: iter.next()
3803                                             .ok_or(DecodeError::InsufficientArgs)?
3804                                             .as_int()?,
3805                height: iter.next()
3806                                             .ok_or(DecodeError::InsufficientArgs)?
3807                                             .as_int()?,
3808
3809            })
3810        },
3811        2 /* popup_done */ => {
3812            let mut iter = args.into_iter();
3813            Ok(Event::PopupDone {
3814
3815            })
3816        },
3817        _ => {
3818            Err(DecodeError::InvalidOpcode(op).into())
3819        },
3820        }
3821    }
3822}
3823::bitflags::bitflags! {
3824
3825    /// edge values for resizing
3826    ///
3827    /// These values are used to indicate which edge of a surface
3828    /// is being dragged in a resize operation. The server may
3829    /// use this information to adapt its behavior, e.g. choose
3830    /// an appropriate cursor image.
3831    #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
3832    pub struct Resize: u32 {
3833        /// no edge,
3834        const None = 0;
3835        /// top edge,
3836        const Top = 1;
3837        /// bottom edge,
3838        const Bottom = 2;
3839        /// left edge,
3840        const Left = 4;
3841        /// top and left edges,
3842        const TopLeft = 5;
3843        /// bottom and left edges,
3844        const BottomLeft = 6;
3845        /// right edge,
3846        const Right = 8;
3847        /// top and right edges,
3848        const TopRight = 9;
3849        /// bottom and right edges,
3850        const BottomRight = 10;
3851    }
3852}
3853impl Into<Arg> for Resize {
3854    fn into(self) -> Arg {
3855        Arg::Uint(self.bits())
3856    }
3857}
3858::bitflags::bitflags! {
3859
3860    /// details of transient behaviour
3861    ///
3862    /// These flags specify details of the expected behaviour
3863    /// of transient surfaces. Used in the set_transient request.
3864    #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
3865    pub struct Transient: u32 {
3866        /// do not set keyboard focus,
3867        const Inactive = 1;
3868    }
3869}
3870impl Into<Arg> for Transient {
3871    fn into(self) -> Arg {
3872        Arg::Uint(self.bits())
3873    }
3874}
3875
3876/// different method to set the surface fullscreen
3877///
3878/// Hints to indicate to the compositor how to deal with a conflict
3879/// between the dimensions of the surface and the dimensions of the
3880/// output. The compositor is free to ignore this parameter.
3881#[derive(Copy, Clone, Debug, Eq, PartialEq)]
3882#[repr(u32)]
3883pub enum FullscreenMethod {
3884    /// no preference, apply default policy,
3885    Default = 0,
3886    /// scale, preserve the surface's aspect ratio and center on output,
3887    Scale = 1,
3888    /// switch output mode to the smallest mode that can fit the surface, add black borders to compensate size mismatch,
3889    Driver = 2,
3890    /// no upscaling, center on output and add black borders to compensate size mismatch,
3891    Fill = 3,
3892}
3893
3894impl FullscreenMethod {
3895    pub fn from_bits(v: u32) -> Option<Self> {
3896        match v {
3897        0 => Some(FullscreenMethod::Default),
3898        1 => Some(FullscreenMethod::Scale),
3899        2 => Some(FullscreenMethod::Driver),
3900        3 => Some(FullscreenMethod::Fill),
3901        _ => None,
3902        }
3903    }
3904
3905    pub fn bits(&self) -> u32 {
3906        *self as u32
3907    }
3908}
3909impl Into<Arg> for FullscreenMethod {
3910    fn into(self) -> Arg {
3911        Arg::Uint(self.bits())
3912    }
3913}
3914} // mod wl_shell_surface
3915
3916pub use crate::wl_shell_surface::WlShellSurface;
3917pub use crate::wl_shell_surface::Request as WlShellSurfaceRequest;
3918pub use crate::wl_shell_surface::Event as WlShellSurfaceEvent;
3919pub mod wl_surface {
3920use super::*;
3921
3922/// an onscreen surface
3923///
3924/// A surface is a rectangular area that may be displayed on zero
3925/// or more outputs, and shown any number of times at the compositor's
3926/// discretion. They can present wl_buffers, receive user input, and
3927/// define a local coordinate system.
3928/// 
3929/// The size of a surface (and relative positions on it) is described
3930/// in surface-local coordinates, which may differ from the buffer
3931/// coordinates of the pixel content, in case a buffer_transform
3932/// or a buffer_scale is used.
3933/// 
3934/// A surface without a "role" is fairly useless: a compositor does
3935/// not know where, when or how to present it. The role is the
3936/// purpose of a wl_surface. Examples of roles are a cursor for a
3937/// pointer (as set by wl_pointer.set_cursor), a drag icon
3938/// (wl_data_device.start_drag), a sub-surface
3939/// (wl_subcompositor.get_subsurface), and a window as defined by a
3940/// shell protocol (e.g. wl_shell.get_shell_surface).
3941/// 
3942/// A surface can have only one role at a time. Initially a
3943/// wl_surface does not have a role. Once a wl_surface is given a
3944/// role, it is set permanently for the whole lifetime of the
3945/// wl_surface object. Giving the current role again is allowed,
3946/// unless explicitly forbidden by the relevant interface
3947/// specification.
3948/// 
3949/// Surface roles are given by requests in other interfaces such as
3950/// wl_pointer.set_cursor. The request should explicitly mention
3951/// that this request gives a role to a wl_surface. Often, this
3952/// request also creates a new protocol object that represents the
3953/// role and adds additional functionality to wl_surface. When a
3954/// client wants to destroy a wl_surface, they must destroy this 'role
3955/// object' before the wl_surface.
3956/// 
3957/// Destroying the role object does not remove the role from the
3958/// wl_surface, but it may stop the wl_surface from "playing the role".
3959/// For instance, if a wl_subsurface object is destroyed, the wl_surface
3960/// it was created for will be unmapped and forget its position and
3961/// z-order. It is allowed to create a wl_subsurface for the same
3962/// wl_surface again, but it is not allowed to use the wl_surface as
3963/// a cursor (cursor is a different role than sub-surface, and role
3964/// switching is not allowed).
3965#[derive(Debug)]
3966pub struct WlSurface;
3967
3968impl Interface for WlSurface {
3969    const NAME: &'static str = "wl_surface";
3970    const VERSION: u32 = 4;
3971    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
3972        // destroy
3973        MessageSpec(&[
3974        ]),
3975        // attach
3976        MessageSpec(&[
3977            ArgKind::Object,
3978            ArgKind::Int,
3979            ArgKind::Int,
3980        ]),
3981        // damage
3982        MessageSpec(&[
3983            ArgKind::Int,
3984            ArgKind::Int,
3985            ArgKind::Int,
3986            ArgKind::Int,
3987        ]),
3988        // frame
3989        MessageSpec(&[
3990            ArgKind::NewId,
3991        ]),
3992        // set_opaque_region
3993        MessageSpec(&[
3994            ArgKind::Object,
3995        ]),
3996        // set_input_region
3997        MessageSpec(&[
3998            ArgKind::Object,
3999        ]),
4000        // commit
4001        MessageSpec(&[
4002        ]),
4003        // set_buffer_transform
4004        MessageSpec(&[
4005            ArgKind::Uint,
4006        ]),
4007        // set_buffer_scale
4008        MessageSpec(&[
4009            ArgKind::Int,
4010        ]),
4011        // damage_buffer
4012        MessageSpec(&[
4013            ArgKind::Int,
4014            ArgKind::Int,
4015            ArgKind::Int,
4016            ArgKind::Int,
4017        ]),
4018    ]);
4019    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
4020        // enter
4021        MessageSpec(&[
4022            ArgKind::Object,
4023        ]),
4024        // leave
4025        MessageSpec(&[
4026            ArgKind::Object,
4027        ]),
4028    ]);
4029    type Incoming = Event;
4030    type Outgoing = Request;
4031}
4032
4033#[derive(Debug)]
4034pub enum Request {
4035
4036    /// delete surface
4037    ///
4038    /// Deletes the surface and invalidates its object ID.
4039    Destroy,
4040
4041    /// set the surface contents
4042    ///
4043    /// Set a buffer as the content of this surface.
4044    /// 
4045    /// The new size of the surface is calculated based on the buffer
4046    /// size transformed by the inverse buffer_transform and the
4047    /// inverse buffer_scale. This means that at commit time the supplied
4048    /// buffer size must be an integer multiple of the buffer_scale. If
4049    /// that's not the case, an invalid_size error is sent.
4050    /// 
4051    /// The x and y arguments specify the location of the new pending
4052    /// buffer's upper left corner, relative to the current buffer's upper
4053    /// left corner, in surface-local coordinates. In other words, the
4054    /// x and y, combined with the new surface size define in which
4055    /// directions the surface's size changes.
4056    /// 
4057    /// Surface contents are double-buffered state, see wl_surface.commit.
4058    /// 
4059    /// The initial surface contents are void; there is no content.
4060    /// wl_surface.attach assigns the given wl_buffer as the pending
4061    /// wl_buffer. wl_surface.commit makes the pending wl_buffer the new
4062    /// surface contents, and the size of the surface becomes the size
4063    /// calculated from the wl_buffer, as described above. After commit,
4064    /// there is no pending buffer until the next attach.
4065    /// 
4066    /// Committing a pending wl_buffer allows the compositor to read the
4067    /// pixels in the wl_buffer. The compositor may access the pixels at
4068    /// any time after the wl_surface.commit request. When the compositor
4069    /// will not access the pixels anymore, it will send the
4070    /// wl_buffer.release event. Only after receiving wl_buffer.release,
4071    /// the client may reuse the wl_buffer. A wl_buffer that has been
4072    /// attached and then replaced by another attach instead of committed
4073    /// will not receive a release event, and is not used by the
4074    /// compositor.
4075    /// 
4076    /// If a pending wl_buffer has been committed to more than one wl_surface,
4077    /// the delivery of wl_buffer.release events becomes undefined. A well
4078    /// behaved client should not rely on wl_buffer.release events in this
4079    /// case. Alternatively, a client could create multiple wl_buffer objects
4080    /// from the same backing storage or use wp_linux_buffer_release.
4081    /// 
4082    /// Destroying the wl_buffer after wl_buffer.release does not change
4083    /// the surface contents. However, if the client destroys the
4084    /// wl_buffer before receiving the wl_buffer.release event, the surface
4085    /// contents become undefined immediately.
4086    /// 
4087    /// If wl_surface.attach is sent with a NULL wl_buffer, the
4088    /// following wl_surface.commit will remove the surface content.
4089    Attach {
4090        /// buffer of surface contents
4091        buffer: ObjectId,
4092        /// surface-local x coordinate
4093        x: i32,
4094        /// surface-local y coordinate
4095        y: i32,
4096    },
4097
4098    /// mark part of the surface damaged
4099    ///
4100    /// This request is used to describe the regions where the pending
4101    /// buffer is different from the current surface contents, and where
4102    /// the surface therefore needs to be repainted. The compositor
4103    /// ignores the parts of the damage that fall outside of the surface.
4104    /// 
4105    /// Damage is double-buffered state, see wl_surface.commit.
4106    /// 
4107    /// The damage rectangle is specified in surface-local coordinates,
4108    /// where x and y specify the upper left corner of the damage rectangle.
4109    /// 
4110    /// The initial value for pending damage is empty: no damage.
4111    /// wl_surface.damage adds pending damage: the new pending damage
4112    /// is the union of old pending damage and the given rectangle.
4113    /// 
4114    /// wl_surface.commit assigns pending damage as the current damage,
4115    /// and clears pending damage. The server will clear the current
4116    /// damage as it repaints the surface.
4117    /// 
4118    /// Note! New clients should not use this request. Instead damage can be
4119    /// posted with wl_surface.damage_buffer which uses buffer coordinates
4120    /// instead of surface coordinates.
4121    Damage {
4122        /// surface-local x coordinate
4123        x: i32,
4124        /// surface-local y coordinate
4125        y: i32,
4126        /// width of damage rectangle
4127        width: i32,
4128        /// height of damage rectangle
4129        height: i32,
4130    },
4131
4132    /// request a frame throttling hint
4133    ///
4134    /// Request a notification when it is a good time to start drawing a new
4135    /// frame, by creating a frame callback. This is useful for throttling
4136    /// redrawing operations, and driving animations.
4137    /// 
4138    /// When a client is animating on a wl_surface, it can use the 'frame'
4139    /// request to get notified when it is a good time to draw and commit the
4140    /// next frame of animation. If the client commits an update earlier than
4141    /// that, it is likely that some updates will not make it to the display,
4142    /// and the client is wasting resources by drawing too often.
4143    /// 
4144    /// The frame request will take effect on the next wl_surface.commit.
4145    /// The notification will only be posted for one frame unless
4146    /// requested again. For a wl_surface, the notifications are posted in
4147    /// the order the frame requests were committed.
4148    /// 
4149    /// The server must send the notifications so that a client
4150    /// will not send excessive updates, while still allowing
4151    /// the highest possible update rate for clients that wait for the reply
4152    /// before drawing again. The server should give some time for the client
4153    /// to draw and commit after sending the frame callback events to let it
4154    /// hit the next output refresh.
4155    /// 
4156    /// A server should avoid signaling the frame callbacks if the
4157    /// surface is not visible in any way, e.g. the surface is off-screen,
4158    /// or completely obscured by other opaque surfaces.
4159    /// 
4160    /// The object returned by this request will be destroyed by the
4161    /// compositor after the callback is fired and as such the client must not
4162    /// attempt to use it after that point.
4163    /// 
4164    /// The callback_data passed in the callback is the current time, in
4165    /// milliseconds, with an undefined base.
4166    Frame {
4167        /// callback object for the frame request
4168        callback: NewId,
4169    },
4170
4171    /// set opaque region
4172    ///
4173    /// This request sets the region of the surface that contains
4174    /// opaque content.
4175    /// 
4176    /// The opaque region is an optimization hint for the compositor
4177    /// that lets it optimize the redrawing of content behind opaque
4178    /// regions.  Setting an opaque region is not required for correct
4179    /// behaviour, but marking transparent content as opaque will result
4180    /// in repaint artifacts.
4181    /// 
4182    /// The opaque region is specified in surface-local coordinates.
4183    /// 
4184    /// The compositor ignores the parts of the opaque region that fall
4185    /// outside of the surface.
4186    /// 
4187    /// Opaque region is double-buffered state, see wl_surface.commit.
4188    /// 
4189    /// wl_surface.set_opaque_region changes the pending opaque region.
4190    /// wl_surface.commit copies the pending region to the current region.
4191    /// Otherwise, the pending and current regions are never changed.
4192    /// 
4193    /// The initial value for an opaque region is empty. Setting the pending
4194    /// opaque region has copy semantics, and the wl_region object can be
4195    /// destroyed immediately. A NULL wl_region causes the pending opaque
4196    /// region to be set to empty.
4197    SetOpaqueRegion {
4198        /// opaque region of the surface
4199        region: ObjectId,
4200    },
4201
4202    /// set input region
4203    ///
4204    /// This request sets the region of the surface that can receive
4205    /// pointer and touch events.
4206    /// 
4207    /// Input events happening outside of this region will try the next
4208    /// surface in the server surface stack. The compositor ignores the
4209    /// parts of the input region that fall outside of the surface.
4210    /// 
4211    /// The input region is specified in surface-local coordinates.
4212    /// 
4213    /// Input region is double-buffered state, see wl_surface.commit.
4214    /// 
4215    /// wl_surface.set_input_region changes the pending input region.
4216    /// wl_surface.commit copies the pending region to the current region.
4217    /// Otherwise the pending and current regions are never changed,
4218    /// except cursor and icon surfaces are special cases, see
4219    /// wl_pointer.set_cursor and wl_data_device.start_drag.
4220    /// 
4221    /// The initial value for an input region is infinite. That means the
4222    /// whole surface will accept input. Setting the pending input region
4223    /// has copy semantics, and the wl_region object can be destroyed
4224    /// immediately. A NULL wl_region causes the input region to be set
4225    /// to infinite.
4226    SetInputRegion {
4227        /// input region of the surface
4228        region: ObjectId,
4229    },
4230
4231    /// commit pending surface state
4232    ///
4233    /// Surface state (input, opaque, and damage regions, attached buffers,
4234    /// etc.) is double-buffered. Protocol requests modify the pending state,
4235    /// as opposed to the current state in use by the compositor. A commit
4236    /// request atomically applies all pending state, replacing the current
4237    /// state. After commit, the new pending state is as documented for each
4238    /// related request.
4239    /// 
4240    /// On commit, a pending wl_buffer is applied first, and all other state
4241    /// second. This means that all coordinates in double-buffered state are
4242    /// relative to the new wl_buffer coming into use, except for
4243    /// wl_surface.attach itself. If there is no pending wl_buffer, the
4244    /// coordinates are relative to the current surface contents.
4245    /// 
4246    /// All requests that need a commit to become effective are documented
4247    /// to affect double-buffered state.
4248    /// 
4249    /// Other interfaces may add further double-buffered surface state.
4250    Commit,
4251
4252    /// sets the buffer transformation
4253    ///
4254    /// This request sets an optional transformation on how the compositor
4255    /// interprets the contents of the buffer attached to the surface. The
4256    /// accepted values for the transform parameter are the values for
4257    /// wl_output.transform.
4258    /// 
4259    /// Buffer transform is double-buffered state, see wl_surface.commit.
4260    /// 
4261    /// A newly created surface has its buffer transformation set to normal.
4262    /// 
4263    /// wl_surface.set_buffer_transform changes the pending buffer
4264    /// transformation. wl_surface.commit copies the pending buffer
4265    /// transformation to the current one. Otherwise, the pending and current
4266    /// values are never changed.
4267    /// 
4268    /// The purpose of this request is to allow clients to render content
4269    /// according to the output transform, thus permitting the compositor to
4270    /// use certain optimizations even if the display is rotated. Using
4271    /// hardware overlays and scanning out a client buffer for fullscreen
4272    /// surfaces are examples of such optimizations. Those optimizations are
4273    /// highly dependent on the compositor implementation, so the use of this
4274    /// request should be considered on a case-by-case basis.
4275    /// 
4276    /// Note that if the transform value includes 90 or 270 degree rotation,
4277    /// the width of the buffer will become the surface height and the height
4278    /// of the buffer will become the surface width.
4279    /// 
4280    /// If transform is not one of the values from the
4281    /// wl_output.transform enum the invalid_transform protocol error
4282    /// is raised.
4283    SetBufferTransform {
4284        /// transform for interpreting buffer contents
4285        transform: crate::wl_output::Transform,
4286    },
4287
4288    /// sets the buffer scaling factor
4289    ///
4290    /// This request sets an optional scaling factor on how the compositor
4291    /// interprets the contents of the buffer attached to the window.
4292    /// 
4293    /// Buffer scale is double-buffered state, see wl_surface.commit.
4294    /// 
4295    /// A newly created surface has its buffer scale set to 1.
4296    /// 
4297    /// wl_surface.set_buffer_scale changes the pending buffer scale.
4298    /// wl_surface.commit copies the pending buffer scale to the current one.
4299    /// Otherwise, the pending and current values are never changed.
4300    /// 
4301    /// The purpose of this request is to allow clients to supply higher
4302    /// resolution buffer data for use on high resolution outputs. It is
4303    /// intended that you pick the same buffer scale as the scale of the
4304    /// output that the surface is displayed on. This means the compositor
4305    /// can avoid scaling when rendering the surface on that output.
4306    /// 
4307    /// Note that if the scale is larger than 1, then you have to attach
4308    /// a buffer that is larger (by a factor of scale in each dimension)
4309    /// than the desired surface size.
4310    /// 
4311    /// If scale is not positive the invalid_scale protocol error is
4312    /// raised.
4313    SetBufferScale {
4314        /// positive scale for interpreting buffer contents
4315        scale: i32,
4316    },
4317
4318    /// mark part of the surface damaged using buffer coordinates
4319    ///
4320    /// This request is used to describe the regions where the pending
4321    /// buffer is different from the current surface contents, and where
4322    /// the surface therefore needs to be repainted. The compositor
4323    /// ignores the parts of the damage that fall outside of the surface.
4324    /// 
4325    /// Damage is double-buffered state, see wl_surface.commit.
4326    /// 
4327    /// The damage rectangle is specified in buffer coordinates,
4328    /// where x and y specify the upper left corner of the damage rectangle.
4329    /// 
4330    /// The initial value for pending damage is empty: no damage.
4331    /// wl_surface.damage_buffer adds pending damage: the new pending
4332    /// damage is the union of old pending damage and the given rectangle.
4333    /// 
4334    /// wl_surface.commit assigns pending damage as the current damage,
4335    /// and clears pending damage. The server will clear the current
4336    /// damage as it repaints the surface.
4337    /// 
4338    /// This request differs from wl_surface.damage in only one way - it
4339    /// takes damage in buffer coordinates instead of surface-local
4340    /// coordinates. While this generally is more intuitive than surface
4341    /// coordinates, it is especially desirable when using wp_viewport
4342    /// or when a drawing library (like EGL) is unaware of buffer scale
4343    /// and buffer transform.
4344    /// 
4345    /// Note: Because buffer transformation changes and damage requests may
4346    /// be interleaved in the protocol stream, it is impossible to determine
4347    /// the actual mapping between surface and buffer damage until
4348    /// wl_surface.commit time. Therefore, compositors wishing to take both
4349    /// kinds of damage into account will have to accumulate damage from the
4350    /// two requests separately and only transform from one to the other
4351    /// after receiving the wl_surface.commit.
4352    DamageBuffer {
4353        /// buffer-local x coordinate
4354        x: i32,
4355        /// buffer-local y coordinate
4356        y: i32,
4357        /// width of damage rectangle
4358        width: i32,
4359        /// height of damage rectangle
4360        height: i32,
4361    },
4362}
4363
4364impl MessageType for Request {
4365    fn log(&self, this: ObjectId) -> String {
4366        match *self {
4367            Request::Destroy {
4368            } => {
4369                format!("wl_surface@{:?}::destroy()", this)
4370            }
4371            Request::Attach {
4372                ref buffer,
4373                ref x,
4374                ref y,
4375            } => {
4376                format!("wl_surface@{:?}::attach(buffer: {:?}, x: {:?}, y: {:?})", this, buffer, x, y)
4377            }
4378            Request::Damage {
4379                ref x,
4380                ref y,
4381                ref width,
4382                ref height,
4383            } => {
4384                format!("wl_surface@{:?}::damage(x: {:?}, y: {:?}, width: {:?}, height: {:?})", this, x, y, width, height)
4385            }
4386            Request::Frame {
4387                ref callback,
4388            } => {
4389                format!("wl_surface@{:?}::frame(callback: {:?})", this, callback)
4390            }
4391            Request::SetOpaqueRegion {
4392                ref region,
4393            } => {
4394                format!("wl_surface@{:?}::set_opaque_region(region: {:?})", this, region)
4395            }
4396            Request::SetInputRegion {
4397                ref region,
4398            } => {
4399                format!("wl_surface@{:?}::set_input_region(region: {:?})", this, region)
4400            }
4401            Request::Commit {
4402            } => {
4403                format!("wl_surface@{:?}::commit()", this)
4404            }
4405            Request::SetBufferTransform {
4406                ref transform,
4407            } => {
4408                format!("wl_surface@{:?}::set_buffer_transform(transform: {:?})", this, transform)
4409            }
4410            Request::SetBufferScale {
4411                ref scale,
4412            } => {
4413                format!("wl_surface@{:?}::set_buffer_scale(scale: {:?})", this, scale)
4414            }
4415            Request::DamageBuffer {
4416                ref x,
4417                ref y,
4418                ref width,
4419                ref height,
4420            } => {
4421                format!("wl_surface@{:?}::damage_buffer(x: {:?}, y: {:?}, width: {:?}, height: {:?})", this, x, y, width, height)
4422            }
4423        }
4424    }
4425    fn message_name(&self) -> &'static std::ffi::CStr{
4426        match *self {
4427            Request::Destroy { .. } => c"wl_surface::destroy",
4428            Request::Attach { .. } => c"wl_surface::attach",
4429            Request::Damage { .. } => c"wl_surface::damage",
4430            Request::Frame { .. } => c"wl_surface::frame",
4431            Request::SetOpaqueRegion { .. } => c"wl_surface::set_opaque_region",
4432            Request::SetInputRegion { .. } => c"wl_surface::set_input_region",
4433            Request::Commit { .. } => c"wl_surface::commit",
4434            Request::SetBufferTransform { .. } => c"wl_surface::set_buffer_transform",
4435            Request::SetBufferScale { .. } => c"wl_surface::set_buffer_scale",
4436            Request::DamageBuffer { .. } => c"wl_surface::damage_buffer",
4437        }
4438    }
4439}
4440#[derive(Debug)]
4441pub enum Event {
4442
4443    /// surface enters an output
4444    ///
4445    /// This is emitted whenever a surface's creation, movement, or resizing
4446    /// results in some part of it being within the scanout region of an
4447    /// output.
4448    /// 
4449    /// Note that a surface may be overlapping with zero or more outputs.
4450    Enter {
4451        /// output entered by the surface
4452        output: ObjectId,
4453    },
4454
4455    /// surface leaves an output
4456    ///
4457    /// This is emitted whenever a surface's creation, movement, or resizing
4458    /// results in it no longer having any part of it within the scanout region
4459    /// of an output.
4460    Leave {
4461        /// output left by the surface
4462        output: ObjectId,
4463    },
4464}
4465
4466impl MessageType for Event {
4467    fn log(&self, this: ObjectId) -> String {
4468        match *self {
4469            Event::Enter {
4470                ref output,
4471            } => {
4472                format!("wl_surface@{:?}::enter(output: {:?})", this, output)
4473            }
4474            Event::Leave {
4475                ref output,
4476            } => {
4477                format!("wl_surface@{:?}::leave(output: {:?})", this, output)
4478            }
4479        }
4480    }
4481    fn message_name(&self) -> &'static std::ffi::CStr{
4482        match *self {
4483            Event::Enter { .. } => c"wl_surface::enter",
4484            Event::Leave { .. } => c"wl_surface::leave",
4485        }
4486    }
4487}
4488impl IntoMessage for Request {
4489    type Error = EncodeError;
4490    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
4491        let mut header = MessageHeader {
4492            sender: id,
4493            opcode: 0,
4494            length: 0,
4495        };
4496        let mut msg = Message::new();
4497        msg.write_header(&header)?;
4498        match self {
4499        Request::Destroy {
4500        } => {
4501            header.opcode = 0;
4502        },
4503        Request::Attach {
4504            buffer,
4505            x,
4506            y,
4507        } => {
4508            msg.write_arg(Arg::Object(buffer))?;
4509            msg.write_arg(Arg::Int(x))?;
4510            msg.write_arg(Arg::Int(y))?;
4511            header.opcode = 1;
4512        },
4513        Request::Damage {
4514            x,
4515            y,
4516            width,
4517            height,
4518        } => {
4519            msg.write_arg(Arg::Int(x))?;
4520            msg.write_arg(Arg::Int(y))?;
4521            msg.write_arg(Arg::Int(width))?;
4522            msg.write_arg(Arg::Int(height))?;
4523            header.opcode = 2;
4524        },
4525        Request::Frame {
4526            callback,
4527        } => {
4528            msg.write_arg(Arg::NewId(callback))?;
4529            header.opcode = 3;
4530        },
4531        Request::SetOpaqueRegion {
4532            region,
4533        } => {
4534            msg.write_arg(Arg::Object(region))?;
4535            header.opcode = 4;
4536        },
4537        Request::SetInputRegion {
4538            region,
4539        } => {
4540            msg.write_arg(Arg::Object(region))?;
4541            header.opcode = 5;
4542        },
4543        Request::Commit {
4544        } => {
4545            header.opcode = 6;
4546        },
4547        Request::SetBufferTransform {
4548            transform,
4549        } => {
4550            msg.write_arg(Arg::Uint(transform.bits()))?;
4551            header.opcode = 7;
4552        },
4553        Request::SetBufferScale {
4554            scale,
4555        } => {
4556            msg.write_arg(Arg::Int(scale))?;
4557            header.opcode = 8;
4558        },
4559        Request::DamageBuffer {
4560            x,
4561            y,
4562            width,
4563            height,
4564        } => {
4565            msg.write_arg(Arg::Int(x))?;
4566            msg.write_arg(Arg::Int(y))?;
4567            msg.write_arg(Arg::Int(width))?;
4568            msg.write_arg(Arg::Int(height))?;
4569            header.opcode = 9;
4570        },
4571        }
4572        header.length = msg.bytes().len() as u16;
4573        msg.rewind();
4574        msg.write_header(&header)?;
4575        Ok(msg)
4576    }
4577}
4578impl FromArgs for Event {
4579    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
4580        match op {
4581        0 /* enter */ => {
4582            let mut iter = args.into_iter();
4583            Ok(Event::Enter {
4584                output: iter.next()
4585                                             .ok_or(DecodeError::InsufficientArgs)?
4586                                             .as_object()?,
4587
4588            })
4589        },
4590        1 /* leave */ => {
4591            let mut iter = args.into_iter();
4592            Ok(Event::Leave {
4593                output: iter.next()
4594                                             .ok_or(DecodeError::InsufficientArgs)?
4595                                             .as_object()?,
4596
4597            })
4598        },
4599        _ => {
4600            Err(DecodeError::InvalidOpcode(op).into())
4601        },
4602        }
4603    }
4604}
4605
4606/// wl_surface error values
4607///
4608/// These errors can be emitted in response to wl_surface requests.
4609#[derive(Copy, Clone, Debug, Eq, PartialEq)]
4610#[repr(u32)]
4611pub enum Error {
4612    /// buffer scale value is invalid,
4613    InvalidScale = 0,
4614    /// buffer transform value is invalid,
4615    InvalidTransform = 1,
4616    /// buffer size is invalid,
4617    InvalidSize = 2,
4618}
4619
4620impl Error {
4621    pub fn from_bits(v: u32) -> Option<Self> {
4622        match v {
4623        0 => Some(Error::InvalidScale),
4624        1 => Some(Error::InvalidTransform),
4625        2 => Some(Error::InvalidSize),
4626        _ => None,
4627        }
4628    }
4629
4630    pub fn bits(&self) -> u32 {
4631        *self as u32
4632    }
4633}
4634impl Into<Arg> for Error {
4635    fn into(self) -> Arg {
4636        Arg::Uint(self.bits())
4637    }
4638}
4639} // mod wl_surface
4640
4641pub use crate::wl_surface::WlSurface;
4642pub use crate::wl_surface::Request as WlSurfaceRequest;
4643pub use crate::wl_surface::Event as WlSurfaceEvent;
4644pub mod wl_seat {
4645use super::*;
4646
4647/// group of input devices
4648///
4649/// A seat is a group of keyboards, pointer and touch devices. This
4650/// object is published as a global during start up, or when such a
4651/// device is hot plugged.  A seat typically has a pointer and
4652/// maintains a keyboard focus and a pointer focus.
4653#[derive(Debug)]
4654pub struct WlSeat;
4655
4656impl Interface for WlSeat {
4657    const NAME: &'static str = "wl_seat";
4658    const VERSION: u32 = 7;
4659    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
4660        // get_pointer
4661        MessageSpec(&[
4662            ArgKind::NewId,
4663        ]),
4664        // get_keyboard
4665        MessageSpec(&[
4666            ArgKind::NewId,
4667        ]),
4668        // get_touch
4669        MessageSpec(&[
4670            ArgKind::NewId,
4671        ]),
4672        // release
4673        MessageSpec(&[
4674        ]),
4675    ]);
4676    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
4677        // capabilities
4678        MessageSpec(&[
4679            ArgKind::Uint,
4680        ]),
4681        // name
4682        MessageSpec(&[
4683            ArgKind::String,
4684        ]),
4685    ]);
4686    type Incoming = Event;
4687    type Outgoing = Request;
4688}
4689
4690#[derive(Debug)]
4691pub enum Request {
4692
4693    /// return pointer object
4694    ///
4695    /// The ID provided will be initialized to the wl_pointer interface
4696    /// for this seat.
4697    /// 
4698    /// This request only takes effect if the seat has the pointer
4699    /// capability, or has had the pointer capability in the past.
4700    /// It is a protocol violation to issue this request on a seat that has
4701    /// never had the pointer capability. The missing_capability error will
4702    /// be sent in this case.
4703    GetPointer {
4704        /// seat pointer
4705        id: NewId,
4706    },
4707
4708    /// return keyboard object
4709    ///
4710    /// The ID provided will be initialized to the wl_keyboard interface
4711    /// for this seat.
4712    /// 
4713    /// This request only takes effect if the seat has the keyboard
4714    /// capability, or has had the keyboard capability in the past.
4715    /// It is a protocol violation to issue this request on a seat that has
4716    /// never had the keyboard capability. The missing_capability error will
4717    /// be sent in this case.
4718    GetKeyboard {
4719        /// seat keyboard
4720        id: NewId,
4721    },
4722
4723    /// return touch object
4724    ///
4725    /// The ID provided will be initialized to the wl_touch interface
4726    /// for this seat.
4727    /// 
4728    /// This request only takes effect if the seat has the touch
4729    /// capability, or has had the touch capability in the past.
4730    /// It is a protocol violation to issue this request on a seat that has
4731    /// never had the touch capability. The missing_capability error will
4732    /// be sent in this case.
4733    GetTouch {
4734        /// seat touch interface
4735        id: NewId,
4736    },
4737
4738    /// release the seat object
4739    ///
4740    /// Using this request a client can tell the server that it is not going to
4741    /// use the seat object anymore.
4742    Release,
4743}
4744
4745impl MessageType for Request {
4746    fn log(&self, this: ObjectId) -> String {
4747        match *self {
4748            Request::GetPointer {
4749                ref id,
4750            } => {
4751                format!("wl_seat@{:?}::get_pointer(id: {:?})", this, id)
4752            }
4753            Request::GetKeyboard {
4754                ref id,
4755            } => {
4756                format!("wl_seat@{:?}::get_keyboard(id: {:?})", this, id)
4757            }
4758            Request::GetTouch {
4759                ref id,
4760            } => {
4761                format!("wl_seat@{:?}::get_touch(id: {:?})", this, id)
4762            }
4763            Request::Release {
4764            } => {
4765                format!("wl_seat@{:?}::release()", this)
4766            }
4767        }
4768    }
4769    fn message_name(&self) -> &'static std::ffi::CStr{
4770        match *self {
4771            Request::GetPointer { .. } => c"wl_seat::get_pointer",
4772            Request::GetKeyboard { .. } => c"wl_seat::get_keyboard",
4773            Request::GetTouch { .. } => c"wl_seat::get_touch",
4774            Request::Release { .. } => c"wl_seat::release",
4775        }
4776    }
4777}
4778#[derive(Debug)]
4779pub enum Event {
4780
4781    /// seat capabilities changed
4782    ///
4783    /// This is emitted whenever a seat gains or loses the pointer,
4784    /// keyboard or touch capabilities.  The argument is a capability
4785    /// enum containing the complete set of capabilities this seat has.
4786    /// 
4787    /// When the pointer capability is added, a client may create a
4788    /// wl_pointer object using the wl_seat.get_pointer request. This object
4789    /// will receive pointer events until the capability is removed in the
4790    /// future.
4791    /// 
4792    /// When the pointer capability is removed, a client should destroy the
4793    /// wl_pointer objects associated with the seat where the capability was
4794    /// removed, using the wl_pointer.release request. No further pointer
4795    /// events will be received on these objects.
4796    /// 
4797    /// In some compositors, if a seat regains the pointer capability and a
4798    /// client has a previously obtained wl_pointer object of version 4 or
4799    /// less, that object may start sending pointer events again. This
4800    /// behavior is considered a misinterpretation of the intended behavior
4801    /// and must not be relied upon by the client. wl_pointer objects of
4802    /// version 5 or later must not send events if created before the most
4803    /// recent event notifying the client of an added pointer capability.
4804    /// 
4805    /// The above behavior also applies to wl_keyboard and wl_touch with the
4806    /// keyboard and touch capabilities, respectively.
4807    Capabilities {
4808        /// capabilities of the seat
4809        capabilities: Enum<Capability>,
4810    },
4811
4812    /// unique identifier for this seat
4813    ///
4814    /// In a multiseat configuration this can be used by the client to help
4815    /// identify which physical devices the seat represents. Based on
4816    /// the seat configuration used by the compositor.
4817    Name {
4818        /// seat identifier
4819        name: String,
4820    },
4821}
4822
4823impl MessageType for Event {
4824    fn log(&self, this: ObjectId) -> String {
4825        match *self {
4826            Event::Capabilities {
4827                ref capabilities,
4828            } => {
4829                format!("wl_seat@{:?}::capabilities(capabilities: {:?})", this, capabilities)
4830            }
4831            Event::Name {
4832                ref name,
4833            } => {
4834                format!("wl_seat@{:?}::name(name: {:?})", this, name)
4835            }
4836        }
4837    }
4838    fn message_name(&self) -> &'static std::ffi::CStr{
4839        match *self {
4840            Event::Capabilities { .. } => c"wl_seat::capabilities",
4841            Event::Name { .. } => c"wl_seat::name",
4842        }
4843    }
4844}
4845impl IntoMessage for Request {
4846    type Error = EncodeError;
4847    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
4848        let mut header = MessageHeader {
4849            sender: id,
4850            opcode: 0,
4851            length: 0,
4852        };
4853        let mut msg = Message::new();
4854        msg.write_header(&header)?;
4855        match self {
4856        Request::GetPointer {
4857            id,
4858        } => {
4859            msg.write_arg(Arg::NewId(id))?;
4860            header.opcode = 0;
4861        },
4862        Request::GetKeyboard {
4863            id,
4864        } => {
4865            msg.write_arg(Arg::NewId(id))?;
4866            header.opcode = 1;
4867        },
4868        Request::GetTouch {
4869            id,
4870        } => {
4871            msg.write_arg(Arg::NewId(id))?;
4872            header.opcode = 2;
4873        },
4874        Request::Release {
4875        } => {
4876            header.opcode = 3;
4877        },
4878        }
4879        header.length = msg.bytes().len() as u16;
4880        msg.rewind();
4881        msg.write_header(&header)?;
4882        Ok(msg)
4883    }
4884}
4885impl FromArgs for Event {
4886    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
4887        match op {
4888        0 /* capabilities */ => {
4889            let mut iter = args.into_iter();
4890            Ok(Event::Capabilities {
4891                capabilities: iter.next()
4892                                             .ok_or(DecodeError::InsufficientArgs)?
4893                                             .as_uint().map(|i| match Capability::from_bits(i) {
4894                                      Some(e) => Enum::Recognized(e),
4895                                      None => Enum::Unrecognized(i),
4896                                 })?,
4897
4898            })
4899        },
4900        1 /* name */ => {
4901            let mut iter = args.into_iter();
4902            Ok(Event::Name {
4903                name: iter.next()
4904                                             .ok_or(DecodeError::InsufficientArgs)?
4905                                             .as_string()?,
4906
4907            })
4908        },
4909        _ => {
4910            Err(DecodeError::InvalidOpcode(op).into())
4911        },
4912        }
4913    }
4914}
4915::bitflags::bitflags! {
4916
4917    /// seat capability bitmask
4918    ///
4919    /// This is a bitmask of capabilities this seat has; if a member is
4920    /// set, then it is present on the seat.
4921    #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
4922    pub struct Capability: u32 {
4923        /// the seat has pointer devices,
4924        const Pointer = 1;
4925        /// the seat has one or more keyboards,
4926        const Keyboard = 2;
4927        /// the seat has touch devices,
4928        const Touch = 4;
4929    }
4930}
4931impl Into<Arg> for Capability {
4932    fn into(self) -> Arg {
4933        Arg::Uint(self.bits())
4934    }
4935}
4936
4937/// wl_seat error values
4938///
4939/// These errors can be emitted in response to wl_seat requests.
4940#[derive(Copy, Clone, Debug, Eq, PartialEq)]
4941#[repr(u32)]
4942pub enum Error {
4943    /// get_pointer, get_keyboard or get_touch called on seat without the matching capability,
4944    MissingCapability = 0,
4945}
4946
4947impl Error {
4948    pub fn from_bits(v: u32) -> Option<Self> {
4949        match v {
4950        0 => Some(Error::MissingCapability),
4951        _ => None,
4952        }
4953    }
4954
4955    pub fn bits(&self) -> u32 {
4956        *self as u32
4957    }
4958}
4959impl Into<Arg> for Error {
4960    fn into(self) -> Arg {
4961        Arg::Uint(self.bits())
4962    }
4963}
4964} // mod wl_seat
4965
4966pub use crate::wl_seat::WlSeat;
4967pub use crate::wl_seat::Request as WlSeatRequest;
4968pub use crate::wl_seat::Event as WlSeatEvent;
4969pub mod wl_pointer {
4970use super::*;
4971
4972/// pointer input device
4973///
4974/// The wl_pointer interface represents one or more input devices,
4975/// such as mice, which control the pointer location and pointer_focus
4976/// of a seat.
4977/// 
4978/// The wl_pointer interface generates motion, enter and leave
4979/// events for the surfaces that the pointer is located over,
4980/// and button and axis events for button presses, button releases
4981/// and scrolling.
4982#[derive(Debug)]
4983pub struct WlPointer;
4984
4985impl Interface for WlPointer {
4986    const NAME: &'static str = "wl_pointer";
4987    const VERSION: u32 = 7;
4988    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
4989        // set_cursor
4990        MessageSpec(&[
4991            ArgKind::Uint,
4992            ArgKind::Object,
4993            ArgKind::Int,
4994            ArgKind::Int,
4995        ]),
4996        // release
4997        MessageSpec(&[
4998        ]),
4999    ]);
5000    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
5001        // enter
5002        MessageSpec(&[
5003            ArgKind::Uint,
5004            ArgKind::Object,
5005            ArgKind::Fixed,
5006            ArgKind::Fixed,
5007        ]),
5008        // leave
5009        MessageSpec(&[
5010            ArgKind::Uint,
5011            ArgKind::Object,
5012        ]),
5013        // motion
5014        MessageSpec(&[
5015            ArgKind::Uint,
5016            ArgKind::Fixed,
5017            ArgKind::Fixed,
5018        ]),
5019        // button
5020        MessageSpec(&[
5021            ArgKind::Uint,
5022            ArgKind::Uint,
5023            ArgKind::Uint,
5024            ArgKind::Uint,
5025        ]),
5026        // axis
5027        MessageSpec(&[
5028            ArgKind::Uint,
5029            ArgKind::Uint,
5030            ArgKind::Fixed,
5031        ]),
5032        // frame
5033        MessageSpec(&[
5034        ]),
5035        // axis_source
5036        MessageSpec(&[
5037            ArgKind::Uint,
5038        ]),
5039        // axis_stop
5040        MessageSpec(&[
5041            ArgKind::Uint,
5042            ArgKind::Uint,
5043        ]),
5044        // axis_discrete
5045        MessageSpec(&[
5046            ArgKind::Uint,
5047            ArgKind::Int,
5048        ]),
5049    ]);
5050    type Incoming = Event;
5051    type Outgoing = Request;
5052}
5053
5054#[derive(Debug)]
5055pub enum Request {
5056
5057    /// set the pointer surface
5058    ///
5059    /// Set the pointer surface, i.e., the surface that contains the
5060    /// pointer image (cursor). This request gives the surface the role
5061    /// of a cursor. If the surface already has another role, it raises
5062    /// a protocol error.
5063    /// 
5064    /// The cursor actually changes only if the pointer
5065    /// focus for this device is one of the requesting client's surfaces
5066    /// or the surface parameter is the current pointer surface. If
5067    /// there was a previous surface set with this request it is
5068    /// replaced. If surface is NULL, the pointer image is hidden.
5069    /// 
5070    /// The parameters hotspot_x and hotspot_y define the position of
5071    /// the pointer surface relative to the pointer location. Its
5072    /// top-left corner is always at (x, y) - (hotspot_x, hotspot_y),
5073    /// where (x, y) are the coordinates of the pointer location, in
5074    /// surface-local coordinates.
5075    /// 
5076    /// On surface.attach requests to the pointer surface, hotspot_x
5077    /// and hotspot_y are decremented by the x and y parameters
5078    /// passed to the request. Attach must be confirmed by
5079    /// wl_surface.commit as usual.
5080    /// 
5081    /// The hotspot can also be updated by passing the currently set
5082    /// pointer surface to this request with new values for hotspot_x
5083    /// and hotspot_y.
5084    /// 
5085    /// The current and pending input regions of the wl_surface are
5086    /// cleared, and wl_surface.set_input_region is ignored until the
5087    /// wl_surface is no longer used as the cursor. When the use as a
5088    /// cursor ends, the current and pending input regions become
5089    /// undefined, and the wl_surface is unmapped.
5090    SetCursor {
5091        /// serial number of the enter event
5092        serial: u32,
5093        /// pointer surface
5094        surface: ObjectId,
5095        /// surface-local x coordinate
5096        hotspot_x: i32,
5097        /// surface-local y coordinate
5098        hotspot_y: i32,
5099    },
5100
5101    /// release the pointer object
5102    ///
5103    /// Using this request a client can tell the server that it is not going to
5104    /// use the pointer object anymore.
5105    /// 
5106    /// This request destroys the pointer proxy object, so clients must not call
5107    /// wl_pointer_destroy() after using this request.
5108    Release,
5109}
5110
5111impl MessageType for Request {
5112    fn log(&self, this: ObjectId) -> String {
5113        match *self {
5114            Request::SetCursor {
5115                ref serial,
5116                ref surface,
5117                ref hotspot_x,
5118                ref hotspot_y,
5119            } => {
5120                format!("wl_pointer@{:?}::set_cursor(serial: {:?}, surface: {:?}, hotspot_x: {:?}, hotspot_y: {:?})", this, serial, surface, hotspot_x, hotspot_y)
5121            }
5122            Request::Release {
5123            } => {
5124                format!("wl_pointer@{:?}::release()", this)
5125            }
5126        }
5127    }
5128    fn message_name(&self) -> &'static std::ffi::CStr{
5129        match *self {
5130            Request::SetCursor { .. } => c"wl_pointer::set_cursor",
5131            Request::Release { .. } => c"wl_pointer::release",
5132        }
5133    }
5134}
5135#[derive(Debug)]
5136pub enum Event {
5137
5138    /// enter event
5139    ///
5140    /// Notification that this seat's pointer is focused on a certain
5141    /// surface.
5142    /// 
5143    /// When a seat's focus enters a surface, the pointer image
5144    /// is undefined and a client should respond to this event by setting
5145    /// an appropriate pointer image with the set_cursor request.
5146    Enter {
5147        /// serial number of the enter event
5148        serial: u32,
5149        /// surface entered by the pointer
5150        surface: ObjectId,
5151        /// surface-local x coordinate
5152        surface_x: Fixed,
5153        /// surface-local y coordinate
5154        surface_y: Fixed,
5155    },
5156
5157    /// leave event
5158    ///
5159    /// Notification that this seat's pointer is no longer focused on
5160    /// a certain surface.
5161    /// 
5162    /// The leave notification is sent before the enter notification
5163    /// for the new focus.
5164    Leave {
5165        /// serial number of the leave event
5166        serial: u32,
5167        /// surface left by the pointer
5168        surface: ObjectId,
5169    },
5170
5171    /// pointer motion event
5172    ///
5173    /// Notification of pointer location change. The arguments
5174    /// surface_x and surface_y are the location relative to the
5175    /// focused surface.
5176    Motion {
5177        /// timestamp with millisecond granularity
5178        time: u32,
5179        /// surface-local x coordinate
5180        surface_x: Fixed,
5181        /// surface-local y coordinate
5182        surface_y: Fixed,
5183    },
5184
5185    /// pointer button event
5186    ///
5187    /// Mouse button click and release notifications.
5188    /// 
5189    /// The location of the click is given by the last motion or
5190    /// enter event.
5191    /// The time argument is a timestamp with millisecond
5192    /// granularity, with an undefined base.
5193    /// 
5194    /// The button is a button code as defined in the Linux kernel's
5195    /// linux/input-event-codes.h header file, e.g. BTN_LEFT.
5196    /// 
5197    /// Any 16-bit button code value is reserved for future additions to the
5198    /// kernel's event code list. All other button codes above 0xFFFF are
5199    /// currently undefined but may be used in future versions of this
5200    /// protocol.
5201    Button {
5202        /// serial number of the button event
5203        serial: u32,
5204        /// timestamp with millisecond granularity
5205        time: u32,
5206        /// button that produced the event
5207        button: u32,
5208        /// physical state of the button
5209        state: Enum<ButtonState>,
5210    },
5211
5212    /// axis event
5213    ///
5214    /// Scroll and other axis notifications.
5215    /// 
5216    /// For scroll events (vertical and horizontal scroll axes), the
5217    /// value parameter is the length of a vector along the specified
5218    /// axis in a coordinate space identical to those of motion events,
5219    /// representing a relative movement along the specified axis.
5220    /// 
5221    /// For devices that support movements non-parallel to axes multiple
5222    /// axis events will be emitted.
5223    /// 
5224    /// When applicable, for example for touch pads, the server can
5225    /// choose to emit scroll events where the motion vector is
5226    /// equivalent to a motion event vector.
5227    /// 
5228    /// When applicable, a client can transform its content relative to the
5229    /// scroll distance.
5230    Axis {
5231        /// timestamp with millisecond granularity
5232        time: u32,
5233        /// axis type
5234        axis: Enum<Axis>,
5235        /// length of vector in surface-local coordinate space
5236        value: Fixed,
5237    },
5238
5239    /// end of a pointer event sequence
5240    ///
5241    /// Indicates the end of a set of events that logically belong together.
5242    /// A client is expected to accumulate the data in all events within the
5243    /// frame before proceeding.
5244    /// 
5245    /// All wl_pointer events before a wl_pointer.frame event belong
5246    /// logically together. For example, in a diagonal scroll motion the
5247    /// compositor will send an optional wl_pointer.axis_source event, two
5248    /// wl_pointer.axis events (horizontal and vertical) and finally a
5249    /// wl_pointer.frame event. The client may use this information to
5250    /// calculate a diagonal vector for scrolling.
5251    /// 
5252    /// When multiple wl_pointer.axis events occur within the same frame,
5253    /// the motion vector is the combined motion of all events.
5254    /// When a wl_pointer.axis and a wl_pointer.axis_stop event occur within
5255    /// the same frame, this indicates that axis movement in one axis has
5256    /// stopped but continues in the other axis.
5257    /// When multiple wl_pointer.axis_stop events occur within the same
5258    /// frame, this indicates that these axes stopped in the same instance.
5259    /// 
5260    /// A wl_pointer.frame event is sent for every logical event group,
5261    /// even if the group only contains a single wl_pointer event.
5262    /// Specifically, a client may get a sequence: motion, frame, button,
5263    /// frame, axis, frame, axis_stop, frame.
5264    /// 
5265    /// The wl_pointer.enter and wl_pointer.leave events are logical events
5266    /// generated by the compositor and not the hardware. These events are
5267    /// also grouped by a wl_pointer.frame. When a pointer moves from one
5268    /// surface to another, a compositor should group the
5269    /// wl_pointer.leave event within the same wl_pointer.frame.
5270    /// However, a client must not rely on wl_pointer.leave and
5271    /// wl_pointer.enter being in the same wl_pointer.frame.
5272    /// Compositor-specific policies may require the wl_pointer.leave and
5273    /// wl_pointer.enter event being split across multiple wl_pointer.frame
5274    /// groups.
5275    Frame,
5276
5277    /// axis source event
5278    ///
5279    /// Source information for scroll and other axes.
5280    /// 
5281    /// This event does not occur on its own. It is sent before a
5282    /// wl_pointer.frame event and carries the source information for
5283    /// all events within that frame.
5284    /// 
5285    /// The source specifies how this event was generated. If the source is
5286    /// wl_pointer.axis_source.finger, a wl_pointer.axis_stop event will be
5287    /// sent when the user lifts the finger off the device.
5288    /// 
5289    /// If the source is wl_pointer.axis_source.wheel,
5290    /// wl_pointer.axis_source.wheel_tilt or
5291    /// wl_pointer.axis_source.continuous, a wl_pointer.axis_stop event may
5292    /// or may not be sent. Whether a compositor sends an axis_stop event
5293    /// for these sources is hardware-specific and implementation-dependent;
5294    /// clients must not rely on receiving an axis_stop event for these
5295    /// scroll sources and should treat scroll sequences from these scroll
5296    /// sources as unterminated by default.
5297    /// 
5298    /// This event is optional. If the source is unknown for a particular
5299    /// axis event sequence, no event is sent.
5300    /// Only one wl_pointer.axis_source event is permitted per frame.
5301    /// 
5302    /// The order of wl_pointer.axis_discrete and wl_pointer.axis_source is
5303    /// not guaranteed.
5304    AxisSource {
5305        /// source of the axis event
5306        axis_source: Enum<AxisSource>,
5307    },
5308
5309    /// axis stop event
5310    ///
5311    /// Stop notification for scroll and other axes.
5312    /// 
5313    /// For some wl_pointer.axis_source types, a wl_pointer.axis_stop event
5314    /// is sent to notify a client that the axis sequence has terminated.
5315    /// This enables the client to implement kinetic scrolling.
5316    /// See the wl_pointer.axis_source documentation for information on when
5317    /// this event may be generated.
5318    /// 
5319    /// Any wl_pointer.axis events with the same axis_source after this
5320    /// event should be considered as the start of a new axis motion.
5321    /// 
5322    /// The timestamp is to be interpreted identical to the timestamp in the
5323    /// wl_pointer.axis event. The timestamp value may be the same as a
5324    /// preceding wl_pointer.axis event.
5325    AxisStop {
5326        /// timestamp with millisecond granularity
5327        time: u32,
5328        /// the axis stopped with this event
5329        axis: Enum<Axis>,
5330    },
5331
5332    /// axis click event
5333    ///
5334    /// Discrete step information for scroll and other axes.
5335    /// 
5336    /// This event carries the axis value of the wl_pointer.axis event in
5337    /// discrete steps (e.g. mouse wheel clicks).
5338    /// 
5339    /// This event does not occur on its own, it is coupled with a
5340    /// wl_pointer.axis event that represents this axis value on a
5341    /// continuous scale. The protocol guarantees that each axis_discrete
5342    /// event is always followed by exactly one axis event with the same
5343    /// axis number within the same wl_pointer.frame. Note that the protocol
5344    /// allows for other events to occur between the axis_discrete and
5345    /// its coupled axis event, including other axis_discrete or axis
5346    /// events.
5347    /// 
5348    /// This event is optional; continuous scrolling devices
5349    /// like two-finger scrolling on touchpads do not have discrete
5350    /// steps and do not generate this event.
5351    /// 
5352    /// The discrete value carries the directional information. e.g. a value
5353    /// of -2 is two steps towards the negative direction of this axis.
5354    /// 
5355    /// The axis number is identical to the axis number in the associated
5356    /// axis event.
5357    /// 
5358    /// The order of wl_pointer.axis_discrete and wl_pointer.axis_source is
5359    /// not guaranteed.
5360    AxisDiscrete {
5361        /// axis type
5362        axis: Enum<Axis>,
5363        /// number of steps
5364        discrete: i32,
5365    },
5366}
5367
5368impl MessageType for Event {
5369    fn log(&self, this: ObjectId) -> String {
5370        match *self {
5371            Event::Enter {
5372                ref serial,
5373                ref surface,
5374                ref surface_x,
5375                ref surface_y,
5376            } => {
5377                format!("wl_pointer@{:?}::enter(serial: {:?}, surface: {:?}, surface_x: {:?}, surface_y: {:?})", this, serial, surface, surface_x, surface_y)
5378            }
5379            Event::Leave {
5380                ref serial,
5381                ref surface,
5382            } => {
5383                format!("wl_pointer@{:?}::leave(serial: {:?}, surface: {:?})", this, serial, surface)
5384            }
5385            Event::Motion {
5386                ref time,
5387                ref surface_x,
5388                ref surface_y,
5389            } => {
5390                format!("wl_pointer@{:?}::motion(time: {:?}, surface_x: {:?}, surface_y: {:?})", this, time, surface_x, surface_y)
5391            }
5392            Event::Button {
5393                ref serial,
5394                ref time,
5395                ref button,
5396                ref state,
5397            } => {
5398                format!("wl_pointer@{:?}::button(serial: {:?}, time: {:?}, button: {:?}, state: {:?})", this, serial, time, button, state)
5399            }
5400            Event::Axis {
5401                ref time,
5402                ref axis,
5403                ref value,
5404            } => {
5405                format!("wl_pointer@{:?}::axis(time: {:?}, axis: {:?}, value: {:?})", this, time, axis, value)
5406            }
5407            Event::Frame {
5408            } => {
5409                format!("wl_pointer@{:?}::frame()", this)
5410            }
5411            Event::AxisSource {
5412                ref axis_source,
5413            } => {
5414                format!("wl_pointer@{:?}::axis_source(axis_source: {:?})", this, axis_source)
5415            }
5416            Event::AxisStop {
5417                ref time,
5418                ref axis,
5419            } => {
5420                format!("wl_pointer@{:?}::axis_stop(time: {:?}, axis: {:?})", this, time, axis)
5421            }
5422            Event::AxisDiscrete {
5423                ref axis,
5424                ref discrete,
5425            } => {
5426                format!("wl_pointer@{:?}::axis_discrete(axis: {:?}, discrete: {:?})", this, axis, discrete)
5427            }
5428        }
5429    }
5430    fn message_name(&self) -> &'static std::ffi::CStr{
5431        match *self {
5432            Event::Enter { .. } => c"wl_pointer::enter",
5433            Event::Leave { .. } => c"wl_pointer::leave",
5434            Event::Motion { .. } => c"wl_pointer::motion",
5435            Event::Button { .. } => c"wl_pointer::button",
5436            Event::Axis { .. } => c"wl_pointer::axis",
5437            Event::Frame { .. } => c"wl_pointer::frame",
5438            Event::AxisSource { .. } => c"wl_pointer::axis_source",
5439            Event::AxisStop { .. } => c"wl_pointer::axis_stop",
5440            Event::AxisDiscrete { .. } => c"wl_pointer::axis_discrete",
5441        }
5442    }
5443}
5444impl IntoMessage for Request {
5445    type Error = EncodeError;
5446    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
5447        let mut header = MessageHeader {
5448            sender: id,
5449            opcode: 0,
5450            length: 0,
5451        };
5452        let mut msg = Message::new();
5453        msg.write_header(&header)?;
5454        match self {
5455        Request::SetCursor {
5456            serial,
5457            surface,
5458            hotspot_x,
5459            hotspot_y,
5460        } => {
5461            msg.write_arg(Arg::Uint(serial))?;
5462            msg.write_arg(Arg::Object(surface))?;
5463            msg.write_arg(Arg::Int(hotspot_x))?;
5464            msg.write_arg(Arg::Int(hotspot_y))?;
5465            header.opcode = 0;
5466        },
5467        Request::Release {
5468        } => {
5469            header.opcode = 1;
5470        },
5471        }
5472        header.length = msg.bytes().len() as u16;
5473        msg.rewind();
5474        msg.write_header(&header)?;
5475        Ok(msg)
5476    }
5477}
5478impl FromArgs for Event {
5479    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
5480        match op {
5481        0 /* enter */ => {
5482            let mut iter = args.into_iter();
5483            Ok(Event::Enter {
5484                serial: iter.next()
5485                                             .ok_or(DecodeError::InsufficientArgs)?
5486                                             .as_uint()?,
5487                surface: iter.next()
5488                                             .ok_or(DecodeError::InsufficientArgs)?
5489                                             .as_object()?,
5490                surface_x: iter.next()
5491                                             .ok_or(DecodeError::InsufficientArgs)?
5492                                             .as_fixed()?.into(),
5493                surface_y: iter.next()
5494                                             .ok_or(DecodeError::InsufficientArgs)?
5495                                             .as_fixed()?.into(),
5496
5497            })
5498        },
5499        1 /* leave */ => {
5500            let mut iter = args.into_iter();
5501            Ok(Event::Leave {
5502                serial: iter.next()
5503                                             .ok_or(DecodeError::InsufficientArgs)?
5504                                             .as_uint()?,
5505                surface: iter.next()
5506                                             .ok_or(DecodeError::InsufficientArgs)?
5507                                             .as_object()?,
5508
5509            })
5510        },
5511        2 /* motion */ => {
5512            let mut iter = args.into_iter();
5513            Ok(Event::Motion {
5514                time: iter.next()
5515                                             .ok_or(DecodeError::InsufficientArgs)?
5516                                             .as_uint()?,
5517                surface_x: iter.next()
5518                                             .ok_or(DecodeError::InsufficientArgs)?
5519                                             .as_fixed()?.into(),
5520                surface_y: iter.next()
5521                                             .ok_or(DecodeError::InsufficientArgs)?
5522                                             .as_fixed()?.into(),
5523
5524            })
5525        },
5526        3 /* button */ => {
5527            let mut iter = args.into_iter();
5528            Ok(Event::Button {
5529                serial: iter.next()
5530                                             .ok_or(DecodeError::InsufficientArgs)?
5531                                             .as_uint()?,
5532                time: iter.next()
5533                                             .ok_or(DecodeError::InsufficientArgs)?
5534                                             .as_uint()?,
5535                button: iter.next()
5536                                             .ok_or(DecodeError::InsufficientArgs)?
5537                                             .as_uint()?,
5538                state: iter.next()
5539                                             .ok_or(DecodeError::InsufficientArgs)?
5540                                             .as_uint().map(|i| match ButtonState::from_bits(i) {
5541                                      Some(e) => Enum::Recognized(e),
5542                                      None => Enum::Unrecognized(i),
5543                                 })?,
5544
5545            })
5546        },
5547        4 /* axis */ => {
5548            let mut iter = args.into_iter();
5549            Ok(Event::Axis {
5550                time: iter.next()
5551                                             .ok_or(DecodeError::InsufficientArgs)?
5552                                             .as_uint()?,
5553                axis: iter.next()
5554                                             .ok_or(DecodeError::InsufficientArgs)?
5555                                             .as_uint().map(|i| match Axis::from_bits(i) {
5556                                      Some(e) => Enum::Recognized(e),
5557                                      None => Enum::Unrecognized(i),
5558                                 })?,
5559                value: iter.next()
5560                                             .ok_or(DecodeError::InsufficientArgs)?
5561                                             .as_fixed()?.into(),
5562
5563            })
5564        },
5565        5 /* frame */ => {
5566            let mut iter = args.into_iter();
5567            Ok(Event::Frame {
5568
5569            })
5570        },
5571        6 /* axis_source */ => {
5572            let mut iter = args.into_iter();
5573            Ok(Event::AxisSource {
5574                axis_source: iter.next()
5575                                             .ok_or(DecodeError::InsufficientArgs)?
5576                                             .as_uint().map(|i| match AxisSource::from_bits(i) {
5577                                      Some(e) => Enum::Recognized(e),
5578                                      None => Enum::Unrecognized(i),
5579                                 })?,
5580
5581            })
5582        },
5583        7 /* axis_stop */ => {
5584            let mut iter = args.into_iter();
5585            Ok(Event::AxisStop {
5586                time: iter.next()
5587                                             .ok_or(DecodeError::InsufficientArgs)?
5588                                             .as_uint()?,
5589                axis: iter.next()
5590                                             .ok_or(DecodeError::InsufficientArgs)?
5591                                             .as_uint().map(|i| match Axis::from_bits(i) {
5592                                      Some(e) => Enum::Recognized(e),
5593                                      None => Enum::Unrecognized(i),
5594                                 })?,
5595
5596            })
5597        },
5598        8 /* axis_discrete */ => {
5599            let mut iter = args.into_iter();
5600            Ok(Event::AxisDiscrete {
5601                axis: iter.next()
5602                                             .ok_or(DecodeError::InsufficientArgs)?
5603                                             .as_uint().map(|i| match Axis::from_bits(i) {
5604                                      Some(e) => Enum::Recognized(e),
5605                                      None => Enum::Unrecognized(i),
5606                                 })?,
5607                discrete: iter.next()
5608                                             .ok_or(DecodeError::InsufficientArgs)?
5609                                             .as_int()?,
5610
5611            })
5612        },
5613        _ => {
5614            Err(DecodeError::InvalidOpcode(op).into())
5615        },
5616        }
5617    }
5618}
5619#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5620#[repr(u32)]
5621pub enum Error {
5622    /// given wl_surface has another role,
5623    Role = 0,
5624}
5625
5626impl Error {
5627    pub fn from_bits(v: u32) -> Option<Self> {
5628        match v {
5629        0 => Some(Error::Role),
5630        _ => None,
5631        }
5632    }
5633
5634    pub fn bits(&self) -> u32 {
5635        *self as u32
5636    }
5637}
5638impl Into<Arg> for Error {
5639    fn into(self) -> Arg {
5640        Arg::Uint(self.bits())
5641    }
5642}
5643
5644/// physical button state
5645///
5646/// Describes the physical state of a button that produced the button
5647/// event.
5648#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5649#[repr(u32)]
5650pub enum ButtonState {
5651    /// the button is not pressed,
5652    Released = 0,
5653    /// the button is pressed,
5654    Pressed = 1,
5655}
5656
5657impl ButtonState {
5658    pub fn from_bits(v: u32) -> Option<Self> {
5659        match v {
5660        0 => Some(ButtonState::Released),
5661        1 => Some(ButtonState::Pressed),
5662        _ => None,
5663        }
5664    }
5665
5666    pub fn bits(&self) -> u32 {
5667        *self as u32
5668    }
5669}
5670impl Into<Arg> for ButtonState {
5671    fn into(self) -> Arg {
5672        Arg::Uint(self.bits())
5673    }
5674}
5675
5676/// axis types
5677///
5678/// Describes the axis types of scroll events.
5679#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5680#[repr(u32)]
5681pub enum Axis {
5682    /// vertical axis,
5683    VerticalScroll = 0,
5684    /// horizontal axis,
5685    HorizontalScroll = 1,
5686}
5687
5688impl Axis {
5689    pub fn from_bits(v: u32) -> Option<Self> {
5690        match v {
5691        0 => Some(Axis::VerticalScroll),
5692        1 => Some(Axis::HorizontalScroll),
5693        _ => None,
5694        }
5695    }
5696
5697    pub fn bits(&self) -> u32 {
5698        *self as u32
5699    }
5700}
5701impl Into<Arg> for Axis {
5702    fn into(self) -> Arg {
5703        Arg::Uint(self.bits())
5704    }
5705}
5706
5707/// axis source types
5708///
5709/// Describes the source types for axis events. This indicates to the
5710/// client how an axis event was physically generated; a client may
5711/// adjust the user interface accordingly. For example, scroll events
5712/// from a "finger" source may be in a smooth coordinate space with
5713/// kinetic scrolling whereas a "wheel" source may be in discrete steps
5714/// of a number of lines.
5715/// 
5716/// The "continuous" axis source is a device generating events in a
5717/// continuous coordinate space, but using something other than a
5718/// finger. One example for this source is button-based scrolling where
5719/// the vertical motion of a device is converted to scroll events while
5720/// a button is held down.
5721/// 
5722/// The "wheel tilt" axis source indicates that the actual device is a
5723/// wheel but the scroll event is not caused by a rotation but a
5724/// (usually sideways) tilt of the wheel.
5725#[derive(Copy, Clone, Debug, Eq, PartialEq)]
5726#[repr(u32)]
5727pub enum AxisSource {
5728    /// a physical wheel rotation,
5729    Wheel = 0,
5730    /// finger on a touch surface,
5731    Finger = 1,
5732    /// continuous coordinate space,
5733    Continuous = 2,
5734    /// a physical wheel tilt,
5735    WheelTilt = 3,
5736}
5737
5738impl AxisSource {
5739    pub fn from_bits(v: u32) -> Option<Self> {
5740        match v {
5741        0 => Some(AxisSource::Wheel),
5742        1 => Some(AxisSource::Finger),
5743        2 => Some(AxisSource::Continuous),
5744        3 => Some(AxisSource::WheelTilt),
5745        _ => None,
5746        }
5747    }
5748
5749    pub fn bits(&self) -> u32 {
5750        *self as u32
5751    }
5752}
5753impl Into<Arg> for AxisSource {
5754    fn into(self) -> Arg {
5755        Arg::Uint(self.bits())
5756    }
5757}
5758} // mod wl_pointer
5759
5760pub use crate::wl_pointer::WlPointer;
5761pub use crate::wl_pointer::Request as WlPointerRequest;
5762pub use crate::wl_pointer::Event as WlPointerEvent;
5763pub mod wl_keyboard {
5764use super::*;
5765
5766/// keyboard input device
5767///
5768/// The wl_keyboard interface represents one or more keyboards
5769/// associated with a seat.
5770#[derive(Debug)]
5771pub struct WlKeyboard;
5772
5773impl Interface for WlKeyboard {
5774    const NAME: &'static str = "wl_keyboard";
5775    const VERSION: u32 = 7;
5776    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
5777        // release
5778        MessageSpec(&[
5779        ]),
5780    ]);
5781    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
5782        // keymap
5783        MessageSpec(&[
5784            ArgKind::Uint,
5785            ArgKind::Handle,
5786            ArgKind::Uint,
5787        ]),
5788        // enter
5789        MessageSpec(&[
5790            ArgKind::Uint,
5791            ArgKind::Object,
5792            ArgKind::Array,
5793        ]),
5794        // leave
5795        MessageSpec(&[
5796            ArgKind::Uint,
5797            ArgKind::Object,
5798        ]),
5799        // key
5800        MessageSpec(&[
5801            ArgKind::Uint,
5802            ArgKind::Uint,
5803            ArgKind::Uint,
5804            ArgKind::Uint,
5805        ]),
5806        // modifiers
5807        MessageSpec(&[
5808            ArgKind::Uint,
5809            ArgKind::Uint,
5810            ArgKind::Uint,
5811            ArgKind::Uint,
5812            ArgKind::Uint,
5813        ]),
5814        // repeat_info
5815        MessageSpec(&[
5816            ArgKind::Int,
5817            ArgKind::Int,
5818        ]),
5819    ]);
5820    type Incoming = Event;
5821    type Outgoing = Request;
5822}
5823
5824#[derive(Debug)]
5825pub enum Request {
5826
5827    /// release the keyboard object
5828    ///
5829    Release,
5830}
5831
5832impl MessageType for Request {
5833    fn log(&self, this: ObjectId) -> String {
5834        match *self {
5835            Request::Release {
5836            } => {
5837                format!("wl_keyboard@{:?}::release()", this)
5838            }
5839        }
5840    }
5841    fn message_name(&self) -> &'static std::ffi::CStr{
5842        match *self {
5843            Request::Release { .. } => c"wl_keyboard::release",
5844        }
5845    }
5846}
5847#[derive(Debug)]
5848pub enum Event {
5849
5850    /// keyboard mapping
5851    ///
5852    /// This event provides a file descriptor to the client which can be
5853    /// memory-mapped to provide a keyboard mapping description.
5854    /// 
5855    /// From version 7 onwards, the fd must be mapped with MAP_PRIVATE by
5856    /// the recipient, as MAP_SHARED may fail.
5857    Keymap {
5858        /// keymap format
5859        format: Enum<KeymapFormat>,
5860        /// keymap file descriptor
5861        fd: zx::Handle,
5862        /// keymap size, in bytes
5863        size: u32,
5864    },
5865
5866    /// enter event
5867    ///
5868    /// Notification that this seat's keyboard focus is on a certain
5869    /// surface.
5870    /// 
5871    /// The compositor must send the wl_keyboard.modifiers event after this
5872    /// event.
5873    Enter {
5874        /// serial number of the enter event
5875        serial: u32,
5876        /// surface gaining keyboard focus
5877        surface: ObjectId,
5878        /// the currently pressed keys
5879        keys: Array,
5880    },
5881
5882    /// leave event
5883    ///
5884    /// Notification that this seat's keyboard focus is no longer on
5885    /// a certain surface.
5886    /// 
5887    /// The leave notification is sent before the enter notification
5888    /// for the new focus.
5889    /// 
5890    /// After this event client must assume that all keys, including modifiers,
5891    /// are lifted and also it must stop key repeating if there's some going on.
5892    Leave {
5893        /// serial number of the leave event
5894        serial: u32,
5895        /// surface that lost keyboard focus
5896        surface: ObjectId,
5897    },
5898
5899    /// key event
5900    ///
5901    /// A key was pressed or released.
5902    /// The time argument is a timestamp with millisecond
5903    /// granularity, with an undefined base.
5904    /// 
5905    /// The key is a platform-specific key code that can be interpreted
5906    /// by feeding it to the keyboard mapping (see the keymap event).
5907    /// 
5908    /// If this event produces a change in modifiers, then the resulting
5909    /// wl_keyboard.modifiers event must be sent after this event.
5910    Key {
5911        /// serial number of the key event
5912        serial: u32,
5913        /// timestamp with millisecond granularity
5914        time: u32,
5915        /// key that produced the event
5916        key: u32,
5917        /// physical state of the key
5918        state: Enum<KeyState>,
5919    },
5920
5921    /// modifier and group state
5922    ///
5923    /// Notifies clients that the modifier and/or group state has
5924    /// changed, and it should update its local state.
5925    Modifiers {
5926        /// serial number of the modifiers event
5927        serial: u32,
5928        /// depressed modifiers
5929        mods_depressed: u32,
5930        /// latched modifiers
5931        mods_latched: u32,
5932        /// locked modifiers
5933        mods_locked: u32,
5934        /// keyboard layout
5935        group: u32,
5936    },
5937
5938    /// repeat rate and delay
5939    ///
5940    /// Informs the client about the keyboard's repeat rate and delay.
5941    /// 
5942    /// This event is sent as soon as the wl_keyboard object has been created,
5943    /// and is guaranteed to be received by the client before any key press
5944    /// event.
5945    /// 
5946    /// Negative values for either rate or delay are illegal. A rate of zero
5947    /// will disable any repeating (regardless of the value of delay).
5948    /// 
5949    /// This event can be sent later on as well with a new value if necessary,
5950    /// so clients should continue listening for the event past the creation
5951    /// of wl_keyboard.
5952    RepeatInfo {
5953        /// the rate of repeating keys in characters per second
5954        rate: i32,
5955        /// delay in milliseconds since key down until repeating starts
5956        delay: i32,
5957    },
5958}
5959
5960impl MessageType for Event {
5961    fn log(&self, this: ObjectId) -> String {
5962        match *self {
5963            Event::Keymap {
5964                ref format,
5965                ref fd,
5966                ref size,
5967            } => {
5968                format!("wl_keyboard@{:?}::keymap(format: {:?}, fd: <handle>, size: {:?})", this, format, size)
5969            }
5970            Event::Enter {
5971                ref serial,
5972                ref surface,
5973                ref keys,
5974            } => {
5975                format!("wl_keyboard@{:?}::enter(serial: {:?}, surface: {:?}, keys: Array[{}])", this, serial, surface, keys.len())
5976            }
5977            Event::Leave {
5978                ref serial,
5979                ref surface,
5980            } => {
5981                format!("wl_keyboard@{:?}::leave(serial: {:?}, surface: {:?})", this, serial, surface)
5982            }
5983            Event::Key {
5984                ref serial,
5985                ref time,
5986                ref key,
5987                ref state,
5988            } => {
5989                format!("wl_keyboard@{:?}::key(serial: {:?}, time: {:?}, key: {:?}, state: {:?})", this, serial, time, key, state)
5990            }
5991            Event::Modifiers {
5992                ref serial,
5993                ref mods_depressed,
5994                ref mods_latched,
5995                ref mods_locked,
5996                ref group,
5997            } => {
5998                format!("wl_keyboard@{:?}::modifiers(serial: {:?}, mods_depressed: {:?}, mods_latched: {:?}, mods_locked: {:?}, group: {:?})", this, serial, mods_depressed, mods_latched, mods_locked, group)
5999            }
6000            Event::RepeatInfo {
6001                ref rate,
6002                ref delay,
6003            } => {
6004                format!("wl_keyboard@{:?}::repeat_info(rate: {:?}, delay: {:?})", this, rate, delay)
6005            }
6006        }
6007    }
6008    fn message_name(&self) -> &'static std::ffi::CStr{
6009        match *self {
6010            Event::Keymap { .. } => c"wl_keyboard::keymap",
6011            Event::Enter { .. } => c"wl_keyboard::enter",
6012            Event::Leave { .. } => c"wl_keyboard::leave",
6013            Event::Key { .. } => c"wl_keyboard::key",
6014            Event::Modifiers { .. } => c"wl_keyboard::modifiers",
6015            Event::RepeatInfo { .. } => c"wl_keyboard::repeat_info",
6016        }
6017    }
6018}
6019impl IntoMessage for Request {
6020    type Error = EncodeError;
6021    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
6022        let mut header = MessageHeader {
6023            sender: id,
6024            opcode: 0,
6025            length: 0,
6026        };
6027        let mut msg = Message::new();
6028        msg.write_header(&header)?;
6029        match self {
6030        Request::Release {
6031        } => {
6032            header.opcode = 0;
6033        },
6034        }
6035        header.length = msg.bytes().len() as u16;
6036        msg.rewind();
6037        msg.write_header(&header)?;
6038        Ok(msg)
6039    }
6040}
6041impl FromArgs for Event {
6042    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
6043        match op {
6044        0 /* keymap */ => {
6045            let mut iter = args.into_iter();
6046            Ok(Event::Keymap {
6047                format: iter.next()
6048                                             .ok_or(DecodeError::InsufficientArgs)?
6049                                             .as_uint().map(|i| match KeymapFormat::from_bits(i) {
6050                                      Some(e) => Enum::Recognized(e),
6051                                      None => Enum::Unrecognized(i),
6052                                 })?,
6053                fd: iter.next()
6054                                             .ok_or(DecodeError::InsufficientArgs)?
6055                                             .as_handle()?,
6056                size: iter.next()
6057                                             .ok_or(DecodeError::InsufficientArgs)?
6058                                             .as_uint()?,
6059
6060            })
6061        },
6062        1 /* enter */ => {
6063            let mut iter = args.into_iter();
6064            Ok(Event::Enter {
6065                serial: iter.next()
6066                                             .ok_or(DecodeError::InsufficientArgs)?
6067                                             .as_uint()?,
6068                surface: iter.next()
6069                                             .ok_or(DecodeError::InsufficientArgs)?
6070                                             .as_object()?,
6071                keys: iter.next()
6072                                             .ok_or(DecodeError::InsufficientArgs)?
6073                                             .as_array()?,
6074
6075            })
6076        },
6077        2 /* leave */ => {
6078            let mut iter = args.into_iter();
6079            Ok(Event::Leave {
6080                serial: iter.next()
6081                                             .ok_or(DecodeError::InsufficientArgs)?
6082                                             .as_uint()?,
6083                surface: iter.next()
6084                                             .ok_or(DecodeError::InsufficientArgs)?
6085                                             .as_object()?,
6086
6087            })
6088        },
6089        3 /* key */ => {
6090            let mut iter = args.into_iter();
6091            Ok(Event::Key {
6092                serial: iter.next()
6093                                             .ok_or(DecodeError::InsufficientArgs)?
6094                                             .as_uint()?,
6095                time: iter.next()
6096                                             .ok_or(DecodeError::InsufficientArgs)?
6097                                             .as_uint()?,
6098                key: iter.next()
6099                                             .ok_or(DecodeError::InsufficientArgs)?
6100                                             .as_uint()?,
6101                state: iter.next()
6102                                             .ok_or(DecodeError::InsufficientArgs)?
6103                                             .as_uint().map(|i| match KeyState::from_bits(i) {
6104                                      Some(e) => Enum::Recognized(e),
6105                                      None => Enum::Unrecognized(i),
6106                                 })?,
6107
6108            })
6109        },
6110        4 /* modifiers */ => {
6111            let mut iter = args.into_iter();
6112            Ok(Event::Modifiers {
6113                serial: iter.next()
6114                                             .ok_or(DecodeError::InsufficientArgs)?
6115                                             .as_uint()?,
6116                mods_depressed: iter.next()
6117                                             .ok_or(DecodeError::InsufficientArgs)?
6118                                             .as_uint()?,
6119                mods_latched: iter.next()
6120                                             .ok_or(DecodeError::InsufficientArgs)?
6121                                             .as_uint()?,
6122                mods_locked: iter.next()
6123                                             .ok_or(DecodeError::InsufficientArgs)?
6124                                             .as_uint()?,
6125                group: iter.next()
6126                                             .ok_or(DecodeError::InsufficientArgs)?
6127                                             .as_uint()?,
6128
6129            })
6130        },
6131        5 /* repeat_info */ => {
6132            let mut iter = args.into_iter();
6133            Ok(Event::RepeatInfo {
6134                rate: iter.next()
6135                                             .ok_or(DecodeError::InsufficientArgs)?
6136                                             .as_int()?,
6137                delay: iter.next()
6138                                             .ok_or(DecodeError::InsufficientArgs)?
6139                                             .as_int()?,
6140
6141            })
6142        },
6143        _ => {
6144            Err(DecodeError::InvalidOpcode(op).into())
6145        },
6146        }
6147    }
6148}
6149
6150/// keyboard mapping format
6151///
6152/// This specifies the format of the keymap provided to the
6153/// client with the wl_keyboard.keymap event.
6154#[derive(Copy, Clone, Debug, Eq, PartialEq)]
6155#[repr(u32)]
6156pub enum KeymapFormat {
6157    /// no keymap; client must understand how to interpret the raw keycode,
6158    NoKeymap = 0,
6159    /// libxkbcommon compatible; to determine the xkb keycode, clients must add 8 to the key event keycode,
6160    XkbV1 = 1,
6161}
6162
6163impl KeymapFormat {
6164    pub fn from_bits(v: u32) -> Option<Self> {
6165        match v {
6166        0 => Some(KeymapFormat::NoKeymap),
6167        1 => Some(KeymapFormat::XkbV1),
6168        _ => None,
6169        }
6170    }
6171
6172    pub fn bits(&self) -> u32 {
6173        *self as u32
6174    }
6175}
6176impl Into<Arg> for KeymapFormat {
6177    fn into(self) -> Arg {
6178        Arg::Uint(self.bits())
6179    }
6180}
6181
6182/// physical key state
6183///
6184/// Describes the physical state of a key that produced the key event.
6185#[derive(Copy, Clone, Debug, Eq, PartialEq)]
6186#[repr(u32)]
6187pub enum KeyState {
6188    /// key is not pressed,
6189    Released = 0,
6190    /// key is pressed,
6191    Pressed = 1,
6192}
6193
6194impl KeyState {
6195    pub fn from_bits(v: u32) -> Option<Self> {
6196        match v {
6197        0 => Some(KeyState::Released),
6198        1 => Some(KeyState::Pressed),
6199        _ => None,
6200        }
6201    }
6202
6203    pub fn bits(&self) -> u32 {
6204        *self as u32
6205    }
6206}
6207impl Into<Arg> for KeyState {
6208    fn into(self) -> Arg {
6209        Arg::Uint(self.bits())
6210    }
6211}
6212} // mod wl_keyboard
6213
6214pub use crate::wl_keyboard::WlKeyboard;
6215pub use crate::wl_keyboard::Request as WlKeyboardRequest;
6216pub use crate::wl_keyboard::Event as WlKeyboardEvent;
6217pub mod wl_touch {
6218use super::*;
6219
6220/// touchscreen input device
6221///
6222/// The wl_touch interface represents a touchscreen
6223/// associated with a seat.
6224/// 
6225/// Touch interactions can consist of one or more contacts.
6226/// For each contact, a series of events is generated, starting
6227/// with a down event, followed by zero or more motion events,
6228/// and ending with an up event. Events relating to the same
6229/// contact point can be identified by the ID of the sequence.
6230#[derive(Debug)]
6231pub struct WlTouch;
6232
6233impl Interface for WlTouch {
6234    const NAME: &'static str = "wl_touch";
6235    const VERSION: u32 = 7;
6236    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
6237        // release
6238        MessageSpec(&[
6239        ]),
6240    ]);
6241    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
6242        // down
6243        MessageSpec(&[
6244            ArgKind::Uint,
6245            ArgKind::Uint,
6246            ArgKind::Object,
6247            ArgKind::Int,
6248            ArgKind::Fixed,
6249            ArgKind::Fixed,
6250        ]),
6251        // up
6252        MessageSpec(&[
6253            ArgKind::Uint,
6254            ArgKind::Uint,
6255            ArgKind::Int,
6256        ]),
6257        // motion
6258        MessageSpec(&[
6259            ArgKind::Uint,
6260            ArgKind::Int,
6261            ArgKind::Fixed,
6262            ArgKind::Fixed,
6263        ]),
6264        // frame
6265        MessageSpec(&[
6266        ]),
6267        // cancel
6268        MessageSpec(&[
6269        ]),
6270        // shape
6271        MessageSpec(&[
6272            ArgKind::Int,
6273            ArgKind::Fixed,
6274            ArgKind::Fixed,
6275        ]),
6276        // orientation
6277        MessageSpec(&[
6278            ArgKind::Int,
6279            ArgKind::Fixed,
6280        ]),
6281    ]);
6282    type Incoming = Event;
6283    type Outgoing = Request;
6284}
6285
6286#[derive(Debug)]
6287pub enum Request {
6288
6289    /// release the touch object
6290    ///
6291    Release,
6292}
6293
6294impl MessageType for Request {
6295    fn log(&self, this: ObjectId) -> String {
6296        match *self {
6297            Request::Release {
6298            } => {
6299                format!("wl_touch@{:?}::release()", this)
6300            }
6301        }
6302    }
6303    fn message_name(&self) -> &'static std::ffi::CStr{
6304        match *self {
6305            Request::Release { .. } => c"wl_touch::release",
6306        }
6307    }
6308}
6309#[derive(Debug)]
6310pub enum Event {
6311
6312    /// touch down event and beginning of a touch sequence
6313    ///
6314    /// A new touch point has appeared on the surface. This touch point is
6315    /// assigned a unique ID. Future events from this touch point reference
6316    /// this ID. The ID ceases to be valid after a touch up event and may be
6317    /// reused in the future.
6318    Down {
6319        /// serial number of the touch down event
6320        serial: u32,
6321        /// timestamp with millisecond granularity
6322        time: u32,
6323        /// surface touched
6324        surface: ObjectId,
6325        /// the unique ID of this touch point
6326        id: i32,
6327        /// surface-local x coordinate
6328        x: Fixed,
6329        /// surface-local y coordinate
6330        y: Fixed,
6331    },
6332
6333    /// end of a touch event sequence
6334    ///
6335    /// The touch point has disappeared. No further events will be sent for
6336    /// this touch point and the touch point's ID is released and may be
6337    /// reused in a future touch down event.
6338    Up {
6339        /// serial number of the touch up event
6340        serial: u32,
6341        /// timestamp with millisecond granularity
6342        time: u32,
6343        /// the unique ID of this touch point
6344        id: i32,
6345    },
6346
6347    /// update of touch point coordinates
6348    ///
6349    /// A touch point has changed coordinates.
6350    Motion {
6351        /// timestamp with millisecond granularity
6352        time: u32,
6353        /// the unique ID of this touch point
6354        id: i32,
6355        /// surface-local x coordinate
6356        x: Fixed,
6357        /// surface-local y coordinate
6358        y: Fixed,
6359    },
6360
6361    /// end of touch frame event
6362    ///
6363    /// Indicates the end of a set of events that logically belong together.
6364    /// A client is expected to accumulate the data in all events within the
6365    /// frame before proceeding.
6366    /// 
6367    /// A wl_touch.frame terminates at least one event but otherwise no
6368    /// guarantee is provided about the set of events within a frame. A client
6369    /// must assume that any state not updated in a frame is unchanged from the
6370    /// previously known state.
6371    Frame,
6372
6373    /// touch session cancelled
6374    ///
6375    /// Sent if the compositor decides the touch stream is a global
6376    /// gesture. No further events are sent to the clients from that
6377    /// particular gesture. Touch cancellation applies to all touch points
6378    /// currently active on this client's surface. The client is
6379    /// responsible for finalizing the touch points, future touch points on
6380    /// this surface may reuse the touch point ID.
6381    Cancel,
6382
6383    /// update shape of touch point
6384    ///
6385    /// Sent when a touchpoint has changed its shape.
6386    /// 
6387    /// This event does not occur on its own. It is sent before a
6388    /// wl_touch.frame event and carries the new shape information for
6389    /// any previously reported, or new touch points of that frame.
6390    /// 
6391    /// Other events describing the touch point such as wl_touch.down,
6392    /// wl_touch.motion or wl_touch.orientation may be sent within the
6393    /// same wl_touch.frame. A client should treat these events as a single
6394    /// logical touch point update. The order of wl_touch.shape,
6395    /// wl_touch.orientation and wl_touch.motion is not guaranteed.
6396    /// A wl_touch.down event is guaranteed to occur before the first
6397    /// wl_touch.shape event for this touch ID but both events may occur within
6398    /// the same wl_touch.frame.
6399    /// 
6400    /// A touchpoint shape is approximated by an ellipse through the major and
6401    /// minor axis length. The major axis length describes the longer diameter
6402    /// of the ellipse, while the minor axis length describes the shorter
6403    /// diameter. Major and minor are orthogonal and both are specified in
6404    /// surface-local coordinates. The center of the ellipse is always at the
6405    /// touchpoint location as reported by wl_touch.down or wl_touch.move.
6406    /// 
6407    /// This event is only sent by the compositor if the touch device supports
6408    /// shape reports. The client has to make reasonable assumptions about the
6409    /// shape if it did not receive this event.
6410    Shape {
6411        /// the unique ID of this touch point
6412        id: i32,
6413        /// length of the major axis in surface-local coordinates
6414        major: Fixed,
6415        /// length of the minor axis in surface-local coordinates
6416        minor: Fixed,
6417    },
6418
6419    /// update orientation of touch point
6420    ///
6421    /// Sent when a touchpoint has changed its orientation.
6422    /// 
6423    /// This event does not occur on its own. It is sent before a
6424    /// wl_touch.frame event and carries the new shape information for
6425    /// any previously reported, or new touch points of that frame.
6426    /// 
6427    /// Other events describing the touch point such as wl_touch.down,
6428    /// wl_touch.motion or wl_touch.shape may be sent within the
6429    /// same wl_touch.frame. A client should treat these events as a single
6430    /// logical touch point update. The order of wl_touch.shape,
6431    /// wl_touch.orientation and wl_touch.motion is not guaranteed.
6432    /// A wl_touch.down event is guaranteed to occur before the first
6433    /// wl_touch.orientation event for this touch ID but both events may occur
6434    /// within the same wl_touch.frame.
6435    /// 
6436    /// The orientation describes the clockwise angle of a touchpoint's major
6437    /// axis to the positive surface y-axis and is normalized to the -180 to
6438    /// +180 degree range. The granularity of orientation depends on the touch
6439    /// device, some devices only support binary rotation values between 0 and
6440    /// 90 degrees.
6441    /// 
6442    /// This event is only sent by the compositor if the touch device supports
6443    /// orientation reports.
6444    Orientation {
6445        /// the unique ID of this touch point
6446        id: i32,
6447        /// angle between major axis and positive surface y-axis in degrees
6448        orientation: Fixed,
6449    },
6450}
6451
6452impl MessageType for Event {
6453    fn log(&self, this: ObjectId) -> String {
6454        match *self {
6455            Event::Down {
6456                ref serial,
6457                ref time,
6458                ref surface,
6459                ref id,
6460                ref x,
6461                ref y,
6462            } => {
6463                format!("wl_touch@{:?}::down(serial: {:?}, time: {:?}, surface: {:?}, id: {:?}, x: {:?}, y: {:?})", this, serial, time, surface, id, x, y)
6464            }
6465            Event::Up {
6466                ref serial,
6467                ref time,
6468                ref id,
6469            } => {
6470                format!("wl_touch@{:?}::up(serial: {:?}, time: {:?}, id: {:?})", this, serial, time, id)
6471            }
6472            Event::Motion {
6473                ref time,
6474                ref id,
6475                ref x,
6476                ref y,
6477            } => {
6478                format!("wl_touch@{:?}::motion(time: {:?}, id: {:?}, x: {:?}, y: {:?})", this, time, id, x, y)
6479            }
6480            Event::Frame {
6481            } => {
6482                format!("wl_touch@{:?}::frame()", this)
6483            }
6484            Event::Cancel {
6485            } => {
6486                format!("wl_touch@{:?}::cancel()", this)
6487            }
6488            Event::Shape {
6489                ref id,
6490                ref major,
6491                ref minor,
6492            } => {
6493                format!("wl_touch@{:?}::shape(id: {:?}, major: {:?}, minor: {:?})", this, id, major, minor)
6494            }
6495            Event::Orientation {
6496                ref id,
6497                ref orientation,
6498            } => {
6499                format!("wl_touch@{:?}::orientation(id: {:?}, orientation: {:?})", this, id, orientation)
6500            }
6501        }
6502    }
6503    fn message_name(&self) -> &'static std::ffi::CStr{
6504        match *self {
6505            Event::Down { .. } => c"wl_touch::down",
6506            Event::Up { .. } => c"wl_touch::up",
6507            Event::Motion { .. } => c"wl_touch::motion",
6508            Event::Frame { .. } => c"wl_touch::frame",
6509            Event::Cancel { .. } => c"wl_touch::cancel",
6510            Event::Shape { .. } => c"wl_touch::shape",
6511            Event::Orientation { .. } => c"wl_touch::orientation",
6512        }
6513    }
6514}
6515impl IntoMessage for Request {
6516    type Error = EncodeError;
6517    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
6518        let mut header = MessageHeader {
6519            sender: id,
6520            opcode: 0,
6521            length: 0,
6522        };
6523        let mut msg = Message::new();
6524        msg.write_header(&header)?;
6525        match self {
6526        Request::Release {
6527        } => {
6528            header.opcode = 0;
6529        },
6530        }
6531        header.length = msg.bytes().len() as u16;
6532        msg.rewind();
6533        msg.write_header(&header)?;
6534        Ok(msg)
6535    }
6536}
6537impl FromArgs for Event {
6538    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
6539        match op {
6540        0 /* down */ => {
6541            let mut iter = args.into_iter();
6542            Ok(Event::Down {
6543                serial: iter.next()
6544                                             .ok_or(DecodeError::InsufficientArgs)?
6545                                             .as_uint()?,
6546                time: iter.next()
6547                                             .ok_or(DecodeError::InsufficientArgs)?
6548                                             .as_uint()?,
6549                surface: iter.next()
6550                                             .ok_or(DecodeError::InsufficientArgs)?
6551                                             .as_object()?,
6552                id: iter.next()
6553                                             .ok_or(DecodeError::InsufficientArgs)?
6554                                             .as_int()?,
6555                x: iter.next()
6556                                             .ok_or(DecodeError::InsufficientArgs)?
6557                                             .as_fixed()?.into(),
6558                y: iter.next()
6559                                             .ok_or(DecodeError::InsufficientArgs)?
6560                                             .as_fixed()?.into(),
6561
6562            })
6563        },
6564        1 /* up */ => {
6565            let mut iter = args.into_iter();
6566            Ok(Event::Up {
6567                serial: iter.next()
6568                                             .ok_or(DecodeError::InsufficientArgs)?
6569                                             .as_uint()?,
6570                time: iter.next()
6571                                             .ok_or(DecodeError::InsufficientArgs)?
6572                                             .as_uint()?,
6573                id: iter.next()
6574                                             .ok_or(DecodeError::InsufficientArgs)?
6575                                             .as_int()?,
6576
6577            })
6578        },
6579        2 /* motion */ => {
6580            let mut iter = args.into_iter();
6581            Ok(Event::Motion {
6582                time: iter.next()
6583                                             .ok_or(DecodeError::InsufficientArgs)?
6584                                             .as_uint()?,
6585                id: iter.next()
6586                                             .ok_or(DecodeError::InsufficientArgs)?
6587                                             .as_int()?,
6588                x: iter.next()
6589                                             .ok_or(DecodeError::InsufficientArgs)?
6590                                             .as_fixed()?.into(),
6591                y: iter.next()
6592                                             .ok_or(DecodeError::InsufficientArgs)?
6593                                             .as_fixed()?.into(),
6594
6595            })
6596        },
6597        3 /* frame */ => {
6598            let mut iter = args.into_iter();
6599            Ok(Event::Frame {
6600
6601            })
6602        },
6603        4 /* cancel */ => {
6604            let mut iter = args.into_iter();
6605            Ok(Event::Cancel {
6606
6607            })
6608        },
6609        5 /* shape */ => {
6610            let mut iter = args.into_iter();
6611            Ok(Event::Shape {
6612                id: iter.next()
6613                                             .ok_or(DecodeError::InsufficientArgs)?
6614                                             .as_int()?,
6615                major: iter.next()
6616                                             .ok_or(DecodeError::InsufficientArgs)?
6617                                             .as_fixed()?.into(),
6618                minor: iter.next()
6619                                             .ok_or(DecodeError::InsufficientArgs)?
6620                                             .as_fixed()?.into(),
6621
6622            })
6623        },
6624        6 /* orientation */ => {
6625            let mut iter = args.into_iter();
6626            Ok(Event::Orientation {
6627                id: iter.next()
6628                                             .ok_or(DecodeError::InsufficientArgs)?
6629                                             .as_int()?,
6630                orientation: iter.next()
6631                                             .ok_or(DecodeError::InsufficientArgs)?
6632                                             .as_fixed()?.into(),
6633
6634            })
6635        },
6636        _ => {
6637            Err(DecodeError::InvalidOpcode(op).into())
6638        },
6639        }
6640    }
6641}
6642} // mod wl_touch
6643
6644pub use crate::wl_touch::WlTouch;
6645pub use crate::wl_touch::Request as WlTouchRequest;
6646pub use crate::wl_touch::Event as WlTouchEvent;
6647pub mod wl_output {
6648use super::*;
6649
6650/// compositor output region
6651///
6652/// An output describes part of the compositor geometry.  The
6653/// compositor works in the 'compositor coordinate system' and an
6654/// output corresponds to a rectangular area in that space that is
6655/// actually visible.  This typically corresponds to a monitor that
6656/// displays part of the compositor space.  This object is published
6657/// as global during start up, or when a monitor is hotplugged.
6658#[derive(Debug)]
6659pub struct WlOutput;
6660
6661impl Interface for WlOutput {
6662    const NAME: &'static str = "wl_output";
6663    const VERSION: u32 = 3;
6664    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
6665        // release
6666        MessageSpec(&[
6667        ]),
6668    ]);
6669    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
6670        // geometry
6671        MessageSpec(&[
6672            ArgKind::Int,
6673            ArgKind::Int,
6674            ArgKind::Int,
6675            ArgKind::Int,
6676            ArgKind::Uint,
6677            ArgKind::String,
6678            ArgKind::String,
6679            ArgKind::Uint,
6680        ]),
6681        // mode
6682        MessageSpec(&[
6683            ArgKind::Uint,
6684            ArgKind::Int,
6685            ArgKind::Int,
6686            ArgKind::Int,
6687        ]),
6688        // done
6689        MessageSpec(&[
6690        ]),
6691        // scale
6692        MessageSpec(&[
6693            ArgKind::Int,
6694        ]),
6695    ]);
6696    type Incoming = Event;
6697    type Outgoing = Request;
6698}
6699
6700#[derive(Debug)]
6701pub enum Request {
6702
6703    /// release the output object
6704    ///
6705    /// Using this request a client can tell the server that it is not going to
6706    /// use the output object anymore.
6707    Release,
6708}
6709
6710impl MessageType for Request {
6711    fn log(&self, this: ObjectId) -> String {
6712        match *self {
6713            Request::Release {
6714            } => {
6715                format!("wl_output@{:?}::release()", this)
6716            }
6717        }
6718    }
6719    fn message_name(&self) -> &'static std::ffi::CStr{
6720        match *self {
6721            Request::Release { .. } => c"wl_output::release",
6722        }
6723    }
6724}
6725#[derive(Debug)]
6726pub enum Event {
6727
6728    /// properties of the output
6729    ///
6730    /// The geometry event describes geometric properties of the output.
6731    /// The event is sent when binding to the output object and whenever
6732    /// any of the properties change.
6733    /// 
6734    /// The physical size can be set to zero if it doesn't make sense for this
6735    /// output (e.g. for projectors or virtual outputs).
6736    /// 
6737    /// Note: wl_output only advertises partial information about the output
6738    /// position and identification. Some compositors, for instance those not
6739    /// implementing a desktop-style output layout or those exposing virtual
6740    /// outputs, might fake this information. Instead of using x and y, clients
6741    /// should use xdg_output.logical_position. Instead of using make and model,
6742    /// clients should use xdg_output.name and xdg_output.description.
6743    Geometry {
6744        /// x position within the global compositor space
6745        x: i32,
6746        /// y position within the global compositor space
6747        y: i32,
6748        /// width in millimeters of the output
6749        physical_width: i32,
6750        /// height in millimeters of the output
6751        physical_height: i32,
6752        /// subpixel orientation of the output
6753        subpixel: Enum<Subpixel>,
6754        /// textual description of the manufacturer
6755        make: String,
6756        /// textual description of the model
6757        model: String,
6758        /// transform that maps framebuffer to output
6759        transform: Enum<Transform>,
6760    },
6761
6762    /// advertise available modes for the output
6763    ///
6764    /// The mode event describes an available mode for the output.
6765    /// 
6766    /// The event is sent when binding to the output object and there
6767    /// will always be one mode, the current mode.  The event is sent
6768    /// again if an output changes mode, for the mode that is now
6769    /// current.  In other words, the current mode is always the last
6770    /// mode that was received with the current flag set.
6771    /// 
6772    /// The size of a mode is given in physical hardware units of
6773    /// the output device. This is not necessarily the same as
6774    /// the output size in the global compositor space. For instance,
6775    /// the output may be scaled, as described in wl_output.scale,
6776    /// or transformed, as described in wl_output.transform. Clients
6777    /// willing to retrieve the output size in the global compositor
6778    /// space should use xdg_output.logical_size instead.
6779    /// 
6780    /// The vertical refresh rate can be set to zero if it doesn't make
6781    /// sense for this output (e.g. for virtual outputs).
6782    /// 
6783    /// Clients should not use the refresh rate to schedule frames. Instead,
6784    /// they should use the wl_surface.frame event or the presentation-time
6785    /// protocol.
6786    /// 
6787    /// Note: this information is not always meaningful for all outputs. Some
6788    /// compositors, such as those exposing virtual outputs, might fake the
6789    /// refresh rate or the size.
6790    Mode {
6791        /// bitfield of mode flags
6792        flags: Enum<Mode>,
6793        /// width of the mode in hardware units
6794        width: i32,
6795        /// height of the mode in hardware units
6796        height: i32,
6797        /// vertical refresh rate in mHz
6798        refresh: i32,
6799    },
6800
6801    /// sent all information about output
6802    ///
6803    /// This event is sent after all other properties have been
6804    /// sent after binding to the output object and after any
6805    /// other property changes done after that. This allows
6806    /// changes to the output properties to be seen as
6807    /// atomic, even if they happen via multiple events.
6808    Done,
6809
6810    /// output scaling properties
6811    ///
6812    /// This event contains scaling geometry information
6813    /// that is not in the geometry event. It may be sent after
6814    /// binding the output object or if the output scale changes
6815    /// later. If it is not sent, the client should assume a
6816    /// scale of 1.
6817    /// 
6818    /// A scale larger than 1 means that the compositor will
6819    /// automatically scale surface buffers by this amount
6820    /// when rendering. This is used for very high resolution
6821    /// displays where applications rendering at the native
6822    /// resolution would be too small to be legible.
6823    /// 
6824    /// It is intended that scaling aware clients track the
6825    /// current output of a surface, and if it is on a scaled
6826    /// output it should use wl_surface.set_buffer_scale with
6827    /// the scale of the output. That way the compositor can
6828    /// avoid scaling the surface, and the client can supply
6829    /// a higher detail image.
6830    Scale {
6831        /// scaling factor of output
6832        factor: i32,
6833    },
6834}
6835
6836impl MessageType for Event {
6837    fn log(&self, this: ObjectId) -> String {
6838        match *self {
6839            Event::Geometry {
6840                ref x,
6841                ref y,
6842                ref physical_width,
6843                ref physical_height,
6844                ref subpixel,
6845                ref make,
6846                ref model,
6847                ref transform,
6848            } => {
6849                format!("wl_output@{:?}::geometry(x: {:?}, y: {:?}, physical_width: {:?}, physical_height: {:?}, subpixel: {:?}, make: {:?}, model: {:?}, transform: {:?})", this, x, y, physical_width, physical_height, subpixel, make, model, transform)
6850            }
6851            Event::Mode {
6852                ref flags,
6853                ref width,
6854                ref height,
6855                ref refresh,
6856            } => {
6857                format!("wl_output@{:?}::mode(flags: {:?}, width: {:?}, height: {:?}, refresh: {:?})", this, flags, width, height, refresh)
6858            }
6859            Event::Done {
6860            } => {
6861                format!("wl_output@{:?}::done()", this)
6862            }
6863            Event::Scale {
6864                ref factor,
6865            } => {
6866                format!("wl_output@{:?}::scale(factor: {:?})", this, factor)
6867            }
6868        }
6869    }
6870    fn message_name(&self) -> &'static std::ffi::CStr{
6871        match *self {
6872            Event::Geometry { .. } => c"wl_output::geometry",
6873            Event::Mode { .. } => c"wl_output::mode",
6874            Event::Done { .. } => c"wl_output::done",
6875            Event::Scale { .. } => c"wl_output::scale",
6876        }
6877    }
6878}
6879impl IntoMessage for Request {
6880    type Error = EncodeError;
6881    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
6882        let mut header = MessageHeader {
6883            sender: id,
6884            opcode: 0,
6885            length: 0,
6886        };
6887        let mut msg = Message::new();
6888        msg.write_header(&header)?;
6889        match self {
6890        Request::Release {
6891        } => {
6892            header.opcode = 0;
6893        },
6894        }
6895        header.length = msg.bytes().len() as u16;
6896        msg.rewind();
6897        msg.write_header(&header)?;
6898        Ok(msg)
6899    }
6900}
6901impl FromArgs for Event {
6902    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
6903        match op {
6904        0 /* geometry */ => {
6905            let mut iter = args.into_iter();
6906            Ok(Event::Geometry {
6907                x: iter.next()
6908                                             .ok_or(DecodeError::InsufficientArgs)?
6909                                             .as_int()?,
6910                y: iter.next()
6911                                             .ok_or(DecodeError::InsufficientArgs)?
6912                                             .as_int()?,
6913                physical_width: iter.next()
6914                                             .ok_or(DecodeError::InsufficientArgs)?
6915                                             .as_int()?,
6916                physical_height: iter.next()
6917                                             .ok_or(DecodeError::InsufficientArgs)?
6918                                             .as_int()?,
6919                subpixel: iter.next()
6920                                             .ok_or(DecodeError::InsufficientArgs)?
6921                                             .as_uint().map(|i| match Subpixel::from_bits(i) {
6922                                      Some(e) => Enum::Recognized(e),
6923                                      None => Enum::Unrecognized(i),
6924                                 })?,
6925                make: iter.next()
6926                                             .ok_or(DecodeError::InsufficientArgs)?
6927                                             .as_string()?,
6928                model: iter.next()
6929                                             .ok_or(DecodeError::InsufficientArgs)?
6930                                             .as_string()?,
6931                transform: iter.next()
6932                                             .ok_or(DecodeError::InsufficientArgs)?
6933                                             .as_uint().map(|i| match Transform::from_bits(i) {
6934                                      Some(e) => Enum::Recognized(e),
6935                                      None => Enum::Unrecognized(i),
6936                                 })?,
6937
6938            })
6939        },
6940        1 /* mode */ => {
6941            let mut iter = args.into_iter();
6942            Ok(Event::Mode {
6943                flags: iter.next()
6944                                             .ok_or(DecodeError::InsufficientArgs)?
6945                                             .as_uint().map(|i| match Mode::from_bits(i) {
6946                                      Some(e) => Enum::Recognized(e),
6947                                      None => Enum::Unrecognized(i),
6948                                 })?,
6949                width: iter.next()
6950                                             .ok_or(DecodeError::InsufficientArgs)?
6951                                             .as_int()?,
6952                height: iter.next()
6953                                             .ok_or(DecodeError::InsufficientArgs)?
6954                                             .as_int()?,
6955                refresh: iter.next()
6956                                             .ok_or(DecodeError::InsufficientArgs)?
6957                                             .as_int()?,
6958
6959            })
6960        },
6961        2 /* done */ => {
6962            let mut iter = args.into_iter();
6963            Ok(Event::Done {
6964
6965            })
6966        },
6967        3 /* scale */ => {
6968            let mut iter = args.into_iter();
6969            Ok(Event::Scale {
6970                factor: iter.next()
6971                                             .ok_or(DecodeError::InsufficientArgs)?
6972                                             .as_int()?,
6973
6974            })
6975        },
6976        _ => {
6977            Err(DecodeError::InvalidOpcode(op).into())
6978        },
6979        }
6980    }
6981}
6982
6983/// subpixel geometry information
6984///
6985/// This enumeration describes how the physical
6986/// pixels on an output are laid out.
6987#[derive(Copy, Clone, Debug, Eq, PartialEq)]
6988#[repr(u32)]
6989pub enum Subpixel {
6990    /// unknown geometry,
6991    Unknown = 0,
6992    /// no geometry,
6993    None = 1,
6994    /// horizontal RGB,
6995    HorizontalRgb = 2,
6996    /// horizontal BGR,
6997    HorizontalBgr = 3,
6998    /// vertical RGB,
6999    VerticalRgb = 4,
7000    /// vertical BGR,
7001    VerticalBgr = 5,
7002}
7003
7004impl Subpixel {
7005    pub fn from_bits(v: u32) -> Option<Self> {
7006        match v {
7007        0 => Some(Subpixel::Unknown),
7008        1 => Some(Subpixel::None),
7009        2 => Some(Subpixel::HorizontalRgb),
7010        3 => Some(Subpixel::HorizontalBgr),
7011        4 => Some(Subpixel::VerticalRgb),
7012        5 => Some(Subpixel::VerticalBgr),
7013        _ => None,
7014        }
7015    }
7016
7017    pub fn bits(&self) -> u32 {
7018        *self as u32
7019    }
7020}
7021impl Into<Arg> for Subpixel {
7022    fn into(self) -> Arg {
7023        Arg::Uint(self.bits())
7024    }
7025}
7026
7027/// transform from framebuffer to output
7028///
7029/// This describes the transform that a compositor will apply to a
7030/// surface to compensate for the rotation or mirroring of an
7031/// output device.
7032/// 
7033/// The flipped values correspond to an initial flip around a
7034/// vertical axis followed by rotation.
7035/// 
7036/// The purpose is mainly to allow clients to render accordingly and
7037/// tell the compositor, so that for fullscreen surfaces, the
7038/// compositor will still be able to scan out directly from client
7039/// surfaces.
7040#[derive(Copy, Clone, Debug, Eq, PartialEq)]
7041#[repr(u32)]
7042pub enum Transform {
7043    /// no transform,
7044    Normal = 0,
7045    /// 90 degrees counter-clockwise,
7046    _90 = 1,
7047    /// 180 degrees counter-clockwise,
7048    _180 = 2,
7049    /// 270 degrees counter-clockwise,
7050    _270 = 3,
7051    /// 180 degree flip around a vertical axis,
7052    Flipped = 4,
7053    /// flip and rotate 90 degrees counter-clockwise,
7054    Flipped90 = 5,
7055    /// flip and rotate 180 degrees counter-clockwise,
7056    Flipped180 = 6,
7057    /// flip and rotate 270 degrees counter-clockwise,
7058    Flipped270 = 7,
7059}
7060
7061impl Transform {
7062    pub fn from_bits(v: u32) -> Option<Self> {
7063        match v {
7064        0 => Some(Transform::Normal),
7065        1 => Some(Transform::_90),
7066        2 => Some(Transform::_180),
7067        3 => Some(Transform::_270),
7068        4 => Some(Transform::Flipped),
7069        5 => Some(Transform::Flipped90),
7070        6 => Some(Transform::Flipped180),
7071        7 => Some(Transform::Flipped270),
7072        _ => None,
7073        }
7074    }
7075
7076    pub fn bits(&self) -> u32 {
7077        *self as u32
7078    }
7079}
7080impl Into<Arg> for Transform {
7081    fn into(self) -> Arg {
7082        Arg::Uint(self.bits())
7083    }
7084}
7085::bitflags::bitflags! {
7086
7087    /// mode information
7088    ///
7089    /// These flags describe properties of an output mode.
7090    /// They are used in the flags bitfield of the mode event.
7091    #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
7092    pub struct Mode: u32 {
7093        /// indicates this is the current mode,
7094        const Current = 1;
7095        /// indicates this is the preferred mode,
7096        const Preferred = 2;
7097    }
7098}
7099impl Into<Arg> for Mode {
7100    fn into(self) -> Arg {
7101        Arg::Uint(self.bits())
7102    }
7103}
7104} // mod wl_output
7105
7106pub use crate::wl_output::WlOutput;
7107pub use crate::wl_output::Request as WlOutputRequest;
7108pub use crate::wl_output::Event as WlOutputEvent;
7109pub mod wl_region {
7110use super::*;
7111
7112/// region interface
7113///
7114/// A region object describes an area.
7115/// 
7116/// Region objects are used to describe the opaque and input
7117/// regions of a surface.
7118#[derive(Debug)]
7119pub struct WlRegion;
7120
7121impl Interface for WlRegion {
7122    const NAME: &'static str = "wl_region";
7123    const VERSION: u32 = 1;
7124    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
7125        // destroy
7126        MessageSpec(&[
7127        ]),
7128        // add
7129        MessageSpec(&[
7130            ArgKind::Int,
7131            ArgKind::Int,
7132            ArgKind::Int,
7133            ArgKind::Int,
7134        ]),
7135        // subtract
7136        MessageSpec(&[
7137            ArgKind::Int,
7138            ArgKind::Int,
7139            ArgKind::Int,
7140            ArgKind::Int,
7141        ]),
7142    ]);
7143    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
7144    ]);
7145    type Incoming = Event;
7146    type Outgoing = Request;
7147}
7148
7149#[derive(Debug)]
7150pub enum Request {
7151
7152    /// destroy region
7153    ///
7154    /// Destroy the region.  This will invalidate the object ID.
7155    Destroy,
7156
7157    /// add rectangle to region
7158    ///
7159    /// Add the specified rectangle to the region.
7160    Add {
7161        /// region-local x coordinate
7162        x: i32,
7163        /// region-local y coordinate
7164        y: i32,
7165        /// rectangle width
7166        width: i32,
7167        /// rectangle height
7168        height: i32,
7169    },
7170
7171    /// subtract rectangle from region
7172    ///
7173    /// Subtract the specified rectangle from the region.
7174    Subtract {
7175        /// region-local x coordinate
7176        x: i32,
7177        /// region-local y coordinate
7178        y: i32,
7179        /// rectangle width
7180        width: i32,
7181        /// rectangle height
7182        height: i32,
7183    },
7184}
7185
7186impl MessageType for Request {
7187    fn log(&self, this: ObjectId) -> String {
7188        match *self {
7189            Request::Destroy {
7190            } => {
7191                format!("wl_region@{:?}::destroy()", this)
7192            }
7193            Request::Add {
7194                ref x,
7195                ref y,
7196                ref width,
7197                ref height,
7198            } => {
7199                format!("wl_region@{:?}::add(x: {:?}, y: {:?}, width: {:?}, height: {:?})", this, x, y, width, height)
7200            }
7201            Request::Subtract {
7202                ref x,
7203                ref y,
7204                ref width,
7205                ref height,
7206            } => {
7207                format!("wl_region@{:?}::subtract(x: {:?}, y: {:?}, width: {:?}, height: {:?})", this, x, y, width, height)
7208            }
7209        }
7210    }
7211    fn message_name(&self) -> &'static std::ffi::CStr{
7212        match *self {
7213            Request::Destroy { .. } => c"wl_region::destroy",
7214            Request::Add { .. } => c"wl_region::add",
7215            Request::Subtract { .. } => c"wl_region::subtract",
7216        }
7217    }
7218}
7219#[derive(Debug)]
7220pub enum Event {
7221}
7222
7223impl MessageType for Event {
7224    fn log(&self, this: ObjectId) -> String {
7225        match *self {
7226        }
7227    }
7228    fn message_name(&self) -> &'static std::ffi::CStr{
7229        match *self {
7230        }
7231    }
7232}
7233impl IntoMessage for Request {
7234    type Error = EncodeError;
7235    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
7236        let mut header = MessageHeader {
7237            sender: id,
7238            opcode: 0,
7239            length: 0,
7240        };
7241        let mut msg = Message::new();
7242        msg.write_header(&header)?;
7243        match self {
7244        Request::Destroy {
7245        } => {
7246            header.opcode = 0;
7247        },
7248        Request::Add {
7249            x,
7250            y,
7251            width,
7252            height,
7253        } => {
7254            msg.write_arg(Arg::Int(x))?;
7255            msg.write_arg(Arg::Int(y))?;
7256            msg.write_arg(Arg::Int(width))?;
7257            msg.write_arg(Arg::Int(height))?;
7258            header.opcode = 1;
7259        },
7260        Request::Subtract {
7261            x,
7262            y,
7263            width,
7264            height,
7265        } => {
7266            msg.write_arg(Arg::Int(x))?;
7267            msg.write_arg(Arg::Int(y))?;
7268            msg.write_arg(Arg::Int(width))?;
7269            msg.write_arg(Arg::Int(height))?;
7270            header.opcode = 2;
7271        },
7272        }
7273        header.length = msg.bytes().len() as u16;
7274        msg.rewind();
7275        msg.write_header(&header)?;
7276        Ok(msg)
7277    }
7278}
7279impl FromArgs for Event {
7280    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
7281        match op {
7282        _ => {
7283            Err(DecodeError::InvalidOpcode(op).into())
7284        },
7285        }
7286    }
7287}
7288} // mod wl_region
7289
7290pub use crate::wl_region::WlRegion;
7291pub use crate::wl_region::Request as WlRegionRequest;
7292pub use crate::wl_region::Event as WlRegionEvent;
7293pub mod wl_subcompositor {
7294use super::*;
7295
7296/// sub-surface compositing
7297///
7298/// The global interface exposing sub-surface compositing capabilities.
7299/// A wl_surface, that has sub-surfaces associated, is called the
7300/// parent surface. Sub-surfaces can be arbitrarily nested and create
7301/// a tree of sub-surfaces.
7302/// 
7303/// The root surface in a tree of sub-surfaces is the main
7304/// surface. The main surface cannot be a sub-surface, because
7305/// sub-surfaces must always have a parent.
7306/// 
7307/// A main surface with its sub-surfaces forms a (compound) window.
7308/// For window management purposes, this set of wl_surface objects is
7309/// to be considered as a single window, and it should also behave as
7310/// such.
7311/// 
7312/// The aim of sub-surfaces is to offload some of the compositing work
7313/// within a window from clients to the compositor. A prime example is
7314/// a video player with decorations and video in separate wl_surface
7315/// objects. This should allow the compositor to pass YUV video buffer
7316/// processing to dedicated overlay hardware when possible.
7317#[derive(Debug)]
7318pub struct WlSubcompositor;
7319
7320impl Interface for WlSubcompositor {
7321    const NAME: &'static str = "wl_subcompositor";
7322    const VERSION: u32 = 1;
7323    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
7324        // destroy
7325        MessageSpec(&[
7326        ]),
7327        // get_subsurface
7328        MessageSpec(&[
7329            ArgKind::NewId,
7330            ArgKind::Object,
7331            ArgKind::Object,
7332        ]),
7333    ]);
7334    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
7335    ]);
7336    type Incoming = Event;
7337    type Outgoing = Request;
7338}
7339
7340#[derive(Debug)]
7341pub enum Request {
7342
7343    /// unbind from the subcompositor interface
7344    ///
7345    /// Informs the server that the client will not be using this
7346    /// protocol object anymore. This does not affect any other
7347    /// objects, wl_subsurface objects included.
7348    Destroy,
7349
7350    /// give a surface the role sub-surface
7351    ///
7352    /// Create a sub-surface interface for the given surface, and
7353    /// associate it with the given parent surface. This turns a
7354    /// plain wl_surface into a sub-surface.
7355    /// 
7356    /// The to-be sub-surface must not already have another role, and it
7357    /// must not have an existing wl_subsurface object. Otherwise a protocol
7358    /// error is raised.
7359    /// 
7360    /// Adding sub-surfaces to a parent is a double-buffered operation on the
7361    /// parent (see wl_surface.commit). The effect of adding a sub-surface
7362    /// becomes visible on the next time the state of the parent surface is
7363    /// applied.
7364    /// 
7365    /// This request modifies the behaviour of wl_surface.commit request on
7366    /// the sub-surface, see the documentation on wl_subsurface interface.
7367    GetSubsurface {
7368        /// the new sub-surface object ID
7369        id: NewId,
7370        /// the surface to be turned into a sub-surface
7371        surface: ObjectId,
7372        /// the parent surface
7373        parent: ObjectId,
7374    },
7375}
7376
7377impl MessageType for Request {
7378    fn log(&self, this: ObjectId) -> String {
7379        match *self {
7380            Request::Destroy {
7381            } => {
7382                format!("wl_subcompositor@{:?}::destroy()", this)
7383            }
7384            Request::GetSubsurface {
7385                ref id,
7386                ref surface,
7387                ref parent,
7388            } => {
7389                format!("wl_subcompositor@{:?}::get_subsurface(id: {:?}, surface: {:?}, parent: {:?})", this, id, surface, parent)
7390            }
7391        }
7392    }
7393    fn message_name(&self) -> &'static std::ffi::CStr{
7394        match *self {
7395            Request::Destroy { .. } => c"wl_subcompositor::destroy",
7396            Request::GetSubsurface { .. } => c"wl_subcompositor::get_subsurface",
7397        }
7398    }
7399}
7400#[derive(Debug)]
7401pub enum Event {
7402}
7403
7404impl MessageType for Event {
7405    fn log(&self, this: ObjectId) -> String {
7406        match *self {
7407        }
7408    }
7409    fn message_name(&self) -> &'static std::ffi::CStr{
7410        match *self {
7411        }
7412    }
7413}
7414impl IntoMessage for Request {
7415    type Error = EncodeError;
7416    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
7417        let mut header = MessageHeader {
7418            sender: id,
7419            opcode: 0,
7420            length: 0,
7421        };
7422        let mut msg = Message::new();
7423        msg.write_header(&header)?;
7424        match self {
7425        Request::Destroy {
7426        } => {
7427            header.opcode = 0;
7428        },
7429        Request::GetSubsurface {
7430            id,
7431            surface,
7432            parent,
7433        } => {
7434            msg.write_arg(Arg::NewId(id))?;
7435            msg.write_arg(Arg::Object(surface))?;
7436            msg.write_arg(Arg::Object(parent))?;
7437            header.opcode = 1;
7438        },
7439        }
7440        header.length = msg.bytes().len() as u16;
7441        msg.rewind();
7442        msg.write_header(&header)?;
7443        Ok(msg)
7444    }
7445}
7446impl FromArgs for Event {
7447    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
7448        match op {
7449        _ => {
7450            Err(DecodeError::InvalidOpcode(op).into())
7451        },
7452        }
7453    }
7454}
7455#[derive(Copy, Clone, Debug, Eq, PartialEq)]
7456#[repr(u32)]
7457pub enum Error {
7458    /// the to-be sub-surface is invalid,
7459    BadSurface = 0,
7460}
7461
7462impl Error {
7463    pub fn from_bits(v: u32) -> Option<Self> {
7464        match v {
7465        0 => Some(Error::BadSurface),
7466        _ => None,
7467        }
7468    }
7469
7470    pub fn bits(&self) -> u32 {
7471        *self as u32
7472    }
7473}
7474impl Into<Arg> for Error {
7475    fn into(self) -> Arg {
7476        Arg::Uint(self.bits())
7477    }
7478}
7479} // mod wl_subcompositor
7480
7481pub use crate::wl_subcompositor::WlSubcompositor;
7482pub use crate::wl_subcompositor::Request as WlSubcompositorRequest;
7483pub use crate::wl_subcompositor::Event as WlSubcompositorEvent;
7484pub mod wl_subsurface {
7485use super::*;
7486
7487/// sub-surface interface to a wl_surface
7488///
7489/// An additional interface to a wl_surface object, which has been
7490/// made a sub-surface. A sub-surface has one parent surface. A
7491/// sub-surface's size and position are not limited to that of the parent.
7492/// Particularly, a sub-surface is not automatically clipped to its
7493/// parent's area.
7494/// 
7495/// A sub-surface becomes mapped, when a non-NULL wl_buffer is applied
7496/// and the parent surface is mapped. The order of which one happens
7497/// first is irrelevant. A sub-surface is hidden if the parent becomes
7498/// hidden, or if a NULL wl_buffer is applied. These rules apply
7499/// recursively through the tree of surfaces.
7500/// 
7501/// The behaviour of a wl_surface.commit request on a sub-surface
7502/// depends on the sub-surface's mode. The possible modes are
7503/// synchronized and desynchronized, see methods
7504/// wl_subsurface.set_sync and wl_subsurface.set_desync. Synchronized
7505/// mode caches the wl_surface state to be applied when the parent's
7506/// state gets applied, and desynchronized mode applies the pending
7507/// wl_surface state directly. A sub-surface is initially in the
7508/// synchronized mode.
7509/// 
7510/// Sub-surfaces also have another kind of state, which is managed by
7511/// wl_subsurface requests, as opposed to wl_surface requests. This
7512/// state includes the sub-surface position relative to the parent
7513/// surface (wl_subsurface.set_position), and the stacking order of
7514/// the parent and its sub-surfaces (wl_subsurface.place_above and
7515/// .place_below). This state is applied when the parent surface's
7516/// wl_surface state is applied, regardless of the sub-surface's mode.
7517/// As the exception, set_sync and set_desync are effective immediately.
7518/// 
7519/// The main surface can be thought to be always in desynchronized mode,
7520/// since it does not have a parent in the sub-surfaces sense.
7521/// 
7522/// Even if a sub-surface is in desynchronized mode, it will behave as
7523/// in synchronized mode, if its parent surface behaves as in
7524/// synchronized mode. This rule is applied recursively throughout the
7525/// tree of surfaces. This means, that one can set a sub-surface into
7526/// synchronized mode, and then assume that all its child and grand-child
7527/// sub-surfaces are synchronized, too, without explicitly setting them.
7528/// 
7529/// If the wl_surface associated with the wl_subsurface is destroyed, the
7530/// wl_subsurface object becomes inert. Note, that destroying either object
7531/// takes effect immediately. If you need to synchronize the removal
7532/// of a sub-surface to the parent surface update, unmap the sub-surface
7533/// first by attaching a NULL wl_buffer, update parent, and then destroy
7534/// the sub-surface.
7535/// 
7536/// If the parent wl_surface object is destroyed, the sub-surface is
7537/// unmapped.
7538#[derive(Debug)]
7539pub struct WlSubsurface;
7540
7541impl Interface for WlSubsurface {
7542    const NAME: &'static str = "wl_subsurface";
7543    const VERSION: u32 = 1;
7544    const REQUESTS: MessageGroupSpec = MessageGroupSpec(&[
7545        // destroy
7546        MessageSpec(&[
7547        ]),
7548        // set_position
7549        MessageSpec(&[
7550            ArgKind::Int,
7551            ArgKind::Int,
7552        ]),
7553        // place_above
7554        MessageSpec(&[
7555            ArgKind::Object,
7556        ]),
7557        // place_below
7558        MessageSpec(&[
7559            ArgKind::Object,
7560        ]),
7561        // set_sync
7562        MessageSpec(&[
7563        ]),
7564        // set_desync
7565        MessageSpec(&[
7566        ]),
7567    ]);
7568    const EVENTS: MessageGroupSpec = MessageGroupSpec(&[
7569    ]);
7570    type Incoming = Event;
7571    type Outgoing = Request;
7572}
7573
7574#[derive(Debug)]
7575pub enum Request {
7576
7577    /// remove sub-surface interface
7578    ///
7579    /// The sub-surface interface is removed from the wl_surface object
7580    /// that was turned into a sub-surface with a
7581    /// wl_subcompositor.get_subsurface request. The wl_surface's association
7582    /// to the parent is deleted, and the wl_surface loses its role as
7583    /// a sub-surface. The wl_surface is unmapped immediately.
7584    Destroy,
7585
7586    /// reposition the sub-surface
7587    ///
7588    /// This schedules a sub-surface position change.
7589    /// The sub-surface will be moved so that its origin (top left
7590    /// corner pixel) will be at the location x, y of the parent surface
7591    /// coordinate system. The coordinates are not restricted to the parent
7592    /// surface area. Negative values are allowed.
7593    /// 
7594    /// The scheduled coordinates will take effect whenever the state of the
7595    /// parent surface is applied. When this happens depends on whether the
7596    /// parent surface is in synchronized mode or not. See
7597    /// wl_subsurface.set_sync and wl_subsurface.set_desync for details.
7598    /// 
7599    /// If more than one set_position request is invoked by the client before
7600    /// the commit of the parent surface, the position of a new request always
7601    /// replaces the scheduled position from any previous request.
7602    /// 
7603    /// The initial position is 0, 0.
7604    SetPosition {
7605        /// x coordinate in the parent surface
7606        x: i32,
7607        /// y coordinate in the parent surface
7608        y: i32,
7609    },
7610
7611    /// restack the sub-surface
7612    ///
7613    /// This sub-surface is taken from the stack, and put back just
7614    /// above the reference surface, changing the z-order of the sub-surfaces.
7615    /// The reference surface must be one of the sibling surfaces, or the
7616    /// parent surface. Using any other surface, including this sub-surface,
7617    /// will cause a protocol error.
7618    /// 
7619    /// The z-order is double-buffered. Requests are handled in order and
7620    /// applied immediately to a pending state. The final pending state is
7621    /// copied to the active state the next time the state of the parent
7622    /// surface is applied. When this happens depends on whether the parent
7623    /// surface is in synchronized mode or not. See wl_subsurface.set_sync and
7624    /// wl_subsurface.set_desync for details.
7625    /// 
7626    /// A new sub-surface is initially added as the top-most in the stack
7627    /// of its siblings and parent.
7628    PlaceAbove {
7629        /// the reference surface
7630        sibling: ObjectId,
7631    },
7632
7633    /// restack the sub-surface
7634    ///
7635    /// The sub-surface is placed just below the reference surface.
7636    /// See wl_subsurface.place_above.
7637    PlaceBelow {
7638        /// the reference surface
7639        sibling: ObjectId,
7640    },
7641
7642    /// set sub-surface to synchronized mode
7643    ///
7644    /// Change the commit behaviour of the sub-surface to synchronized
7645    /// mode, also described as the parent dependent mode.
7646    /// 
7647    /// In synchronized mode, wl_surface.commit on a sub-surface will
7648    /// accumulate the committed state in a cache, but the state will
7649    /// not be applied and hence will not change the compositor output.
7650    /// The cached state is applied to the sub-surface immediately after
7651    /// the parent surface's state is applied. This ensures atomic
7652    /// updates of the parent and all its synchronized sub-surfaces.
7653    /// Applying the cached state will invalidate the cache, so further
7654    /// parent surface commits do not (re-)apply old state.
7655    /// 
7656    /// See wl_subsurface for the recursive effect of this mode.
7657    SetSync,
7658
7659    /// set sub-surface to desynchronized mode
7660    ///
7661    /// Change the commit behaviour of the sub-surface to desynchronized
7662    /// mode, also described as independent or freely running mode.
7663    /// 
7664    /// In desynchronized mode, wl_surface.commit on a sub-surface will
7665    /// apply the pending state directly, without caching, as happens
7666    /// normally with a wl_surface. Calling wl_surface.commit on the
7667    /// parent surface has no effect on the sub-surface's wl_surface
7668    /// state. This mode allows a sub-surface to be updated on its own.
7669    /// 
7670    /// If cached state exists when wl_surface.commit is called in
7671    /// desynchronized mode, the pending state is added to the cached
7672    /// state, and applied as a whole. This invalidates the cache.
7673    /// 
7674    /// Note: even if a sub-surface is set to desynchronized, a parent
7675    /// sub-surface may override it to behave as synchronized. For details,
7676    /// see wl_subsurface.
7677    /// 
7678    /// If a surface's parent surface behaves as desynchronized, then
7679    /// the cached state is applied on set_desync.
7680    SetDesync,
7681}
7682
7683impl MessageType for Request {
7684    fn log(&self, this: ObjectId) -> String {
7685        match *self {
7686            Request::Destroy {
7687            } => {
7688                format!("wl_subsurface@{:?}::destroy()", this)
7689            }
7690            Request::SetPosition {
7691                ref x,
7692                ref y,
7693            } => {
7694                format!("wl_subsurface@{:?}::set_position(x: {:?}, y: {:?})", this, x, y)
7695            }
7696            Request::PlaceAbove {
7697                ref sibling,
7698            } => {
7699                format!("wl_subsurface@{:?}::place_above(sibling: {:?})", this, sibling)
7700            }
7701            Request::PlaceBelow {
7702                ref sibling,
7703            } => {
7704                format!("wl_subsurface@{:?}::place_below(sibling: {:?})", this, sibling)
7705            }
7706            Request::SetSync {
7707            } => {
7708                format!("wl_subsurface@{:?}::set_sync()", this)
7709            }
7710            Request::SetDesync {
7711            } => {
7712                format!("wl_subsurface@{:?}::set_desync()", this)
7713            }
7714        }
7715    }
7716    fn message_name(&self) -> &'static std::ffi::CStr{
7717        match *self {
7718            Request::Destroy { .. } => c"wl_subsurface::destroy",
7719            Request::SetPosition { .. } => c"wl_subsurface::set_position",
7720            Request::PlaceAbove { .. } => c"wl_subsurface::place_above",
7721            Request::PlaceBelow { .. } => c"wl_subsurface::place_below",
7722            Request::SetSync { .. } => c"wl_subsurface::set_sync",
7723            Request::SetDesync { .. } => c"wl_subsurface::set_desync",
7724        }
7725    }
7726}
7727#[derive(Debug)]
7728pub enum Event {
7729}
7730
7731impl MessageType for Event {
7732    fn log(&self, this: ObjectId) -> String {
7733        match *self {
7734        }
7735    }
7736    fn message_name(&self) -> &'static std::ffi::CStr{
7737        match *self {
7738        }
7739    }
7740}
7741impl IntoMessage for Request {
7742    type Error = EncodeError;
7743    fn into_message(self, id: u32) -> Result<Message, <Self as IntoMessage>::Error> {
7744        let mut header = MessageHeader {
7745            sender: id,
7746            opcode: 0,
7747            length: 0,
7748        };
7749        let mut msg = Message::new();
7750        msg.write_header(&header)?;
7751        match self {
7752        Request::Destroy {
7753        } => {
7754            header.opcode = 0;
7755        },
7756        Request::SetPosition {
7757            x,
7758            y,
7759        } => {
7760            msg.write_arg(Arg::Int(x))?;
7761            msg.write_arg(Arg::Int(y))?;
7762            header.opcode = 1;
7763        },
7764        Request::PlaceAbove {
7765            sibling,
7766        } => {
7767            msg.write_arg(Arg::Object(sibling))?;
7768            header.opcode = 2;
7769        },
7770        Request::PlaceBelow {
7771            sibling,
7772        } => {
7773            msg.write_arg(Arg::Object(sibling))?;
7774            header.opcode = 3;
7775        },
7776        Request::SetSync {
7777        } => {
7778            header.opcode = 4;
7779        },
7780        Request::SetDesync {
7781        } => {
7782            header.opcode = 5;
7783        },
7784        }
7785        header.length = msg.bytes().len() as u16;
7786        msg.rewind();
7787        msg.write_header(&header)?;
7788        Ok(msg)
7789    }
7790}
7791impl FromArgs for Event {
7792    fn from_args(op: u16, mut args: Vec<Arg>) -> Result<Self, anyhow::Error> {
7793        match op {
7794        _ => {
7795            Err(DecodeError::InvalidOpcode(op).into())
7796        },
7797        }
7798    }
7799}
7800#[derive(Copy, Clone, Debug, Eq, PartialEq)]
7801#[repr(u32)]
7802pub enum Error {
7803    /// wl_surface is not a sibling or the parent,
7804    BadSurface = 0,
7805}
7806
7807impl Error {
7808    pub fn from_bits(v: u32) -> Option<Self> {
7809        match v {
7810        0 => Some(Error::BadSurface),
7811        _ => None,
7812        }
7813    }
7814
7815    pub fn bits(&self) -> u32 {
7816        *self as u32
7817    }
7818}
7819impl Into<Arg> for Error {
7820    fn into(self) -> Arg {
7821        Arg::Uint(self.bits())
7822    }
7823}
7824} // mod wl_subsurface
7825
7826pub use crate::wl_subsurface::WlSubsurface;
7827pub use crate::wl_subsurface::Request as WlSubsurfaceRequest;
7828pub use crate::wl_subsurface::Event as WlSubsurfaceEvent;