simple_window/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        data: *mut u8,
487        slf: &UntypedBorrowedProxy,
488        opcode: u32,
489        args: *mut wl_argument,
490    ) {
491        // SAFETY: This function requires that slf has the interface INTERFACE
492        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<ZwpTabletPadV2Ref>(slf) };
493        match opcode {
494            0 => {
495                // SAFETY: INTERFACE requires that there are 1 arguments
496                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
497                // SAFETY: - INTERFACE requires that args[0] contains an object
498                //         - ownership is transferred to this function
499                //         - INTERFACE requires that the object has the interface ZwpTabletPadGroupV2::WL_INTERFACE
500                let arg0 = unsafe {
501                    UntypedOwnedProxy::from_plain_wl_proxy(
502                        queue,
503                        NonNull::new_unchecked(args[0].o.cast()),
504                        ZwpTabletPadGroupV2::WL_INTERFACE,
505                    )
506                };
507                // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletPadGroupV2::WL_INTERFACE
508                let arg0 =
509                    unsafe { proxy::low_level::from_untyped_owned::<ZwpTabletPadGroupV2>(arg0) };
510                self.0.group(slf, arg0);
511            }
512            1 => {
513                // SAFETY: INTERFACE requires that there are 1 arguments
514                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
515                // SAFETY: - INTERFACE requires that args[0] contains a string
516                //         - if the pointer is not null, then it is a c string
517                let arg0 = unsafe { convert_string_arg("zwp_tablet_pad_v2", "path", args[0].s) };
518                self.0.path(slf, arg0);
519            }
520            2 => {
521                // SAFETY: INTERFACE requires that there are 1 arguments
522                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
523                // SAFETY: - INTERFACE requires that args[0] contains a uint
524                let arg0 = unsafe { args[0].u };
525                self.0.buttons(slf, arg0);
526            }
527            3 => {
528                self.0.done(slf);
529            }
530            4 => {
531                // SAFETY: INTERFACE requires that there are 3 arguments
532                let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
533                // SAFETY: - INTERFACE requires that args[0] contains a uint
534                let arg0 = unsafe { args[0].u };
535                // SAFETY: - INTERFACE requires that args[1] contains a uint
536                let arg1 = unsafe { args[1].u };
537                // SAFETY: - INTERFACE requires that args[2] contains a uint
538                let arg2 = unsafe { ZwpTabletPadV2ButtonState(args[2].u) };
539                self.0.button(slf, arg0, arg1, arg2);
540            }
541            5 => {
542                // SAFETY: INTERFACE requires that there are 3 arguments
543                let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
544                // SAFETY: - INTERFACE requires that args[0] contains a uint
545                let arg0 = unsafe { args[0].u };
546                // SAFETY: - INTERFACE requires that args[1] contains an object
547                let arg1 = unsafe {
548                    if let Some(p) = NonNull::new(args[1].o.cast()) {
549                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
550                    } else {
551                        None
552                    }
553                };
554                // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletV2::WL_INTERFACE
555                let arg1 = arg1.as_ref().map(|arg1| unsafe {
556                    proxy::low_level::from_untyped_borrowed::<ZwpTabletV2Ref>(arg1)
557                });
558                // SAFETY: - INTERFACE requires that args[2] contains an object
559                let arg2 = unsafe {
560                    if let Some(p) = NonNull::new(args[2].o.cast()) {
561                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
562                    } else {
563                        None
564                    }
565                };
566                // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
567                let arg2 = arg2.as_ref().map(|arg2| unsafe {
568                    proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg2)
569                });
570                self.0.enter(slf, arg0, arg1, arg2);
571            }
572            6 => {
573                // SAFETY: INTERFACE requires that there are 2 arguments
574                let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
575                // SAFETY: - INTERFACE requires that args[0] contains a uint
576                let arg0 = unsafe { args[0].u };
577                // SAFETY: - INTERFACE requires that args[1] contains an object
578                let arg1 = unsafe {
579                    if let Some(p) = NonNull::new(args[1].o.cast()) {
580                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
581                    } else {
582                        None
583                    }
584                };
585                // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
586                let arg1 = arg1.as_ref().map(|arg1| unsafe {
587                    proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
588                });
589                self.0.leave(slf, arg0, arg1);
590            }
591            7 => {
592                self.0.removed(slf);
593            }
594            _ => {
595                invalid_opcode("zwp_tablet_pad_v2", opcode);
596            }
597        }
598    }
599}
600
601impl<H> CreateEventHandler<H> for private::ProxyApi
602where
603    H: ZwpTabletPadV2EventHandler,
604{
605    type EventHandler = private::EventHandler<H>;
606
607    #[inline]
608    fn create_event_handler(handler: H) -> Self::EventHandler {
609        private::EventHandler(handler)
610    }
611}
612
613impl ZwpTabletPadV2 {
614    /// Since when the button_state.released enum variant is available.
615    #[allow(dead_code)]
616    pub const ENM__BUTTON_STATE_RELEASED__SINCE: u32 = 1;
617    /// Since when the button_state.pressed enum variant is available.
618    #[allow(dead_code)]
619    pub const ENM__BUTTON_STATE_PRESSED__SINCE: u32 = 1;
620}
621
622/// physical button state
623///
624/// Describes the physical state of a button that caused the button
625/// event.
626#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
627#[allow(dead_code)]
628pub struct ZwpTabletPadV2ButtonState(pub u32);
629
630impl ZwpTabletPadV2ButtonState {
631    /// the button is not pressed
632    #[allow(dead_code)]
633    pub const RELEASED: Self = Self(0);
634
635    /// the button is pressed
636    #[allow(dead_code)]
637    pub const PRESSED: Self = Self(1);
638}
639
640impl Debug for ZwpTabletPadV2ButtonState {
641    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
642        let name = match *self {
643            Self::RELEASED => "RELEASED",
644            Self::PRESSED => "PRESSED",
645            _ => return Debug::fmt(&self.0, f),
646        };
647        f.write_str(name)
648    }
649}
650
651/// Functional event handlers.
652pub mod event_handlers {
653    use super::*;
654
655    /// Event handler for group events.
656    pub struct Group<F>(F);
657    impl<F> ZwpTabletPadV2EventHandler for Group<F>
658    where
659        F: Fn(&ZwpTabletPadV2Ref, ZwpTabletPadGroupV2),
660    {
661        #[inline]
662        fn group(&self, _slf: &ZwpTabletPadV2Ref, pad_group: ZwpTabletPadGroupV2) {
663            self.0(_slf, pad_group)
664        }
665    }
666
667    /// Event handler for path events.
668    pub struct Path<F>(F);
669    impl<F> ZwpTabletPadV2EventHandler for Path<F>
670    where
671        F: Fn(&ZwpTabletPadV2Ref, &str),
672    {
673        #[inline]
674        fn path(&self, _slf: &ZwpTabletPadV2Ref, path: &str) {
675            self.0(_slf, path)
676        }
677    }
678
679    /// Event handler for buttons events.
680    pub struct Buttons<F>(F);
681    impl<F> ZwpTabletPadV2EventHandler for Buttons<F>
682    where
683        F: Fn(&ZwpTabletPadV2Ref, u32),
684    {
685        #[inline]
686        fn buttons(&self, _slf: &ZwpTabletPadV2Ref, buttons: u32) {
687            self.0(_slf, buttons)
688        }
689    }
690
691    /// Event handler for done events.
692    pub struct Done<F>(F);
693    impl<F> ZwpTabletPadV2EventHandler for Done<F>
694    where
695        F: Fn(&ZwpTabletPadV2Ref),
696    {
697        #[inline]
698        fn done(&self, _slf: &ZwpTabletPadV2Ref) {
699            self.0(_slf)
700        }
701    }
702
703    /// Event handler for button events.
704    pub struct Button<F>(F);
705    impl<F> ZwpTabletPadV2EventHandler for Button<F>
706    where
707        F: Fn(&ZwpTabletPadV2Ref, u32, u32, ZwpTabletPadV2ButtonState),
708    {
709        #[inline]
710        fn button(
711            &self,
712            _slf: &ZwpTabletPadV2Ref,
713            time: u32,
714            button: u32,
715            state: ZwpTabletPadV2ButtonState,
716        ) {
717            self.0(_slf, time, button, state)
718        }
719    }
720
721    /// Event handler for enter events.
722    pub struct Enter<F>(F);
723    impl<F> ZwpTabletPadV2EventHandler for Enter<F>
724    where
725        F: Fn(&ZwpTabletPadV2Ref, u32, Option<&ZwpTabletV2Ref>, Option<&WlSurfaceRef>),
726    {
727        #[inline]
728        fn enter(
729            &self,
730            _slf: &ZwpTabletPadV2Ref,
731            serial: u32,
732            tablet: Option<&ZwpTabletV2Ref>,
733            surface: Option<&WlSurfaceRef>,
734        ) {
735            self.0(_slf, serial, tablet, surface)
736        }
737    }
738
739    /// Event handler for leave events.
740    pub struct Leave<F>(F);
741    impl<F> ZwpTabletPadV2EventHandler for Leave<F>
742    where
743        F: Fn(&ZwpTabletPadV2Ref, u32, Option<&WlSurfaceRef>),
744    {
745        #[inline]
746        fn leave(&self, _slf: &ZwpTabletPadV2Ref, serial: u32, surface: Option<&WlSurfaceRef>) {
747            self.0(_slf, serial, surface)
748        }
749    }
750
751    /// Event handler for removed events.
752    pub struct Removed<F>(F);
753    impl<F> ZwpTabletPadV2EventHandler for Removed<F>
754    where
755        F: Fn(&ZwpTabletPadV2Ref),
756    {
757        #[inline]
758        fn removed(&self, _slf: &ZwpTabletPadV2Ref) {
759            self.0(_slf)
760        }
761    }
762
763    impl ZwpTabletPadV2 {
764        /// Creates an event handler for group events.
765        ///
766        /// The event handler ignores all other events.
767        #[allow(dead_code)]
768        pub fn on_group<F>(f: F) -> Group<F>
769        where
770            F: Fn(&ZwpTabletPadV2Ref, ZwpTabletPadGroupV2),
771        {
772            Group(f)
773        }
774
775        /// Creates an event handler for path events.
776        ///
777        /// The event handler ignores all other events.
778        #[allow(dead_code)]
779        pub fn on_path<F>(f: F) -> Path<F>
780        where
781            F: Fn(&ZwpTabletPadV2Ref, &str),
782        {
783            Path(f)
784        }
785
786        /// Creates an event handler for buttons events.
787        ///
788        /// The event handler ignores all other events.
789        #[allow(dead_code)]
790        pub fn on_buttons<F>(f: F) -> Buttons<F>
791        where
792            F: Fn(&ZwpTabletPadV2Ref, u32),
793        {
794            Buttons(f)
795        }
796
797        /// Creates an event handler for done events.
798        ///
799        /// The event handler ignores all other events.
800        #[allow(dead_code)]
801        pub fn on_done<F>(f: F) -> Done<F>
802        where
803            F: Fn(&ZwpTabletPadV2Ref),
804        {
805            Done(f)
806        }
807
808        /// Creates an event handler for button events.
809        ///
810        /// The event handler ignores all other events.
811        #[allow(dead_code)]
812        pub fn on_button<F>(f: F) -> Button<F>
813        where
814            F: Fn(&ZwpTabletPadV2Ref, u32, u32, ZwpTabletPadV2ButtonState),
815        {
816            Button(f)
817        }
818
819        /// Creates an event handler for enter events.
820        ///
821        /// The event handler ignores all other events.
822        #[allow(dead_code)]
823        pub fn on_enter<F>(f: F) -> Enter<F>
824        where
825            F: Fn(&ZwpTabletPadV2Ref, u32, Option<&ZwpTabletV2Ref>, Option<&WlSurfaceRef>),
826        {
827            Enter(f)
828        }
829
830        /// Creates an event handler for leave events.
831        ///
832        /// The event handler ignores all other events.
833        #[allow(dead_code)]
834        pub fn on_leave<F>(f: F) -> Leave<F>
835        where
836            F: Fn(&ZwpTabletPadV2Ref, u32, Option<&WlSurfaceRef>),
837        {
838            Leave(f)
839        }
840
841        /// Creates an event handler for removed events.
842        ///
843        /// The event handler ignores all other events.
844        #[allow(dead_code)]
845        pub fn on_removed<F>(f: F) -> Removed<F>
846        where
847            F: Fn(&ZwpTabletPadV2Ref),
848        {
849            Removed(f)
850        }
851    }
852}