async_roundtrip/common/protocols_data/wayland/wl_pointer.rs
1//! pointer input device
2//!
3//! The wl_pointer interface represents one or more input devices,
4//! such as mice, which control the pointer location and pointer_focus
5//! of a seat.
6//!
7//! The wl_pointer interface generates motion, enter and leave
8//! events for the surfaces that the pointer is located over,
9//! and button and axis events for button presses, button releases
10//! and scrolling.
11
12use {super::super::all_types::*, ::wl_client::builder::prelude::*};
13
14static INTERFACE: wl_interface = wl_interface {
15 name: c"wl_pointer".as_ptr(),
16 version: 10,
17 method_count: 2,
18 methods: {
19 static MESSAGES: [wl_message; 2] = [
20 wl_message {
21 name: c"set_cursor".as_ptr(),
22 signature: c"u?oii".as_ptr(),
23 types: {
24 static TYPES: [Option<&'static wl_interface>; 4] =
25 [None, Some(WlSurface::WL_INTERFACE), None, None];
26 TYPES.as_ptr().cast()
27 },
28 },
29 wl_message {
30 name: c"release".as_ptr(),
31 signature: c"".as_ptr(),
32 types: {
33 static TYPES: [Option<&'static wl_interface>; 0] = [];
34 TYPES.as_ptr().cast()
35 },
36 },
37 ];
38 MESSAGES.as_ptr()
39 },
40 event_count: 11,
41 events: {
42 static MESSAGES: [wl_message; 11] = [
43 wl_message {
44 name: c"enter".as_ptr(),
45 signature: c"uoff".as_ptr(),
46 types: {
47 static TYPES: [Option<&'static wl_interface>; 4] =
48 [None, Some(WlSurface::WL_INTERFACE), None, None];
49 TYPES.as_ptr().cast()
50 },
51 },
52 wl_message {
53 name: c"leave".as_ptr(),
54 signature: c"uo".as_ptr(),
55 types: {
56 static TYPES: [Option<&'static wl_interface>; 2] =
57 [None, Some(WlSurface::WL_INTERFACE)];
58 TYPES.as_ptr().cast()
59 },
60 },
61 wl_message {
62 name: c"motion".as_ptr(),
63 signature: c"uff".as_ptr(),
64 types: {
65 static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
66 TYPES.as_ptr().cast()
67 },
68 },
69 wl_message {
70 name: c"button".as_ptr(),
71 signature: c"uuuu".as_ptr(),
72 types: {
73 static TYPES: [Option<&'static wl_interface>; 4] = [None, None, None, None];
74 TYPES.as_ptr().cast()
75 },
76 },
77 wl_message {
78 name: c"axis".as_ptr(),
79 signature: c"uuf".as_ptr(),
80 types: {
81 static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
82 TYPES.as_ptr().cast()
83 },
84 },
85 wl_message {
86 name: c"frame".as_ptr(),
87 signature: c"".as_ptr(),
88 types: {
89 static TYPES: [Option<&'static wl_interface>; 0] = [];
90 TYPES.as_ptr().cast()
91 },
92 },
93 wl_message {
94 name: c"axis_source".as_ptr(),
95 signature: c"u".as_ptr(),
96 types: {
97 static TYPES: [Option<&'static wl_interface>; 1] = [None];
98 TYPES.as_ptr().cast()
99 },
100 },
101 wl_message {
102 name: c"axis_stop".as_ptr(),
103 signature: c"uu".as_ptr(),
104 types: {
105 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
106 TYPES.as_ptr().cast()
107 },
108 },
109 wl_message {
110 name: c"axis_discrete".as_ptr(),
111 signature: c"ui".as_ptr(),
112 types: {
113 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
114 TYPES.as_ptr().cast()
115 },
116 },
117 wl_message {
118 name: c"axis_value120".as_ptr(),
119 signature: c"ui".as_ptr(),
120 types: {
121 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
122 TYPES.as_ptr().cast()
123 },
124 },
125 wl_message {
126 name: c"axis_relative_direction".as_ptr(),
127 signature: c"uu".as_ptr(),
128 types: {
129 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
130 TYPES.as_ptr().cast()
131 },
132 },
133 ];
134 MESSAGES.as_ptr()
135 },
136};
137
138/// An owned wl_pointer proxy.
139///
140/// See the documentation of [the module][self] for the interface description.
141#[derive(Clone, Eq, PartialEq)]
142#[repr(transparent)]
143pub struct WlPointer {
144 /// This proxy has the interface INTERFACE.
145 proxy: UntypedOwnedProxy,
146}
147
148/// A borrowed wl_pointer proxy.
149///
150/// See the documentation of [the module][self] for the interface description.
151#[derive(Eq, PartialEq)]
152#[repr(transparent)]
153pub struct WlPointerRef {
154 /// This proxy has the interface INTERFACE.
155 proxy: UntypedBorrowedProxy,
156}
157
158// SAFETY: WlPointer is a transparent wrapper around UntypedOwnedProxy
159unsafe impl UntypedOwnedProxyWrapper for WlPointer {}
160
161// SAFETY: - INTERFACE is a valid wl_interface
162// - The only invariant is that self.proxy has a compatible interface
163unsafe impl OwnedProxy for WlPointer {
164 const INTERFACE: &'static str = "wl_pointer";
165 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
166 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
167 private::EventHandler(private::NoOpEventHandler);
168 const MAX_VERSION: u32 = 10;
169
170 type Borrowed = WlPointerRef;
171 type Api = private::ProxyApi;
172 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
173}
174
175// SAFETY: WlPointerRef is a transparent wrapper around UntypedBorrowedProxy
176unsafe impl UntypedBorrowedProxyWrapper for WlPointerRef {}
177
178// SAFETY: - The only invariant is that self.proxy has a compatible interface
179unsafe impl BorrowedProxy for WlPointerRef {
180 type Owned = WlPointer;
181}
182
183impl Deref for WlPointer {
184 type Target = WlPointerRef;
185
186 fn deref(&self) -> &Self::Target {
187 proxy::low_level::deref(self)
188 }
189}
190
191mod private {
192 pub struct ProxyApi;
193
194 #[allow(dead_code)]
195 pub struct EventHandler<H>(pub(super) H);
196
197 #[allow(dead_code)]
198 pub struct NoOpEventHandler;
199}
200
201impl Debug for WlPointer {
202 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
203 write!(f, "wl_pointer#{}", self.proxy.id())
204 }
205}
206
207impl Debug for WlPointerRef {
208 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
209 write!(f, "wl_pointer#{}", self.proxy.id())
210 }
211}
212
213impl PartialEq<WlPointerRef> for WlPointer {
214 fn eq(&self, other: &WlPointerRef) -> bool {
215 self.proxy == other.proxy
216 }
217}
218
219impl PartialEq<WlPointer> for WlPointerRef {
220 fn eq(&self, other: &WlPointer) -> bool {
221 self.proxy == other.proxy
222 }
223}
224
225#[allow(dead_code)]
226impl WlPointer {
227 /// Since when the release request is available.
228 #[allow(dead_code)]
229 pub const REQ__RELEASE__SINCE: u32 = 3;
230
231 /// release the pointer object
232 ///
233 /// Using this request a client can tell the server that it is not going to
234 /// use the pointer object anymore.
235 ///
236 /// This request destroys the pointer proxy object, so clients must not call
237 /// wl_pointer_destroy() after using this request.
238 #[inline]
239 pub fn release(&self) {
240 let mut args = [];
241 // SAFETY: - self.proxy has the interface INTERFACE
242 // - 1 < INTERFACE.method_count = 2
243 // - the request signature is ``
244 unsafe {
245 self.proxy.send_destructor(1, &mut args);
246 }
247 }
248}
249
250#[allow(dead_code)]
251impl WlPointerRef {
252 /// set the pointer surface
253 ///
254 /// Set the pointer surface, i.e., the surface that contains the
255 /// pointer image (cursor). This request gives the surface the role
256 /// of a cursor. If the surface already has another role, it raises
257 /// a protocol error.
258 ///
259 /// The cursor actually changes only if the pointer
260 /// focus for this device is one of the requesting client's surfaces
261 /// or the surface parameter is the current pointer surface. If
262 /// there was a previous surface set with this request it is
263 /// replaced. If surface is NULL, the pointer image is hidden.
264 ///
265 /// The parameters hotspot_x and hotspot_y define the position of
266 /// the pointer surface relative to the pointer location. Its
267 /// top-left corner is always at (x, y) - (hotspot_x, hotspot_y),
268 /// where (x, y) are the coordinates of the pointer location, in
269 /// surface-local coordinates.
270 ///
271 /// On wl_surface.offset requests to the pointer surface, hotspot_x
272 /// and hotspot_y are decremented by the x and y parameters
273 /// passed to the request. The offset must be applied by
274 /// wl_surface.commit as usual.
275 ///
276 /// The hotspot can also be updated by passing the currently set
277 /// pointer surface to this request with new values for hotspot_x
278 /// and hotspot_y.
279 ///
280 /// The input region is ignored for wl_surfaces with the role of
281 /// a cursor. When the use as a cursor ends, the wl_surface is
282 /// unmapped.
283 ///
284 /// The serial parameter must match the latest wl_pointer.enter
285 /// serial number sent to the client. Otherwise the request will be
286 /// ignored.
287 ///
288 /// # Arguments
289 ///
290 /// - `serial`: serial number of the enter event
291 /// - `surface`: pointer surface
292 /// - `hotspot_x`: surface-local x coordinate
293 /// - `hotspot_y`: surface-local y coordinate
294 #[inline]
295 pub fn set_cursor(
296 &self,
297 serial: u32,
298 surface: Option<&WlSurfaceRef>,
299 hotspot_x: i32,
300 hotspot_y: i32,
301 ) {
302 let (arg0, arg1, arg2, arg3) = (serial, surface, hotspot_x, hotspot_y);
303 let obj1_lock = arg1.map(|arg1| proxy::lock(arg1));
304 let obj1 = obj1_lock
305 .map(|obj1_lock| check_argument_proxy("surface", obj1_lock.wl_proxy()))
306 .unwrap_or(ptr::null_mut());
307 let mut args = [
308 wl_argument { u: arg0 },
309 wl_argument { o: obj1 },
310 wl_argument { i: arg2 },
311 wl_argument { i: arg3 },
312 ];
313 // SAFETY: - self.proxy has the interface INTERFACE
314 // - 0 < INTERFACE.method_count = 2
315 // - the request signature is `u?oii`
316 unsafe {
317 self.proxy.send_request(0, &mut args);
318 }
319 }
320}
321
322impl WlPointer {
323 /// Since when the enter event is available.
324 #[allow(dead_code)]
325 pub const EVT__ENTER__SINCE: u32 = 1;
326
327 /// Since when the leave event is available.
328 #[allow(dead_code)]
329 pub const EVT__LEAVE__SINCE: u32 = 1;
330
331 /// Since when the motion event is available.
332 #[allow(dead_code)]
333 pub const EVT__MOTION__SINCE: u32 = 1;
334
335 /// Since when the button event is available.
336 #[allow(dead_code)]
337 pub const EVT__BUTTON__SINCE: u32 = 1;
338
339 /// Since when the axis event is available.
340 #[allow(dead_code)]
341 pub const EVT__AXIS__SINCE: u32 = 1;
342
343 /// Since when the frame event is available.
344 #[allow(dead_code)]
345 pub const EVT__FRAME__SINCE: u32 = 5;
346
347 /// Since when the axis_source event is available.
348 #[allow(dead_code)]
349 pub const EVT__AXIS_SOURCE__SINCE: u32 = 5;
350
351 /// Since when the axis_stop event is available.
352 #[allow(dead_code)]
353 pub const EVT__AXIS_STOP__SINCE: u32 = 5;
354
355 /// Since when the axis_discrete event is available.
356 #[allow(dead_code)]
357 pub const EVT__AXIS_DISCRETE__SINCE: u32 = 5;
358
359 /// Since when the axis_discrete event is deprecated.
360 #[allow(dead_code)]
361 pub const EVT__AXIS_DISCRETE__DEPRECATED_SINCE: u32 = 8;
362
363 /// Since when the axis_value120 event is available.
364 #[allow(dead_code)]
365 pub const EVT__AXIS_VALUE120__SINCE: u32 = 8;
366
367 /// Since when the axis_relative_direction event is available.
368 #[allow(dead_code)]
369 pub const EVT__AXIS_RELATIVE_DIRECTION__SINCE: u32 = 9;
370}
371
372/// An event handler for [WlPointer] proxies.
373#[allow(dead_code)]
374pub trait WlPointerEventHandler {
375 type Data: 'static;
376
377 /// enter event
378 ///
379 /// Notification that this seat's pointer is focused on a certain
380 /// surface.
381 ///
382 /// When a seat's focus enters a surface, the pointer image
383 /// is undefined and a client should respond to this event by setting
384 /// an appropriate pointer image with the set_cursor request.
385 ///
386 /// # Arguments
387 ///
388 /// - `serial`: serial number of the enter event
389 /// - `surface`: surface entered by the pointer
390 /// - `surface_x`: surface-local x coordinate
391 /// - `surface_y`: surface-local y coordinate
392 ///
393 /// All borrowed proxies passed to this function are guaranteed to be
394 /// immutable and non-null.
395 #[inline]
396 fn enter(
397 &self,
398 _data: &mut Self::Data,
399 _slf: &WlPointerRef,
400 serial: u32,
401 surface: Option<&WlSurfaceRef>,
402 surface_x: Fixed,
403 surface_y: Fixed,
404 ) {
405 let _ = serial;
406 let _ = surface;
407 let _ = surface_x;
408 let _ = surface_y;
409 }
410
411 /// leave event
412 ///
413 /// Notification that this seat's pointer is no longer focused on
414 /// a certain surface.
415 ///
416 /// The leave notification is sent before the enter notification
417 /// for the new focus.
418 ///
419 /// # Arguments
420 ///
421 /// - `serial`: serial number of the leave event
422 /// - `surface`: surface left by the pointer
423 ///
424 /// All borrowed proxies passed to this function are guaranteed to be
425 /// immutable and non-null.
426 #[inline]
427 fn leave(
428 &self,
429 _data: &mut Self::Data,
430 _slf: &WlPointerRef,
431 serial: u32,
432 surface: Option<&WlSurfaceRef>,
433 ) {
434 let _ = serial;
435 let _ = surface;
436 }
437
438 /// pointer motion event
439 ///
440 /// Notification of pointer location change. The arguments
441 /// surface_x and surface_y are the location relative to the
442 /// focused surface.
443 ///
444 /// # Arguments
445 ///
446 /// - `time`: timestamp with millisecond granularity
447 /// - `surface_x`: surface-local x coordinate
448 /// - `surface_y`: surface-local y coordinate
449 #[inline]
450 fn motion(
451 &self,
452 _data: &mut Self::Data,
453 _slf: &WlPointerRef,
454 time: u32,
455 surface_x: Fixed,
456 surface_y: Fixed,
457 ) {
458 let _ = time;
459 let _ = surface_x;
460 let _ = surface_y;
461 }
462
463 /// pointer button event
464 ///
465 /// Mouse button click and release notifications.
466 ///
467 /// The location of the click is given by the last motion or
468 /// enter event.
469 /// The time argument is a timestamp with millisecond
470 /// granularity, with an undefined base.
471 ///
472 /// The button is a button code as defined in the Linux kernel's
473 /// linux/input-event-codes.h header file, e.g. BTN_LEFT.
474 ///
475 /// Any 16-bit button code value is reserved for future additions to the
476 /// kernel's event code list. All other button codes above 0xFFFF are
477 /// currently undefined but may be used in future versions of this
478 /// protocol.
479 ///
480 /// # Arguments
481 ///
482 /// - `serial`: serial number of the button event
483 /// - `time`: timestamp with millisecond granularity
484 /// - `button`: button that produced the event
485 /// - `state`: physical state of the button
486 #[inline]
487 fn button(
488 &self,
489 _data: &mut Self::Data,
490 _slf: &WlPointerRef,
491 serial: u32,
492 time: u32,
493 button: u32,
494 state: WlPointerButtonState,
495 ) {
496 let _ = serial;
497 let _ = time;
498 let _ = button;
499 let _ = state;
500 }
501
502 /// axis event
503 ///
504 /// Scroll and other axis notifications.
505 ///
506 /// For scroll events (vertical and horizontal scroll axes), the
507 /// value parameter is the length of a vector along the specified
508 /// axis in a coordinate space identical to those of motion events,
509 /// representing a relative movement along the specified axis.
510 ///
511 /// For devices that support movements non-parallel to axes multiple
512 /// axis events will be emitted.
513 ///
514 /// When applicable, for example for touch pads, the server can
515 /// choose to emit scroll events where the motion vector is
516 /// equivalent to a motion event vector.
517 ///
518 /// When applicable, a client can transform its content relative to the
519 /// scroll distance.
520 ///
521 /// # Arguments
522 ///
523 /// - `time`: timestamp with millisecond granularity
524 /// - `axis`: axis type
525 /// - `value`: length of vector in surface-local coordinate space
526 #[inline]
527 fn axis(
528 &self,
529 _data: &mut Self::Data,
530 _slf: &WlPointerRef,
531 time: u32,
532 axis: WlPointerAxis,
533 value: Fixed,
534 ) {
535 let _ = time;
536 let _ = axis;
537 let _ = value;
538 }
539
540 /// end of a pointer event sequence
541 ///
542 /// Indicates the end of a set of events that logically belong together.
543 /// A client is expected to accumulate the data in all events within the
544 /// frame before proceeding.
545 ///
546 /// All wl_pointer events before a wl_pointer.frame event belong
547 /// logically together. For example, in a diagonal scroll motion the
548 /// compositor will send an optional wl_pointer.axis_source event, two
549 /// wl_pointer.axis events (horizontal and vertical) and finally a
550 /// wl_pointer.frame event. The client may use this information to
551 /// calculate a diagonal vector for scrolling.
552 ///
553 /// When multiple wl_pointer.axis events occur within the same frame,
554 /// the motion vector is the combined motion of all events.
555 /// When a wl_pointer.axis and a wl_pointer.axis_stop event occur within
556 /// the same frame, this indicates that axis movement in one axis has
557 /// stopped but continues in the other axis.
558 /// When multiple wl_pointer.axis_stop events occur within the same
559 /// frame, this indicates that these axes stopped in the same instance.
560 ///
561 /// A wl_pointer.frame event is sent for every logical event group,
562 /// even if the group only contains a single wl_pointer event.
563 /// Specifically, a client may get a sequence: motion, frame, button,
564 /// frame, axis, frame, axis_stop, frame.
565 ///
566 /// The wl_pointer.enter and wl_pointer.leave events are logical events
567 /// generated by the compositor and not the hardware. These events are
568 /// also grouped by a wl_pointer.frame. When a pointer moves from one
569 /// surface to another, a compositor should group the
570 /// wl_pointer.leave event within the same wl_pointer.frame.
571 /// However, a client must not rely on wl_pointer.leave and
572 /// wl_pointer.enter being in the same wl_pointer.frame.
573 /// Compositor-specific policies may require the wl_pointer.leave and
574 /// wl_pointer.enter event being split across multiple wl_pointer.frame
575 /// groups.
576 #[inline]
577 fn frame(&self, _data: &mut Self::Data, _slf: &WlPointerRef) {}
578
579 /// axis source event
580 ///
581 /// Source information for scroll and other axes.
582 ///
583 /// This event does not occur on its own. It is sent before a
584 /// wl_pointer.frame event and carries the source information for
585 /// all events within that frame.
586 ///
587 /// The source specifies how this event was generated. If the source is
588 /// wl_pointer.axis_source.finger, a wl_pointer.axis_stop event will be
589 /// sent when the user lifts the finger off the device.
590 ///
591 /// If the source is wl_pointer.axis_source.wheel,
592 /// wl_pointer.axis_source.wheel_tilt or
593 /// wl_pointer.axis_source.continuous, a wl_pointer.axis_stop event may
594 /// or may not be sent. Whether a compositor sends an axis_stop event
595 /// for these sources is hardware-specific and implementation-dependent;
596 /// clients must not rely on receiving an axis_stop event for these
597 /// scroll sources and should treat scroll sequences from these scroll
598 /// sources as unterminated by default.
599 ///
600 /// This event is optional. If the source is unknown for a particular
601 /// axis event sequence, no event is sent.
602 /// Only one wl_pointer.axis_source event is permitted per frame.
603 ///
604 /// The order of wl_pointer.axis_discrete and wl_pointer.axis_source is
605 /// not guaranteed.
606 ///
607 /// # Arguments
608 ///
609 /// - `axis_source`: source of the axis event
610 #[inline]
611 fn axis_source(
612 &self,
613 _data: &mut Self::Data,
614 _slf: &WlPointerRef,
615 axis_source: WlPointerAxisSource,
616 ) {
617 let _ = axis_source;
618 }
619
620 /// axis stop event
621 ///
622 /// Stop notification for scroll and other axes.
623 ///
624 /// For some wl_pointer.axis_source types, a wl_pointer.axis_stop event
625 /// is sent to notify a client that the axis sequence has terminated.
626 /// This enables the client to implement kinetic scrolling.
627 /// See the wl_pointer.axis_source documentation for information on when
628 /// this event may be generated.
629 ///
630 /// Any wl_pointer.axis events with the same axis_source after this
631 /// event should be considered as the start of a new axis motion.
632 ///
633 /// The timestamp is to be interpreted identical to the timestamp in the
634 /// wl_pointer.axis event. The timestamp value may be the same as a
635 /// preceding wl_pointer.axis event.
636 ///
637 /// # Arguments
638 ///
639 /// - `time`: timestamp with millisecond granularity
640 /// - `axis`: the axis stopped with this event
641 #[inline]
642 fn axis_stop(
643 &self,
644 _data: &mut Self::Data,
645 _slf: &WlPointerRef,
646 time: u32,
647 axis: WlPointerAxis,
648 ) {
649 let _ = time;
650 let _ = axis;
651 }
652
653 /// axis click event
654 ///
655 /// Discrete step information for scroll and other axes.
656 ///
657 /// This event carries the axis value of the wl_pointer.axis event in
658 /// discrete steps (e.g. mouse wheel clicks).
659 ///
660 /// This event is deprecated with wl_pointer version 8 - this event is not
661 /// sent to clients supporting version 8 or later.
662 ///
663 /// This event does not occur on its own, it is coupled with a
664 /// wl_pointer.axis event that represents this axis value on a
665 /// continuous scale. The protocol guarantees that each axis_discrete
666 /// event is always followed by exactly one axis event with the same
667 /// axis number within the same wl_pointer.frame. Note that the protocol
668 /// allows for other events to occur between the axis_discrete and
669 /// its coupled axis event, including other axis_discrete or axis
670 /// events. A wl_pointer.frame must not contain more than one axis_discrete
671 /// event per axis type.
672 ///
673 /// This event is optional; continuous scrolling devices
674 /// like two-finger scrolling on touchpads do not have discrete
675 /// steps and do not generate this event.
676 ///
677 /// The discrete value carries the directional information. e.g. a value
678 /// of -2 is two steps towards the negative direction of this axis.
679 ///
680 /// The axis number is identical to the axis number in the associated
681 /// axis event.
682 ///
683 /// The order of wl_pointer.axis_discrete and wl_pointer.axis_source is
684 /// not guaranteed.
685 ///
686 /// # Arguments
687 ///
688 /// - `axis`: axis type
689 /// - `discrete`: number of steps
690 #[inline]
691 fn axis_discrete(
692 &self,
693 _data: &mut Self::Data,
694 _slf: &WlPointerRef,
695 axis: WlPointerAxis,
696 discrete: i32,
697 ) {
698 let _ = axis;
699 let _ = discrete;
700 }
701
702 /// axis high-resolution scroll event
703 ///
704 /// Discrete high-resolution scroll information.
705 ///
706 /// This event carries high-resolution wheel scroll information,
707 /// with each multiple of 120 representing one logical scroll step
708 /// (a wheel detent). For example, an axis_value120 of 30 is one quarter of
709 /// a logical scroll step in the positive direction, a value120 of
710 /// -240 are two logical scroll steps in the negative direction within the
711 /// same hardware event.
712 /// Clients that rely on discrete scrolling should accumulate the
713 /// value120 to multiples of 120 before processing the event.
714 ///
715 /// The value120 must not be zero.
716 ///
717 /// This event replaces the wl_pointer.axis_discrete event in clients
718 /// supporting wl_pointer version 8 or later.
719 ///
720 /// Where a wl_pointer.axis_source event occurs in the same
721 /// wl_pointer.frame, the axis source applies to this event.
722 ///
723 /// The order of wl_pointer.axis_value120 and wl_pointer.axis_source is
724 /// not guaranteed.
725 ///
726 /// # Arguments
727 ///
728 /// - `axis`: axis type
729 /// - `value120`: scroll distance as fraction of 120
730 #[inline]
731 fn axis_value120(
732 &self,
733 _data: &mut Self::Data,
734 _slf: &WlPointerRef,
735 axis: WlPointerAxis,
736 value120: i32,
737 ) {
738 let _ = axis;
739 let _ = value120;
740 }
741
742 /// axis relative physical direction event
743 ///
744 /// Relative directional information of the entity causing the axis
745 /// motion.
746 ///
747 /// For a wl_pointer.axis event, the wl_pointer.axis_relative_direction
748 /// event specifies the movement direction of the entity causing the
749 /// wl_pointer.axis event. For example:
750 /// - if a user's fingers on a touchpad move down and this
751 /// causes a wl_pointer.axis vertical_scroll down event, the physical
752 /// direction is 'identical'
753 /// - if a user's fingers on a touchpad move down and this causes a
754 /// wl_pointer.axis vertical_scroll up scroll up event ('natural
755 /// scrolling'), the physical direction is 'inverted'.
756 ///
757 /// A client may use this information to adjust scroll motion of
758 /// components. Specifically, enabling natural scrolling causes the
759 /// content to change direction compared to traditional scrolling.
760 /// Some widgets like volume control sliders should usually match the
761 /// physical direction regardless of whether natural scrolling is
762 /// active. This event enables clients to match the scroll direction of
763 /// a widget to the physical direction.
764 ///
765 /// This event does not occur on its own, it is coupled with a
766 /// wl_pointer.axis event that represents this axis value.
767 /// The protocol guarantees that each axis_relative_direction event is
768 /// always followed by exactly one axis event with the same
769 /// axis number within the same wl_pointer.frame. Note that the protocol
770 /// allows for other events to occur between the axis_relative_direction
771 /// and its coupled axis event.
772 ///
773 /// The axis number is identical to the axis number in the associated
774 /// axis event.
775 ///
776 /// The order of wl_pointer.axis_relative_direction,
777 /// wl_pointer.axis_discrete and wl_pointer.axis_source is not
778 /// guaranteed.
779 ///
780 /// # Arguments
781 ///
782 /// - `axis`: axis type
783 /// - `direction`: physical direction relative to axis motion
784 #[inline]
785 fn axis_relative_direction(
786 &self,
787 _data: &mut Self::Data,
788 _slf: &WlPointerRef,
789 axis: WlPointerAxis,
790 direction: WlPointerAxisRelativeDirection,
791 ) {
792 let _ = axis;
793 let _ = direction;
794 }
795}
796
797impl WlPointerEventHandler for private::NoOpEventHandler {
798 type Data = ();
799}
800
801// SAFETY: - INTERFACE is a valid wl_interface
802// - mutable_type always returns the same value
803unsafe impl<H> EventHandler for private::EventHandler<H>
804where
805 H: WlPointerEventHandler,
806{
807 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
808
809 #[inline]
810 fn mutable_type() -> Option<(TypeId, &'static str)> {
811 let id = TypeId::of::<H::Data>();
812 let name = std::any::type_name::<H::Data>();
813 Some((id, name))
814 }
815
816 #[allow(unused_variables)]
817 unsafe fn handle_event(
818 &self,
819 queue: &Queue,
820 data: *mut u8,
821 slf: &UntypedBorrowedProxy,
822 opcode: u32,
823 args: *mut wl_argument,
824 ) {
825 // SAFETY: This function requires that slf has the interface INTERFACE
826 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlPointerRef>(slf) };
827 // SAFETY: This function requires that data is `&mut T` where `T`
828 // has the type id returned by `Self::mutable_type`, i.e.,
829 // `T = H::Data`.
830 let data: &mut H::Data = unsafe { &mut *data.cast() };
831 match opcode {
832 0 => {
833 // SAFETY: INTERFACE requires that there are 4 arguments
834 let args = unsafe { &*args.cast::<[wl_argument; 4]>() };
835 // SAFETY: - INTERFACE requires that args[0] contains a uint
836 let arg0 = unsafe { args[0].u };
837 // SAFETY: - INTERFACE requires that args[1] contains an object
838 let arg1 = unsafe {
839 if let Some(p) = NonNull::new(args[1].o.cast()) {
840 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
841 } else {
842 None
843 }
844 };
845 // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
846 let arg1 = arg1.as_ref().map(|arg1| unsafe {
847 proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
848 });
849 // SAFETY: - INTERFACE requires that args[2] contains a fixed
850 let arg2 = unsafe { Fixed::from_wire(args[2].f) };
851 // SAFETY: - INTERFACE requires that args[3] contains a fixed
852 let arg3 = unsafe { Fixed::from_wire(args[3].f) };
853 self.0.enter(data, slf, arg0, arg1, arg2, arg3);
854 }
855 1 => {
856 // SAFETY: INTERFACE requires that there are 2 arguments
857 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
858 // SAFETY: - INTERFACE requires that args[0] contains a uint
859 let arg0 = unsafe { args[0].u };
860 // SAFETY: - INTERFACE requires that args[1] contains an object
861 let arg1 = unsafe {
862 if let Some(p) = NonNull::new(args[1].o.cast()) {
863 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
864 } else {
865 None
866 }
867 };
868 // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
869 let arg1 = arg1.as_ref().map(|arg1| unsafe {
870 proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
871 });
872 self.0.leave(data, slf, arg0, arg1);
873 }
874 2 => {
875 // SAFETY: INTERFACE requires that there are 3 arguments
876 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
877 // SAFETY: - INTERFACE requires that args[0] contains a uint
878 let arg0 = unsafe { args[0].u };
879 // SAFETY: - INTERFACE requires that args[1] contains a fixed
880 let arg1 = unsafe { Fixed::from_wire(args[1].f) };
881 // SAFETY: - INTERFACE requires that args[2] contains a fixed
882 let arg2 = unsafe { Fixed::from_wire(args[2].f) };
883 self.0.motion(data, slf, arg0, arg1, arg2);
884 }
885 3 => {
886 // SAFETY: INTERFACE requires that there are 4 arguments
887 let args = unsafe { &*args.cast::<[wl_argument; 4]>() };
888 // SAFETY: - INTERFACE requires that args[0] contains a uint
889 let arg0 = unsafe { args[0].u };
890 // SAFETY: - INTERFACE requires that args[1] contains a uint
891 let arg1 = unsafe { args[1].u };
892 // SAFETY: - INTERFACE requires that args[2] contains a uint
893 let arg2 = unsafe { args[2].u };
894 // SAFETY: - INTERFACE requires that args[3] contains a uint
895 let arg3 = unsafe { WlPointerButtonState(args[3].u) };
896 self.0.button(data, slf, arg0, arg1, arg2, arg3);
897 }
898 4 => {
899 // SAFETY: INTERFACE requires that there are 3 arguments
900 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
901 // SAFETY: - INTERFACE requires that args[0] contains a uint
902 let arg0 = unsafe { args[0].u };
903 // SAFETY: - INTERFACE requires that args[1] contains a uint
904 let arg1 = unsafe { WlPointerAxis(args[1].u) };
905 // SAFETY: - INTERFACE requires that args[2] contains a fixed
906 let arg2 = unsafe { Fixed::from_wire(args[2].f) };
907 self.0.axis(data, slf, arg0, arg1, arg2);
908 }
909 5 => {
910 self.0.frame(data, slf);
911 }
912 6 => {
913 // SAFETY: INTERFACE requires that there are 1 arguments
914 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
915 // SAFETY: - INTERFACE requires that args[0] contains a uint
916 let arg0 = unsafe { WlPointerAxisSource(args[0].u) };
917 self.0.axis_source(data, slf, arg0);
918 }
919 7 => {
920 // SAFETY: INTERFACE requires that there are 2 arguments
921 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
922 // SAFETY: - INTERFACE requires that args[0] contains a uint
923 let arg0 = unsafe { args[0].u };
924 // SAFETY: - INTERFACE requires that args[1] contains a uint
925 let arg1 = unsafe { WlPointerAxis(args[1].u) };
926 self.0.axis_stop(data, slf, arg0, arg1);
927 }
928 8 => {
929 // SAFETY: INTERFACE requires that there are 2 arguments
930 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
931 // SAFETY: - INTERFACE requires that args[0] contains a uint
932 let arg0 = unsafe { WlPointerAxis(args[0].u) };
933 // SAFETY: - INTERFACE requires that args[1] contains an int
934 let arg1 = unsafe { args[1].i };
935 self.0.axis_discrete(data, slf, arg0, arg1);
936 }
937 9 => {
938 // SAFETY: INTERFACE requires that there are 2 arguments
939 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
940 // SAFETY: - INTERFACE requires that args[0] contains a uint
941 let arg0 = unsafe { WlPointerAxis(args[0].u) };
942 // SAFETY: - INTERFACE requires that args[1] contains an int
943 let arg1 = unsafe { args[1].i };
944 self.0.axis_value120(data, slf, arg0, arg1);
945 }
946 10 => {
947 // SAFETY: INTERFACE requires that there are 2 arguments
948 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
949 // SAFETY: - INTERFACE requires that args[0] contains a uint
950 let arg0 = unsafe { WlPointerAxis(args[0].u) };
951 // SAFETY: - INTERFACE requires that args[1] contains a uint
952 let arg1 = unsafe { WlPointerAxisRelativeDirection(args[1].u) };
953 self.0.axis_relative_direction(data, slf, arg0, arg1);
954 }
955 _ => {
956 invalid_opcode("wl_pointer", opcode);
957 }
958 }
959 }
960}
961
962impl<H> CreateEventHandler<H> for private::ProxyApi
963where
964 H: WlPointerEventHandler,
965{
966 type EventHandler = private::EventHandler<H>;
967
968 #[inline]
969 fn create_event_handler(handler: H) -> Self::EventHandler {
970 private::EventHandler(handler)
971 }
972}
973
974impl WlPointer {
975 /// Since when the error.role enum variant is available.
976 #[allow(dead_code)]
977 pub const ENM__ERROR_ROLE__SINCE: u32 = 1;
978
979 /// Since when the button_state.released enum variant is available.
980 #[allow(dead_code)]
981 pub const ENM__BUTTON_STATE_RELEASED__SINCE: u32 = 1;
982 /// Since when the button_state.pressed enum variant is available.
983 #[allow(dead_code)]
984 pub const ENM__BUTTON_STATE_PRESSED__SINCE: u32 = 1;
985
986 /// Since when the axis.vertical_scroll enum variant is available.
987 #[allow(dead_code)]
988 pub const ENM__AXIS_VERTICAL_SCROLL__SINCE: u32 = 1;
989 /// Since when the axis.horizontal_scroll enum variant is available.
990 #[allow(dead_code)]
991 pub const ENM__AXIS_HORIZONTAL_SCROLL__SINCE: u32 = 1;
992
993 /// Since when the axis_source.wheel enum variant is available.
994 #[allow(dead_code)]
995 pub const ENM__AXIS_SOURCE_WHEEL__SINCE: u32 = 1;
996 /// Since when the axis_source.finger enum variant is available.
997 #[allow(dead_code)]
998 pub const ENM__AXIS_SOURCE_FINGER__SINCE: u32 = 1;
999 /// Since when the axis_source.continuous enum variant is available.
1000 #[allow(dead_code)]
1001 pub const ENM__AXIS_SOURCE_CONTINUOUS__SINCE: u32 = 1;
1002 /// Since when the axis_source.wheel_tilt enum variant is available.
1003 #[allow(dead_code)]
1004 pub const ENM__AXIS_SOURCE_WHEEL_TILT__SINCE: u32 = 6;
1005
1006 /// Since when the axis_relative_direction.identical enum variant is available.
1007 #[allow(dead_code)]
1008 pub const ENM__AXIS_RELATIVE_DIRECTION_IDENTICAL__SINCE: u32 = 1;
1009 /// Since when the axis_relative_direction.inverted enum variant is available.
1010 #[allow(dead_code)]
1011 pub const ENM__AXIS_RELATIVE_DIRECTION_INVERTED__SINCE: u32 = 1;
1012}
1013
1014#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1015#[allow(dead_code)]
1016pub struct WlPointerError(pub u32);
1017
1018impl WlPointerError {
1019 /// given wl_surface has another role
1020 #[allow(dead_code)]
1021 pub const ROLE: Self = Self(0);
1022}
1023
1024impl Debug for WlPointerError {
1025 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1026 let name = match *self {
1027 Self::ROLE => "ROLE",
1028 _ => return Debug::fmt(&self.0, f),
1029 };
1030 f.write_str(name)
1031 }
1032}
1033
1034/// physical button state
1035///
1036/// Describes the physical state of a button that produced the button
1037/// event.
1038#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1039#[allow(dead_code)]
1040pub struct WlPointerButtonState(pub u32);
1041
1042impl WlPointerButtonState {
1043 /// the button is not pressed
1044 #[allow(dead_code)]
1045 pub const RELEASED: Self = Self(0);
1046
1047 /// the button is pressed
1048 #[allow(dead_code)]
1049 pub const PRESSED: Self = Self(1);
1050}
1051
1052impl Debug for WlPointerButtonState {
1053 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1054 let name = match *self {
1055 Self::RELEASED => "RELEASED",
1056 Self::PRESSED => "PRESSED",
1057 _ => return Debug::fmt(&self.0, f),
1058 };
1059 f.write_str(name)
1060 }
1061}
1062
1063/// axis types
1064///
1065/// Describes the axis types of scroll events.
1066#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1067#[allow(dead_code)]
1068pub struct WlPointerAxis(pub u32);
1069
1070impl WlPointerAxis {
1071 /// vertical axis
1072 #[allow(dead_code)]
1073 pub const VERTICAL_SCROLL: Self = Self(0);
1074
1075 /// horizontal axis
1076 #[allow(dead_code)]
1077 pub const HORIZONTAL_SCROLL: Self = Self(1);
1078}
1079
1080impl Debug for WlPointerAxis {
1081 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1082 let name = match *self {
1083 Self::VERTICAL_SCROLL => "VERTICAL_SCROLL",
1084 Self::HORIZONTAL_SCROLL => "HORIZONTAL_SCROLL",
1085 _ => return Debug::fmt(&self.0, f),
1086 };
1087 f.write_str(name)
1088 }
1089}
1090
1091/// axis source types
1092///
1093/// Describes the source types for axis events. This indicates to the
1094/// client how an axis event was physically generated; a client may
1095/// adjust the user interface accordingly. For example, scroll events
1096/// from a "finger" source may be in a smooth coordinate space with
1097/// kinetic scrolling whereas a "wheel" source may be in discrete steps
1098/// of a number of lines.
1099///
1100/// The "continuous" axis source is a device generating events in a
1101/// continuous coordinate space, but using something other than a
1102/// finger. One example for this source is button-based scrolling where
1103/// the vertical motion of a device is converted to scroll events while
1104/// a button is held down.
1105///
1106/// The "wheel tilt" axis source indicates that the actual device is a
1107/// wheel but the scroll event is not caused by a rotation but a
1108/// (usually sideways) tilt of the wheel.
1109#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1110#[allow(dead_code)]
1111pub struct WlPointerAxisSource(pub u32);
1112
1113impl WlPointerAxisSource {
1114 /// a physical wheel rotation
1115 #[allow(dead_code)]
1116 pub const WHEEL: Self = Self(0);
1117
1118 /// finger on a touch surface
1119 #[allow(dead_code)]
1120 pub const FINGER: Self = Self(1);
1121
1122 /// continuous coordinate space
1123 #[allow(dead_code)]
1124 pub const CONTINUOUS: Self = Self(2);
1125
1126 /// a physical wheel tilt
1127 #[allow(dead_code)]
1128 pub const WHEEL_TILT: Self = Self(3);
1129}
1130
1131impl Debug for WlPointerAxisSource {
1132 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1133 let name = match *self {
1134 Self::WHEEL => "WHEEL",
1135 Self::FINGER => "FINGER",
1136 Self::CONTINUOUS => "CONTINUOUS",
1137 Self::WHEEL_TILT => "WHEEL_TILT",
1138 _ => return Debug::fmt(&self.0, f),
1139 };
1140 f.write_str(name)
1141 }
1142}
1143
1144/// axis relative direction
1145///
1146/// This specifies the direction of the physical motion that caused a
1147/// wl_pointer.axis event, relative to the wl_pointer.axis direction.
1148#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1149#[allow(dead_code)]
1150pub struct WlPointerAxisRelativeDirection(pub u32);
1151
1152impl WlPointerAxisRelativeDirection {
1153 /// physical motion matches axis direction
1154 #[allow(dead_code)]
1155 pub const IDENTICAL: Self = Self(0);
1156
1157 /// physical motion is the inverse of the axis direction
1158 #[allow(dead_code)]
1159 pub const INVERTED: Self = Self(1);
1160}
1161
1162impl Debug for WlPointerAxisRelativeDirection {
1163 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1164 let name = match *self {
1165 Self::IDENTICAL => "IDENTICAL",
1166 Self::INVERTED => "INVERTED",
1167 _ => return Debug::fmt(&self.0, f),
1168 };
1169 f.write_str(name)
1170 }
1171}
1172
1173/// Functional event handlers.
1174pub mod event_handlers {
1175 use super::*;
1176
1177 /// Event handler for enter events.
1178 pub struct Enter<T, F>(F, PhantomData<fn(&mut T)>);
1179 impl<T, F> WlPointerEventHandler for Enter<T, F>
1180 where
1181 T: 'static,
1182 F: Fn(&mut T, &WlPointerRef, u32, Option<&WlSurfaceRef>, Fixed, Fixed),
1183 {
1184 type Data = T;
1185
1186 #[inline]
1187 fn enter(
1188 &self,
1189 _data: &mut T,
1190 _slf: &WlPointerRef,
1191 serial: u32,
1192 surface: Option<&WlSurfaceRef>,
1193 surface_x: Fixed,
1194 surface_y: Fixed,
1195 ) {
1196 self.0(_data, _slf, serial, surface, surface_x, surface_y)
1197 }
1198 }
1199
1200 /// Event handler for leave events.
1201 pub struct Leave<T, F>(F, PhantomData<fn(&mut T)>);
1202 impl<T, F> WlPointerEventHandler for Leave<T, F>
1203 where
1204 T: 'static,
1205 F: Fn(&mut T, &WlPointerRef, u32, Option<&WlSurfaceRef>),
1206 {
1207 type Data = T;
1208
1209 #[inline]
1210 fn leave(
1211 &self,
1212 _data: &mut T,
1213 _slf: &WlPointerRef,
1214 serial: u32,
1215 surface: Option<&WlSurfaceRef>,
1216 ) {
1217 self.0(_data, _slf, serial, surface)
1218 }
1219 }
1220
1221 /// Event handler for motion events.
1222 pub struct Motion<T, F>(F, PhantomData<fn(&mut T)>);
1223 impl<T, F> WlPointerEventHandler for Motion<T, F>
1224 where
1225 T: 'static,
1226 F: Fn(&mut T, &WlPointerRef, u32, Fixed, Fixed),
1227 {
1228 type Data = T;
1229
1230 #[inline]
1231 fn motion(
1232 &self,
1233 _data: &mut T,
1234 _slf: &WlPointerRef,
1235 time: u32,
1236 surface_x: Fixed,
1237 surface_y: Fixed,
1238 ) {
1239 self.0(_data, _slf, time, surface_x, surface_y)
1240 }
1241 }
1242
1243 /// Event handler for button events.
1244 pub struct Button<T, F>(F, PhantomData<fn(&mut T)>);
1245 impl<T, F> WlPointerEventHandler for Button<T, F>
1246 where
1247 T: 'static,
1248 F: Fn(&mut T, &WlPointerRef, u32, u32, u32, WlPointerButtonState),
1249 {
1250 type Data = T;
1251
1252 #[inline]
1253 fn button(
1254 &self,
1255 _data: &mut T,
1256 _slf: &WlPointerRef,
1257 serial: u32,
1258 time: u32,
1259 button: u32,
1260 state: WlPointerButtonState,
1261 ) {
1262 self.0(_data, _slf, serial, time, button, state)
1263 }
1264 }
1265
1266 /// Event handler for axis events.
1267 pub struct Axis<T, F>(F, PhantomData<fn(&mut T)>);
1268 impl<T, F> WlPointerEventHandler for Axis<T, F>
1269 where
1270 T: 'static,
1271 F: Fn(&mut T, &WlPointerRef, u32, WlPointerAxis, Fixed),
1272 {
1273 type Data = T;
1274
1275 #[inline]
1276 fn axis(
1277 &self,
1278 _data: &mut T,
1279 _slf: &WlPointerRef,
1280 time: u32,
1281 axis: WlPointerAxis,
1282 value: Fixed,
1283 ) {
1284 self.0(_data, _slf, time, axis, value)
1285 }
1286 }
1287
1288 /// Event handler for frame events.
1289 pub struct Frame<T, F>(F, PhantomData<fn(&mut T)>);
1290 impl<T, F> WlPointerEventHandler for Frame<T, F>
1291 where
1292 T: 'static,
1293 F: Fn(&mut T, &WlPointerRef),
1294 {
1295 type Data = T;
1296
1297 #[inline]
1298 fn frame(&self, _data: &mut T, _slf: &WlPointerRef) {
1299 self.0(_data, _slf)
1300 }
1301 }
1302
1303 /// Event handler for axis_source events.
1304 pub struct AxisSource<T, F>(F, PhantomData<fn(&mut T)>);
1305 impl<T, F> WlPointerEventHandler for AxisSource<T, F>
1306 where
1307 T: 'static,
1308 F: Fn(&mut T, &WlPointerRef, WlPointerAxisSource),
1309 {
1310 type Data = T;
1311
1312 #[inline]
1313 fn axis_source(
1314 &self,
1315 _data: &mut T,
1316 _slf: &WlPointerRef,
1317 axis_source: WlPointerAxisSource,
1318 ) {
1319 self.0(_data, _slf, axis_source)
1320 }
1321 }
1322
1323 /// Event handler for axis_stop events.
1324 pub struct AxisStop<T, F>(F, PhantomData<fn(&mut T)>);
1325 impl<T, F> WlPointerEventHandler for AxisStop<T, F>
1326 where
1327 T: 'static,
1328 F: Fn(&mut T, &WlPointerRef, u32, WlPointerAxis),
1329 {
1330 type Data = T;
1331
1332 #[inline]
1333 fn axis_stop(&self, _data: &mut T, _slf: &WlPointerRef, time: u32, axis: WlPointerAxis) {
1334 self.0(_data, _slf, time, axis)
1335 }
1336 }
1337
1338 /// Event handler for axis_discrete events.
1339 pub struct AxisDiscrete<T, F>(F, PhantomData<fn(&mut T)>);
1340 impl<T, F> WlPointerEventHandler for AxisDiscrete<T, F>
1341 where
1342 T: 'static,
1343 F: Fn(&mut T, &WlPointerRef, WlPointerAxis, i32),
1344 {
1345 type Data = T;
1346
1347 #[inline]
1348 fn axis_discrete(
1349 &self,
1350 _data: &mut T,
1351 _slf: &WlPointerRef,
1352 axis: WlPointerAxis,
1353 discrete: i32,
1354 ) {
1355 self.0(_data, _slf, axis, discrete)
1356 }
1357 }
1358
1359 /// Event handler for axis_value120 events.
1360 pub struct AxisValue120<T, F>(F, PhantomData<fn(&mut T)>);
1361 impl<T, F> WlPointerEventHandler for AxisValue120<T, F>
1362 where
1363 T: 'static,
1364 F: Fn(&mut T, &WlPointerRef, WlPointerAxis, i32),
1365 {
1366 type Data = T;
1367
1368 #[inline]
1369 fn axis_value120(
1370 &self,
1371 _data: &mut T,
1372 _slf: &WlPointerRef,
1373 axis: WlPointerAxis,
1374 value120: i32,
1375 ) {
1376 self.0(_data, _slf, axis, value120)
1377 }
1378 }
1379
1380 /// Event handler for axis_relative_direction events.
1381 pub struct AxisRelativeDirection<T, F>(F, PhantomData<fn(&mut T)>);
1382 impl<T, F> WlPointerEventHandler for AxisRelativeDirection<T, F>
1383 where
1384 T: 'static,
1385 F: Fn(&mut T, &WlPointerRef, WlPointerAxis, WlPointerAxisRelativeDirection),
1386 {
1387 type Data = T;
1388
1389 #[inline]
1390 fn axis_relative_direction(
1391 &self,
1392 _data: &mut T,
1393 _slf: &WlPointerRef,
1394 axis: WlPointerAxis,
1395 direction: WlPointerAxisRelativeDirection,
1396 ) {
1397 self.0(_data, _slf, axis, direction)
1398 }
1399 }
1400
1401 impl WlPointer {
1402 /// Creates an event handler for enter events.
1403 ///
1404 /// The event handler ignores all other events.
1405 #[allow(dead_code)]
1406 pub fn on_enter<T, F>(f: F) -> Enter<T, F>
1407 where
1408 T: 'static,
1409 F: Fn(&mut T, &WlPointerRef, u32, Option<&WlSurfaceRef>, Fixed, Fixed),
1410 {
1411 Enter(f, PhantomData)
1412 }
1413
1414 /// Creates an event handler for leave events.
1415 ///
1416 /// The event handler ignores all other events.
1417 #[allow(dead_code)]
1418 pub fn on_leave<T, F>(f: F) -> Leave<T, F>
1419 where
1420 T: 'static,
1421 F: Fn(&mut T, &WlPointerRef, u32, Option<&WlSurfaceRef>),
1422 {
1423 Leave(f, PhantomData)
1424 }
1425
1426 /// Creates an event handler for motion events.
1427 ///
1428 /// The event handler ignores all other events.
1429 #[allow(dead_code)]
1430 pub fn on_motion<T, F>(f: F) -> Motion<T, F>
1431 where
1432 T: 'static,
1433 F: Fn(&mut T, &WlPointerRef, u32, Fixed, Fixed),
1434 {
1435 Motion(f, PhantomData)
1436 }
1437
1438 /// Creates an event handler for button events.
1439 ///
1440 /// The event handler ignores all other events.
1441 #[allow(dead_code)]
1442 pub fn on_button<T, F>(f: F) -> Button<T, F>
1443 where
1444 T: 'static,
1445 F: Fn(&mut T, &WlPointerRef, u32, u32, u32, WlPointerButtonState),
1446 {
1447 Button(f, PhantomData)
1448 }
1449
1450 /// Creates an event handler for axis events.
1451 ///
1452 /// The event handler ignores all other events.
1453 #[allow(dead_code)]
1454 pub fn on_axis<T, F>(f: F) -> Axis<T, F>
1455 where
1456 T: 'static,
1457 F: Fn(&mut T, &WlPointerRef, u32, WlPointerAxis, Fixed),
1458 {
1459 Axis(f, PhantomData)
1460 }
1461
1462 /// Creates an event handler for frame events.
1463 ///
1464 /// The event handler ignores all other events.
1465 #[allow(dead_code)]
1466 pub fn on_frame<T, F>(f: F) -> Frame<T, F>
1467 where
1468 T: 'static,
1469 F: Fn(&mut T, &WlPointerRef),
1470 {
1471 Frame(f, PhantomData)
1472 }
1473
1474 /// Creates an event handler for axis_source events.
1475 ///
1476 /// The event handler ignores all other events.
1477 #[allow(dead_code)]
1478 pub fn on_axis_source<T, F>(f: F) -> AxisSource<T, F>
1479 where
1480 T: 'static,
1481 F: Fn(&mut T, &WlPointerRef, WlPointerAxisSource),
1482 {
1483 AxisSource(f, PhantomData)
1484 }
1485
1486 /// Creates an event handler for axis_stop events.
1487 ///
1488 /// The event handler ignores all other events.
1489 #[allow(dead_code)]
1490 pub fn on_axis_stop<T, F>(f: F) -> AxisStop<T, F>
1491 where
1492 T: 'static,
1493 F: Fn(&mut T, &WlPointerRef, u32, WlPointerAxis),
1494 {
1495 AxisStop(f, PhantomData)
1496 }
1497
1498 /// Creates an event handler for axis_discrete events.
1499 ///
1500 /// The event handler ignores all other events.
1501 #[allow(dead_code)]
1502 pub fn on_axis_discrete<T, F>(f: F) -> AxisDiscrete<T, F>
1503 where
1504 T: 'static,
1505 F: Fn(&mut T, &WlPointerRef, WlPointerAxis, i32),
1506 {
1507 AxisDiscrete(f, PhantomData)
1508 }
1509
1510 /// Creates an event handler for axis_value120 events.
1511 ///
1512 /// The event handler ignores all other events.
1513 #[allow(dead_code)]
1514 pub fn on_axis_value120<T, F>(f: F) -> AxisValue120<T, F>
1515 where
1516 T: 'static,
1517 F: Fn(&mut T, &WlPointerRef, WlPointerAxis, i32),
1518 {
1519 AxisValue120(f, PhantomData)
1520 }
1521
1522 /// Creates an event handler for axis_relative_direction events.
1523 ///
1524 /// The event handler ignores all other events.
1525 #[allow(dead_code)]
1526 pub fn on_axis_relative_direction<T, F>(f: F) -> AxisRelativeDirection<T, F>
1527 where
1528 T: 'static,
1529 F: Fn(&mut T, &WlPointerRef, WlPointerAxis, WlPointerAxisRelativeDirection),
1530 {
1531 AxisRelativeDirection(f, PhantomData)
1532 }
1533 }
1534}