Skip to main content

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