simple_window/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::*, ::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 type Data: 'static;
335
336 /// group announced
337 ///
338 /// Sent on wp_tablet_pad initialization to announce available groups.
339 /// One event is sent for each pad group available.
340 ///
341 /// This event is sent in the initial burst of events before the
342 /// wp_tablet_pad.done event. At least one group will be announced.
343 ///
344 /// # Arguments
345 ///
346 /// - `pad_group`:
347 #[inline]
348 fn group(
349 &self,
350 _data: &mut Self::Data,
351 _slf: &ZwpTabletPadV2Ref,
352 pad_group: ZwpTabletPadGroupV2,
353 ) {
354 let _ = pad_group;
355 }
356
357 /// path to the device
358 ///
359 /// A system-specific device path that indicates which device is behind
360 /// this wp_tablet_pad. This information may be used to gather additional
361 /// information about the device, e.g. through libwacom.
362 ///
363 /// The format of the path is unspecified, it may be a device node, a
364 /// sysfs path, or some other identifier. It is up to the client to
365 /// identify the string provided.
366 ///
367 /// This event is sent in the initial burst of events before the
368 /// wp_tablet_pad.done event.
369 ///
370 /// # Arguments
371 ///
372 /// - `path`: path to local device
373 #[inline]
374 fn path(&self, _data: &mut Self::Data, _slf: &ZwpTabletPadV2Ref, path: &str) {
375 let _ = path;
376 }
377
378 /// buttons announced
379 ///
380 /// Sent on wp_tablet_pad initialization to announce the available
381 /// buttons.
382 ///
383 /// This event is sent in the initial burst of events before the
384 /// wp_tablet_pad.done event. This event is only sent when at least one
385 /// button is available.
386 ///
387 /// # Arguments
388 ///
389 /// - `buttons`: the number of buttons
390 #[inline]
391 fn buttons(&self, _data: &mut Self::Data, _slf: &ZwpTabletPadV2Ref, buttons: u32) {
392 let _ = buttons;
393 }
394
395 /// pad description event sequence complete
396 ///
397 /// This event signals the end of the initial burst of descriptive
398 /// events. A client may consider the static description of the pad to
399 /// be complete and finalize initialization of the pad.
400 #[inline]
401 fn done(&self, _data: &mut Self::Data, _slf: &ZwpTabletPadV2Ref) {}
402
403 /// physical button state
404 ///
405 /// Sent whenever the physical state of a button changes.
406 ///
407 /// # Arguments
408 ///
409 /// - `time`: the time of the event with millisecond granularity
410 /// - `button`: the index of the button that changed state
411 /// - `state`:
412 #[inline]
413 fn button(
414 &self,
415 _data: &mut Self::Data,
416 _slf: &ZwpTabletPadV2Ref,
417 time: u32,
418 button: u32,
419 state: ZwpTabletPadV2ButtonState,
420 ) {
421 let _ = time;
422 let _ = button;
423 let _ = state;
424 }
425
426 /// enter event
427 ///
428 /// Notification that this pad is focused on the specified surface.
429 ///
430 /// # Arguments
431 ///
432 /// - `serial`: serial number of the enter event
433 /// - `tablet`: the tablet the pad is attached to
434 /// - `surface`: surface the pad is focused on
435 ///
436 /// All borrowed proxies passed to this function are guaranteed to be
437 /// immutable and non-null.
438 #[inline]
439 fn enter(
440 &self,
441 _data: &mut Self::Data,
442 _slf: &ZwpTabletPadV2Ref,
443 serial: u32,
444 tablet: Option<&ZwpTabletV2Ref>,
445 surface: Option<&WlSurfaceRef>,
446 ) {
447 let _ = serial;
448 let _ = tablet;
449 let _ = surface;
450 }
451
452 /// leave event
453 ///
454 /// Notification that this pad is no longer focused on the specified
455 /// surface.
456 ///
457 /// # Arguments
458 ///
459 /// - `serial`: serial number of the leave event
460 /// - `surface`: surface the pad is no longer focused on
461 ///
462 /// All borrowed proxies passed to this function are guaranteed to be
463 /// immutable and non-null.
464 #[inline]
465 fn leave(
466 &self,
467 _data: &mut Self::Data,
468 _slf: &ZwpTabletPadV2Ref,
469 serial: u32,
470 surface: Option<&WlSurfaceRef>,
471 ) {
472 let _ = serial;
473 let _ = surface;
474 }
475
476 /// pad removed event
477 ///
478 /// Sent when the pad has been removed from the system. When a tablet
479 /// is removed its pad(s) will be removed too.
480 ///
481 /// When this event is received, the client must destroy all rings, strips
482 /// and groups that were offered by this pad, and issue wp_tablet_pad.destroy
483 /// the pad itself.
484 #[inline]
485 fn removed(&self, _data: &mut Self::Data, _slf: &ZwpTabletPadV2Ref) {}
486}
487
488impl ZwpTabletPadV2EventHandler for private::NoOpEventHandler {
489 type Data = ();
490}
491
492// SAFETY: - INTERFACE is a valid wl_interface
493// - mutable_type always returns the same value
494unsafe impl<H> EventHandler for private::EventHandler<H>
495where
496 H: ZwpTabletPadV2EventHandler,
497{
498 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
499
500 #[inline]
501 fn mutable_type() -> Option<(TypeId, &'static str)> {
502 let id = TypeId::of::<H::Data>();
503 let name = std::any::type_name::<H::Data>();
504 Some((id, name))
505 }
506
507 #[allow(unused_variables)]
508 unsafe fn handle_event(
509 &self,
510 queue: &Queue,
511 data: *mut u8,
512 slf: &UntypedBorrowedProxy,
513 opcode: u32,
514 args: *mut wl_argument,
515 ) {
516 // SAFETY: This function requires that slf has the interface INTERFACE
517 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<ZwpTabletPadV2Ref>(slf) };
518 // SAFETY: This function requires that data is `&mut T` where `T`
519 // has the type id returned by `Self::mutable_type`, i.e.,
520 // `T = H::Data`.
521 let data: &mut H::Data = unsafe { &mut *data.cast() };
522 match opcode {
523 0 => {
524 // SAFETY: INTERFACE requires that there are 1 arguments
525 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
526 // SAFETY: - INTERFACE requires that args[0] contains an object
527 // - ownership is transferred to this function
528 // - INTERFACE requires that the object has the interface ZwpTabletPadGroupV2::WL_INTERFACE
529 let arg0 = unsafe {
530 UntypedOwnedProxy::from_plain_wl_proxy(
531 queue,
532 NonNull::new_unchecked(args[0].o.cast()),
533 ZwpTabletPadGroupV2::WL_INTERFACE,
534 )
535 };
536 // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletPadGroupV2::WL_INTERFACE
537 let arg0 =
538 unsafe { proxy::low_level::from_untyped_owned::<ZwpTabletPadGroupV2>(arg0) };
539 self.0.group(data, slf, arg0);
540 }
541 1 => {
542 // SAFETY: INTERFACE requires that there are 1 arguments
543 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
544 // SAFETY: - INTERFACE requires that args[0] contains a string
545 // - if the pointer is not null, then it is a c string
546 let arg0 = unsafe { convert_string_arg("zwp_tablet_pad_v2", "path", args[0].s) };
547 self.0.path(data, slf, arg0);
548 }
549 2 => {
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 uint
553 let arg0 = unsafe { args[0].u };
554 self.0.buttons(data, slf, arg0);
555 }
556 3 => {
557 self.0.done(data, slf);
558 }
559 4 => {
560 // SAFETY: INTERFACE requires that there are 3 arguments
561 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
562 // SAFETY: - INTERFACE requires that args[0] contains a uint
563 let arg0 = unsafe { args[0].u };
564 // SAFETY: - INTERFACE requires that args[1] contains a uint
565 let arg1 = unsafe { args[1].u };
566 // SAFETY: - INTERFACE requires that args[2] contains a uint
567 let arg2 = unsafe { ZwpTabletPadV2ButtonState(args[2].u) };
568 self.0.button(data, slf, arg0, arg1, arg2);
569 }
570 5 => {
571 // SAFETY: INTERFACE requires that there are 3 arguments
572 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
573 // SAFETY: - INTERFACE requires that args[0] contains a uint
574 let arg0 = unsafe { args[0].u };
575 // SAFETY: - INTERFACE requires that args[1] contains an object
576 let arg1 = unsafe {
577 if let Some(p) = NonNull::new(args[1].o.cast()) {
578 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
579 } else {
580 None
581 }
582 };
583 // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletV2::WL_INTERFACE
584 let arg1 = arg1.as_ref().map(|arg1| unsafe {
585 proxy::low_level::from_untyped_borrowed::<ZwpTabletV2Ref>(arg1)
586 });
587 // SAFETY: - INTERFACE requires that args[2] contains an object
588 let arg2 = unsafe {
589 if let Some(p) = NonNull::new(args[2].o.cast()) {
590 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
591 } else {
592 None
593 }
594 };
595 // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
596 let arg2 = arg2.as_ref().map(|arg2| unsafe {
597 proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg2)
598 });
599 self.0.enter(data, slf, arg0, arg1, arg2);
600 }
601 6 => {
602 // SAFETY: INTERFACE requires that there are 2 arguments
603 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
604 // SAFETY: - INTERFACE requires that args[0] contains a uint
605 let arg0 = unsafe { args[0].u };
606 // SAFETY: - INTERFACE requires that args[1] contains an object
607 let arg1 = unsafe {
608 if let Some(p) = NonNull::new(args[1].o.cast()) {
609 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
610 } else {
611 None
612 }
613 };
614 // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
615 let arg1 = arg1.as_ref().map(|arg1| unsafe {
616 proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
617 });
618 self.0.leave(data, slf, arg0, arg1);
619 }
620 7 => {
621 self.0.removed(data, slf);
622 }
623 _ => {
624 invalid_opcode("zwp_tablet_pad_v2", opcode);
625 }
626 }
627 }
628}
629
630impl<H> CreateEventHandler<H> for private::ProxyApi
631where
632 H: ZwpTabletPadV2EventHandler,
633{
634 type EventHandler = private::EventHandler<H>;
635
636 #[inline]
637 fn create_event_handler(handler: H) -> Self::EventHandler {
638 private::EventHandler(handler)
639 }
640}
641
642impl ZwpTabletPadV2 {
643 /// Since when the button_state.released enum variant is available.
644 #[allow(dead_code)]
645 pub const ENM__BUTTON_STATE_RELEASED__SINCE: u32 = 1;
646 /// Since when the button_state.pressed enum variant is available.
647 #[allow(dead_code)]
648 pub const ENM__BUTTON_STATE_PRESSED__SINCE: u32 = 1;
649}
650
651/// physical button state
652///
653/// Describes the physical state of a button that caused the button
654/// event.
655#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
656#[allow(dead_code)]
657pub struct ZwpTabletPadV2ButtonState(pub u32);
658
659impl ZwpTabletPadV2ButtonState {
660 /// the button is not pressed
661 #[allow(dead_code)]
662 pub const RELEASED: Self = Self(0);
663
664 /// the button is pressed
665 #[allow(dead_code)]
666 pub const PRESSED: Self = Self(1);
667}
668
669impl Debug for ZwpTabletPadV2ButtonState {
670 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
671 let name = match *self {
672 Self::RELEASED => "RELEASED",
673 Self::PRESSED => "PRESSED",
674 _ => return Debug::fmt(&self.0, f),
675 };
676 f.write_str(name)
677 }
678}
679
680/// Functional event handlers.
681pub mod event_handlers {
682 use super::*;
683
684 /// Event handler for group events.
685 pub struct Group<T, F>(F, PhantomData<fn(&mut T)>);
686 impl<T, F> ZwpTabletPadV2EventHandler for Group<T, F>
687 where
688 T: 'static,
689 F: Fn(&mut T, &ZwpTabletPadV2Ref, ZwpTabletPadGroupV2),
690 {
691 type Data = T;
692
693 #[inline]
694 fn group(&self, _data: &mut T, _slf: &ZwpTabletPadV2Ref, pad_group: ZwpTabletPadGroupV2) {
695 self.0(_data, _slf, pad_group)
696 }
697 }
698
699 /// Event handler for path events.
700 pub struct Path<T, F>(F, PhantomData<fn(&mut T)>);
701 impl<T, F> ZwpTabletPadV2EventHandler for Path<T, F>
702 where
703 T: 'static,
704 F: Fn(&mut T, &ZwpTabletPadV2Ref, &str),
705 {
706 type Data = T;
707
708 #[inline]
709 fn path(&self, _data: &mut T, _slf: &ZwpTabletPadV2Ref, path: &str) {
710 self.0(_data, _slf, path)
711 }
712 }
713
714 /// Event handler for buttons events.
715 pub struct Buttons<T, F>(F, PhantomData<fn(&mut T)>);
716 impl<T, F> ZwpTabletPadV2EventHandler for Buttons<T, F>
717 where
718 T: 'static,
719 F: Fn(&mut T, &ZwpTabletPadV2Ref, u32),
720 {
721 type Data = T;
722
723 #[inline]
724 fn buttons(&self, _data: &mut T, _slf: &ZwpTabletPadV2Ref, buttons: u32) {
725 self.0(_data, _slf, buttons)
726 }
727 }
728
729 /// Event handler for done events.
730 pub struct Done<T, F>(F, PhantomData<fn(&mut T)>);
731 impl<T, F> ZwpTabletPadV2EventHandler for Done<T, F>
732 where
733 T: 'static,
734 F: Fn(&mut T, &ZwpTabletPadV2Ref),
735 {
736 type Data = T;
737
738 #[inline]
739 fn done(&self, _data: &mut T, _slf: &ZwpTabletPadV2Ref) {
740 self.0(_data, _slf)
741 }
742 }
743
744 /// Event handler for button events.
745 pub struct Button<T, F>(F, PhantomData<fn(&mut T)>);
746 impl<T, F> ZwpTabletPadV2EventHandler for Button<T, F>
747 where
748 T: 'static,
749 F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, u32, ZwpTabletPadV2ButtonState),
750 {
751 type Data = T;
752
753 #[inline]
754 fn button(
755 &self,
756 _data: &mut T,
757 _slf: &ZwpTabletPadV2Ref,
758 time: u32,
759 button: u32,
760 state: ZwpTabletPadV2ButtonState,
761 ) {
762 self.0(_data, _slf, time, button, state)
763 }
764 }
765
766 /// Event handler for enter events.
767 pub struct Enter<T, F>(F, PhantomData<fn(&mut T)>);
768 impl<T, F> ZwpTabletPadV2EventHandler for Enter<T, F>
769 where
770 T: 'static,
771 F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, Option<&ZwpTabletV2Ref>, Option<&WlSurfaceRef>),
772 {
773 type Data = T;
774
775 #[inline]
776 fn enter(
777 &self,
778 _data: &mut T,
779 _slf: &ZwpTabletPadV2Ref,
780 serial: u32,
781 tablet: Option<&ZwpTabletV2Ref>,
782 surface: Option<&WlSurfaceRef>,
783 ) {
784 self.0(_data, _slf, serial, tablet, surface)
785 }
786 }
787
788 /// Event handler for leave events.
789 pub struct Leave<T, F>(F, PhantomData<fn(&mut T)>);
790 impl<T, F> ZwpTabletPadV2EventHandler for Leave<T, F>
791 where
792 T: 'static,
793 F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, Option<&WlSurfaceRef>),
794 {
795 type Data = T;
796
797 #[inline]
798 fn leave(
799 &self,
800 _data: &mut T,
801 _slf: &ZwpTabletPadV2Ref,
802 serial: u32,
803 surface: Option<&WlSurfaceRef>,
804 ) {
805 self.0(_data, _slf, serial, surface)
806 }
807 }
808
809 /// Event handler for removed events.
810 pub struct Removed<T, F>(F, PhantomData<fn(&mut T)>);
811 impl<T, F> ZwpTabletPadV2EventHandler for Removed<T, F>
812 where
813 T: 'static,
814 F: Fn(&mut T, &ZwpTabletPadV2Ref),
815 {
816 type Data = T;
817
818 #[inline]
819 fn removed(&self, _data: &mut T, _slf: &ZwpTabletPadV2Ref) {
820 self.0(_data, _slf)
821 }
822 }
823
824 impl ZwpTabletPadV2 {
825 /// Creates an event handler for group events.
826 ///
827 /// The event handler ignores all other events.
828 #[allow(dead_code)]
829 pub fn on_group<T, F>(f: F) -> Group<T, F>
830 where
831 T: 'static,
832 F: Fn(&mut T, &ZwpTabletPadV2Ref, ZwpTabletPadGroupV2),
833 {
834 Group(f, PhantomData)
835 }
836
837 /// Creates an event handler for path events.
838 ///
839 /// The event handler ignores all other events.
840 #[allow(dead_code)]
841 pub fn on_path<T, F>(f: F) -> Path<T, F>
842 where
843 T: 'static,
844 F: Fn(&mut T, &ZwpTabletPadV2Ref, &str),
845 {
846 Path(f, PhantomData)
847 }
848
849 /// Creates an event handler for buttons events.
850 ///
851 /// The event handler ignores all other events.
852 #[allow(dead_code)]
853 pub fn on_buttons<T, F>(f: F) -> Buttons<T, F>
854 where
855 T: 'static,
856 F: Fn(&mut T, &ZwpTabletPadV2Ref, u32),
857 {
858 Buttons(f, PhantomData)
859 }
860
861 /// Creates an event handler for done events.
862 ///
863 /// The event handler ignores all other events.
864 #[allow(dead_code)]
865 pub fn on_done<T, F>(f: F) -> Done<T, F>
866 where
867 T: 'static,
868 F: Fn(&mut T, &ZwpTabletPadV2Ref),
869 {
870 Done(f, PhantomData)
871 }
872
873 /// Creates an event handler for button events.
874 ///
875 /// The event handler ignores all other events.
876 #[allow(dead_code)]
877 pub fn on_button<T, F>(f: F) -> Button<T, F>
878 where
879 T: 'static,
880 F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, u32, ZwpTabletPadV2ButtonState),
881 {
882 Button(f, PhantomData)
883 }
884
885 /// Creates an event handler for enter events.
886 ///
887 /// The event handler ignores all other events.
888 #[allow(dead_code)]
889 pub fn on_enter<T, F>(f: F) -> Enter<T, F>
890 where
891 T: 'static,
892 F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, Option<&ZwpTabletV2Ref>, Option<&WlSurfaceRef>),
893 {
894 Enter(f, PhantomData)
895 }
896
897 /// Creates an event handler for leave events.
898 ///
899 /// The event handler ignores all other events.
900 #[allow(dead_code)]
901 pub fn on_leave<T, F>(f: F) -> Leave<T, F>
902 where
903 T: 'static,
904 F: Fn(&mut T, &ZwpTabletPadV2Ref, u32, Option<&WlSurfaceRef>),
905 {
906 Leave(f, PhantomData)
907 }
908
909 /// Creates an event handler for removed events.
910 ///
911 /// The event handler ignores all other events.
912 #[allow(dead_code)]
913 pub fn on_removed<T, F>(f: F) -> Removed<T, F>
914 where
915 T: 'static,
916 F: Fn(&mut T, &ZwpTabletPadV2Ref),
917 {
918 Removed(f, PhantomData)
919 }
920 }
921}