poll_integration/common/protocols/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 /// enter event
376 ///
377 /// Notification that this seat's pointer is focused on a certain
378 /// surface.
379 ///
380 /// When a seat's focus enters a surface, the pointer image
381 /// is undefined and a client should respond to this event by setting
382 /// an appropriate pointer image with the set_cursor request.
383 ///
384 /// # Arguments
385 ///
386 /// - `serial`: serial number of the enter event
387 /// - `surface`: surface entered by the pointer
388 /// - `surface_x`: surface-local x coordinate
389 /// - `surface_y`: surface-local y coordinate
390 ///
391 /// All borrowed proxies passed to this function are guaranteed to be
392 /// immutable and non-null.
393 #[inline]
394 fn enter(
395 &self,
396 _slf: &WlPointerRef,
397 serial: u32,
398 surface: Option<&WlSurfaceRef>,
399 surface_x: Fixed,
400 surface_y: Fixed,
401 ) {
402 let _ = serial;
403 let _ = surface;
404 let _ = surface_x;
405 let _ = surface_y;
406 }
407
408 /// leave event
409 ///
410 /// Notification that this seat's pointer is no longer focused on
411 /// a certain surface.
412 ///
413 /// The leave notification is sent before the enter notification
414 /// for the new focus.
415 ///
416 /// # Arguments
417 ///
418 /// - `serial`: serial number of the leave event
419 /// - `surface`: surface left by the pointer
420 ///
421 /// All borrowed proxies passed to this function are guaranteed to be
422 /// immutable and non-null.
423 #[inline]
424 fn leave(&self, _slf: &WlPointerRef, serial: u32, surface: Option<&WlSurfaceRef>) {
425 let _ = serial;
426 let _ = surface;
427 }
428
429 /// pointer motion event
430 ///
431 /// Notification of pointer location change. The arguments
432 /// surface_x and surface_y are the location relative to the
433 /// focused surface.
434 ///
435 /// # Arguments
436 ///
437 /// - `time`: timestamp with millisecond granularity
438 /// - `surface_x`: surface-local x coordinate
439 /// - `surface_y`: surface-local y coordinate
440 #[inline]
441 fn motion(&self, _slf: &WlPointerRef, time: u32, surface_x: Fixed, surface_y: Fixed) {
442 let _ = time;
443 let _ = surface_x;
444 let _ = surface_y;
445 }
446
447 /// pointer button event
448 ///
449 /// Mouse button click and release notifications.
450 ///
451 /// The location of the click is given by the last motion or
452 /// enter event.
453 /// The time argument is a timestamp with millisecond
454 /// granularity, with an undefined base.
455 ///
456 /// The button is a button code as defined in the Linux kernel's
457 /// linux/input-event-codes.h header file, e.g. BTN_LEFT.
458 ///
459 /// Any 16-bit button code value is reserved for future additions to the
460 /// kernel's event code list. All other button codes above 0xFFFF are
461 /// currently undefined but may be used in future versions of this
462 /// protocol.
463 ///
464 /// # Arguments
465 ///
466 /// - `serial`: serial number of the button event
467 /// - `time`: timestamp with millisecond granularity
468 /// - `button`: button that produced the event
469 /// - `state`: physical state of the button
470 #[inline]
471 fn button(
472 &self,
473 _slf: &WlPointerRef,
474 serial: u32,
475 time: u32,
476 button: u32,
477 state: WlPointerButtonState,
478 ) {
479 let _ = serial;
480 let _ = time;
481 let _ = button;
482 let _ = state;
483 }
484
485 /// axis event
486 ///
487 /// Scroll and other axis notifications.
488 ///
489 /// For scroll events (vertical and horizontal scroll axes), the
490 /// value parameter is the length of a vector along the specified
491 /// axis in a coordinate space identical to those of motion events,
492 /// representing a relative movement along the specified axis.
493 ///
494 /// For devices that support movements non-parallel to axes multiple
495 /// axis events will be emitted.
496 ///
497 /// When applicable, for example for touch pads, the server can
498 /// choose to emit scroll events where the motion vector is
499 /// equivalent to a motion event vector.
500 ///
501 /// When applicable, a client can transform its content relative to the
502 /// scroll distance.
503 ///
504 /// # Arguments
505 ///
506 /// - `time`: timestamp with millisecond granularity
507 /// - `axis`: axis type
508 /// - `value`: length of vector in surface-local coordinate space
509 #[inline]
510 fn axis(&self, _slf: &WlPointerRef, time: u32, axis: WlPointerAxis, value: Fixed) {
511 let _ = time;
512 let _ = axis;
513 let _ = value;
514 }
515
516 /// end of a pointer event sequence
517 ///
518 /// Indicates the end of a set of events that logically belong together.
519 /// A client is expected to accumulate the data in all events within the
520 /// frame before proceeding.
521 ///
522 /// All wl_pointer events before a wl_pointer.frame event belong
523 /// logically together. For example, in a diagonal scroll motion the
524 /// compositor will send an optional wl_pointer.axis_source event, two
525 /// wl_pointer.axis events (horizontal and vertical) and finally a
526 /// wl_pointer.frame event. The client may use this information to
527 /// calculate a diagonal vector for scrolling.
528 ///
529 /// When multiple wl_pointer.axis events occur within the same frame,
530 /// the motion vector is the combined motion of all events.
531 /// When a wl_pointer.axis and a wl_pointer.axis_stop event occur within
532 /// the same frame, this indicates that axis movement in one axis has
533 /// stopped but continues in the other axis.
534 /// When multiple wl_pointer.axis_stop events occur within the same
535 /// frame, this indicates that these axes stopped in the same instance.
536 ///
537 /// A wl_pointer.frame event is sent for every logical event group,
538 /// even if the group only contains a single wl_pointer event.
539 /// Specifically, a client may get a sequence: motion, frame, button,
540 /// frame, axis, frame, axis_stop, frame.
541 ///
542 /// The wl_pointer.enter and wl_pointer.leave events are logical events
543 /// generated by the compositor and not the hardware. These events are
544 /// also grouped by a wl_pointer.frame. When a pointer moves from one
545 /// surface to another, a compositor should group the
546 /// wl_pointer.leave event within the same wl_pointer.frame.
547 /// However, a client must not rely on wl_pointer.leave and
548 /// wl_pointer.enter being in the same wl_pointer.frame.
549 /// Compositor-specific policies may require the wl_pointer.leave and
550 /// wl_pointer.enter event being split across multiple wl_pointer.frame
551 /// groups.
552 #[inline]
553 fn frame(&self, _slf: &WlPointerRef) {}
554
555 /// axis source event
556 ///
557 /// Source information for scroll and other axes.
558 ///
559 /// This event does not occur on its own. It is sent before a
560 /// wl_pointer.frame event and carries the source information for
561 /// all events within that frame.
562 ///
563 /// The source specifies how this event was generated. If the source is
564 /// wl_pointer.axis_source.finger, a wl_pointer.axis_stop event will be
565 /// sent when the user lifts the finger off the device.
566 ///
567 /// If the source is wl_pointer.axis_source.wheel,
568 /// wl_pointer.axis_source.wheel_tilt or
569 /// wl_pointer.axis_source.continuous, a wl_pointer.axis_stop event may
570 /// or may not be sent. Whether a compositor sends an axis_stop event
571 /// for these sources is hardware-specific and implementation-dependent;
572 /// clients must not rely on receiving an axis_stop event for these
573 /// scroll sources and should treat scroll sequences from these scroll
574 /// sources as unterminated by default.
575 ///
576 /// This event is optional. If the source is unknown for a particular
577 /// axis event sequence, no event is sent.
578 /// Only one wl_pointer.axis_source event is permitted per frame.
579 ///
580 /// The order of wl_pointer.axis_discrete and wl_pointer.axis_source is
581 /// not guaranteed.
582 ///
583 /// # Arguments
584 ///
585 /// - `axis_source`: source of the axis event
586 #[inline]
587 fn axis_source(&self, _slf: &WlPointerRef, axis_source: WlPointerAxisSource) {
588 let _ = axis_source;
589 }
590
591 /// axis stop event
592 ///
593 /// Stop notification for scroll and other axes.
594 ///
595 /// For some wl_pointer.axis_source types, a wl_pointer.axis_stop event
596 /// is sent to notify a client that the axis sequence has terminated.
597 /// This enables the client to implement kinetic scrolling.
598 /// See the wl_pointer.axis_source documentation for information on when
599 /// this event may be generated.
600 ///
601 /// Any wl_pointer.axis events with the same axis_source after this
602 /// event should be considered as the start of a new axis motion.
603 ///
604 /// The timestamp is to be interpreted identical to the timestamp in the
605 /// wl_pointer.axis event. The timestamp value may be the same as a
606 /// preceding wl_pointer.axis event.
607 ///
608 /// # Arguments
609 ///
610 /// - `time`: timestamp with millisecond granularity
611 /// - `axis`: the axis stopped with this event
612 #[inline]
613 fn axis_stop(&self, _slf: &WlPointerRef, time: u32, axis: WlPointerAxis) {
614 let _ = time;
615 let _ = axis;
616 }
617
618 /// axis click event
619 ///
620 /// Discrete step information for scroll and other axes.
621 ///
622 /// This event carries the axis value of the wl_pointer.axis event in
623 /// discrete steps (e.g. mouse wheel clicks).
624 ///
625 /// This event is deprecated with wl_pointer version 8 - this event is not
626 /// sent to clients supporting version 8 or later.
627 ///
628 /// This event does not occur on its own, it is coupled with a
629 /// wl_pointer.axis event that represents this axis value on a
630 /// continuous scale. The protocol guarantees that each axis_discrete
631 /// event is always followed by exactly one axis event with the same
632 /// axis number within the same wl_pointer.frame. Note that the protocol
633 /// allows for other events to occur between the axis_discrete and
634 /// its coupled axis event, including other axis_discrete or axis
635 /// events. A wl_pointer.frame must not contain more than one axis_discrete
636 /// event per axis type.
637 ///
638 /// This event is optional; continuous scrolling devices
639 /// like two-finger scrolling on touchpads do not have discrete
640 /// steps and do not generate this event.
641 ///
642 /// The discrete value carries the directional information. e.g. a value
643 /// of -2 is two steps towards the negative direction of this axis.
644 ///
645 /// The axis number is identical to the axis number in the associated
646 /// axis event.
647 ///
648 /// The order of wl_pointer.axis_discrete and wl_pointer.axis_source is
649 /// not guaranteed.
650 ///
651 /// # Arguments
652 ///
653 /// - `axis`: axis type
654 /// - `discrete`: number of steps
655 #[inline]
656 fn axis_discrete(&self, _slf: &WlPointerRef, axis: WlPointerAxis, discrete: i32) {
657 let _ = axis;
658 let _ = discrete;
659 }
660
661 /// axis high-resolution scroll event
662 ///
663 /// Discrete high-resolution scroll information.
664 ///
665 /// This event carries high-resolution wheel scroll information,
666 /// with each multiple of 120 representing one logical scroll step
667 /// (a wheel detent). For example, an axis_value120 of 30 is one quarter of
668 /// a logical scroll step in the positive direction, a value120 of
669 /// -240 are two logical scroll steps in the negative direction within the
670 /// same hardware event.
671 /// Clients that rely on discrete scrolling should accumulate the
672 /// value120 to multiples of 120 before processing the event.
673 ///
674 /// The value120 must not be zero.
675 ///
676 /// This event replaces the wl_pointer.axis_discrete event in clients
677 /// supporting wl_pointer version 8 or later.
678 ///
679 /// Where a wl_pointer.axis_source event occurs in the same
680 /// wl_pointer.frame, the axis source applies to this event.
681 ///
682 /// The order of wl_pointer.axis_value120 and wl_pointer.axis_source is
683 /// not guaranteed.
684 ///
685 /// # Arguments
686 ///
687 /// - `axis`: axis type
688 /// - `value120`: scroll distance as fraction of 120
689 #[inline]
690 fn axis_value120(&self, _slf: &WlPointerRef, axis: WlPointerAxis, value120: i32) {
691 let _ = axis;
692 let _ = value120;
693 }
694
695 /// axis relative physical direction event
696 ///
697 /// Relative directional information of the entity causing the axis
698 /// motion.
699 ///
700 /// For a wl_pointer.axis event, the wl_pointer.axis_relative_direction
701 /// event specifies the movement direction of the entity causing the
702 /// wl_pointer.axis event. For example:
703 /// - if a user's fingers on a touchpad move down and this
704 /// causes a wl_pointer.axis vertical_scroll down event, the physical
705 /// direction is 'identical'
706 /// - if a user's fingers on a touchpad move down and this causes a
707 /// wl_pointer.axis vertical_scroll up scroll up event ('natural
708 /// scrolling'), the physical direction is 'inverted'.
709 ///
710 /// A client may use this information to adjust scroll motion of
711 /// components. Specifically, enabling natural scrolling causes the
712 /// content to change direction compared to traditional scrolling.
713 /// Some widgets like volume control sliders should usually match the
714 /// physical direction regardless of whether natural scrolling is
715 /// active. This event enables clients to match the scroll direction of
716 /// a widget to the physical direction.
717 ///
718 /// This event does not occur on its own, it is coupled with a
719 /// wl_pointer.axis event that represents this axis value.
720 /// The protocol guarantees that each axis_relative_direction event is
721 /// always followed by exactly one axis event with the same
722 /// axis number within the same wl_pointer.frame. Note that the protocol
723 /// allows for other events to occur between the axis_relative_direction
724 /// and its coupled axis event.
725 ///
726 /// The axis number is identical to the axis number in the associated
727 /// axis event.
728 ///
729 /// The order of wl_pointer.axis_relative_direction,
730 /// wl_pointer.axis_discrete and wl_pointer.axis_source is not
731 /// guaranteed.
732 ///
733 /// # Arguments
734 ///
735 /// - `axis`: axis type
736 /// - `direction`: physical direction relative to axis motion
737 #[inline]
738 fn axis_relative_direction(
739 &self,
740 _slf: &WlPointerRef,
741 axis: WlPointerAxis,
742 direction: WlPointerAxisRelativeDirection,
743 ) {
744 let _ = axis;
745 let _ = direction;
746 }
747}
748
749impl WlPointerEventHandler for private::NoOpEventHandler {}
750
751// SAFETY: INTERFACE is a valid wl_interface
752unsafe impl<H> EventHandler for private::EventHandler<H>
753where
754 H: WlPointerEventHandler,
755{
756 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
757
758 #[allow(unused_variables)]
759 unsafe fn handle_event(
760 &self,
761 queue: &Queue,
762 slf: &UntypedBorrowedProxy,
763 opcode: u32,
764 args: *mut wl_argument,
765 ) {
766 // SAFETY: This function required that slf has the interface INTERFACE
767 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlPointerRef>(slf) };
768 match opcode {
769 0 => {
770 // SAFETY: INTERFACE requires that there are 4 arguments
771 let args = unsafe { &*args.cast::<[wl_argument; 4]>() };
772 // SAFETY: - INTERFACE requires that args[0] contains a uint
773 let arg0 = unsafe { args[0].u };
774 // SAFETY: - INTERFACE requires that args[1] contains an object
775 let arg1 = unsafe {
776 if let Some(p) = NonNull::new(args[1].o.cast()) {
777 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
778 } else {
779 None
780 }
781 };
782 // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
783 let arg1 = arg1.as_ref().map(|arg1| unsafe {
784 proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
785 });
786 // SAFETY: - INTERFACE requires that args[2] contains a fixed
787 let arg2 = unsafe { Fixed::from_wire(args[2].f) };
788 // SAFETY: - INTERFACE requires that args[3] contains a fixed
789 let arg3 = unsafe { Fixed::from_wire(args[3].f) };
790 self.0.enter(slf, arg0, arg1, arg2, arg3);
791 }
792 1 => {
793 // SAFETY: INTERFACE requires that there are 2 arguments
794 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
795 // SAFETY: - INTERFACE requires that args[0] contains a uint
796 let arg0 = unsafe { args[0].u };
797 // SAFETY: - INTERFACE requires that args[1] contains an object
798 let arg1 = unsafe {
799 if let Some(p) = NonNull::new(args[1].o.cast()) {
800 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
801 } else {
802 None
803 }
804 };
805 // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
806 let arg1 = arg1.as_ref().map(|arg1| unsafe {
807 proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
808 });
809 self.0.leave(slf, arg0, arg1);
810 }
811 2 => {
812 // SAFETY: INTERFACE requires that there are 3 arguments
813 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
814 // SAFETY: - INTERFACE requires that args[0] contains a uint
815 let arg0 = unsafe { args[0].u };
816 // SAFETY: - INTERFACE requires that args[1] contains a fixed
817 let arg1 = unsafe { Fixed::from_wire(args[1].f) };
818 // SAFETY: - INTERFACE requires that args[2] contains a fixed
819 let arg2 = unsafe { Fixed::from_wire(args[2].f) };
820 self.0.motion(slf, arg0, arg1, arg2);
821 }
822 3 => {
823 // SAFETY: INTERFACE requires that there are 4 arguments
824 let args = unsafe { &*args.cast::<[wl_argument; 4]>() };
825 // SAFETY: - INTERFACE requires that args[0] contains a uint
826 let arg0 = unsafe { args[0].u };
827 // SAFETY: - INTERFACE requires that args[1] contains a uint
828 let arg1 = unsafe { args[1].u };
829 // SAFETY: - INTERFACE requires that args[2] contains a uint
830 let arg2 = unsafe { args[2].u };
831 // SAFETY: - INTERFACE requires that args[3] contains a uint
832 let arg3 = unsafe { WlPointerButtonState(args[3].u) };
833 self.0.button(slf, arg0, arg1, arg2, arg3);
834 }
835 4 => {
836 // SAFETY: INTERFACE requires that there are 3 arguments
837 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
838 // SAFETY: - INTERFACE requires that args[0] contains a uint
839 let arg0 = unsafe { args[0].u };
840 // SAFETY: - INTERFACE requires that args[1] contains a uint
841 let arg1 = unsafe { WlPointerAxis(args[1].u) };
842 // SAFETY: - INTERFACE requires that args[2] contains a fixed
843 let arg2 = unsafe { Fixed::from_wire(args[2].f) };
844 self.0.axis(slf, arg0, arg1, arg2);
845 }
846 5 => {
847 self.0.frame(slf);
848 }
849 6 => {
850 // SAFETY: INTERFACE requires that there are 1 arguments
851 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
852 // SAFETY: - INTERFACE requires that args[0] contains a uint
853 let arg0 = unsafe { WlPointerAxisSource(args[0].u) };
854 self.0.axis_source(slf, arg0);
855 }
856 7 => {
857 // SAFETY: INTERFACE requires that there are 2 arguments
858 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
859 // SAFETY: - INTERFACE requires that args[0] contains a uint
860 let arg0 = unsafe { args[0].u };
861 // SAFETY: - INTERFACE requires that args[1] contains a uint
862 let arg1 = unsafe { WlPointerAxis(args[1].u) };
863 self.0.axis_stop(slf, arg0, arg1);
864 }
865 8 => {
866 // SAFETY: INTERFACE requires that there are 2 arguments
867 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
868 // SAFETY: - INTERFACE requires that args[0] contains a uint
869 let arg0 = unsafe { WlPointerAxis(args[0].u) };
870 // SAFETY: - INTERFACE requires that args[1] contains an int
871 let arg1 = unsafe { args[1].i };
872 self.0.axis_discrete(slf, arg0, arg1);
873 }
874 9 => {
875 // SAFETY: INTERFACE requires that there are 2 arguments
876 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
877 // SAFETY: - INTERFACE requires that args[0] contains a uint
878 let arg0 = unsafe { WlPointerAxis(args[0].u) };
879 // SAFETY: - INTERFACE requires that args[1] contains an int
880 let arg1 = unsafe { args[1].i };
881 self.0.axis_value120(slf, arg0, arg1);
882 }
883 10 => {
884 // SAFETY: INTERFACE requires that there are 2 arguments
885 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
886 // SAFETY: - INTERFACE requires that args[0] contains a uint
887 let arg0 = unsafe { WlPointerAxis(args[0].u) };
888 // SAFETY: - INTERFACE requires that args[1] contains a uint
889 let arg1 = unsafe { WlPointerAxisRelativeDirection(args[1].u) };
890 self.0.axis_relative_direction(slf, arg0, arg1);
891 }
892 _ => {
893 invalid_opcode("wl_pointer", opcode);
894 }
895 }
896 }
897}
898
899impl<H> CreateEventHandler<H> for private::ProxyApi
900where
901 H: WlPointerEventHandler,
902{
903 type EventHandler = private::EventHandler<H>;
904
905 #[inline]
906 fn create_event_handler(handler: H) -> Self::EventHandler {
907 private::EventHandler(handler)
908 }
909}
910
911impl WlPointer {
912 /// Since when the error.role enum variant is available.
913 #[allow(dead_code)]
914 pub const ENM__ERROR_ROLE__SINCE: u32 = 1;
915
916 /// Since when the button_state.released enum variant is available.
917 #[allow(dead_code)]
918 pub const ENM__BUTTON_STATE_RELEASED__SINCE: u32 = 1;
919 /// Since when the button_state.pressed enum variant is available.
920 #[allow(dead_code)]
921 pub const ENM__BUTTON_STATE_PRESSED__SINCE: u32 = 1;
922
923 /// Since when the axis.vertical_scroll enum variant is available.
924 #[allow(dead_code)]
925 pub const ENM__AXIS_VERTICAL_SCROLL__SINCE: u32 = 1;
926 /// Since when the axis.horizontal_scroll enum variant is available.
927 #[allow(dead_code)]
928 pub const ENM__AXIS_HORIZONTAL_SCROLL__SINCE: u32 = 1;
929
930 /// Since when the axis_source.wheel enum variant is available.
931 #[allow(dead_code)]
932 pub const ENM__AXIS_SOURCE_WHEEL__SINCE: u32 = 1;
933 /// Since when the axis_source.finger enum variant is available.
934 #[allow(dead_code)]
935 pub const ENM__AXIS_SOURCE_FINGER__SINCE: u32 = 1;
936 /// Since when the axis_source.continuous enum variant is available.
937 #[allow(dead_code)]
938 pub const ENM__AXIS_SOURCE_CONTINUOUS__SINCE: u32 = 1;
939 /// Since when the axis_source.wheel_tilt enum variant is available.
940 #[allow(dead_code)]
941 pub const ENM__AXIS_SOURCE_WHEEL_TILT__SINCE: u32 = 6;
942
943 /// Since when the axis_relative_direction.identical enum variant is available.
944 #[allow(dead_code)]
945 pub const ENM__AXIS_RELATIVE_DIRECTION_IDENTICAL__SINCE: u32 = 1;
946 /// Since when the axis_relative_direction.inverted enum variant is available.
947 #[allow(dead_code)]
948 pub const ENM__AXIS_RELATIVE_DIRECTION_INVERTED__SINCE: u32 = 1;
949}
950
951#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
952#[allow(dead_code)]
953pub struct WlPointerError(pub u32);
954
955impl WlPointerError {
956 /// given wl_surface has another role
957 #[allow(dead_code)]
958 pub const ROLE: Self = Self(0);
959}
960
961impl Debug for WlPointerError {
962 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
963 let name = match *self {
964 Self::ROLE => "ROLE",
965 _ => return Debug::fmt(&self.0, f),
966 };
967 f.write_str(name)
968 }
969}
970
971/// physical button state
972///
973/// Describes the physical state of a button that produced the button
974/// event.
975#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
976#[allow(dead_code)]
977pub struct WlPointerButtonState(pub u32);
978
979impl WlPointerButtonState {
980 /// the button is not pressed
981 #[allow(dead_code)]
982 pub const RELEASED: Self = Self(0);
983
984 /// the button is pressed
985 #[allow(dead_code)]
986 pub const PRESSED: Self = Self(1);
987}
988
989impl Debug for WlPointerButtonState {
990 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
991 let name = match *self {
992 Self::RELEASED => "RELEASED",
993 Self::PRESSED => "PRESSED",
994 _ => return Debug::fmt(&self.0, f),
995 };
996 f.write_str(name)
997 }
998}
999
1000/// axis types
1001///
1002/// Describes the axis types of scroll events.
1003#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1004#[allow(dead_code)]
1005pub struct WlPointerAxis(pub u32);
1006
1007impl WlPointerAxis {
1008 /// vertical axis
1009 #[allow(dead_code)]
1010 pub const VERTICAL_SCROLL: Self = Self(0);
1011
1012 /// horizontal axis
1013 #[allow(dead_code)]
1014 pub const HORIZONTAL_SCROLL: Self = Self(1);
1015}
1016
1017impl Debug for WlPointerAxis {
1018 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1019 let name = match *self {
1020 Self::VERTICAL_SCROLL => "VERTICAL_SCROLL",
1021 Self::HORIZONTAL_SCROLL => "HORIZONTAL_SCROLL",
1022 _ => return Debug::fmt(&self.0, f),
1023 };
1024 f.write_str(name)
1025 }
1026}
1027
1028/// axis source types
1029///
1030/// Describes the source types for axis events. This indicates to the
1031/// client how an axis event was physically generated; a client may
1032/// adjust the user interface accordingly. For example, scroll events
1033/// from a "finger" source may be in a smooth coordinate space with
1034/// kinetic scrolling whereas a "wheel" source may be in discrete steps
1035/// of a number of lines.
1036///
1037/// The "continuous" axis source is a device generating events in a
1038/// continuous coordinate space, but using something other than a
1039/// finger. One example for this source is button-based scrolling where
1040/// the vertical motion of a device is converted to scroll events while
1041/// a button is held down.
1042///
1043/// The "wheel tilt" axis source indicates that the actual device is a
1044/// wheel but the scroll event is not caused by a rotation but a
1045/// (usually sideways) tilt of the wheel.
1046#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1047#[allow(dead_code)]
1048pub struct WlPointerAxisSource(pub u32);
1049
1050impl WlPointerAxisSource {
1051 /// a physical wheel rotation
1052 #[allow(dead_code)]
1053 pub const WHEEL: Self = Self(0);
1054
1055 /// finger on a touch surface
1056 #[allow(dead_code)]
1057 pub const FINGER: Self = Self(1);
1058
1059 /// continuous coordinate space
1060 #[allow(dead_code)]
1061 pub const CONTINUOUS: Self = Self(2);
1062
1063 /// a physical wheel tilt
1064 #[allow(dead_code)]
1065 pub const WHEEL_TILT: Self = Self(3);
1066}
1067
1068impl Debug for WlPointerAxisSource {
1069 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1070 let name = match *self {
1071 Self::WHEEL => "WHEEL",
1072 Self::FINGER => "FINGER",
1073 Self::CONTINUOUS => "CONTINUOUS",
1074 Self::WHEEL_TILT => "WHEEL_TILT",
1075 _ => return Debug::fmt(&self.0, f),
1076 };
1077 f.write_str(name)
1078 }
1079}
1080
1081/// axis relative direction
1082///
1083/// This specifies the direction of the physical motion that caused a
1084/// wl_pointer.axis event, relative to the wl_pointer.axis direction.
1085#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
1086#[allow(dead_code)]
1087pub struct WlPointerAxisRelativeDirection(pub u32);
1088
1089impl WlPointerAxisRelativeDirection {
1090 /// physical motion matches axis direction
1091 #[allow(dead_code)]
1092 pub const IDENTICAL: Self = Self(0);
1093
1094 /// physical motion is the inverse of the axis direction
1095 #[allow(dead_code)]
1096 pub const INVERTED: Self = Self(1);
1097}
1098
1099impl Debug for WlPointerAxisRelativeDirection {
1100 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
1101 let name = match *self {
1102 Self::IDENTICAL => "IDENTICAL",
1103 Self::INVERTED => "INVERTED",
1104 _ => return Debug::fmt(&self.0, f),
1105 };
1106 f.write_str(name)
1107 }
1108}
1109
1110/// Functional event handlers.
1111pub mod event_handlers {
1112 use super::*;
1113
1114 /// Event handler for enter events.
1115 pub struct Enter<F>(F);
1116 impl<F> WlPointerEventHandler for Enter<F>
1117 where
1118 F: Fn(&WlPointerRef, u32, Option<&WlSurfaceRef>, Fixed, Fixed),
1119 {
1120 #[inline]
1121 fn enter(
1122 &self,
1123 _slf: &WlPointerRef,
1124 serial: u32,
1125 surface: Option<&WlSurfaceRef>,
1126 surface_x: Fixed,
1127 surface_y: Fixed,
1128 ) {
1129 self.0(_slf, serial, surface, surface_x, surface_y)
1130 }
1131 }
1132
1133 /// Event handler for leave events.
1134 pub struct Leave<F>(F);
1135 impl<F> WlPointerEventHandler for Leave<F>
1136 where
1137 F: Fn(&WlPointerRef, u32, Option<&WlSurfaceRef>),
1138 {
1139 #[inline]
1140 fn leave(&self, _slf: &WlPointerRef, serial: u32, surface: Option<&WlSurfaceRef>) {
1141 self.0(_slf, serial, surface)
1142 }
1143 }
1144
1145 /// Event handler for motion events.
1146 pub struct Motion<F>(F);
1147 impl<F> WlPointerEventHandler for Motion<F>
1148 where
1149 F: Fn(&WlPointerRef, u32, Fixed, Fixed),
1150 {
1151 #[inline]
1152 fn motion(&self, _slf: &WlPointerRef, time: u32, surface_x: Fixed, surface_y: Fixed) {
1153 self.0(_slf, time, surface_x, surface_y)
1154 }
1155 }
1156
1157 /// Event handler for button events.
1158 pub struct Button<F>(F);
1159 impl<F> WlPointerEventHandler for Button<F>
1160 where
1161 F: Fn(&WlPointerRef, u32, u32, u32, WlPointerButtonState),
1162 {
1163 #[inline]
1164 fn button(
1165 &self,
1166 _slf: &WlPointerRef,
1167 serial: u32,
1168 time: u32,
1169 button: u32,
1170 state: WlPointerButtonState,
1171 ) {
1172 self.0(_slf, serial, time, button, state)
1173 }
1174 }
1175
1176 /// Event handler for axis events.
1177 pub struct Axis<F>(F);
1178 impl<F> WlPointerEventHandler for Axis<F>
1179 where
1180 F: Fn(&WlPointerRef, u32, WlPointerAxis, Fixed),
1181 {
1182 #[inline]
1183 fn axis(&self, _slf: &WlPointerRef, time: u32, axis: WlPointerAxis, value: Fixed) {
1184 self.0(_slf, time, axis, value)
1185 }
1186 }
1187
1188 /// Event handler for frame events.
1189 pub struct Frame<F>(F);
1190 impl<F> WlPointerEventHandler for Frame<F>
1191 where
1192 F: Fn(&WlPointerRef),
1193 {
1194 #[inline]
1195 fn frame(&self, _slf: &WlPointerRef) {
1196 self.0(_slf)
1197 }
1198 }
1199
1200 /// Event handler for axis_source events.
1201 pub struct AxisSource<F>(F);
1202 impl<F> WlPointerEventHandler for AxisSource<F>
1203 where
1204 F: Fn(&WlPointerRef, WlPointerAxisSource),
1205 {
1206 #[inline]
1207 fn axis_source(&self, _slf: &WlPointerRef, axis_source: WlPointerAxisSource) {
1208 self.0(_slf, axis_source)
1209 }
1210 }
1211
1212 /// Event handler for axis_stop events.
1213 pub struct AxisStop<F>(F);
1214 impl<F> WlPointerEventHandler for AxisStop<F>
1215 where
1216 F: Fn(&WlPointerRef, u32, WlPointerAxis),
1217 {
1218 #[inline]
1219 fn axis_stop(&self, _slf: &WlPointerRef, time: u32, axis: WlPointerAxis) {
1220 self.0(_slf, time, axis)
1221 }
1222 }
1223
1224 /// Event handler for axis_discrete events.
1225 pub struct AxisDiscrete<F>(F);
1226 impl<F> WlPointerEventHandler for AxisDiscrete<F>
1227 where
1228 F: Fn(&WlPointerRef, WlPointerAxis, i32),
1229 {
1230 #[inline]
1231 fn axis_discrete(&self, _slf: &WlPointerRef, axis: WlPointerAxis, discrete: i32) {
1232 self.0(_slf, axis, discrete)
1233 }
1234 }
1235
1236 /// Event handler for axis_value120 events.
1237 pub struct AxisValue120<F>(F);
1238 impl<F> WlPointerEventHandler for AxisValue120<F>
1239 where
1240 F: Fn(&WlPointerRef, WlPointerAxis, i32),
1241 {
1242 #[inline]
1243 fn axis_value120(&self, _slf: &WlPointerRef, axis: WlPointerAxis, value120: i32) {
1244 self.0(_slf, axis, value120)
1245 }
1246 }
1247
1248 /// Event handler for axis_relative_direction events.
1249 pub struct AxisRelativeDirection<F>(F);
1250 impl<F> WlPointerEventHandler for AxisRelativeDirection<F>
1251 where
1252 F: Fn(&WlPointerRef, WlPointerAxis, WlPointerAxisRelativeDirection),
1253 {
1254 #[inline]
1255 fn axis_relative_direction(
1256 &self,
1257 _slf: &WlPointerRef,
1258 axis: WlPointerAxis,
1259 direction: WlPointerAxisRelativeDirection,
1260 ) {
1261 self.0(_slf, axis, direction)
1262 }
1263 }
1264
1265 impl WlPointer {
1266 /// Creates an event handler for enter events.
1267 ///
1268 /// The event handler ignores all other events.
1269 #[allow(dead_code)]
1270 pub fn on_enter<F>(f: F) -> Enter<F>
1271 where
1272 F: Fn(&WlPointerRef, u32, Option<&WlSurfaceRef>, Fixed, Fixed),
1273 {
1274 Enter(f)
1275 }
1276
1277 /// Creates an event handler for leave events.
1278 ///
1279 /// The event handler ignores all other events.
1280 #[allow(dead_code)]
1281 pub fn on_leave<F>(f: F) -> Leave<F>
1282 where
1283 F: Fn(&WlPointerRef, u32, Option<&WlSurfaceRef>),
1284 {
1285 Leave(f)
1286 }
1287
1288 /// Creates an event handler for motion events.
1289 ///
1290 /// The event handler ignores all other events.
1291 #[allow(dead_code)]
1292 pub fn on_motion<F>(f: F) -> Motion<F>
1293 where
1294 F: Fn(&WlPointerRef, u32, Fixed, Fixed),
1295 {
1296 Motion(f)
1297 }
1298
1299 /// Creates an event handler for button events.
1300 ///
1301 /// The event handler ignores all other events.
1302 #[allow(dead_code)]
1303 pub fn on_button<F>(f: F) -> Button<F>
1304 where
1305 F: Fn(&WlPointerRef, u32, u32, u32, WlPointerButtonState),
1306 {
1307 Button(f)
1308 }
1309
1310 /// Creates an event handler for axis events.
1311 ///
1312 /// The event handler ignores all other events.
1313 #[allow(dead_code)]
1314 pub fn on_axis<F>(f: F) -> Axis<F>
1315 where
1316 F: Fn(&WlPointerRef, u32, WlPointerAxis, Fixed),
1317 {
1318 Axis(f)
1319 }
1320
1321 /// Creates an event handler for frame events.
1322 ///
1323 /// The event handler ignores all other events.
1324 #[allow(dead_code)]
1325 pub fn on_frame<F>(f: F) -> Frame<F>
1326 where
1327 F: Fn(&WlPointerRef),
1328 {
1329 Frame(f)
1330 }
1331
1332 /// Creates an event handler for axis_source events.
1333 ///
1334 /// The event handler ignores all other events.
1335 #[allow(dead_code)]
1336 pub fn on_axis_source<F>(f: F) -> AxisSource<F>
1337 where
1338 F: Fn(&WlPointerRef, WlPointerAxisSource),
1339 {
1340 AxisSource(f)
1341 }
1342
1343 /// Creates an event handler for axis_stop events.
1344 ///
1345 /// The event handler ignores all other events.
1346 #[allow(dead_code)]
1347 pub fn on_axis_stop<F>(f: F) -> AxisStop<F>
1348 where
1349 F: Fn(&WlPointerRef, u32, WlPointerAxis),
1350 {
1351 AxisStop(f)
1352 }
1353
1354 /// Creates an event handler for axis_discrete events.
1355 ///
1356 /// The event handler ignores all other events.
1357 #[allow(dead_code)]
1358 pub fn on_axis_discrete<F>(f: F) -> AxisDiscrete<F>
1359 where
1360 F: Fn(&WlPointerRef, WlPointerAxis, i32),
1361 {
1362 AxisDiscrete(f)
1363 }
1364
1365 /// Creates an event handler for axis_value120 events.
1366 ///
1367 /// The event handler ignores all other events.
1368 #[allow(dead_code)]
1369 pub fn on_axis_value120<F>(f: F) -> AxisValue120<F>
1370 where
1371 F: Fn(&WlPointerRef, WlPointerAxis, i32),
1372 {
1373 AxisValue120(f)
1374 }
1375
1376 /// Creates an event handler for axis_relative_direction events.
1377 ///
1378 /// The event handler ignores all other events.
1379 #[allow(dead_code)]
1380 pub fn on_axis_relative_direction<F>(f: F) -> AxisRelativeDirection<F>
1381 where
1382 F: Fn(&WlPointerRef, WlPointerAxis, WlPointerAxisRelativeDirection),
1383 {
1384 AxisRelativeDirection(f)
1385 }
1386 }
1387}