simple_window/common/protocols_data/wayland/
wl_seat.rs

1//! group of input devices
2//!
3//! A seat is a group of keyboards, pointer and touch devices. This
4//! object is published as a global during start up, or when such a
5//! device is hot plugged.  A seat typically has a pointer and
6//! maintains a keyboard focus and a pointer focus.
7
8use {super::super::all_types::*, ::wl_client::builder::prelude::*};
9
10static INTERFACE: wl_interface = wl_interface {
11    name: c"wl_seat".as_ptr(),
12    version: 10,
13    method_count: 4,
14    methods: {
15        static MESSAGES: [wl_message; 4] = [
16            wl_message {
17                name: c"get_pointer".as_ptr(),
18                signature: c"n".as_ptr(),
19                types: {
20                    static TYPES: [Option<&'static wl_interface>; 1] =
21                        [Some(WlPointer::WL_INTERFACE)];
22                    TYPES.as_ptr().cast()
23                },
24            },
25            wl_message {
26                name: c"get_keyboard".as_ptr(),
27                signature: c"n".as_ptr(),
28                types: {
29                    static TYPES: [Option<&'static wl_interface>; 1] =
30                        [Some(WlKeyboard::WL_INTERFACE)];
31                    TYPES.as_ptr().cast()
32                },
33            },
34            wl_message {
35                name: c"get_touch".as_ptr(),
36                signature: c"n".as_ptr(),
37                types: {
38                    static TYPES: [Option<&'static wl_interface>; 1] =
39                        [Some(WlTouch::WL_INTERFACE)];
40                    TYPES.as_ptr().cast()
41                },
42            },
43            wl_message {
44                name: c"release".as_ptr(),
45                signature: c"".as_ptr(),
46                types: {
47                    static TYPES: [Option<&'static wl_interface>; 0] = [];
48                    TYPES.as_ptr().cast()
49                },
50            },
51        ];
52        MESSAGES.as_ptr()
53    },
54    event_count: 2,
55    events: {
56        static MESSAGES: [wl_message; 2] = [
57            wl_message {
58                name: c"capabilities".as_ptr(),
59                signature: c"u".as_ptr(),
60                types: {
61                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
62                    TYPES.as_ptr().cast()
63                },
64            },
65            wl_message {
66                name: c"name".as_ptr(),
67                signature: c"s".as_ptr(),
68                types: {
69                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
70                    TYPES.as_ptr().cast()
71                },
72            },
73        ];
74        MESSAGES.as_ptr()
75    },
76};
77
78/// An owned wl_seat proxy.
79///
80/// See the documentation of [the module][self] for the interface description.
81#[derive(Clone, Eq, PartialEq)]
82#[repr(transparent)]
83pub struct WlSeat {
84    /// This proxy has the interface INTERFACE.
85    proxy: UntypedOwnedProxy,
86}
87
88/// A borrowed wl_seat proxy.
89///
90/// See the documentation of [the module][self] for the interface description.
91#[derive(Eq, PartialEq)]
92#[repr(transparent)]
93pub struct WlSeatRef {
94    /// This proxy has the interface INTERFACE.
95    proxy: UntypedBorrowedProxy,
96}
97
98// SAFETY: WlSeat is a transparent wrapper around UntypedOwnedProxy
99unsafe impl UntypedOwnedProxyWrapper for WlSeat {}
100
101// SAFETY: - INTERFACE is a valid wl_interface
102//         - The only invariant is that self.proxy has a compatible interface
103unsafe impl OwnedProxy for WlSeat {
104    const INTERFACE: &'static str = "wl_seat";
105    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
106    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
107        private::EventHandler(private::NoOpEventHandler);
108    const MAX_VERSION: u32 = 10;
109
110    type Borrowed = WlSeatRef;
111    type Api = private::ProxyApi;
112    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
113}
114
115// SAFETY: WlSeatRef is a transparent wrapper around UntypedBorrowedProxy
116unsafe impl UntypedBorrowedProxyWrapper for WlSeatRef {}
117
118// SAFETY: - The only invariant is that self.proxy has a compatible interface
119unsafe impl BorrowedProxy for WlSeatRef {
120    type Owned = WlSeat;
121}
122
123impl Deref for WlSeat {
124    type Target = WlSeatRef;
125
126    fn deref(&self) -> &Self::Target {
127        proxy::low_level::deref(self)
128    }
129}
130
131mod private {
132    pub struct ProxyApi;
133
134    #[allow(dead_code)]
135    pub struct EventHandler<H>(pub(super) H);
136
137    #[allow(dead_code)]
138    pub struct NoOpEventHandler;
139}
140
141impl Debug for WlSeat {
142    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
143        write!(f, "wl_seat#{}", self.proxy.id())
144    }
145}
146
147impl Debug for WlSeatRef {
148    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
149        write!(f, "wl_seat#{}", self.proxy.id())
150    }
151}
152
153impl PartialEq<WlSeatRef> for WlSeat {
154    fn eq(&self, other: &WlSeatRef) -> bool {
155        self.proxy == other.proxy
156    }
157}
158
159impl PartialEq<WlSeat> for WlSeatRef {
160    fn eq(&self, other: &WlSeat) -> bool {
161        self.proxy == other.proxy
162    }
163}
164
165#[allow(dead_code)]
166impl WlSeat {
167    /// Since when the get_pointer request is available.
168    #[allow(dead_code)]
169    pub const REQ__GET_POINTER__SINCE: u32 = 1;
170
171    /// return pointer object
172    ///
173    /// The ID provided will be initialized to the wl_pointer interface
174    /// for this seat.
175    ///
176    /// This request only takes effect if the seat has the pointer
177    /// capability, or has had the pointer capability in the past.
178    /// It is a protocol violation to issue this request on a seat that has
179    /// never had the pointer capability. The missing_capability error will
180    /// be sent in this case.
181    #[inline]
182    pub fn get_pointer(&self) -> WlPointer {
183        let mut args = [wl_argument { n: 0 }];
184        // SAFETY: - self.proxy has the interface INTERFACE
185        //         - 0 < INTERFACE.method_count = 4
186        //         - the request signature is `n`
187        //         - OwnedProxy::WL_INTERFACE is always a valid interface
188        let data = unsafe {
189            self.proxy
190                .send_constructor::<false>(0, &mut args, WlPointer::WL_INTERFACE, None)
191        };
192        // SAFETY: data has the interface WlPointer::WL_INTERFACE
193        unsafe { proxy::low_level::from_untyped_owned(data) }
194    }
195
196    /// Since when the get_keyboard request is available.
197    #[allow(dead_code)]
198    pub const REQ__GET_KEYBOARD__SINCE: u32 = 1;
199
200    /// return keyboard object
201    ///
202    /// The ID provided will be initialized to the wl_keyboard interface
203    /// for this seat.
204    ///
205    /// This request only takes effect if the seat has the keyboard
206    /// capability, or has had the keyboard capability in the past.
207    /// It is a protocol violation to issue this request on a seat that has
208    /// never had the keyboard capability. The missing_capability error will
209    /// be sent in this case.
210    #[inline]
211    pub fn get_keyboard(&self) -> WlKeyboard {
212        let mut args = [wl_argument { n: 0 }];
213        // SAFETY: - self.proxy has the interface INTERFACE
214        //         - 1 < INTERFACE.method_count = 4
215        //         - the request signature is `n`
216        //         - OwnedProxy::WL_INTERFACE is always a valid interface
217        let data = unsafe {
218            self.proxy
219                .send_constructor::<false>(1, &mut args, WlKeyboard::WL_INTERFACE, None)
220        };
221        // SAFETY: data has the interface WlKeyboard::WL_INTERFACE
222        unsafe { proxy::low_level::from_untyped_owned(data) }
223    }
224
225    /// Since when the get_touch request is available.
226    #[allow(dead_code)]
227    pub const REQ__GET_TOUCH__SINCE: u32 = 1;
228
229    /// return touch object
230    ///
231    /// The ID provided will be initialized to the wl_touch interface
232    /// for this seat.
233    ///
234    /// This request only takes effect if the seat has the touch
235    /// capability, or has had the touch capability in the past.
236    /// It is a protocol violation to issue this request on a seat that has
237    /// never had the touch capability. The missing_capability error will
238    /// be sent in this case.
239    #[inline]
240    pub fn get_touch(&self) -> WlTouch {
241        let mut args = [wl_argument { n: 0 }];
242        // SAFETY: - self.proxy has the interface INTERFACE
243        //         - 2 < INTERFACE.method_count = 4
244        //         - the request signature is `n`
245        //         - OwnedProxy::WL_INTERFACE is always a valid interface
246        let data = unsafe {
247            self.proxy
248                .send_constructor::<false>(2, &mut args, WlTouch::WL_INTERFACE, None)
249        };
250        // SAFETY: data has the interface WlTouch::WL_INTERFACE
251        unsafe { proxy::low_level::from_untyped_owned(data) }
252    }
253
254    /// Since when the release request is available.
255    #[allow(dead_code)]
256    pub const REQ__RELEASE__SINCE: u32 = 5;
257
258    /// release the seat object
259    ///
260    /// Using this request a client can tell the server that it is not going to
261    /// use the seat object anymore.
262    #[inline]
263    pub fn release(&self) {
264        let mut args = [];
265        // SAFETY: - self.proxy has the interface INTERFACE
266        //         - 3 < INTERFACE.method_count = 4
267        //         - the request signature is ``
268        unsafe {
269            self.proxy.send_destructor(3, &mut args);
270        }
271    }
272}
273
274#[allow(dead_code)]
275impl WlSeatRef {
276    /// return pointer object
277    ///
278    /// The ID provided will be initialized to the wl_pointer interface
279    /// for this seat.
280    ///
281    /// This request only takes effect if the seat has the pointer
282    /// capability, or has had the pointer capability in the past.
283    /// It is a protocol violation to issue this request on a seat that has
284    /// never had the pointer capability. The missing_capability error will
285    /// be sent in this case.
286    ///
287    /// # Arguments
288    ///
289    /// - `_queue`: The queue that the returned proxy is assigned to.
290    #[inline]
291    pub fn get_pointer(&self, _queue: &Queue) -> WlPointer {
292        let mut args = [wl_argument { n: 0 }];
293        // SAFETY: - self.proxy has the interface INTERFACE
294        //         - 0 < INTERFACE.method_count = 4
295        //         - the request signature is `n`
296        //         - OwnedProxy::WL_INTERFACE is always a valid interface
297        let data = unsafe {
298            self.proxy
299                .send_constructor(_queue, 0, &mut args, WlPointer::WL_INTERFACE, None)
300        };
301        // SAFETY: data has the interface WlPointer::WL_INTERFACE
302        unsafe { proxy::low_level::from_untyped_owned(data) }
303    }
304
305    /// return keyboard object
306    ///
307    /// The ID provided will be initialized to the wl_keyboard interface
308    /// for this seat.
309    ///
310    /// This request only takes effect if the seat has the keyboard
311    /// capability, or has had the keyboard capability in the past.
312    /// It is a protocol violation to issue this request on a seat that has
313    /// never had the keyboard capability. The missing_capability error will
314    /// be sent in this case.
315    ///
316    /// # Arguments
317    ///
318    /// - `_queue`: The queue that the returned proxy is assigned to.
319    #[inline]
320    pub fn get_keyboard(&self, _queue: &Queue) -> WlKeyboard {
321        let mut args = [wl_argument { n: 0 }];
322        // SAFETY: - self.proxy has the interface INTERFACE
323        //         - 1 < INTERFACE.method_count = 4
324        //         - the request signature is `n`
325        //         - OwnedProxy::WL_INTERFACE is always a valid interface
326        let data = unsafe {
327            self.proxy
328                .send_constructor(_queue, 1, &mut args, WlKeyboard::WL_INTERFACE, None)
329        };
330        // SAFETY: data has the interface WlKeyboard::WL_INTERFACE
331        unsafe { proxy::low_level::from_untyped_owned(data) }
332    }
333
334    /// return touch object
335    ///
336    /// The ID provided will be initialized to the wl_touch interface
337    /// for this seat.
338    ///
339    /// This request only takes effect if the seat has the touch
340    /// capability, or has had the touch capability in the past.
341    /// It is a protocol violation to issue this request on a seat that has
342    /// never had the touch capability. The missing_capability error will
343    /// be sent in this case.
344    ///
345    /// # Arguments
346    ///
347    /// - `_queue`: The queue that the returned proxy is assigned to.
348    #[inline]
349    pub fn get_touch(&self, _queue: &Queue) -> WlTouch {
350        let mut args = [wl_argument { n: 0 }];
351        // SAFETY: - self.proxy has the interface INTERFACE
352        //         - 2 < INTERFACE.method_count = 4
353        //         - the request signature is `n`
354        //         - OwnedProxy::WL_INTERFACE is always a valid interface
355        let data = unsafe {
356            self.proxy
357                .send_constructor(_queue, 2, &mut args, WlTouch::WL_INTERFACE, None)
358        };
359        // SAFETY: data has the interface WlTouch::WL_INTERFACE
360        unsafe { proxy::low_level::from_untyped_owned(data) }
361    }
362}
363
364impl WlSeat {
365    /// Since when the capabilities event is available.
366    #[allow(dead_code)]
367    pub const EVT__CAPABILITIES__SINCE: u32 = 1;
368
369    /// Since when the name event is available.
370    #[allow(dead_code)]
371    pub const EVT__NAME__SINCE: u32 = 2;
372}
373
374/// An event handler for [WlSeat] proxies.
375#[allow(dead_code)]
376pub trait WlSeatEventHandler {
377    type Data: 'static;
378
379    /// seat capabilities changed
380    ///
381    /// This is emitted whenever a seat gains or loses the pointer,
382    /// keyboard or touch capabilities.  The argument is a capability
383    /// enum containing the complete set of capabilities this seat has.
384    ///
385    /// When the pointer capability is added, a client may create a
386    /// wl_pointer object using the wl_seat.get_pointer request. This object
387    /// will receive pointer events until the capability is removed in the
388    /// future.
389    ///
390    /// When the pointer capability is removed, a client should destroy the
391    /// wl_pointer objects associated with the seat where the capability was
392    /// removed, using the wl_pointer.release request. No further pointer
393    /// events will be received on these objects.
394    ///
395    /// In some compositors, if a seat regains the pointer capability and a
396    /// client has a previously obtained wl_pointer object of version 4 or
397    /// less, that object may start sending pointer events again. This
398    /// behavior is considered a misinterpretation of the intended behavior
399    /// and must not be relied upon by the client. wl_pointer objects of
400    /// version 5 or later must not send events if created before the most
401    /// recent event notifying the client of an added pointer capability.
402    ///
403    /// The above behavior also applies to wl_keyboard and wl_touch with the
404    /// keyboard and touch capabilities, respectively.
405    ///
406    /// # Arguments
407    ///
408    /// - `capabilities`: capabilities of the seat
409    #[inline]
410    fn capabilities(
411        &self,
412        _data: &mut Self::Data,
413        _slf: &WlSeatRef,
414        capabilities: WlSeatCapability,
415    ) {
416        let _ = capabilities;
417    }
418
419    /// unique identifier for this seat
420    ///
421    /// In a multi-seat configuration the seat name can be used by clients to
422    /// help identify which physical devices the seat represents.
423    ///
424    /// The seat name is a UTF-8 string with no convention defined for its
425    /// contents. Each name is unique among all wl_seat globals. The name is
426    /// only guaranteed to be unique for the current compositor instance.
427    ///
428    /// The same seat names are used for all clients. Thus, the name can be
429    /// shared across processes to refer to a specific wl_seat global.
430    ///
431    /// The name event is sent after binding to the seat global. This event is
432    /// only sent once per seat object, and the name does not change over the
433    /// lifetime of the wl_seat global.
434    ///
435    /// Compositors may re-use the same seat name if the wl_seat global is
436    /// destroyed and re-created later.
437    ///
438    /// # Arguments
439    ///
440    /// - `name`: seat identifier
441    #[inline]
442    fn name(&self, _data: &mut Self::Data, _slf: &WlSeatRef, name: &str) {
443        let _ = name;
444    }
445}
446
447impl WlSeatEventHandler for private::NoOpEventHandler {
448    type Data = ();
449}
450
451// SAFETY: - INTERFACE is a valid wl_interface
452//         - mutable_type always returns the same value
453unsafe impl<H> EventHandler for private::EventHandler<H>
454where
455    H: WlSeatEventHandler,
456{
457    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
458
459    #[inline]
460    fn mutable_type() -> Option<(TypeId, &'static str)> {
461        let id = TypeId::of::<H::Data>();
462        let name = std::any::type_name::<H::Data>();
463        Some((id, name))
464    }
465
466    #[allow(unused_variables)]
467    unsafe fn handle_event(
468        &self,
469        queue: &Queue,
470        data: *mut u8,
471        slf: &UntypedBorrowedProxy,
472        opcode: u32,
473        args: *mut wl_argument,
474    ) {
475        // SAFETY: This function requires that slf has the interface INTERFACE
476        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlSeatRef>(slf) };
477        // SAFETY: This function requires that data is `&mut T` where `T`
478        //         has the type id returned by `Self::mutable_type`, i.e.,
479        //         `T = H::Data`.
480        let data: &mut H::Data = unsafe { &mut *data.cast() };
481        match opcode {
482            0 => {
483                // SAFETY: INTERFACE requires that there are 1 arguments
484                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
485                // SAFETY: - INTERFACE requires that args[0] contains a uint
486                let arg0 = unsafe { WlSeatCapability(args[0].u) };
487                self.0.capabilities(data, slf, arg0);
488            }
489            1 => {
490                // SAFETY: INTERFACE requires that there are 1 arguments
491                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
492                // SAFETY: - INTERFACE requires that args[0] contains a string
493                //         - if the pointer is not null, then it is a c string
494                let arg0 = unsafe { convert_string_arg("wl_seat", "name", args[0].s) };
495                self.0.name(data, slf, arg0);
496            }
497            _ => {
498                invalid_opcode("wl_seat", opcode);
499            }
500        }
501    }
502}
503
504impl<H> CreateEventHandler<H> for private::ProxyApi
505where
506    H: WlSeatEventHandler,
507{
508    type EventHandler = private::EventHandler<H>;
509
510    #[inline]
511    fn create_event_handler(handler: H) -> Self::EventHandler {
512        private::EventHandler(handler)
513    }
514}
515
516impl WlSeat {
517    /// Since when the capability.pointer enum variant is available.
518    #[allow(dead_code)]
519    pub const ENM__CAPABILITY_POINTER__SINCE: u32 = 1;
520    /// Since when the capability.keyboard enum variant is available.
521    #[allow(dead_code)]
522    pub const ENM__CAPABILITY_KEYBOARD__SINCE: u32 = 1;
523    /// Since when the capability.touch enum variant is available.
524    #[allow(dead_code)]
525    pub const ENM__CAPABILITY_TOUCH__SINCE: u32 = 1;
526
527    /// Since when the error.missing_capability enum variant is available.
528    #[allow(dead_code)]
529    pub const ENM__ERROR_MISSING_CAPABILITY__SINCE: u32 = 1;
530}
531
532/// seat capability bitmask
533///
534/// This is a bitmask of capabilities this seat has; if a member is
535/// set, then it is present on the seat.
536#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
537#[allow(dead_code)]
538pub struct WlSeatCapability(pub u32);
539
540/// An iterator over the set bits in a [WlSeatCapability].
541///
542/// You can construct this with the `IntoIterator` implementation of `WlSeatCapability`.
543#[derive(Clone, Debug)]
544pub struct WlSeatCapabilityIter(pub u32);
545
546impl WlSeatCapability {
547    /// the seat has pointer devices
548    #[allow(dead_code)]
549    pub const POINTER: Self = Self(1);
550
551    /// the seat has one or more keyboards
552    #[allow(dead_code)]
553    pub const KEYBOARD: Self = Self(2);
554
555    /// the seat has touch devices
556    #[allow(dead_code)]
557    pub const TOUCH: Self = Self(4);
558}
559
560#[allow(dead_code)]
561impl WlSeatCapability {
562    #[inline]
563    pub const fn empty() -> Self {
564        Self(0)
565    }
566
567    #[inline]
568    #[must_use]
569    pub const fn is_empty(self) -> bool {
570        self.0 == 0
571    }
572
573    #[inline]
574    #[must_use]
575    pub const fn contains(self, other: Self) -> bool {
576        self.0 & other.0 == other.0
577    }
578
579    #[inline]
580    #[must_use]
581    pub const fn intersects(self, other: Self) -> bool {
582        self.0 & other.0 != 0
583    }
584
585    #[inline]
586    pub const fn insert(&mut self, other: Self) {
587        *self = self.union(other);
588    }
589
590    #[inline]
591    pub const fn remove(&mut self, other: Self) {
592        *self = self.difference(other);
593    }
594
595    #[inline]
596    pub const fn toggle(&mut self, other: Self) {
597        *self = self.symmetric_difference(other);
598    }
599
600    #[inline]
601    pub const fn set(&mut self, other: Self, value: bool) {
602        if value {
603            self.insert(other);
604        } else {
605            self.remove(other);
606        }
607    }
608
609    #[inline]
610    #[must_use]
611    pub const fn intersection(self, other: Self) -> Self {
612        Self(self.0 & other.0)
613    }
614
615    #[inline]
616    #[must_use]
617    pub const fn union(self, other: Self) -> Self {
618        Self(self.0 | other.0)
619    }
620
621    #[inline]
622    #[must_use]
623    pub const fn difference(self, other: Self) -> Self {
624        Self(self.0 & !other.0)
625    }
626
627    #[inline]
628    #[must_use]
629    pub const fn complement(self) -> Self {
630        Self(!self.0)
631    }
632
633    #[inline]
634    #[must_use]
635    pub const fn symmetric_difference(self, other: Self) -> Self {
636        Self(self.0 ^ other.0)
637    }
638
639    #[inline]
640    pub const fn all_known() -> Self {
641        #[allow(clippy::eq_op, clippy::identity_op)]
642        Self(0 | 1 | 2 | 4)
643    }
644}
645
646impl Iterator for WlSeatCapabilityIter {
647    type Item = WlSeatCapability;
648
649    fn next(&mut self) -> Option<Self::Item> {
650        if self.0 == 0 {
651            return None;
652        }
653        let bit = 1 << self.0.trailing_zeros();
654        self.0 &= !bit;
655        Some(WlSeatCapability(bit))
656    }
657}
658
659impl IntoIterator for WlSeatCapability {
660    type Item = WlSeatCapability;
661    type IntoIter = WlSeatCapabilityIter;
662
663    fn into_iter(self) -> Self::IntoIter {
664        WlSeatCapabilityIter(self.0)
665    }
666}
667
668impl BitAnd for WlSeatCapability {
669    type Output = Self;
670
671    fn bitand(self, rhs: Self) -> Self::Output {
672        self.intersection(rhs)
673    }
674}
675
676impl BitAndAssign for WlSeatCapability {
677    fn bitand_assign(&mut self, rhs: Self) {
678        *self = self.intersection(rhs);
679    }
680}
681
682impl BitOr for WlSeatCapability {
683    type Output = Self;
684
685    fn bitor(self, rhs: Self) -> Self::Output {
686        self.union(rhs)
687    }
688}
689
690impl BitOrAssign for WlSeatCapability {
691    fn bitor_assign(&mut self, rhs: Self) {
692        *self = self.union(rhs);
693    }
694}
695
696impl BitXor for WlSeatCapability {
697    type Output = Self;
698
699    fn bitxor(self, rhs: Self) -> Self::Output {
700        self.symmetric_difference(rhs)
701    }
702}
703
704impl BitXorAssign for WlSeatCapability {
705    fn bitxor_assign(&mut self, rhs: Self) {
706        *self = self.symmetric_difference(rhs);
707    }
708}
709
710impl Sub for WlSeatCapability {
711    type Output = Self;
712
713    fn sub(self, rhs: Self) -> Self::Output {
714        self.difference(rhs)
715    }
716}
717
718impl SubAssign for WlSeatCapability {
719    fn sub_assign(&mut self, rhs: Self) {
720        *self = self.difference(rhs);
721    }
722}
723
724impl Not for WlSeatCapability {
725    type Output = Self;
726
727    fn not(self) -> Self::Output {
728        self.complement()
729    }
730}
731
732impl Debug for WlSeatCapability {
733    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
734        let mut v = self.0;
735        let mut first = true;
736        if v & 1 == 1 {
737            v &= !1;
738            if first {
739                first = false;
740            } else {
741                f.write_str(" | ")?;
742            }
743            f.write_str("POINTER")?;
744        }
745        if v & 2 == 2 {
746            v &= !2;
747            if first {
748                first = false;
749            } else {
750                f.write_str(" | ")?;
751            }
752            f.write_str("KEYBOARD")?;
753        }
754        if v & 4 == 4 {
755            v &= !4;
756            if first {
757                first = false;
758            } else {
759                f.write_str(" | ")?;
760            }
761            f.write_str("TOUCH")?;
762        }
763        if v != 0 {
764            if first {
765                first = false;
766            } else {
767                f.write_str(" | ")?;
768            }
769            write!(f, "0x{v:032x}")?;
770        }
771        if first {
772            f.write_str("0")?;
773        }
774        Ok(())
775    }
776}
777
778/// wl_seat error values
779///
780/// These errors can be emitted in response to wl_seat requests.
781#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
782#[allow(dead_code)]
783pub struct WlSeatError(pub u32);
784
785impl WlSeatError {
786    /// get_pointer, get_keyboard or get_touch called on seat without the matching capability
787    #[allow(dead_code)]
788    pub const MISSING_CAPABILITY: Self = Self(0);
789}
790
791impl Debug for WlSeatError {
792    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
793        let name = match *self {
794            Self::MISSING_CAPABILITY => "MISSING_CAPABILITY",
795            _ => return Debug::fmt(&self.0, f),
796        };
797        f.write_str(name)
798    }
799}
800
801/// Functional event handlers.
802pub mod event_handlers {
803    use super::*;
804
805    /// Event handler for capabilities events.
806    pub struct Capabilities<T, F>(F, PhantomData<fn(&mut T)>);
807    impl<T, F> WlSeatEventHandler for Capabilities<T, F>
808    where
809        T: 'static,
810        F: Fn(&mut T, &WlSeatRef, WlSeatCapability),
811    {
812        type Data = T;
813
814        #[inline]
815        fn capabilities(&self, _data: &mut T, _slf: &WlSeatRef, capabilities: WlSeatCapability) {
816            self.0(_data, _slf, capabilities)
817        }
818    }
819
820    /// Event handler for name events.
821    pub struct Name<T, F>(F, PhantomData<fn(&mut T)>);
822    impl<T, F> WlSeatEventHandler for Name<T, F>
823    where
824        T: 'static,
825        F: Fn(&mut T, &WlSeatRef, &str),
826    {
827        type Data = T;
828
829        #[inline]
830        fn name(&self, _data: &mut T, _slf: &WlSeatRef, name: &str) {
831            self.0(_data, _slf, name)
832        }
833    }
834
835    impl WlSeat {
836        /// Creates an event handler for capabilities events.
837        ///
838        /// The event handler ignores all other events.
839        #[allow(dead_code)]
840        pub fn on_capabilities<T, F>(f: F) -> Capabilities<T, F>
841        where
842            T: 'static,
843            F: Fn(&mut T, &WlSeatRef, WlSeatCapability),
844        {
845            Capabilities(f, PhantomData)
846        }
847
848        /// Creates an event handler for name events.
849        ///
850        /// The event handler ignores all other events.
851        #[allow(dead_code)]
852        pub fn on_name<T, F>(f: F) -> Name<T, F>
853        where
854            T: 'static,
855            F: Fn(&mut T, &WlSeatRef, &str),
856        {
857            Name(f, PhantomData)
858        }
859    }
860}