simple_window/common/protocols_data/tablet_v2/zwp_tablet_tool_v2.rs
1//! a physical tablet tool
2//!
3//! An object that represents a physical tool that has been, or is
4//! currently in use with a tablet in this seat. Each wp_tablet_tool
5//! object stays valid until the client destroys it; the compositor
6//! reuses the wp_tablet_tool object to indicate that the object's
7//! respective physical tool has come into proximity of a tablet again.
8//!
9//! A wp_tablet_tool object's relation to a physical tool depends on the
10//! tablet's ability to report serial numbers. If the tablet supports
11//! this capability, then the object represents a specific physical tool
12//! and can be identified even when used on multiple tablets.
13//!
14//! A tablet tool has a number of static characteristics, e.g. tool type,
15//! hardware_serial and capabilities. These capabilities are sent in an
16//! event sequence after the wp_tablet_seat.tool_added event before any
17//! actual events from this tool. This initial event sequence is
18//! terminated by a wp_tablet_tool.done event.
19//!
20//! Tablet tool events are grouped by wp_tablet_tool.frame events.
21//! Any events received before a wp_tablet_tool.frame event should be
22//! considered part of the same hardware state change.
23
24use {super::super::all_types::*, ::wl_client::builder::prelude::*};
25
26static INTERFACE: wl_interface = wl_interface {
27 name: c"zwp_tablet_tool_v2".as_ptr(),
28 version: 1,
29 method_count: 2,
30 methods: {
31 static MESSAGES: [wl_message; 2] = [
32 wl_message {
33 name: c"set_cursor".as_ptr(),
34 signature: c"u?oii".as_ptr(),
35 types: {
36 static TYPES: [Option<&'static wl_interface>; 4] =
37 [None, Some(WlSurface::WL_INTERFACE), None, None];
38 TYPES.as_ptr().cast()
39 },
40 },
41 wl_message {
42 name: c"destroy".as_ptr(),
43 signature: c"".as_ptr(),
44 types: {
45 static TYPES: [Option<&'static wl_interface>; 0] = [];
46 TYPES.as_ptr().cast()
47 },
48 },
49 ];
50 MESSAGES.as_ptr()
51 },
52 event_count: 19,
53 events: {
54 static MESSAGES: [wl_message; 19] = [
55 wl_message {
56 name: c"type".as_ptr(),
57 signature: c"u".as_ptr(),
58 types: {
59 static TYPES: [Option<&'static wl_interface>; 1] = [None];
60 TYPES.as_ptr().cast()
61 },
62 },
63 wl_message {
64 name: c"hardware_serial".as_ptr(),
65 signature: c"uu".as_ptr(),
66 types: {
67 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
68 TYPES.as_ptr().cast()
69 },
70 },
71 wl_message {
72 name: c"hardware_id_wacom".as_ptr(),
73 signature: c"uu".as_ptr(),
74 types: {
75 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
76 TYPES.as_ptr().cast()
77 },
78 },
79 wl_message {
80 name: c"capability".as_ptr(),
81 signature: c"u".as_ptr(),
82 types: {
83 static TYPES: [Option<&'static wl_interface>; 1] = [None];
84 TYPES.as_ptr().cast()
85 },
86 },
87 wl_message {
88 name: c"done".as_ptr(),
89 signature: c"".as_ptr(),
90 types: {
91 static TYPES: [Option<&'static wl_interface>; 0] = [];
92 TYPES.as_ptr().cast()
93 },
94 },
95 wl_message {
96 name: c"removed".as_ptr(),
97 signature: c"".as_ptr(),
98 types: {
99 static TYPES: [Option<&'static wl_interface>; 0] = [];
100 TYPES.as_ptr().cast()
101 },
102 },
103 wl_message {
104 name: c"proximity_in".as_ptr(),
105 signature: c"uoo".as_ptr(),
106 types: {
107 static TYPES: [Option<&'static wl_interface>; 3] = [
108 None,
109 Some(ZwpTabletV2::WL_INTERFACE),
110 Some(WlSurface::WL_INTERFACE),
111 ];
112 TYPES.as_ptr().cast()
113 },
114 },
115 wl_message {
116 name: c"proximity_out".as_ptr(),
117 signature: c"".as_ptr(),
118 types: {
119 static TYPES: [Option<&'static wl_interface>; 0] = [];
120 TYPES.as_ptr().cast()
121 },
122 },
123 wl_message {
124 name: c"down".as_ptr(),
125 signature: c"u".as_ptr(),
126 types: {
127 static TYPES: [Option<&'static wl_interface>; 1] = [None];
128 TYPES.as_ptr().cast()
129 },
130 },
131 wl_message {
132 name: c"up".as_ptr(),
133 signature: c"".as_ptr(),
134 types: {
135 static TYPES: [Option<&'static wl_interface>; 0] = [];
136 TYPES.as_ptr().cast()
137 },
138 },
139 wl_message {
140 name: c"motion".as_ptr(),
141 signature: c"ff".as_ptr(),
142 types: {
143 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
144 TYPES.as_ptr().cast()
145 },
146 },
147 wl_message {
148 name: c"pressure".as_ptr(),
149 signature: c"u".as_ptr(),
150 types: {
151 static TYPES: [Option<&'static wl_interface>; 1] = [None];
152 TYPES.as_ptr().cast()
153 },
154 },
155 wl_message {
156 name: c"distance".as_ptr(),
157 signature: c"u".as_ptr(),
158 types: {
159 static TYPES: [Option<&'static wl_interface>; 1] = [None];
160 TYPES.as_ptr().cast()
161 },
162 },
163 wl_message {
164 name: c"tilt".as_ptr(),
165 signature: c"ff".as_ptr(),
166 types: {
167 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
168 TYPES.as_ptr().cast()
169 },
170 },
171 wl_message {
172 name: c"rotation".as_ptr(),
173 signature: c"f".as_ptr(),
174 types: {
175 static TYPES: [Option<&'static wl_interface>; 1] = [None];
176 TYPES.as_ptr().cast()
177 },
178 },
179 wl_message {
180 name: c"slider".as_ptr(),
181 signature: c"i".as_ptr(),
182 types: {
183 static TYPES: [Option<&'static wl_interface>; 1] = [None];
184 TYPES.as_ptr().cast()
185 },
186 },
187 wl_message {
188 name: c"wheel".as_ptr(),
189 signature: c"fi".as_ptr(),
190 types: {
191 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
192 TYPES.as_ptr().cast()
193 },
194 },
195 wl_message {
196 name: c"button".as_ptr(),
197 signature: c"uuu".as_ptr(),
198 types: {
199 static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
200 TYPES.as_ptr().cast()
201 },
202 },
203 wl_message {
204 name: c"frame".as_ptr(),
205 signature: c"u".as_ptr(),
206 types: {
207 static TYPES: [Option<&'static wl_interface>; 1] = [None];
208 TYPES.as_ptr().cast()
209 },
210 },
211 ];
212 MESSAGES.as_ptr()
213 },
214};
215
216/// An owned zwp_tablet_tool_v2 proxy.
217///
218/// See the documentation of [the module][self] for the interface description.
219#[derive(Clone, Eq, PartialEq)]
220#[repr(transparent)]
221pub struct ZwpTabletToolV2 {
222 /// This proxy has the interface INTERFACE.
223 proxy: UntypedOwnedProxy,
224}
225
226/// A borrowed zwp_tablet_tool_v2 proxy.
227///
228/// See the documentation of [the module][self] for the interface description.
229#[derive(Eq, PartialEq)]
230#[repr(transparent)]
231pub struct ZwpTabletToolV2Ref {
232 /// This proxy has the interface INTERFACE.
233 proxy: UntypedBorrowedProxy,
234}
235
236// SAFETY: ZwpTabletToolV2 is a transparent wrapper around UntypedOwnedProxy
237unsafe impl UntypedOwnedProxyWrapper for ZwpTabletToolV2 {}
238
239// SAFETY: - INTERFACE is a valid wl_interface
240// - The only invariant is that self.proxy has a compatible interface
241unsafe impl OwnedProxy for ZwpTabletToolV2 {
242 const INTERFACE: &'static str = "zwp_tablet_tool_v2";
243 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
244 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
245 private::EventHandler(private::NoOpEventHandler);
246 const MAX_VERSION: u32 = 1;
247
248 type Borrowed = ZwpTabletToolV2Ref;
249 type Api = private::ProxyApi;
250 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
251}
252
253// SAFETY: ZwpTabletToolV2Ref is a transparent wrapper around UntypedBorrowedProxy
254unsafe impl UntypedBorrowedProxyWrapper for ZwpTabletToolV2Ref {}
255
256// SAFETY: - The only invariant is that self.proxy has a compatible interface
257unsafe impl BorrowedProxy for ZwpTabletToolV2Ref {
258 type Owned = ZwpTabletToolV2;
259}
260
261impl Deref for ZwpTabletToolV2 {
262 type Target = ZwpTabletToolV2Ref;
263
264 fn deref(&self) -> &Self::Target {
265 proxy::low_level::deref(self)
266 }
267}
268
269mod private {
270 pub struct ProxyApi;
271
272 #[allow(dead_code)]
273 pub struct EventHandler<H>(pub(super) H);
274
275 #[allow(dead_code)]
276 pub struct NoOpEventHandler;
277}
278
279impl Debug for ZwpTabletToolV2 {
280 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
281 write!(f, "zwp_tablet_tool_v2#{}", self.proxy.id())
282 }
283}
284
285impl Debug for ZwpTabletToolV2Ref {
286 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
287 write!(f, "zwp_tablet_tool_v2#{}", self.proxy.id())
288 }
289}
290
291impl PartialEq<ZwpTabletToolV2Ref> for ZwpTabletToolV2 {
292 fn eq(&self, other: &ZwpTabletToolV2Ref) -> bool {
293 self.proxy == other.proxy
294 }
295}
296
297impl PartialEq<ZwpTabletToolV2> for ZwpTabletToolV2Ref {
298 fn eq(&self, other: &ZwpTabletToolV2) -> bool {
299 self.proxy == other.proxy
300 }
301}
302
303#[allow(dead_code)]
304impl ZwpTabletToolV2 {
305 /// Since when the destroy request is available.
306 #[allow(dead_code)]
307 pub const REQ__DESTROY__SINCE: u32 = 1;
308
309 /// destroy the tool object
310 ///
311 /// This destroys the client's resource for this tool object.
312 #[inline]
313 pub fn destroy(&self) {
314 let mut args = [];
315 // SAFETY: - self.proxy has the interface INTERFACE
316 // - 1 < INTERFACE.method_count = 2
317 // - the request signature is ``
318 unsafe {
319 self.proxy.send_destructor(1, &mut args);
320 }
321 }
322}
323
324#[allow(dead_code)]
325impl ZwpTabletToolV2Ref {
326 /// set the tablet tool's surface
327 ///
328 /// Sets the surface of the cursor used for this tool on the given
329 /// tablet. This request only takes effect if the tool is in proximity
330 /// of one of the requesting client's surfaces or the surface parameter
331 /// is the current pointer surface. If there was a previous surface set
332 /// with this request it is replaced. If surface is NULL, the cursor
333 /// image is hidden.
334 ///
335 /// The parameters hotspot_x and hotspot_y define the position of the
336 /// pointer surface relative to the pointer location. Its top-left corner
337 /// is always at (x, y) - (hotspot_x, hotspot_y), where (x, y) are the
338 /// coordinates of the pointer location, in surface-local coordinates.
339 ///
340 /// On surface.attach requests to the pointer surface, hotspot_x and
341 /// hotspot_y are decremented by the x and y parameters passed to the
342 /// request. Attach must be confirmed by wl_surface.commit as usual.
343 ///
344 /// The hotspot can also be updated by passing the currently set pointer
345 /// surface to this request with new values for hotspot_x and hotspot_y.
346 ///
347 /// The current and pending input regions of the wl_surface are cleared,
348 /// and wl_surface.set_input_region is ignored until the wl_surface is no
349 /// longer used as the cursor. When the use as a cursor ends, the current
350 /// and pending input regions become undefined, and the wl_surface is
351 /// unmapped.
352 ///
353 /// This request gives the surface the role of a wp_tablet_tool cursor. A
354 /// surface may only ever be used as the cursor surface for one
355 /// wp_tablet_tool. If the surface already has another role or has
356 /// previously been used as cursor surface for a different tool, a
357 /// protocol error is raised.
358 ///
359 /// # Arguments
360 ///
361 /// - `serial`: serial of the proximity_in event
362 /// - `surface`:
363 /// - `hotspot_x`: surface-local x coordinate
364 /// - `hotspot_y`: surface-local y coordinate
365 #[inline]
366 pub fn set_cursor(
367 &self,
368 serial: u32,
369 surface: Option<&WlSurfaceRef>,
370 hotspot_x: i32,
371 hotspot_y: i32,
372 ) {
373 let (arg0, arg1, arg2, arg3) = (serial, surface, hotspot_x, hotspot_y);
374 let obj1_lock = arg1.map(|arg1| proxy::lock(arg1));
375 let obj1 = obj1_lock
376 .map(|obj1_lock| check_argument_proxy("surface", obj1_lock.wl_proxy()))
377 .unwrap_or(ptr::null_mut());
378 let mut args = [
379 wl_argument { u: arg0 },
380 wl_argument { o: obj1 },
381 wl_argument { i: arg2 },
382 wl_argument { i: arg3 },
383 ];
384 // SAFETY: - self.proxy has the interface INTERFACE
385 // - 0 < INTERFACE.method_count = 2
386 // - the request signature is `u?oii`
387 unsafe {
388 self.proxy.send_request(0, &mut args);
389 }
390 }
391}
392
393impl ZwpTabletToolV2 {
394 /// Since when the type event is available.
395 #[allow(dead_code)]
396 pub const EVT__TYPE__SINCE: u32 = 1;
397
398 /// Since when the hardware_serial event is available.
399 #[allow(dead_code)]
400 pub const EVT__HARDWARE_SERIAL__SINCE: u32 = 1;
401
402 /// Since when the hardware_id_wacom event is available.
403 #[allow(dead_code)]
404 pub const EVT__HARDWARE_ID_WACOM__SINCE: u32 = 1;
405
406 /// Since when the capability event is available.
407 #[allow(dead_code)]
408 pub const EVT__CAPABILITY__SINCE: u32 = 1;
409
410 /// Since when the done event is available.
411 #[allow(dead_code)]
412 pub const EVT__DONE__SINCE: u32 = 1;
413
414 /// Since when the removed event is available.
415 #[allow(dead_code)]
416 pub const EVT__REMOVED__SINCE: u32 = 1;
417
418 /// Since when the proximity_in event is available.
419 #[allow(dead_code)]
420 pub const EVT__PROXIMITY_IN__SINCE: u32 = 1;
421
422 /// Since when the proximity_out event is available.
423 #[allow(dead_code)]
424 pub const EVT__PROXIMITY_OUT__SINCE: u32 = 1;
425
426 /// Since when the down event is available.
427 #[allow(dead_code)]
428 pub const EVT__DOWN__SINCE: u32 = 1;
429
430 /// Since when the up event is available.
431 #[allow(dead_code)]
432 pub const EVT__UP__SINCE: u32 = 1;
433
434 /// Since when the motion event is available.
435 #[allow(dead_code)]
436 pub const EVT__MOTION__SINCE: u32 = 1;
437
438 /// Since when the pressure event is available.
439 #[allow(dead_code)]
440 pub const EVT__PRESSURE__SINCE: u32 = 1;
441
442 /// Since when the distance event is available.
443 #[allow(dead_code)]
444 pub const EVT__DISTANCE__SINCE: u32 = 1;
445
446 /// Since when the tilt event is available.
447 #[allow(dead_code)]
448 pub const EVT__TILT__SINCE: u32 = 1;
449
450 /// Since when the rotation event is available.
451 #[allow(dead_code)]
452 pub const EVT__ROTATION__SINCE: u32 = 1;
453
454 /// Since when the slider event is available.
455 #[allow(dead_code)]
456 pub const EVT__SLIDER__SINCE: u32 = 1;
457
458 /// Since when the wheel event is available.
459 #[allow(dead_code)]
460 pub const EVT__WHEEL__SINCE: u32 = 1;
461
462 /// Since when the button event is available.
463 #[allow(dead_code)]
464 pub const EVT__BUTTON__SINCE: u32 = 1;
465
466 /// Since when the frame event is available.
467 #[allow(dead_code)]
468 pub const EVT__FRAME__SINCE: u32 = 1;
469}
470
471/// An event handler for [ZwpTabletToolV2] proxies.
472#[allow(dead_code)]
473pub trait ZwpTabletToolV2EventHandler {
474 type Data: 'static;
475
476 /// tool type
477 ///
478 /// The tool type is the high-level type of the tool and usually decides
479 /// the interaction expected from this tool.
480 ///
481 /// This event is sent in the initial burst of events before the
482 /// wp_tablet_tool.done event.
483 ///
484 /// # Arguments
485 ///
486 /// - `tool_type`: the physical tool type
487 #[inline]
488 fn r#type(
489 &self,
490 _data: &mut Self::Data,
491 _slf: &ZwpTabletToolV2Ref,
492 tool_type: ZwpTabletToolV2Type,
493 ) {
494 let _ = tool_type;
495 }
496
497 /// unique hardware serial number of the tool
498 ///
499 /// If the physical tool can be identified by a unique 64-bit serial
500 /// number, this event notifies the client of this serial number.
501 ///
502 /// If multiple tablets are available in the same seat and the tool is
503 /// uniquely identifiable by the serial number, that tool may move
504 /// between tablets.
505 ///
506 /// Otherwise, if the tool has no serial number and this event is
507 /// missing, the tool is tied to the tablet it first comes into
508 /// proximity with. Even if the physical tool is used on multiple
509 /// tablets, separate wp_tablet_tool objects will be created, one per
510 /// tablet.
511 ///
512 /// This event is sent in the initial burst of events before the
513 /// wp_tablet_tool.done event.
514 ///
515 /// # Arguments
516 ///
517 /// - `hardware_serial_hi`: the unique serial number of the tool, most significant bits
518 /// - `hardware_serial_lo`: the unique serial number of the tool, least significant bits
519 #[inline]
520 fn hardware_serial(
521 &self,
522 _data: &mut Self::Data,
523 _slf: &ZwpTabletToolV2Ref,
524 hardware_serial_hi: u32,
525 hardware_serial_lo: u32,
526 ) {
527 let _ = hardware_serial_hi;
528 let _ = hardware_serial_lo;
529 }
530
531 /// hardware id notification in Wacom's format
532 ///
533 /// This event notifies the client of a hardware id available on this tool.
534 ///
535 /// The hardware id is a device-specific 64-bit id that provides extra
536 /// information about the tool in use, beyond the wl_tool.type
537 /// enumeration. The format of the id is specific to tablets made by
538 /// Wacom Inc. For example, the hardware id of a Wacom Grip
539 /// Pen (a stylus) is 0x802.
540 ///
541 /// This event is sent in the initial burst of events before the
542 /// wp_tablet_tool.done event.
543 ///
544 /// # Arguments
545 ///
546 /// - `hardware_id_hi`: the hardware id, most significant bits
547 /// - `hardware_id_lo`: the hardware id, least significant bits
548 #[inline]
549 fn hardware_id_wacom(
550 &self,
551 _data: &mut Self::Data,
552 _slf: &ZwpTabletToolV2Ref,
553 hardware_id_hi: u32,
554 hardware_id_lo: u32,
555 ) {
556 let _ = hardware_id_hi;
557 let _ = hardware_id_lo;
558 }
559
560 /// tool capability notification
561 ///
562 /// This event notifies the client of any capabilities of this tool,
563 /// beyond the main set of x/y axes and tip up/down detection.
564 ///
565 /// One event is sent for each extra capability available on this tool.
566 ///
567 /// This event is sent in the initial burst of events before the
568 /// wp_tablet_tool.done event.
569 ///
570 /// # Arguments
571 ///
572 /// - `capability`: the capability
573 #[inline]
574 fn capability(
575 &self,
576 _data: &mut Self::Data,
577 _slf: &ZwpTabletToolV2Ref,
578 capability: ZwpTabletToolV2Capability,
579 ) {
580 let _ = capability;
581 }
582
583 /// tool description events sequence complete
584 ///
585 /// This event signals the end of the initial burst of descriptive
586 /// events. A client may consider the static description of the tool to
587 /// be complete and finalize initialization of the tool.
588 #[inline]
589 fn done(&self, _data: &mut Self::Data, _slf: &ZwpTabletToolV2Ref) {}
590
591 /// tool removed
592 ///
593 /// This event is sent when the tool is removed from the system and will
594 /// send no further events. Should the physical tool come back into
595 /// proximity later, a new wp_tablet_tool object will be created.
596 ///
597 /// It is compositor-dependent when a tool is removed. A compositor may
598 /// remove a tool on proximity out, tablet removal or any other reason.
599 /// A compositor may also keep a tool alive until shutdown.
600 ///
601 /// If the tool is currently in proximity, a proximity_out event will be
602 /// sent before the removed event. See wp_tablet_tool.proximity_out for
603 /// the handling of any buttons logically down.
604 ///
605 /// When this event is received, the client must wp_tablet_tool.destroy
606 /// the object.
607 #[inline]
608 fn removed(&self, _data: &mut Self::Data, _slf: &ZwpTabletToolV2Ref) {}
609
610 /// proximity in event
611 ///
612 /// Notification that this tool is focused on a certain surface.
613 ///
614 /// This event can be received when the tool has moved from one surface to
615 /// another, or when the tool has come back into proximity above the
616 /// surface.
617 ///
618 /// If any button is logically down when the tool comes into proximity,
619 /// the respective button event is sent after the proximity_in event but
620 /// within the same frame as the proximity_in event.
621 ///
622 /// # Arguments
623 ///
624 /// - `serial`:
625 /// - `tablet`: The tablet the tool is in proximity of
626 /// - `surface`: The current surface the tablet tool is over
627 ///
628 /// All borrowed proxies passed to this function are guaranteed to be
629 /// immutable and non-null.
630 #[inline]
631 fn proximity_in(
632 &self,
633 _data: &mut Self::Data,
634 _slf: &ZwpTabletToolV2Ref,
635 serial: u32,
636 tablet: Option<&ZwpTabletV2Ref>,
637 surface: Option<&WlSurfaceRef>,
638 ) {
639 let _ = serial;
640 let _ = tablet;
641 let _ = surface;
642 }
643
644 /// proximity out event
645 ///
646 /// Notification that this tool has either left proximity, or is no
647 /// longer focused on a certain surface.
648 ///
649 /// When the tablet tool leaves proximity of the tablet, button release
650 /// events are sent for each button that was held down at the time of
651 /// leaving proximity. These events are sent before the proximity_out
652 /// event but within the same wp_tablet.frame.
653 ///
654 /// If the tool stays within proximity of the tablet, but the focus
655 /// changes from one surface to another, a button release event may not
656 /// be sent until the button is actually released or the tool leaves the
657 /// proximity of the tablet.
658 #[inline]
659 fn proximity_out(&self, _data: &mut Self::Data, _slf: &ZwpTabletToolV2Ref) {}
660
661 /// tablet tool is making contact
662 ///
663 /// Sent whenever the tablet tool comes in contact with the surface of the
664 /// tablet.
665 ///
666 /// If the tool is already in contact with the tablet when entering the
667 /// input region, the client owning said region will receive a
668 /// wp_tablet.proximity_in event, followed by a wp_tablet.down
669 /// event and a wp_tablet.frame event.
670 ///
671 /// Note that this event describes logical contact, not physical
672 /// contact. On some devices, a compositor may not consider a tool in
673 /// logical contact until a minimum physical pressure threshold is
674 /// exceeded.
675 ///
676 /// # Arguments
677 ///
678 /// - `serial`:
679 #[inline]
680 fn down(&self, _data: &mut Self::Data, _slf: &ZwpTabletToolV2Ref, serial: u32) {
681 let _ = serial;
682 }
683
684 /// tablet tool is no longer making contact
685 ///
686 /// Sent whenever the tablet tool stops making contact with the surface of
687 /// the tablet, or when the tablet tool moves out of the input region
688 /// and the compositor grab (if any) is dismissed.
689 ///
690 /// If the tablet tool moves out of the input region while in contact
691 /// with the surface of the tablet and the compositor does not have an
692 /// ongoing grab on the surface, the client owning said region will
693 /// receive a wp_tablet.up event, followed by a wp_tablet.proximity_out
694 /// event and a wp_tablet.frame event. If the compositor has an ongoing
695 /// grab on this device, this event sequence is sent whenever the grab
696 /// is dismissed in the future.
697 ///
698 /// Note that this event describes logical contact, not physical
699 /// contact. On some devices, a compositor may not consider a tool out
700 /// of logical contact until physical pressure falls below a specific
701 /// threshold.
702 #[inline]
703 fn up(&self, _data: &mut Self::Data, _slf: &ZwpTabletToolV2Ref) {}
704
705 /// motion event
706 ///
707 /// Sent whenever a tablet tool moves.
708 ///
709 /// # Arguments
710 ///
711 /// - `x`: surface-local x coordinate
712 /// - `y`: surface-local y coordinate
713 #[inline]
714 fn motion(&self, _data: &mut Self::Data, _slf: &ZwpTabletToolV2Ref, x: Fixed, y: Fixed) {
715 let _ = x;
716 let _ = y;
717 }
718
719 /// pressure change event
720 ///
721 /// Sent whenever the pressure axis on a tool changes. The value of this
722 /// event is normalized to a value between 0 and 65535.
723 ///
724 /// Note that pressure may be nonzero even when a tool is not in logical
725 /// contact. See the down and up events for more details.
726 ///
727 /// # Arguments
728 ///
729 /// - `pressure`: The current pressure value
730 #[inline]
731 fn pressure(&self, _data: &mut Self::Data, _slf: &ZwpTabletToolV2Ref, pressure: u32) {
732 let _ = pressure;
733 }
734
735 /// distance change event
736 ///
737 /// Sent whenever the distance axis on a tool changes. The value of this
738 /// event is normalized to a value between 0 and 65535.
739 ///
740 /// Note that distance may be nonzero even when a tool is not in logical
741 /// contact. See the down and up events for more details.
742 ///
743 /// # Arguments
744 ///
745 /// - `distance`: The current distance value
746 #[inline]
747 fn distance(&self, _data: &mut Self::Data, _slf: &ZwpTabletToolV2Ref, distance: u32) {
748 let _ = distance;
749 }
750
751 /// tilt change event
752 ///
753 /// Sent whenever one or both of the tilt axes on a tool change. Each tilt
754 /// value is in degrees, relative to the z-axis of the tablet.
755 /// The angle is positive when the top of a tool tilts along the
756 /// positive x or y axis.
757 ///
758 /// # Arguments
759 ///
760 /// - `tilt_x`: The current value of the X tilt axis
761 /// - `tilt_y`: The current value of the Y tilt axis
762 #[inline]
763 fn tilt(
764 &self,
765 _data: &mut Self::Data,
766 _slf: &ZwpTabletToolV2Ref,
767 tilt_x: Fixed,
768 tilt_y: Fixed,
769 ) {
770 let _ = tilt_x;
771 let _ = tilt_y;
772 }
773
774 /// z-rotation change event
775 ///
776 /// Sent whenever the z-rotation axis on the tool changes. The
777 /// rotation value is in degrees clockwise from the tool's
778 /// logical neutral position.
779 ///
780 /// # Arguments
781 ///
782 /// - `degrees`: The current rotation of the Z axis
783 #[inline]
784 fn rotation(&self, _data: &mut Self::Data, _slf: &ZwpTabletToolV2Ref, degrees: Fixed) {
785 let _ = degrees;
786 }
787
788 /// Slider position change event
789 ///
790 /// Sent whenever the slider position on the tool changes. The
791 /// value is normalized between -65535 and 65535, with 0 as the logical
792 /// neutral position of the slider.
793 ///
794 /// The slider is available on e.g. the Wacom Airbrush tool.
795 ///
796 /// # Arguments
797 ///
798 /// - `position`: The current position of slider
799 #[inline]
800 fn slider(&self, _data: &mut Self::Data, _slf: &ZwpTabletToolV2Ref, position: i32) {
801 let _ = position;
802 }
803
804 /// Wheel delta event
805 ///
806 /// Sent whenever the wheel on the tool emits an event. This event
807 /// contains two values for the same axis change. The degrees value is
808 /// in the same orientation as the wl_pointer.vertical_scroll axis. The
809 /// clicks value is in discrete logical clicks of the mouse wheel. This
810 /// value may be zero if the movement of the wheel was less
811 /// than one logical click.
812 ///
813 /// Clients should choose either value and avoid mixing degrees and
814 /// clicks. The compositor may accumulate values smaller than a logical
815 /// click and emulate click events when a certain threshold is met.
816 /// Thus, wl_tablet_tool.wheel events with non-zero clicks values may
817 /// have different degrees values.
818 ///
819 /// # Arguments
820 ///
821 /// - `degrees`: The wheel delta in degrees
822 /// - `clicks`: The wheel delta in discrete clicks
823 #[inline]
824 fn wheel(
825 &self,
826 _data: &mut Self::Data,
827 _slf: &ZwpTabletToolV2Ref,
828 degrees: Fixed,
829 clicks: i32,
830 ) {
831 let _ = degrees;
832 let _ = clicks;
833 }
834
835 /// button event
836 ///
837 /// Sent whenever a button on the tool is pressed or released.
838 ///
839 /// If a button is held down when the tool moves in or out of proximity,
840 /// button events are generated by the compositor. See
841 /// wp_tablet_tool.proximity_in and wp_tablet_tool.proximity_out for
842 /// details.
843 ///
844 /// # Arguments
845 ///
846 /// - `serial`:
847 /// - `button`: The button whose state has changed
848 /// - `state`: Whether the button was pressed or released
849 #[inline]
850 fn button(
851 &self,
852 _data: &mut Self::Data,
853 _slf: &ZwpTabletToolV2Ref,
854 serial: u32,
855 button: u32,
856 state: ZwpTabletToolV2ButtonState,
857 ) {
858 let _ = serial;
859 let _ = button;
860 let _ = state;
861 }
862
863 /// frame event
864 ///
865 /// Marks the end of a series of axis and/or button updates from the
866 /// tablet. The Wayland protocol requires axis updates to be sent
867 /// sequentially, however all events within a frame should be considered
868 /// one hardware event.
869 ///
870 /// # Arguments
871 ///
872 /// - `time`: The time of the event with millisecond granularity
873 #[inline]
874 fn frame(&self, _data: &mut Self::Data, _slf: &ZwpTabletToolV2Ref, time: u32) {
875 let _ = time;
876 }
877}
878
879impl ZwpTabletToolV2EventHandler for private::NoOpEventHandler {
880 type Data = ();
881}
882
883// SAFETY: - INTERFACE is a valid wl_interface
884// - mutable_type always returns the same value
885unsafe impl<H> EventHandler for private::EventHandler<H>
886where
887 H: ZwpTabletToolV2EventHandler,
888{
889 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
890
891 #[inline]
892 fn mutable_type() -> Option<(TypeId, &'static str)> {
893 let id = TypeId::of::<H::Data>();
894 let name = std::any::type_name::<H::Data>();
895 Some((id, name))
896 }
897
898 #[allow(unused_variables)]
899 unsafe fn handle_event(
900 &self,
901 queue: &Queue,
902 data: *mut u8,
903 slf: &UntypedBorrowedProxy,
904 opcode: u32,
905 args: *mut wl_argument,
906 ) {
907 // SAFETY: This function requires that slf has the interface INTERFACE
908 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<ZwpTabletToolV2Ref>(slf) };
909 // SAFETY: This function requires that data is `&mut T` where `T`
910 // has the type id returned by `Self::mutable_type`, i.e.,
911 // `T = H::Data`.
912 let data: &mut H::Data = unsafe { &mut *data.cast() };
913 match opcode {
914 0 => {
915 // SAFETY: INTERFACE requires that there are 1 arguments
916 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
917 // SAFETY: - INTERFACE requires that args[0] contains a uint
918 let arg0 = unsafe { ZwpTabletToolV2Type(args[0].u) };
919 self.0.r#type(data, slf, arg0);
920 }
921 1 => {
922 // SAFETY: INTERFACE requires that there are 2 arguments
923 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
924 // SAFETY: - INTERFACE requires that args[0] contains a uint
925 let arg0 = unsafe { args[0].u };
926 // SAFETY: - INTERFACE requires that args[1] contains a uint
927 let arg1 = unsafe { args[1].u };
928 self.0.hardware_serial(data, slf, arg0, arg1);
929 }
930 2 => {
931 // SAFETY: INTERFACE requires that there are 2 arguments
932 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
933 // SAFETY: - INTERFACE requires that args[0] contains a uint
934 let arg0 = unsafe { args[0].u };
935 // SAFETY: - INTERFACE requires that args[1] contains a uint
936 let arg1 = unsafe { args[1].u };
937 self.0.hardware_id_wacom(data, slf, arg0, arg1);
938 }
939 3 => {
940 // SAFETY: INTERFACE requires that there are 1 arguments
941 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
942 // SAFETY: - INTERFACE requires that args[0] contains a uint
943 let arg0 = unsafe { ZwpTabletToolV2Capability(args[0].u) };
944 self.0.capability(data, slf, arg0);
945 }
946 4 => {
947 self.0.done(data, slf);
948 }
949 5 => {
950 self.0.removed(data, slf);
951 }
952 6 => {
953 // SAFETY: INTERFACE requires that there are 3 arguments
954 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
955 // SAFETY: - INTERFACE requires that args[0] contains a uint
956 let arg0 = unsafe { args[0].u };
957 // SAFETY: - INTERFACE requires that args[1] contains an object
958 let arg1 = unsafe {
959 if let Some(p) = NonNull::new(args[1].o.cast()) {
960 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
961 } else {
962 None
963 }
964 };
965 // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletV2::WL_INTERFACE
966 let arg1 = arg1.as_ref().map(|arg1| unsafe {
967 proxy::low_level::from_untyped_borrowed::<ZwpTabletV2Ref>(arg1)
968 });
969 // SAFETY: - INTERFACE requires that args[2] contains an object
970 let arg2 = unsafe {
971 if let Some(p) = NonNull::new(args[2].o.cast()) {
972 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
973 } else {
974 None
975 }
976 };
977 // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
978 let arg2 = arg2.as_ref().map(|arg2| unsafe {
979 proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg2)
980 });
981 self.0.proximity_in(data, slf, arg0, arg1, arg2);
982 }
983 7 => {
984 self.0.proximity_out(data, slf);
985 }
986 8 => {
987 // SAFETY: INTERFACE requires that there are 1 arguments
988 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
989 // SAFETY: - INTERFACE requires that args[0] contains a uint
990 let arg0 = unsafe { args[0].u };
991 self.0.down(data, slf, arg0);
992 }
993 9 => {
994 self.0.up(data, slf);
995 }
996 10 => {
997 // SAFETY: INTERFACE requires that there are 2 arguments
998 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
999 // SAFETY: - INTERFACE requires that args[0] contains a fixed
1000 let arg0 = unsafe { Fixed::from_wire(args[0].f) };
1001 // SAFETY: - INTERFACE requires that args[1] contains a fixed
1002 let arg1 = unsafe { Fixed::from_wire(args[1].f) };
1003 self.0.motion(data, slf, arg0, arg1);
1004 }
1005 11 => {
1006 // SAFETY: INTERFACE requires that there are 1 arguments
1007 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
1008 // SAFETY: - INTERFACE requires that args[0] contains a uint
1009 let arg0 = unsafe { args[0].u };
1010 self.0.pressure(data, slf, arg0);
1011 }
1012 12 => {
1013 // SAFETY: INTERFACE requires that there are 1 arguments
1014 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
1015 // SAFETY: - INTERFACE requires that args[0] contains a uint
1016 let arg0 = unsafe { args[0].u };
1017 self.0.distance(data, slf, arg0);
1018 }
1019 13 => {
1020 // SAFETY: INTERFACE requires that there are 2 arguments
1021 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
1022 // SAFETY: - INTERFACE requires that args[0] contains a fixed
1023 let arg0 = unsafe { Fixed::from_wire(args[0].f) };
1024 // SAFETY: - INTERFACE requires that args[1] contains a fixed
1025 let arg1 = unsafe { Fixed::from_wire(args[1].f) };
1026 self.0.tilt(data, slf, arg0, arg1);
1027 }
1028 14 => {
1029 // SAFETY: INTERFACE requires that there are 1 arguments
1030 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
1031 // SAFETY: - INTERFACE requires that args[0] contains a fixed
1032 let arg0 = unsafe { Fixed::from_wire(args[0].f) };
1033 self.0.rotation(data, slf, arg0);
1034 }
1035 15 => {
1036 // SAFETY: INTERFACE requires that there are 1 arguments
1037 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
1038 // SAFETY: - INTERFACE requires that args[0] contains an int
1039 let arg0 = unsafe { args[0].i };
1040 self.0.slider(data, slf, arg0);
1041 }
1042 16 => {
1043 // SAFETY: INTERFACE requires that there are 2 arguments
1044 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
1045 // SAFETY: - INTERFACE requires that args[0] contains a fixed
1046 let arg0 = unsafe { Fixed::from_wire(args[0].f) };
1047 // SAFETY: - INTERFACE requires that args[1] contains an int
1048 let arg1 = unsafe { args[1].i };
1049 self.0.wheel(data, slf, arg0, arg1);
1050 }
1051 17 => {
1052 // SAFETY: INTERFACE requires that there are 3 arguments
1053 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
1054 // SAFETY: - INTERFACE requires that args[0] contains a uint
1055 let arg0 = unsafe { args[0].u };
1056 // SAFETY: - INTERFACE requires that args[1] contains a uint
1057 let arg1 = unsafe { args[1].u };
1058 // SAFETY: - INTERFACE requires that args[2] contains a uint
1059 let arg2 = unsafe { ZwpTabletToolV2ButtonState(args[2].u) };
1060 self.0.button(data, slf, arg0, arg1, arg2);
1061 }
1062 18 => {
1063 // SAFETY: INTERFACE requires that there are 1 arguments
1064 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
1065 // SAFETY: - INTERFACE requires that args[0] contains a uint
1066 let arg0 = unsafe { args[0].u };
1067 self.0.frame(data, slf, arg0);
1068 }
1069 _ => {
1070 invalid_opcode("zwp_tablet_tool_v2", opcode);
1071 }
1072 }
1073 }
1074}
1075
1076impl<H> CreateEventHandler<H> for private::ProxyApi
1077where
1078 H: ZwpTabletToolV2EventHandler,
1079{
1080 type EventHandler = private::EventHandler<H>;
1081
1082 #[inline]
1083 fn create_event_handler(handler: H) -> Self::EventHandler {
1084 private::EventHandler(handler)
1085 }
1086}
1087
1088impl ZwpTabletToolV2 {
1089 /// Since when the type.pen enum variant is available.
1090 #[allow(dead_code)]
1091 pub const ENM__TYPE_PEN__SINCE: u32 = 1;
1092 /// Since when the type.eraser enum variant is available.
1093 #[allow(dead_code)]
1094 pub const ENM__TYPE_ERASER__SINCE: u32 = 1;
1095 /// Since when the type.brush enum variant is available.
1096 #[allow(dead_code)]
1097 pub const ENM__TYPE_BRUSH__SINCE: u32 = 1;
1098 /// Since when the type.pencil enum variant is available.
1099 #[allow(dead_code)]
1100 pub const ENM__TYPE_PENCIL__SINCE: u32 = 1;
1101 /// Since when the type.airbrush enum variant is available.
1102 #[allow(dead_code)]
1103 pub const ENM__TYPE_AIRBRUSH__SINCE: u32 = 1;
1104 /// Since when the type.finger enum variant is available.
1105 #[allow(dead_code)]
1106 pub const ENM__TYPE_FINGER__SINCE: u32 = 1;
1107 /// Since when the type.mouse enum variant is available.
1108 #[allow(dead_code)]
1109 pub const ENM__TYPE_MOUSE__SINCE: u32 = 1;
1110 /// Since when the type.lens enum variant is available.
1111 #[allow(dead_code)]
1112 pub const ENM__TYPE_LENS__SINCE: u32 = 1;
1113
1114 /// Since when the capability.tilt enum variant is available.
1115 #[allow(dead_code)]
1116 pub const ENM__CAPABILITY_TILT__SINCE: u32 = 1;
1117 /// Since when the capability.pressure enum variant is available.
1118 #[allow(dead_code)]
1119 pub const ENM__CAPABILITY_PRESSURE__SINCE: u32 = 1;
1120 /// Since when the capability.distance enum variant is available.
1121 #[allow(dead_code)]
1122 pub const ENM__CAPABILITY_DISTANCE__SINCE: u32 = 1;
1123 /// Since when the capability.rotation enum variant is available.
1124 #[allow(dead_code)]
1125 pub const ENM__CAPABILITY_ROTATION__SINCE: u32 = 1;
1126 /// Since when the capability.slider enum variant is available.
1127 #[allow(dead_code)]
1128 pub const ENM__CAPABILITY_SLIDER__SINCE: u32 = 1;
1129 /// Since when the capability.wheel enum variant is available.
1130 #[allow(dead_code)]
1131 pub const ENM__CAPABILITY_WHEEL__SINCE: u32 = 1;
1132
1133 /// Since when the button_state.released enum variant is available.
1134 #[allow(dead_code)]
1135 pub const ENM__BUTTON_STATE_RELEASED__SINCE: u32 = 1;
1136 /// Since when the button_state.pressed enum variant is available.
1137 #[allow(dead_code)]
1138 pub const ENM__BUTTON_STATE_PRESSED__SINCE: u32 = 1;
1139
1140 /// Since when the error.role enum variant is available.
1141 #[allow(dead_code)]
1142 pub const ENM__ERROR_ROLE__SINCE: u32 = 1;
1143}
1144
1145/// a physical tool type
1146///
1147/// Describes the physical type of a tool. The physical type of a tool
1148/// generally defines its base usage.
1149///
1150/// The mouse tool represents a mouse-shaped tool that is not a relative
1151/// device but bound to the tablet's surface, providing absolute
1152/// coordinates.
1153///
1154/// The lens tool is a mouse-shaped tool with an attached lens to
1155/// provide precision focus.
1156#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1157#[allow(dead_code)]
1158pub struct ZwpTabletToolV2Type(pub u32);
1159
1160impl ZwpTabletToolV2Type {
1161 /// Pen
1162 #[allow(dead_code)]
1163 pub const PEN: Self = Self(0x140);
1164
1165 /// Eraser
1166 #[allow(dead_code)]
1167 pub const ERASER: Self = Self(0x141);
1168
1169 /// Brush
1170 #[allow(dead_code)]
1171 pub const BRUSH: Self = Self(0x142);
1172
1173 /// Pencil
1174 #[allow(dead_code)]
1175 pub const PENCIL: Self = Self(0x143);
1176
1177 /// Airbrush
1178 #[allow(dead_code)]
1179 pub const AIRBRUSH: Self = Self(0x144);
1180
1181 /// Finger
1182 #[allow(dead_code)]
1183 pub const FINGER: Self = Self(0x145);
1184
1185 /// Mouse
1186 #[allow(dead_code)]
1187 pub const MOUSE: Self = Self(0x146);
1188
1189 /// Lens
1190 #[allow(dead_code)]
1191 pub const LENS: Self = Self(0x147);
1192}
1193
1194impl Debug for ZwpTabletToolV2Type {
1195 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1196 let name = match *self {
1197 Self::PEN => "PEN",
1198 Self::ERASER => "ERASER",
1199 Self::BRUSH => "BRUSH",
1200 Self::PENCIL => "PENCIL",
1201 Self::AIRBRUSH => "AIRBRUSH",
1202 Self::FINGER => "FINGER",
1203 Self::MOUSE => "MOUSE",
1204 Self::LENS => "LENS",
1205 _ => return Debug::fmt(&self.0, f),
1206 };
1207 f.write_str(name)
1208 }
1209}
1210
1211/// capability flags for a tool
1212///
1213/// Describes extra capabilities on a tablet.
1214///
1215/// Any tool must provide x and y values, extra axes are
1216/// device-specific.
1217#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1218#[allow(dead_code)]
1219pub struct ZwpTabletToolV2Capability(pub u32);
1220
1221impl ZwpTabletToolV2Capability {
1222 /// Tilt axes
1223 #[allow(dead_code)]
1224 pub const TILT: Self = Self(1);
1225
1226 /// Pressure axis
1227 #[allow(dead_code)]
1228 pub const PRESSURE: Self = Self(2);
1229
1230 /// Distance axis
1231 #[allow(dead_code)]
1232 pub const DISTANCE: Self = Self(3);
1233
1234 /// Z-rotation axis
1235 #[allow(dead_code)]
1236 pub const ROTATION: Self = Self(4);
1237
1238 /// Slider axis
1239 #[allow(dead_code)]
1240 pub const SLIDER: Self = Self(5);
1241
1242 /// Wheel axis
1243 #[allow(dead_code)]
1244 pub const WHEEL: Self = Self(6);
1245}
1246
1247impl Debug for ZwpTabletToolV2Capability {
1248 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1249 let name = match *self {
1250 Self::TILT => "TILT",
1251 Self::PRESSURE => "PRESSURE",
1252 Self::DISTANCE => "DISTANCE",
1253 Self::ROTATION => "ROTATION",
1254 Self::SLIDER => "SLIDER",
1255 Self::WHEEL => "WHEEL",
1256 _ => return Debug::fmt(&self.0, f),
1257 };
1258 f.write_str(name)
1259 }
1260}
1261
1262/// physical button state
1263///
1264/// Describes the physical state of a button that produced the button event.
1265#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1266#[allow(dead_code)]
1267pub struct ZwpTabletToolV2ButtonState(pub u32);
1268
1269impl ZwpTabletToolV2ButtonState {
1270 /// button is not pressed
1271 #[allow(dead_code)]
1272 pub const RELEASED: Self = Self(0);
1273
1274 /// button is pressed
1275 #[allow(dead_code)]
1276 pub const PRESSED: Self = Self(1);
1277}
1278
1279impl Debug for ZwpTabletToolV2ButtonState {
1280 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1281 let name = match *self {
1282 Self::RELEASED => "RELEASED",
1283 Self::PRESSED => "PRESSED",
1284 _ => return Debug::fmt(&self.0, f),
1285 };
1286 f.write_str(name)
1287 }
1288}
1289
1290#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1291#[allow(dead_code)]
1292pub struct ZwpTabletToolV2Error(pub u32);
1293
1294impl ZwpTabletToolV2Error {
1295 /// given wl_surface has another role
1296 #[allow(dead_code)]
1297 pub const ROLE: Self = Self(0);
1298}
1299
1300impl Debug for ZwpTabletToolV2Error {
1301 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1302 let name = match *self {
1303 Self::ROLE => "ROLE",
1304 _ => return Debug::fmt(&self.0, f),
1305 };
1306 f.write_str(name)
1307 }
1308}
1309
1310/// Functional event handlers.
1311pub mod event_handlers {
1312 use super::*;
1313
1314 /// Event handler for type events.
1315 pub struct Type<T, F>(F, PhantomData<fn(&mut T)>);
1316 impl<T, F> ZwpTabletToolV2EventHandler for Type<T, F>
1317 where
1318 T: 'static,
1319 F: Fn(&mut T, &ZwpTabletToolV2Ref, ZwpTabletToolV2Type),
1320 {
1321 type Data = T;
1322
1323 #[inline]
1324 fn r#type(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref, tool_type: ZwpTabletToolV2Type) {
1325 self.0(_data, _slf, tool_type)
1326 }
1327 }
1328
1329 /// Event handler for hardware_serial events.
1330 pub struct HardwareSerial<T, F>(F, PhantomData<fn(&mut T)>);
1331 impl<T, F> ZwpTabletToolV2EventHandler for HardwareSerial<T, F>
1332 where
1333 T: 'static,
1334 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32, u32),
1335 {
1336 type Data = T;
1337
1338 #[inline]
1339 fn hardware_serial(
1340 &self,
1341 _data: &mut T,
1342 _slf: &ZwpTabletToolV2Ref,
1343 hardware_serial_hi: u32,
1344 hardware_serial_lo: u32,
1345 ) {
1346 self.0(_data, _slf, hardware_serial_hi, hardware_serial_lo)
1347 }
1348 }
1349
1350 /// Event handler for hardware_id_wacom events.
1351 pub struct HardwareIdWacom<T, F>(F, PhantomData<fn(&mut T)>);
1352 impl<T, F> ZwpTabletToolV2EventHandler for HardwareIdWacom<T, F>
1353 where
1354 T: 'static,
1355 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32, u32),
1356 {
1357 type Data = T;
1358
1359 #[inline]
1360 fn hardware_id_wacom(
1361 &self,
1362 _data: &mut T,
1363 _slf: &ZwpTabletToolV2Ref,
1364 hardware_id_hi: u32,
1365 hardware_id_lo: u32,
1366 ) {
1367 self.0(_data, _slf, hardware_id_hi, hardware_id_lo)
1368 }
1369 }
1370
1371 /// Event handler for capability events.
1372 pub struct Capability<T, F>(F, PhantomData<fn(&mut T)>);
1373 impl<T, F> ZwpTabletToolV2EventHandler for Capability<T, F>
1374 where
1375 T: 'static,
1376 F: Fn(&mut T, &ZwpTabletToolV2Ref, ZwpTabletToolV2Capability),
1377 {
1378 type Data = T;
1379
1380 #[inline]
1381 fn capability(
1382 &self,
1383 _data: &mut T,
1384 _slf: &ZwpTabletToolV2Ref,
1385 capability: ZwpTabletToolV2Capability,
1386 ) {
1387 self.0(_data, _slf, capability)
1388 }
1389 }
1390
1391 /// Event handler for done events.
1392 pub struct Done<T, F>(F, PhantomData<fn(&mut T)>);
1393 impl<T, F> ZwpTabletToolV2EventHandler for Done<T, F>
1394 where
1395 T: 'static,
1396 F: Fn(&mut T, &ZwpTabletToolV2Ref),
1397 {
1398 type Data = T;
1399
1400 #[inline]
1401 fn done(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref) {
1402 self.0(_data, _slf)
1403 }
1404 }
1405
1406 /// Event handler for removed events.
1407 pub struct Removed<T, F>(F, PhantomData<fn(&mut T)>);
1408 impl<T, F> ZwpTabletToolV2EventHandler for Removed<T, F>
1409 where
1410 T: 'static,
1411 F: Fn(&mut T, &ZwpTabletToolV2Ref),
1412 {
1413 type Data = T;
1414
1415 #[inline]
1416 fn removed(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref) {
1417 self.0(_data, _slf)
1418 }
1419 }
1420
1421 /// Event handler for proximity_in events.
1422 pub struct ProximityIn<T, F>(F, PhantomData<fn(&mut T)>);
1423 impl<T, F> ZwpTabletToolV2EventHandler for ProximityIn<T, F>
1424 where
1425 T: 'static,
1426 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32, Option<&ZwpTabletV2Ref>, Option<&WlSurfaceRef>),
1427 {
1428 type Data = T;
1429
1430 #[inline]
1431 fn proximity_in(
1432 &self,
1433 _data: &mut T,
1434 _slf: &ZwpTabletToolV2Ref,
1435 serial: u32,
1436 tablet: Option<&ZwpTabletV2Ref>,
1437 surface: Option<&WlSurfaceRef>,
1438 ) {
1439 self.0(_data, _slf, serial, tablet, surface)
1440 }
1441 }
1442
1443 /// Event handler for proximity_out events.
1444 pub struct ProximityOut<T, F>(F, PhantomData<fn(&mut T)>);
1445 impl<T, F> ZwpTabletToolV2EventHandler for ProximityOut<T, F>
1446 where
1447 T: 'static,
1448 F: Fn(&mut T, &ZwpTabletToolV2Ref),
1449 {
1450 type Data = T;
1451
1452 #[inline]
1453 fn proximity_out(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref) {
1454 self.0(_data, _slf)
1455 }
1456 }
1457
1458 /// Event handler for down events.
1459 pub struct Down<T, F>(F, PhantomData<fn(&mut T)>);
1460 impl<T, F> ZwpTabletToolV2EventHandler for Down<T, F>
1461 where
1462 T: 'static,
1463 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32),
1464 {
1465 type Data = T;
1466
1467 #[inline]
1468 fn down(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref, serial: u32) {
1469 self.0(_data, _slf, serial)
1470 }
1471 }
1472
1473 /// Event handler for up events.
1474 pub struct Up<T, F>(F, PhantomData<fn(&mut T)>);
1475 impl<T, F> ZwpTabletToolV2EventHandler for Up<T, F>
1476 where
1477 T: 'static,
1478 F: Fn(&mut T, &ZwpTabletToolV2Ref),
1479 {
1480 type Data = T;
1481
1482 #[inline]
1483 fn up(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref) {
1484 self.0(_data, _slf)
1485 }
1486 }
1487
1488 /// Event handler for motion events.
1489 pub struct Motion<T, F>(F, PhantomData<fn(&mut T)>);
1490 impl<T, F> ZwpTabletToolV2EventHandler for Motion<T, F>
1491 where
1492 T: 'static,
1493 F: Fn(&mut T, &ZwpTabletToolV2Ref, Fixed, Fixed),
1494 {
1495 type Data = T;
1496
1497 #[inline]
1498 fn motion(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref, x: Fixed, y: Fixed) {
1499 self.0(_data, _slf, x, y)
1500 }
1501 }
1502
1503 /// Event handler for pressure events.
1504 pub struct Pressure<T, F>(F, PhantomData<fn(&mut T)>);
1505 impl<T, F> ZwpTabletToolV2EventHandler for Pressure<T, F>
1506 where
1507 T: 'static,
1508 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32),
1509 {
1510 type Data = T;
1511
1512 #[inline]
1513 fn pressure(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref, pressure: u32) {
1514 self.0(_data, _slf, pressure)
1515 }
1516 }
1517
1518 /// Event handler for distance events.
1519 pub struct Distance<T, F>(F, PhantomData<fn(&mut T)>);
1520 impl<T, F> ZwpTabletToolV2EventHandler for Distance<T, F>
1521 where
1522 T: 'static,
1523 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32),
1524 {
1525 type Data = T;
1526
1527 #[inline]
1528 fn distance(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref, distance: u32) {
1529 self.0(_data, _slf, distance)
1530 }
1531 }
1532
1533 /// Event handler for tilt events.
1534 pub struct Tilt<T, F>(F, PhantomData<fn(&mut T)>);
1535 impl<T, F> ZwpTabletToolV2EventHandler for Tilt<T, F>
1536 where
1537 T: 'static,
1538 F: Fn(&mut T, &ZwpTabletToolV2Ref, Fixed, Fixed),
1539 {
1540 type Data = T;
1541
1542 #[inline]
1543 fn tilt(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref, tilt_x: Fixed, tilt_y: Fixed) {
1544 self.0(_data, _slf, tilt_x, tilt_y)
1545 }
1546 }
1547
1548 /// Event handler for rotation events.
1549 pub struct Rotation<T, F>(F, PhantomData<fn(&mut T)>);
1550 impl<T, F> ZwpTabletToolV2EventHandler for Rotation<T, F>
1551 where
1552 T: 'static,
1553 F: Fn(&mut T, &ZwpTabletToolV2Ref, Fixed),
1554 {
1555 type Data = T;
1556
1557 #[inline]
1558 fn rotation(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref, degrees: Fixed) {
1559 self.0(_data, _slf, degrees)
1560 }
1561 }
1562
1563 /// Event handler for slider events.
1564 pub struct Slider<T, F>(F, PhantomData<fn(&mut T)>);
1565 impl<T, F> ZwpTabletToolV2EventHandler for Slider<T, F>
1566 where
1567 T: 'static,
1568 F: Fn(&mut T, &ZwpTabletToolV2Ref, i32),
1569 {
1570 type Data = T;
1571
1572 #[inline]
1573 fn slider(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref, position: i32) {
1574 self.0(_data, _slf, position)
1575 }
1576 }
1577
1578 /// Event handler for wheel events.
1579 pub struct Wheel<T, F>(F, PhantomData<fn(&mut T)>);
1580 impl<T, F> ZwpTabletToolV2EventHandler for Wheel<T, F>
1581 where
1582 T: 'static,
1583 F: Fn(&mut T, &ZwpTabletToolV2Ref, Fixed, i32),
1584 {
1585 type Data = T;
1586
1587 #[inline]
1588 fn wheel(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref, degrees: Fixed, clicks: i32) {
1589 self.0(_data, _slf, degrees, clicks)
1590 }
1591 }
1592
1593 /// Event handler for button events.
1594 pub struct Button<T, F>(F, PhantomData<fn(&mut T)>);
1595 impl<T, F> ZwpTabletToolV2EventHandler for Button<T, F>
1596 where
1597 T: 'static,
1598 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32, u32, ZwpTabletToolV2ButtonState),
1599 {
1600 type Data = T;
1601
1602 #[inline]
1603 fn button(
1604 &self,
1605 _data: &mut T,
1606 _slf: &ZwpTabletToolV2Ref,
1607 serial: u32,
1608 button: u32,
1609 state: ZwpTabletToolV2ButtonState,
1610 ) {
1611 self.0(_data, _slf, serial, button, state)
1612 }
1613 }
1614
1615 /// Event handler for frame events.
1616 pub struct Frame<T, F>(F, PhantomData<fn(&mut T)>);
1617 impl<T, F> ZwpTabletToolV2EventHandler for Frame<T, F>
1618 where
1619 T: 'static,
1620 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32),
1621 {
1622 type Data = T;
1623
1624 #[inline]
1625 fn frame(&self, _data: &mut T, _slf: &ZwpTabletToolV2Ref, time: u32) {
1626 self.0(_data, _slf, time)
1627 }
1628 }
1629
1630 impl ZwpTabletToolV2 {
1631 /// Creates an event handler for type events.
1632 ///
1633 /// The event handler ignores all other events.
1634 #[allow(dead_code)]
1635 pub fn on_type<T, F>(f: F) -> Type<T, F>
1636 where
1637 T: 'static,
1638 F: Fn(&mut T, &ZwpTabletToolV2Ref, ZwpTabletToolV2Type),
1639 {
1640 Type(f, PhantomData)
1641 }
1642
1643 /// Creates an event handler for hardware_serial events.
1644 ///
1645 /// The event handler ignores all other events.
1646 #[allow(dead_code)]
1647 pub fn on_hardware_serial<T, F>(f: F) -> HardwareSerial<T, F>
1648 where
1649 T: 'static,
1650 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32, u32),
1651 {
1652 HardwareSerial(f, PhantomData)
1653 }
1654
1655 /// Creates an event handler for hardware_id_wacom events.
1656 ///
1657 /// The event handler ignores all other events.
1658 #[allow(dead_code)]
1659 pub fn on_hardware_id_wacom<T, F>(f: F) -> HardwareIdWacom<T, F>
1660 where
1661 T: 'static,
1662 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32, u32),
1663 {
1664 HardwareIdWacom(f, PhantomData)
1665 }
1666
1667 /// Creates an event handler for capability events.
1668 ///
1669 /// The event handler ignores all other events.
1670 #[allow(dead_code)]
1671 pub fn on_capability<T, F>(f: F) -> Capability<T, F>
1672 where
1673 T: 'static,
1674 F: Fn(&mut T, &ZwpTabletToolV2Ref, ZwpTabletToolV2Capability),
1675 {
1676 Capability(f, PhantomData)
1677 }
1678
1679 /// Creates an event handler for done events.
1680 ///
1681 /// The event handler ignores all other events.
1682 #[allow(dead_code)]
1683 pub fn on_done<T, F>(f: F) -> Done<T, F>
1684 where
1685 T: 'static,
1686 F: Fn(&mut T, &ZwpTabletToolV2Ref),
1687 {
1688 Done(f, PhantomData)
1689 }
1690
1691 /// Creates an event handler for removed events.
1692 ///
1693 /// The event handler ignores all other events.
1694 #[allow(dead_code)]
1695 pub fn on_removed<T, F>(f: F) -> Removed<T, F>
1696 where
1697 T: 'static,
1698 F: Fn(&mut T, &ZwpTabletToolV2Ref),
1699 {
1700 Removed(f, PhantomData)
1701 }
1702
1703 /// Creates an event handler for proximity_in events.
1704 ///
1705 /// The event handler ignores all other events.
1706 #[allow(dead_code)]
1707 pub fn on_proximity_in<T, F>(f: F) -> ProximityIn<T, F>
1708 where
1709 T: 'static,
1710 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32, Option<&ZwpTabletV2Ref>, Option<&WlSurfaceRef>),
1711 {
1712 ProximityIn(f, PhantomData)
1713 }
1714
1715 /// Creates an event handler for proximity_out events.
1716 ///
1717 /// The event handler ignores all other events.
1718 #[allow(dead_code)]
1719 pub fn on_proximity_out<T, F>(f: F) -> ProximityOut<T, F>
1720 where
1721 T: 'static,
1722 F: Fn(&mut T, &ZwpTabletToolV2Ref),
1723 {
1724 ProximityOut(f, PhantomData)
1725 }
1726
1727 /// Creates an event handler for down events.
1728 ///
1729 /// The event handler ignores all other events.
1730 #[allow(dead_code)]
1731 pub fn on_down<T, F>(f: F) -> Down<T, F>
1732 where
1733 T: 'static,
1734 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32),
1735 {
1736 Down(f, PhantomData)
1737 }
1738
1739 /// Creates an event handler for up events.
1740 ///
1741 /// The event handler ignores all other events.
1742 #[allow(dead_code)]
1743 pub fn on_up<T, F>(f: F) -> Up<T, F>
1744 where
1745 T: 'static,
1746 F: Fn(&mut T, &ZwpTabletToolV2Ref),
1747 {
1748 Up(f, PhantomData)
1749 }
1750
1751 /// Creates an event handler for motion events.
1752 ///
1753 /// The event handler ignores all other events.
1754 #[allow(dead_code)]
1755 pub fn on_motion<T, F>(f: F) -> Motion<T, F>
1756 where
1757 T: 'static,
1758 F: Fn(&mut T, &ZwpTabletToolV2Ref, Fixed, Fixed),
1759 {
1760 Motion(f, PhantomData)
1761 }
1762
1763 /// Creates an event handler for pressure events.
1764 ///
1765 /// The event handler ignores all other events.
1766 #[allow(dead_code)]
1767 pub fn on_pressure<T, F>(f: F) -> Pressure<T, F>
1768 where
1769 T: 'static,
1770 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32),
1771 {
1772 Pressure(f, PhantomData)
1773 }
1774
1775 /// Creates an event handler for distance events.
1776 ///
1777 /// The event handler ignores all other events.
1778 #[allow(dead_code)]
1779 pub fn on_distance<T, F>(f: F) -> Distance<T, F>
1780 where
1781 T: 'static,
1782 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32),
1783 {
1784 Distance(f, PhantomData)
1785 }
1786
1787 /// Creates an event handler for tilt events.
1788 ///
1789 /// The event handler ignores all other events.
1790 #[allow(dead_code)]
1791 pub fn on_tilt<T, F>(f: F) -> Tilt<T, F>
1792 where
1793 T: 'static,
1794 F: Fn(&mut T, &ZwpTabletToolV2Ref, Fixed, Fixed),
1795 {
1796 Tilt(f, PhantomData)
1797 }
1798
1799 /// Creates an event handler for rotation events.
1800 ///
1801 /// The event handler ignores all other events.
1802 #[allow(dead_code)]
1803 pub fn on_rotation<T, F>(f: F) -> Rotation<T, F>
1804 where
1805 T: 'static,
1806 F: Fn(&mut T, &ZwpTabletToolV2Ref, Fixed),
1807 {
1808 Rotation(f, PhantomData)
1809 }
1810
1811 /// Creates an event handler for slider events.
1812 ///
1813 /// The event handler ignores all other events.
1814 #[allow(dead_code)]
1815 pub fn on_slider<T, F>(f: F) -> Slider<T, F>
1816 where
1817 T: 'static,
1818 F: Fn(&mut T, &ZwpTabletToolV2Ref, i32),
1819 {
1820 Slider(f, PhantomData)
1821 }
1822
1823 /// Creates an event handler for wheel events.
1824 ///
1825 /// The event handler ignores all other events.
1826 #[allow(dead_code)]
1827 pub fn on_wheel<T, F>(f: F) -> Wheel<T, F>
1828 where
1829 T: 'static,
1830 F: Fn(&mut T, &ZwpTabletToolV2Ref, Fixed, i32),
1831 {
1832 Wheel(f, PhantomData)
1833 }
1834
1835 /// Creates an event handler for button events.
1836 ///
1837 /// The event handler ignores all other events.
1838 #[allow(dead_code)]
1839 pub fn on_button<T, F>(f: F) -> Button<T, F>
1840 where
1841 T: 'static,
1842 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32, u32, ZwpTabletToolV2ButtonState),
1843 {
1844 Button(f, PhantomData)
1845 }
1846
1847 /// Creates an event handler for frame events.
1848 ///
1849 /// The event handler ignores all other events.
1850 #[allow(dead_code)]
1851 pub fn on_frame<T, F>(f: F) -> Frame<T, F>
1852 where
1853 T: 'static,
1854 F: Fn(&mut T, &ZwpTabletToolV2Ref, u32),
1855 {
1856 Frame(f, PhantomData)
1857 }
1858 }
1859}