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