Skip to main content

get_registry/common/protocols_data/tablet_v2/
zwp_tablet_pad_v2.rs

1//! a set of buttons, rings and strips
2//!
3//! A pad device is a set of buttons, rings and strips
4//! usually physically present on the tablet device itself. Some
5//! exceptions exist where the pad device is physically detached, e.g. the
6//! Wacom ExpressKey Remote.
7//!
8//! Pad devices have no axes that control the cursor and are generally
9//! auxiliary devices to the tool devices used on the tablet surface.
10//!
11//! A pad device has a number of static characteristics, e.g. the number
12//! of rings. These capabilities are sent in an event sequence after the
13//! wp_tablet_seat.pad_added event before any actual events from this pad.
14//! This initial event sequence is terminated by a wp_tablet_pad.done
15//! event.
16//!
17//! All pad features (buttons, rings and strips) are logically divided into
18//! groups and all pads have at least one group. The available groups are
19//! notified through the wp_tablet_pad.group event; the compositor will
20//! emit one event per group before emitting wp_tablet_pad.done.
21//!
22//! Groups may have multiple modes. Modes allow clients to map multiple
23//! actions to a single pad feature. Only one mode can be active per group,
24//! although different groups may have different active modes.
25
26use super::super::all_types::*;
27use ::wl_client::builder::prelude::*;
28
29static INTERFACE: wl_interface = wl_interface {
30    name: c"zwp_tablet_pad_v2".as_ptr(),
31    version: 1,
32    method_count: 2,
33    methods: {
34        static MESSAGES: [wl_message; 2] = [
35            wl_message {
36                name: c"set_feedback".as_ptr(),
37                signature: c"usu".as_ptr(),
38                types: {
39                    static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
40                    TYPES.as_ptr().cast()
41                },
42            },
43            wl_message {
44                name: c"destroy".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: 8,
55    events: {
56        static MESSAGES: [wl_message; 8] = [
57            wl_message {
58                name: c"group".as_ptr(),
59                signature: c"n".as_ptr(),
60                types: {
61                    static TYPES: [Option<&'static wl_interface>; 1] =
62                        [Some(ZwpTabletPadGroupV2::WL_INTERFACE)];
63                    TYPES.as_ptr().cast()
64                },
65            },
66            wl_message {
67                name: c"path".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            wl_message {
75                name: c"buttons".as_ptr(),
76                signature: c"u".as_ptr(),
77                types: {
78                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
79                    TYPES.as_ptr().cast()
80                },
81            },
82            wl_message {
83                name: c"done".as_ptr(),
84                signature: c"".as_ptr(),
85                types: {
86                    static TYPES: [Option<&'static wl_interface>; 0] = [];
87                    TYPES.as_ptr().cast()
88                },
89            },
90            wl_message {
91                name: c"button".as_ptr(),
92                signature: c"uuu".as_ptr(),
93                types: {
94                    static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
95                    TYPES.as_ptr().cast()
96                },
97            },
98            wl_message {
99                name: c"enter".as_ptr(),
100                signature: c"uoo".as_ptr(),
101                types: {
102                    static TYPES: [Option<&'static wl_interface>; 3] = [
103                        None,
104                        Some(ZwpTabletV2::WL_INTERFACE),
105                        Some(WlSurface::WL_INTERFACE),
106                    ];
107                    TYPES.as_ptr().cast()
108                },
109            },
110            wl_message {
111                name: c"leave".as_ptr(),
112                signature: c"uo".as_ptr(),
113                types: {
114                    static TYPES: [Option<&'static wl_interface>; 2] =
115                        [None, Some(WlSurface::WL_INTERFACE)];
116                    TYPES.as_ptr().cast()
117                },
118            },
119            wl_message {
120                name: c"removed".as_ptr(),
121                signature: c"".as_ptr(),
122                types: {
123                    static TYPES: [Option<&'static wl_interface>; 0] = [];
124                    TYPES.as_ptr().cast()
125                },
126            },
127        ];
128        MESSAGES.as_ptr()
129    },
130};
131
132/// An owned zwp_tablet_pad_v2 proxy.
133///
134/// See the documentation of [the module][self] for the interface description.
135#[derive(Clone, Eq, PartialEq)]
136#[repr(transparent)]
137pub struct ZwpTabletPadV2 {
138    /// This proxy has the interface INTERFACE.
139    proxy: UntypedOwnedProxy,
140}
141
142/// A borrowed zwp_tablet_pad_v2 proxy.
143///
144/// See the documentation of [the module][self] for the interface description.
145#[derive(Eq, PartialEq)]
146#[repr(transparent)]
147pub struct ZwpTabletPadV2Ref {
148    /// This proxy has the interface INTERFACE.
149    proxy: UntypedBorrowedProxy,
150}
151
152// SAFETY: ZwpTabletPadV2 is a transparent wrapper around UntypedOwnedProxy
153unsafe impl UntypedOwnedProxyWrapper for ZwpTabletPadV2 {}
154
155// SAFETY: - INTERFACE is a valid wl_interface
156//         - The only invariant is that self.proxy has a compatible interface
157unsafe impl OwnedProxy for ZwpTabletPadV2 {
158    const INTERFACE: &'static str = "zwp_tablet_pad_v2";
159    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
160    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
161        private::EventHandler(private::NoOpEventHandler);
162    const MAX_VERSION: u32 = 1;
163
164    type Borrowed = ZwpTabletPadV2Ref;
165    type Api = private::ProxyApi;
166    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
167}
168
169// SAFETY: ZwpTabletPadV2Ref is a transparent wrapper around UntypedBorrowedProxy
170unsafe impl UntypedBorrowedProxyWrapper for ZwpTabletPadV2Ref {}
171
172// SAFETY: - The only invariant is that self.proxy has a compatible interface
173unsafe impl BorrowedProxy for ZwpTabletPadV2Ref {
174    type Owned = ZwpTabletPadV2;
175}
176
177impl Deref for ZwpTabletPadV2 {
178    type Target = ZwpTabletPadV2Ref;
179
180    fn deref(&self) -> &Self::Target {
181        proxy::low_level::deref(self)
182    }
183}
184
185mod private {
186    pub struct ProxyApi;
187
188    #[allow(dead_code)]
189    pub struct EventHandler<H>(pub(super) H);
190
191    #[allow(dead_code)]
192    pub struct NoOpEventHandler;
193}
194
195impl Debug for ZwpTabletPadV2 {
196    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
197        write!(f, "zwp_tablet_pad_v2#{}", self.proxy.id())
198    }
199}
200
201impl Debug for ZwpTabletPadV2Ref {
202    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
203        write!(f, "zwp_tablet_pad_v2#{}", self.proxy.id())
204    }
205}
206
207impl PartialEq<ZwpTabletPadV2Ref> for ZwpTabletPadV2 {
208    fn eq(&self, other: &ZwpTabletPadV2Ref) -> bool {
209        self.proxy == other.proxy
210    }
211}
212
213impl PartialEq<ZwpTabletPadV2> for ZwpTabletPadV2Ref {
214    fn eq(&self, other: &ZwpTabletPadV2) -> bool {
215        self.proxy == other.proxy
216    }
217}
218
219#[allow(dead_code)]
220impl ZwpTabletPadV2 {
221    /// Since when the set_feedback request is available.
222    #[allow(dead_code)]
223    pub const REQ__SET_FEEDBACK__SINCE: u32 = 1;
224
225    /// Since when the destroy request is available.
226    #[allow(dead_code)]
227    pub const REQ__DESTROY__SINCE: u32 = 1;
228}
229
230#[allow(dead_code)]
231impl ZwpTabletPadV2 {
232    /// destroy the pad object
233    ///
234    /// Destroy the wp_tablet_pad object. Objects created from this object
235    /// are unaffected and should be destroyed separately.
236    #[inline]
237    pub fn destroy(&self) {
238        let mut args = [];
239        // SAFETY: - self.proxy has the interface INTERFACE
240        //         - 1 < INTERFACE.method_count = 2
241        //         - the request signature is ``
242        unsafe {
243            self.proxy.send_destructor(1, &mut args);
244        }
245    }
246}
247
248#[allow(dead_code)]
249impl ZwpTabletPadV2Ref {
250    /// set compositor feedback
251    ///
252    /// Requests the compositor to use the provided feedback string
253    /// associated with this button. This request should be issued immediately
254    /// after a wp_tablet_pad_group.mode_switch event from the corresponding
255    /// group is received, or whenever a button is mapped to a different
256    /// action. See wp_tablet_pad_group.mode_switch for more details.
257    ///
258    /// Clients are encouraged to provide context-aware descriptions for
259    /// the actions associated with each button, and compositors may use
260    /// this information to offer visual feedback on the button layout
261    /// (e.g. on-screen displays).
262    ///
263    /// Button indices start at 0. Setting the feedback string on a button
264    /// that is reserved by the compositor (i.e. not belonging to any
265    /// wp_tablet_pad_group) does not generate an error but the compositor
266    /// is free to ignore the request.
267    ///
268    /// The provided string 'description' is a UTF-8 encoded string to be
269    /// associated with this ring, and is considered user-visible; general
270    /// internationalization rules apply.
271    ///
272    /// The serial argument will be that of the last
273    /// wp_tablet_pad_group.mode_switch event received for the group of this
274    /// button. Requests providing other serials than the most recent one will
275    /// be ignored.
276    ///
277    /// # Arguments
278    ///
279    /// - `button`: button index
280    /// - `description`: button description
281    /// - `serial`: serial of the mode switch event
282    #[inline]
283    pub fn set_feedback(&self, button: u32, description: &str, serial: u32) {
284        let (arg0, arg1, arg2) = (button, description, serial);
285        with_cstr_cache(|cache| {
286            let str1_offset = cache.len();
287            cache.extend_from_slice(arg1.as_bytes());
288            cache.push(0);
289            let str1 = cache[str1_offset..].as_ptr().cast();
290            let mut args = [
291                wl_argument { u: arg0 },
292                wl_argument { s: str1 },
293                wl_argument { u: arg2 },
294            ];
295            // SAFETY: - self.proxy has the interface INTERFACE
296            //         - 0 < INTERFACE.method_count = 2
297            //         - the request signature is `usu`
298            unsafe {
299                self.proxy.send_request(0, &mut args);
300            }
301        })
302    }
303}
304
305impl ZwpTabletPadV2 {
306    /// Since when the group event is available.
307    #[allow(dead_code)]
308    pub const EVT__GROUP__SINCE: u32 = 1;
309
310    /// Since when the path event is available.
311    #[allow(dead_code)]
312    pub const EVT__PATH__SINCE: u32 = 1;
313
314    /// Since when the buttons event is available.
315    #[allow(dead_code)]
316    pub const EVT__BUTTONS__SINCE: u32 = 1;
317
318    /// Since when the done event is available.
319    #[allow(dead_code)]
320    pub const EVT__DONE__SINCE: u32 = 1;
321
322    /// Since when the button event is available.
323    #[allow(dead_code)]
324    pub const EVT__BUTTON__SINCE: u32 = 1;
325
326    /// Since when the enter event is available.
327    #[allow(dead_code)]
328    pub const EVT__ENTER__SINCE: u32 = 1;
329
330    /// Since when the leave event is available.
331    #[allow(dead_code)]
332    pub const EVT__LEAVE__SINCE: u32 = 1;
333
334    /// Since when the removed event is available.
335    #[allow(dead_code)]
336    pub const EVT__REMOVED__SINCE: u32 = 1;
337}
338
339/// An event handler for [ZwpTabletPadV2] proxies.
340#[allow(dead_code)]
341pub trait ZwpTabletPadV2EventHandler {
342    type Data: 'static;
343
344    /// group announced
345    ///
346    /// Sent on wp_tablet_pad initialization to announce available groups.
347    /// One event is sent for each pad group available.
348    ///
349    /// This event is sent in the initial burst of events before the
350    /// wp_tablet_pad.done event. At least one group will be announced.
351    ///
352    /// # Arguments
353    ///
354    /// - `pad_group`:
355    #[inline]
356    fn group(
357        &self,
358        _data: &mut Self::Data,
359        _slf: &ZwpTabletPadV2Ref,
360        pad_group: ZwpTabletPadGroupV2,
361    ) {
362        let _ = pad_group;
363    }
364
365    /// path to the device
366    ///
367    /// A system-specific device path that indicates which device is behind
368    /// this wp_tablet_pad. This information may be used to gather additional
369    /// information about the device, e.g. through libwacom.
370    ///
371    /// The format of the path is unspecified, it may be a device node, a
372    /// sysfs path, or some other identifier. It is up to the client to
373    /// identify the string provided.
374    ///
375    /// This event is sent in the initial burst of events before the
376    /// wp_tablet_pad.done event.
377    ///
378    /// # Arguments
379    ///
380    /// - `path`: path to local device
381    #[inline]
382    fn path(&self, _data: &mut Self::Data, _slf: &ZwpTabletPadV2Ref, path: &str) {
383        let _ = path;
384    }
385
386    /// buttons announced
387    ///
388    /// Sent on wp_tablet_pad initialization to announce the available
389    /// buttons.
390    ///
391    /// This event is sent in the initial burst of events before the
392    /// wp_tablet_pad.done event. This event is only sent when at least one
393    /// button is available.
394    ///
395    /// # Arguments
396    ///
397    /// - `buttons`: the number of buttons
398    #[inline]
399    fn buttons(&self, _data: &mut Self::Data, _slf: &ZwpTabletPadV2Ref, buttons: u32) {
400        let _ = buttons;
401    }
402
403    /// pad description event sequence complete
404    ///
405    /// This event signals the end of the initial burst of descriptive
406    /// events. A client may consider the static description of the pad to
407    /// be complete and finalize initialization of the pad.
408    #[inline]
409    fn done(&self, _data: &mut Self::Data, _slf: &ZwpTabletPadV2Ref) {}
410
411    /// physical button state
412    ///
413    /// Sent whenever the physical state of a button changes.
414    ///
415    /// # Arguments
416    ///
417    /// - `time`: the time of the event with millisecond granularity
418    /// - `button`: the index of the button that changed state
419    /// - `state`:
420    #[inline]
421    fn button(
422        &self,
423        _data: &mut Self::Data,
424        _slf: &ZwpTabletPadV2Ref,
425        time: u32,
426        button: u32,
427        state: ZwpTabletPadV2ButtonState,
428    ) {
429        let _ = time;
430        let _ = button;
431        let _ = state;
432    }
433
434    /// enter event
435    ///
436    /// Notification that this pad is focused on the specified surface.
437    ///
438    /// # Arguments
439    ///
440    /// - `serial`: serial number of the enter event
441    /// - `tablet`: the tablet the pad is attached to
442    /// - `surface`: surface the pad is focused on
443    ///
444    /// All borrowed proxies passed to this function are guaranteed to be
445    /// immutable and non-null.
446    #[inline]
447    fn enter(
448        &self,
449        _data: &mut Self::Data,
450        _slf: &ZwpTabletPadV2Ref,
451        serial: u32,
452        tablet: Option<&ZwpTabletV2Ref>,
453        surface: Option<&WlSurfaceRef>,
454    ) {
455        let _ = serial;
456        let _ = tablet;
457        let _ = surface;
458    }
459
460    /// leave event
461    ///
462    /// Notification that this pad is no longer focused on the specified
463    /// surface.
464    ///
465    /// # Arguments
466    ///
467    /// - `serial`: serial number of the leave event
468    /// - `surface`: surface the pad is no longer focused on
469    ///
470    /// All borrowed proxies passed to this function are guaranteed to be
471    /// immutable and non-null.
472    #[inline]
473    fn leave(
474        &self,
475        _data: &mut Self::Data,
476        _slf: &ZwpTabletPadV2Ref,
477        serial: u32,
478        surface: Option<&WlSurfaceRef>,
479    ) {
480        let _ = serial;
481        let _ = surface;
482    }
483
484    /// pad removed event
485    ///
486    /// Sent when the pad has been removed from the system. When a tablet
487    /// is removed its pad(s) will be removed too.
488    ///
489    /// When this event is received, the client must destroy all rings, strips
490    /// and groups that were offered by this pad, and issue wp_tablet_pad.destroy
491    /// the pad itself.
492    #[inline]
493    fn removed(&self, _data: &mut Self::Data, _slf: &ZwpTabletPadV2Ref) {}
494}
495
496impl ZwpTabletPadV2EventHandler for private::NoOpEventHandler {
497    type Data = ();
498}
499
500// SAFETY: - INTERFACE is a valid wl_interface
501//         - mutable_type always returns the same value
502unsafe impl<H> EventHandler for private::EventHandler<H>
503where
504    H: ZwpTabletPadV2EventHandler,
505{
506    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
507
508    #[inline]
509    fn mutable_type() -> Option<(TypeId, &'static str)> {
510        let id = TypeId::of::<H::Data>();
511        let name = std::any::type_name::<H::Data>();
512        Some((id, name))
513    }
514
515    #[allow(unused_variables)]
516    unsafe fn handle_event(
517        &self,
518        queue: &Queue,
519        data: *mut u8,
520        slf: &UntypedBorrowedProxy,
521        opcode: u32,
522        args: *mut wl_argument,
523    ) {
524        // SAFETY: This function requires that slf has the interface INTERFACE
525        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<ZwpTabletPadV2Ref>(slf) };
526        // SAFETY: This function requires that data is `&mut T` where `T`
527        //         has the type id returned by `Self::mutable_type`, i.e.,
528        //         `T = H::Data`.
529        let data: &mut H::Data = unsafe { &mut *data.cast() };
530        match opcode {
531            0 => {
532                // SAFETY: INTERFACE requires that there are 1 arguments
533                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
534                // SAFETY: - INTERFACE requires that args[0] contains an object
535                //         - ownership is transferred to this function
536                //         - INTERFACE requires that the object has the interface ZwpTabletPadGroupV2::WL_INTERFACE
537                let arg0 = unsafe {
538                    UntypedOwnedProxy::from_plain_wl_proxy(
539                        queue,
540                        NonNull::new_unchecked(args[0].o.cast()),
541                        ZwpTabletPadGroupV2::WL_INTERFACE,
542                    )
543                };
544                // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletPadGroupV2::WL_INTERFACE
545                let arg0 =
546                    unsafe { proxy::low_level::from_untyped_owned::<ZwpTabletPadGroupV2>(arg0) };
547                self.0.group(data, slf, arg0);
548            }
549            1 => {
550                // SAFETY: INTERFACE requires that there are 1 arguments
551                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
552                // SAFETY: - INTERFACE requires that args[0] contains a string
553                //         - if the pointer is not null, then it is a c string
554                let arg0 = unsafe { convert_string_arg("zwp_tablet_pad_v2", "path", args[0].s) };
555                self.0.path(data, slf, arg0);
556            }
557            2 => {
558                // SAFETY: INTERFACE requires that there are 1 arguments
559                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
560                // SAFETY: - INTERFACE requires that args[0] contains a uint
561                let arg0 = unsafe { args[0].u };
562                self.0.buttons(data, slf, arg0);
563            }
564            3 => {
565                self.0.done(data, slf);
566            }
567            4 => {
568                // SAFETY: INTERFACE requires that there are 3 arguments
569                let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
570                // SAFETY: - INTERFACE requires that args[0] contains a uint
571                let arg0 = unsafe { args[0].u };
572                // SAFETY: - INTERFACE requires that args[1] contains a uint
573                let arg1 = unsafe { args[1].u };
574                // SAFETY: - INTERFACE requires that args[2] contains a uint
575                let arg2 = unsafe { ZwpTabletPadV2ButtonState(args[2].u) };
576                self.0.button(data, slf, arg0, arg1, arg2);
577            }
578            5 => {
579                // SAFETY: INTERFACE requires that there are 3 arguments
580                let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
581                // SAFETY: - INTERFACE requires that args[0] contains a uint
582                let arg0 = unsafe { args[0].u };
583                // SAFETY: - INTERFACE requires that args[1] contains an object
584                let arg1 = unsafe {
585                    if let Some(p) = NonNull::new(args[1].o.cast()) {
586                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
587                    } else {
588                        None
589                    }
590                };
591                // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletV2::WL_INTERFACE
592                let arg1 = arg1.as_ref().map(|arg1| unsafe {
593                    proxy::low_level::from_untyped_borrowed::<ZwpTabletV2Ref>(arg1)
594                });
595                // SAFETY: - INTERFACE requires that args[2] contains an object
596                let arg2 = unsafe {
597                    if let Some(p) = NonNull::new(args[2].o.cast()) {
598                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
599                    } else {
600                        None
601                    }
602                };
603                // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
604                let arg2 = arg2.as_ref().map(|arg2| unsafe {
605                    proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg2)
606                });
607                self.0.enter(data, slf, arg0, arg1, arg2);
608            }
609            6 => {
610                // SAFETY: INTERFACE requires that there are 2 arguments
611                let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
612                // SAFETY: - INTERFACE requires that args[0] contains a uint
613                let arg0 = unsafe { args[0].u };
614                // SAFETY: - INTERFACE requires that args[1] contains an object
615                let arg1 = unsafe {
616                    if let Some(p) = NonNull::new(args[1].o.cast()) {
617                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
618                    } else {
619                        None
620                    }
621                };
622                // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
623                let arg1 = arg1.as_ref().map(|arg1| unsafe {
624                    proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
625                });
626                self.0.leave(data, slf, arg0, arg1);
627            }
628            7 => {
629                self.0.removed(data, slf);
630            }
631            _ => {
632                invalid_opcode("zwp_tablet_pad_v2", opcode);
633            }
634        }
635    }
636}
637
638impl<H> CreateEventHandler<H> for private::ProxyApi
639where
640    H: ZwpTabletPadV2EventHandler,
641{
642    type EventHandler = private::EventHandler<H>;
643
644    #[inline]
645    fn create_event_handler(handler: H) -> Self::EventHandler {
646        private::EventHandler(handler)
647    }
648}
649
650impl ZwpTabletPadV2 {
651    /// Since when the button_state.released enum variant is available.
652    #[allow(dead_code)]
653    pub const ENM__BUTTON_STATE_RELEASED__SINCE: u32 = 1;
654    /// Since when the button_state.pressed enum variant is available.
655    #[allow(dead_code)]
656    pub const ENM__BUTTON_STATE_PRESSED__SINCE: u32 = 1;
657}
658
659/// physical button state
660///
661/// Describes the physical state of a button that caused the button
662/// event.
663#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
664#[allow(dead_code)]
665pub struct ZwpTabletPadV2ButtonState(pub u32);
666
667impl ZwpTabletPadV2ButtonState {
668    /// the button is not pressed
669    #[allow(dead_code)]
670    pub const RELEASED: Self = Self(0);
671
672    /// the button is pressed
673    #[allow(dead_code)]
674    pub const PRESSED: Self = Self(1);
675}
676
677impl Debug for ZwpTabletPadV2ButtonState {
678    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
679        let name = match *self {
680            Self::RELEASED => "RELEASED",
681            Self::PRESSED => "PRESSED",
682            _ => return Debug::fmt(&self.0, f),
683        };
684        f.write_str(name)
685    }
686}
687
688/// Functional event handlers.
689pub mod event_handlers {
690    use super::*;
691
692    /// Event handler for group events.
693    pub struct Group<T, F>(F, PhantomData<fn(&mut T)>);
694    impl<T, F> ZwpTabletPadV2EventHandler for Group<T, F>
695    where
696        T: 'static,
697        F: Fn(&mut T, &ZwpTabletPadV2Ref, ZwpTabletPadGroupV2),
698    {
699        type Data = T;
700
701        #[inline]
702        fn group(&self, _data: &mut T, _slf: &ZwpTabletPadV2Ref, pad_group: ZwpTabletPadGroupV2) {
703            self.0(_data, _slf, pad_group)
704        }
705    }
706
707    /// Event handler for path events.
708    pub struct Path<T, F>(F, PhantomData<fn(&mut T)>);
709    impl<T, F> ZwpTabletPadV2EventHandler for Path<T, F>
710    where
711        T: 'static,
712        F: Fn(&mut T, &ZwpTabletPadV2Ref, &str),
713    {
714        type Data = T;
715
716        #[inline]
717        fn path(&self, _data: &mut T, _slf: &ZwpTabletPadV2Ref, path: &str) {
718            self.0(_data, _slf, path)
719        }
720    }
721
722    /// Event handler for buttons events.
723    pub struct Buttons<T, F>(F, PhantomData<fn(&mut T)>);
724    impl<T, F> ZwpTabletPadV2EventHandler for Buttons<T, F>
725    where
726        T: 'static,
727        F: Fn(&mut T, &ZwpTabletPadV2Ref, u32),
728    {
729        type Data = T;
730
731        #[inline]
732        fn buttons(&self, _data: &mut T, _slf: &ZwpTabletPadV2Ref, buttons: u32) {
733            self.0(_data, _slf, buttons)
734        }
735    }
736
737    /// Event handler for done events.
738    pub struct Done<T, F>(F, PhantomData<fn(&mut T)>);
739    impl<T, F> ZwpTabletPadV2EventHandler for Done<T, F>
740    where
741        T: 'static,
742        F: Fn(&mut T, &ZwpTabletPadV2Ref),
743    {
744        type Data = T;
745
746        #[inline]
747        fn done(&self, _data: &mut T, _slf: &ZwpTabletPadV2Ref) {
748            self.0(_data, _slf)
749        }
750    }
751
752    /// Event handler for button events.
753    pub struct Button<T, F>(F, PhantomData<fn(&mut T)>);
754    impl<T, F> ZwpTabletPadV2EventHandler for Button<T, F>
755    where
756        T: 'static,
757        F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, u32, ZwpTabletPadV2ButtonState),
758    {
759        type Data = T;
760
761        #[inline]
762        fn button(
763            &self,
764            _data: &mut T,
765            _slf: &ZwpTabletPadV2Ref,
766            time: u32,
767            button: u32,
768            state: ZwpTabletPadV2ButtonState,
769        ) {
770            self.0(_data, _slf, time, button, state)
771        }
772    }
773
774    /// Event handler for enter events.
775    pub struct Enter<T, F>(F, PhantomData<fn(&mut T)>);
776    impl<T, F> ZwpTabletPadV2EventHandler for Enter<T, F>
777    where
778        T: 'static,
779        F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, Option<&ZwpTabletV2Ref>, Option<&WlSurfaceRef>),
780    {
781        type Data = T;
782
783        #[inline]
784        fn enter(
785            &self,
786            _data: &mut T,
787            _slf: &ZwpTabletPadV2Ref,
788            serial: u32,
789            tablet: Option<&ZwpTabletV2Ref>,
790            surface: Option<&WlSurfaceRef>,
791        ) {
792            self.0(_data, _slf, serial, tablet, surface)
793        }
794    }
795
796    /// Event handler for leave events.
797    pub struct Leave<T, F>(F, PhantomData<fn(&mut T)>);
798    impl<T, F> ZwpTabletPadV2EventHandler for Leave<T, F>
799    where
800        T: 'static,
801        F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, Option<&WlSurfaceRef>),
802    {
803        type Data = T;
804
805        #[inline]
806        fn leave(
807            &self,
808            _data: &mut T,
809            _slf: &ZwpTabletPadV2Ref,
810            serial: u32,
811            surface: Option<&WlSurfaceRef>,
812        ) {
813            self.0(_data, _slf, serial, surface)
814        }
815    }
816
817    /// Event handler for removed events.
818    pub struct Removed<T, F>(F, PhantomData<fn(&mut T)>);
819    impl<T, F> ZwpTabletPadV2EventHandler for Removed<T, F>
820    where
821        T: 'static,
822        F: Fn(&mut T, &ZwpTabletPadV2Ref),
823    {
824        type Data = T;
825
826        #[inline]
827        fn removed(&self, _data: &mut T, _slf: &ZwpTabletPadV2Ref) {
828            self.0(_data, _slf)
829        }
830    }
831
832    impl ZwpTabletPadV2 {
833        /// Creates an event handler for group events.
834        ///
835        /// The event handler ignores all other events.
836        #[allow(dead_code)]
837        pub fn on_group<T, F>(f: F) -> Group<T, F>
838        where
839            T: 'static,
840            F: Fn(&mut T, &ZwpTabletPadV2Ref, ZwpTabletPadGroupV2),
841        {
842            Group(f, PhantomData)
843        }
844
845        /// Creates an event handler for path events.
846        ///
847        /// The event handler ignores all other events.
848        #[allow(dead_code)]
849        pub fn on_path<T, F>(f: F) -> Path<T, F>
850        where
851            T: 'static,
852            F: Fn(&mut T, &ZwpTabletPadV2Ref, &str),
853        {
854            Path(f, PhantomData)
855        }
856
857        /// Creates an event handler for buttons events.
858        ///
859        /// The event handler ignores all other events.
860        #[allow(dead_code)]
861        pub fn on_buttons<T, F>(f: F) -> Buttons<T, F>
862        where
863            T: 'static,
864            F: Fn(&mut T, &ZwpTabletPadV2Ref, u32),
865        {
866            Buttons(f, PhantomData)
867        }
868
869        /// Creates an event handler for done events.
870        ///
871        /// The event handler ignores all other events.
872        #[allow(dead_code)]
873        pub fn on_done<T, F>(f: F) -> Done<T, F>
874        where
875            T: 'static,
876            F: Fn(&mut T, &ZwpTabletPadV2Ref),
877        {
878            Done(f, PhantomData)
879        }
880
881        /// Creates an event handler for button events.
882        ///
883        /// The event handler ignores all other events.
884        #[allow(dead_code)]
885        pub fn on_button<T, F>(f: F) -> Button<T, F>
886        where
887            T: 'static,
888            F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, u32, ZwpTabletPadV2ButtonState),
889        {
890            Button(f, PhantomData)
891        }
892
893        /// Creates an event handler for enter events.
894        ///
895        /// The event handler ignores all other events.
896        #[allow(dead_code)]
897        pub fn on_enter<T, F>(f: F) -> Enter<T, F>
898        where
899            T: 'static,
900            F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, Option<&ZwpTabletV2Ref>, Option<&WlSurfaceRef>),
901        {
902            Enter(f, PhantomData)
903        }
904
905        /// Creates an event handler for leave events.
906        ///
907        /// The event handler ignores all other events.
908        #[allow(dead_code)]
909        pub fn on_leave<T, F>(f: F) -> Leave<T, F>
910        where
911            T: 'static,
912            F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, Option<&WlSurfaceRef>),
913        {
914            Leave(f, PhantomData)
915        }
916
917        /// Creates an event handler for removed events.
918        ///
919        /// The event handler ignores all other events.
920        #[allow(dead_code)]
921        pub fn on_removed<T, F>(f: F) -> Removed<T, F>
922        where
923            T: 'static,
924            F: Fn(&mut T, &ZwpTabletPadV2Ref),
925        {
926            Removed(f, PhantomData)
927        }
928    }
929}