poll_integration/common/protocols/wayland/
wl_data_device.rs

1//! data transfer device
2//!
3//! There is one wl_data_device per seat which can be obtained
4//! from the global wl_data_device_manager singleton.
5//!
6//! A wl_data_device provides access to inter-client data transfer
7//! mechanisms such as copy-and-paste and drag-and-drop.
8
9use {super::super::all_types::*, ::wl_client::builder::prelude::*};
10
11static INTERFACE: wl_interface = wl_interface {
12    name: c"wl_data_device".as_ptr(),
13    version: 3,
14    method_count: 3,
15    methods: {
16        static MESSAGES: [wl_message; 3] = [
17            wl_message {
18                name: c"start_drag".as_ptr(),
19                signature: c"?oo?ou".as_ptr(),
20                types: {
21                    static TYPES: [Option<&'static wl_interface>; 4] = [
22                        Some(WlDataSource::WL_INTERFACE),
23                        Some(WlSurface::WL_INTERFACE),
24                        Some(WlSurface::WL_INTERFACE),
25                        None,
26                    ];
27                    TYPES.as_ptr().cast()
28                },
29            },
30            wl_message {
31                name: c"set_selection".as_ptr(),
32                signature: c"?ou".as_ptr(),
33                types: {
34                    static TYPES: [Option<&'static wl_interface>; 2] =
35                        [Some(WlDataSource::WL_INTERFACE), None];
36                    TYPES.as_ptr().cast()
37                },
38            },
39            wl_message {
40                name: c"release".as_ptr(),
41                signature: c"".as_ptr(),
42                types: {
43                    static TYPES: [Option<&'static wl_interface>; 0] = [];
44                    TYPES.as_ptr().cast()
45                },
46            },
47        ];
48        MESSAGES.as_ptr()
49    },
50    event_count: 6,
51    events: {
52        static MESSAGES: [wl_message; 6] = [
53            wl_message {
54                name: c"data_offer".as_ptr(),
55                signature: c"n".as_ptr(),
56                types: {
57                    static TYPES: [Option<&'static wl_interface>; 1] =
58                        [Some(WlDataOffer::WL_INTERFACE)];
59                    TYPES.as_ptr().cast()
60                },
61            },
62            wl_message {
63                name: c"enter".as_ptr(),
64                signature: c"uoff?o".as_ptr(),
65                types: {
66                    static TYPES: [Option<&'static wl_interface>; 5] = [
67                        None,
68                        Some(WlSurface::WL_INTERFACE),
69                        None,
70                        None,
71                        Some(WlDataOffer::WL_INTERFACE),
72                    ];
73                    TYPES.as_ptr().cast()
74                },
75            },
76            wl_message {
77                name: c"leave".as_ptr(),
78                signature: c"".as_ptr(),
79                types: {
80                    static TYPES: [Option<&'static wl_interface>; 0] = [];
81                    TYPES.as_ptr().cast()
82                },
83            },
84            wl_message {
85                name: c"motion".as_ptr(),
86                signature: c"uff".as_ptr(),
87                types: {
88                    static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
89                    TYPES.as_ptr().cast()
90                },
91            },
92            wl_message {
93                name: c"drop".as_ptr(),
94                signature: c"".as_ptr(),
95                types: {
96                    static TYPES: [Option<&'static wl_interface>; 0] = [];
97                    TYPES.as_ptr().cast()
98                },
99            },
100            wl_message {
101                name: c"selection".as_ptr(),
102                signature: c"?o".as_ptr(),
103                types: {
104                    static TYPES: [Option<&'static wl_interface>; 1] =
105                        [Some(WlDataOffer::WL_INTERFACE)];
106                    TYPES.as_ptr().cast()
107                },
108            },
109        ];
110        MESSAGES.as_ptr()
111    },
112};
113
114/// An owned wl_data_device proxy.
115///
116/// See the documentation of [the module][self] for the interface description.
117#[derive(Clone, Eq, PartialEq)]
118#[repr(transparent)]
119pub struct WlDataDevice {
120    /// This proxy has the interface INTERFACE.
121    proxy: UntypedOwnedProxy,
122}
123
124/// A borrowed wl_data_device proxy.
125///
126/// See the documentation of [the module][self] for the interface description.
127#[derive(Eq, PartialEq)]
128#[repr(transparent)]
129pub struct WlDataDeviceRef {
130    /// This proxy has the interface INTERFACE.
131    proxy: UntypedBorrowedProxy,
132}
133
134// SAFETY: WlDataDevice is a transparent wrapper around UntypedOwnedProxy
135unsafe impl UntypedOwnedProxyWrapper for WlDataDevice {}
136
137// SAFETY: - INTERFACE is a valid wl_interface
138//         - The only invariant is that self.proxy has a compatible interface
139unsafe impl OwnedProxy for WlDataDevice {
140    const INTERFACE: &'static str = "wl_data_device";
141    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
142    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
143        private::EventHandler(private::NoOpEventHandler);
144    const MAX_VERSION: u32 = 3;
145
146    type Borrowed = WlDataDeviceRef;
147    type Api = private::ProxyApi;
148    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
149}
150
151// SAFETY: WlDataDeviceRef is a transparent wrapper around UntypedBorrowedProxy
152unsafe impl UntypedBorrowedProxyWrapper for WlDataDeviceRef {}
153
154// SAFETY: - The only invariant is that self.proxy has a compatible interface
155unsafe impl BorrowedProxy for WlDataDeviceRef {
156    type Owned = WlDataDevice;
157}
158
159impl Deref for WlDataDevice {
160    type Target = WlDataDeviceRef;
161
162    fn deref(&self) -> &Self::Target {
163        proxy::low_level::deref(self)
164    }
165}
166
167mod private {
168    pub struct ProxyApi;
169
170    #[allow(dead_code)]
171    pub struct EventHandler<H>(pub(super) H);
172
173    #[allow(dead_code)]
174    pub struct NoOpEventHandler;
175}
176
177impl Debug for WlDataDevice {
178    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
179        write!(f, "wl_data_device#{}", self.proxy.id())
180    }
181}
182
183impl Debug for WlDataDeviceRef {
184    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
185        write!(f, "wl_data_device#{}", self.proxy.id())
186    }
187}
188
189impl PartialEq<WlDataDeviceRef> for WlDataDevice {
190    fn eq(&self, other: &WlDataDeviceRef) -> bool {
191        self.proxy == other.proxy
192    }
193}
194
195impl PartialEq<WlDataDevice> for WlDataDeviceRef {
196    fn eq(&self, other: &WlDataDevice) -> bool {
197        self.proxy == other.proxy
198    }
199}
200
201#[allow(dead_code)]
202impl WlDataDevice {
203    /// Since when the release request is available.
204    #[allow(dead_code)]
205    pub const REQ__RELEASE__SINCE: u32 = 2;
206
207    /// destroy data device
208    ///
209    /// This request destroys the data device.
210    #[inline]
211    pub fn release(&self) {
212        let mut args = [];
213        // SAFETY: - self.proxy has the interface INTERFACE
214        //         - 2 < INTERFACE.method_count = 3
215        //         - the request signature is ``
216        unsafe {
217            self.proxy.send_destructor(2, &mut args);
218        }
219    }
220}
221
222#[allow(dead_code)]
223impl WlDataDeviceRef {
224    /// start drag-and-drop operation
225    ///
226    /// This request asks the compositor to start a drag-and-drop
227    /// operation on behalf of the client.
228    ///
229    /// The source argument is the data source that provides the data
230    /// for the eventual data transfer. If source is NULL, enter, leave
231    /// and motion events are sent only to the client that initiated the
232    /// drag and the client is expected to handle the data passing
233    /// internally. If source is destroyed, the drag-and-drop session will be
234    /// cancelled.
235    ///
236    /// The origin surface is the surface where the drag originates and
237    /// the client must have an active implicit grab that matches the
238    /// serial.
239    ///
240    /// The icon surface is an optional (can be NULL) surface that
241    /// provides an icon to be moved around with the cursor.  Initially,
242    /// the top-left corner of the icon surface is placed at the cursor
243    /// hotspot, but subsequent wl_surface.offset requests can move the
244    /// relative position. Attach requests must be confirmed with
245    /// wl_surface.commit as usual. The icon surface is given the role of
246    /// a drag-and-drop icon. If the icon surface already has another role,
247    /// it raises a protocol error.
248    ///
249    /// The input region is ignored for wl_surfaces with the role of a
250    /// drag-and-drop icon.
251    ///
252    /// The given source may not be used in any further set_selection or
253    /// start_drag requests. Attempting to reuse a previously-used source
254    /// may send a used_source error.
255    ///
256    /// # Arguments
257    ///
258    /// - `source`: data source for the eventual transfer
259    /// - `origin`: surface where the drag originates
260    /// - `icon`: drag-and-drop icon surface
261    /// - `serial`: serial number of the implicit grab on the origin
262    #[inline]
263    pub fn start_drag(
264        &self,
265        source: Option<&WlDataSourceRef>,
266        origin: &WlSurfaceRef,
267        icon: Option<&WlSurfaceRef>,
268        serial: u32,
269    ) {
270        let (arg0, arg1, arg2, arg3) = (source, origin, icon, serial);
271        let obj0_lock = arg0.map(|arg0| proxy::lock(arg0));
272        let obj0 = obj0_lock
273            .map(|obj0_lock| check_argument_proxy("source", obj0_lock.wl_proxy()))
274            .unwrap_or(ptr::null_mut());
275        let obj1_lock = proxy::lock(arg1);
276        let obj1 = check_argument_proxy("origin", obj1_lock.wl_proxy());
277        let obj2_lock = arg2.map(|arg2| proxy::lock(arg2));
278        let obj2 = obj2_lock
279            .map(|obj2_lock| check_argument_proxy("icon", obj2_lock.wl_proxy()))
280            .unwrap_or(ptr::null_mut());
281        let mut args = [
282            wl_argument { o: obj0 },
283            wl_argument { o: obj1 },
284            wl_argument { o: obj2 },
285            wl_argument { u: arg3 },
286        ];
287        // SAFETY: - self.proxy has the interface INTERFACE
288        //         - 0 < INTERFACE.method_count = 3
289        //         - the request signature is `?oo?ou`
290        unsafe {
291            self.proxy.send_request(0, &mut args);
292        }
293    }
294
295    /// copy data to the selection
296    ///
297    /// This request asks the compositor to set the selection
298    /// to the data from the source on behalf of the client.
299    ///
300    /// To unset the selection, set the source to NULL.
301    ///
302    /// The given source may not be used in any further set_selection or
303    /// start_drag requests. Attempting to reuse a previously-used source
304    /// may send a used_source error.
305    ///
306    /// # Arguments
307    ///
308    /// - `source`: data source for the selection
309    /// - `serial`: serial number of the event that triggered this request
310    #[inline]
311    pub fn set_selection(&self, source: Option<&WlDataSourceRef>, serial: u32) {
312        let (arg0, arg1) = (source, serial);
313        let obj0_lock = arg0.map(|arg0| proxy::lock(arg0));
314        let obj0 = obj0_lock
315            .map(|obj0_lock| check_argument_proxy("source", obj0_lock.wl_proxy()))
316            .unwrap_or(ptr::null_mut());
317        let mut args = [wl_argument { o: obj0 }, wl_argument { u: arg1 }];
318        // SAFETY: - self.proxy has the interface INTERFACE
319        //         - 1 < INTERFACE.method_count = 3
320        //         - the request signature is `?ou`
321        unsafe {
322            self.proxy.send_request(1, &mut args);
323        }
324    }
325}
326
327impl WlDataDevice {
328    /// Since when the data_offer event is available.
329    #[allow(dead_code)]
330    pub const EVT__DATA_OFFER__SINCE: u32 = 1;
331
332    /// Since when the enter event is available.
333    #[allow(dead_code)]
334    pub const EVT__ENTER__SINCE: u32 = 1;
335
336    /// Since when the leave event is available.
337    #[allow(dead_code)]
338    pub const EVT__LEAVE__SINCE: u32 = 1;
339
340    /// Since when the motion event is available.
341    #[allow(dead_code)]
342    pub const EVT__MOTION__SINCE: u32 = 1;
343
344    /// Since when the drop event is available.
345    #[allow(dead_code)]
346    pub const EVT__DROP__SINCE: u32 = 1;
347
348    /// Since when the selection event is available.
349    #[allow(dead_code)]
350    pub const EVT__SELECTION__SINCE: u32 = 1;
351}
352
353/// An event handler for [WlDataDevice] proxies.
354#[allow(dead_code)]
355pub trait WlDataDeviceEventHandler {
356    /// introduce a new wl_data_offer
357    ///
358    /// The data_offer event introduces a new wl_data_offer object,
359    /// which will subsequently be used in either the
360    /// data_device.enter event (for drag-and-drop) or the
361    /// data_device.selection event (for selections).  Immediately
362    /// following the data_device.data_offer event, the new data_offer
363    /// object will send out data_offer.offer events to describe the
364    /// mime types it offers.
365    ///
366    /// # Arguments
367    ///
368    /// - `id`: the new data_offer object
369    #[inline]
370    fn data_offer(&self, _slf: &WlDataDeviceRef, id: WlDataOffer) {
371        let _ = id;
372    }
373
374    /// initiate drag-and-drop session
375    ///
376    /// This event is sent when an active drag-and-drop pointer enters
377    /// a surface owned by the client.  The position of the pointer at
378    /// enter time is provided by the x and y arguments, in surface-local
379    /// coordinates.
380    ///
381    /// # Arguments
382    ///
383    /// - `serial`: serial number of the enter event
384    /// - `surface`: client surface entered
385    /// - `x`: surface-local x coordinate
386    /// - `y`: surface-local y coordinate
387    /// - `id`: source data_offer object
388    ///
389    /// All borrowed proxies passed to this function are guaranteed to be
390    /// immutable and non-null.
391    #[inline]
392    fn enter(
393        &self,
394        _slf: &WlDataDeviceRef,
395        serial: u32,
396        surface: Option<&WlSurfaceRef>,
397        x: Fixed,
398        y: Fixed,
399        id: Option<&WlDataOfferRef>,
400    ) {
401        let _ = serial;
402        let _ = surface;
403        let _ = x;
404        let _ = y;
405        let _ = id;
406    }
407
408    /// end drag-and-drop session
409    ///
410    /// This event is sent when the drag-and-drop pointer leaves the
411    /// surface and the session ends.  The client must destroy the
412    /// wl_data_offer introduced at enter time at this point.
413    #[inline]
414    fn leave(&self, _slf: &WlDataDeviceRef) {}
415
416    /// drag-and-drop session motion
417    ///
418    /// This event is sent when the drag-and-drop pointer moves within
419    /// the currently focused surface. The new position of the pointer
420    /// is provided by the x and y arguments, in surface-local
421    /// coordinates.
422    ///
423    /// # Arguments
424    ///
425    /// - `time`: timestamp with millisecond granularity
426    /// - `x`: surface-local x coordinate
427    /// - `y`: surface-local y coordinate
428    #[inline]
429    fn motion(&self, _slf: &WlDataDeviceRef, time: u32, x: Fixed, y: Fixed) {
430        let _ = time;
431        let _ = x;
432        let _ = y;
433    }
434
435    /// end drag-and-drop session successfully
436    ///
437    /// The event is sent when a drag-and-drop operation is ended
438    /// because the implicit grab is removed.
439    ///
440    /// The drag-and-drop destination is expected to honor the last action
441    /// received through wl_data_offer.action, if the resulting action is
442    /// "copy" or "move", the destination can still perform
443    /// wl_data_offer.receive requests, and is expected to end all
444    /// transfers with a wl_data_offer.finish request.
445    ///
446    /// If the resulting action is "ask", the action will not be considered
447    /// final. The drag-and-drop destination is expected to perform one last
448    /// wl_data_offer.set_actions request, or wl_data_offer.destroy in order
449    /// to cancel the operation.
450    #[inline]
451    fn drop(&self, _slf: &WlDataDeviceRef) {}
452
453    /// advertise new selection
454    ///
455    /// The selection event is sent out to notify the client of a new
456    /// wl_data_offer for the selection for this device.  The
457    /// data_device.data_offer and the data_offer.offer events are
458    /// sent out immediately before this event to introduce the data
459    /// offer object.  The selection event is sent to a client
460    /// immediately before receiving keyboard focus and when a new
461    /// selection is set while the client has keyboard focus.  The
462    /// data_offer is valid until a new data_offer or NULL is received
463    /// or until the client loses keyboard focus.  Switching surface with
464    /// keyboard focus within the same client doesn't mean a new selection
465    /// will be sent.  The client must destroy the previous selection
466    /// data_offer, if any, upon receiving this event.
467    ///
468    /// # Arguments
469    ///
470    /// - `id`: selection data_offer object
471    ///
472    /// All borrowed proxies passed to this function are guaranteed to be
473    /// immutable and non-null.
474    #[inline]
475    fn selection(&self, _slf: &WlDataDeviceRef, id: Option<&WlDataOfferRef>) {
476        let _ = id;
477    }
478}
479
480impl WlDataDeviceEventHandler for private::NoOpEventHandler {}
481
482// SAFETY: INTERFACE is a valid wl_interface
483unsafe impl<H> EventHandler for private::EventHandler<H>
484where
485    H: WlDataDeviceEventHandler,
486{
487    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
488
489    #[allow(unused_variables)]
490    unsafe fn handle_event(
491        &self,
492        queue: &Queue,
493        slf: &UntypedBorrowedProxy,
494        opcode: u32,
495        args: *mut wl_argument,
496    ) {
497        // SAFETY: This function required that slf has the interface INTERFACE
498        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlDataDeviceRef>(slf) };
499        match opcode {
500            0 => {
501                // SAFETY: INTERFACE requires that there are 1 arguments
502                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
503                // SAFETY: - INTERFACE requires that args[0] contains an object
504                //         - ownership is transferred to this function
505                //         - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
506                let arg0 = unsafe {
507                    UntypedOwnedProxy::from_plain_wl_proxy(
508                        queue,
509                        NonNull::new_unchecked(args[0].o.cast()),
510                        WlDataOffer::WL_INTERFACE,
511                    )
512                };
513                // SAFETY: - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
514                let arg0 = unsafe { proxy::low_level::from_untyped_owned::<WlDataOffer>(arg0) };
515                self.0.data_offer(slf, arg0);
516            }
517            1 => {
518                // SAFETY: INTERFACE requires that there are 5 arguments
519                let args = unsafe { &*args.cast::<[wl_argument; 5]>() };
520                // SAFETY: - INTERFACE requires that args[0] contains a uint
521                let arg0 = unsafe { args[0].u };
522                // SAFETY: - INTERFACE requires that args[1] contains an object
523                let arg1 = unsafe {
524                    if let Some(p) = NonNull::new(args[1].o.cast()) {
525                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
526                    } else {
527                        None
528                    }
529                };
530                // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
531                let arg1 = arg1.as_ref().map(|arg1| unsafe {
532                    proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
533                });
534                // SAFETY: - INTERFACE requires that args[2] contains a fixed
535                let arg2 = unsafe { Fixed::from_wire(args[2].f) };
536                // SAFETY: - INTERFACE requires that args[3] contains a fixed
537                let arg3 = unsafe { Fixed::from_wire(args[3].f) };
538                // SAFETY: - INTERFACE requires that args[4] contains an object
539                let arg4 = unsafe {
540                    if let Some(p) = NonNull::new(args[4].o.cast()) {
541                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
542                    } else {
543                        None
544                    }
545                };
546                // SAFETY: - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
547                let arg4 = arg4.as_ref().map(|arg4| unsafe {
548                    proxy::low_level::from_untyped_borrowed::<WlDataOfferRef>(arg4)
549                });
550                self.0.enter(slf, arg0, arg1, arg2, arg3, arg4);
551            }
552            2 => {
553                self.0.leave(slf);
554            }
555            3 => {
556                // SAFETY: INTERFACE requires that there are 3 arguments
557                let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
558                // SAFETY: - INTERFACE requires that args[0] contains a uint
559                let arg0 = unsafe { args[0].u };
560                // SAFETY: - INTERFACE requires that args[1] contains a fixed
561                let arg1 = unsafe { Fixed::from_wire(args[1].f) };
562                // SAFETY: - INTERFACE requires that args[2] contains a fixed
563                let arg2 = unsafe { Fixed::from_wire(args[2].f) };
564                self.0.motion(slf, arg0, arg1, arg2);
565            }
566            4 => {
567                self.0.drop(slf);
568            }
569            5 => {
570                // SAFETY: INTERFACE requires that there are 1 arguments
571                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
572                // SAFETY: - INTERFACE requires that args[0] contains an object
573                let arg0 = unsafe {
574                    if let Some(p) = NonNull::new(args[0].o.cast()) {
575                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
576                    } else {
577                        None
578                    }
579                };
580                // SAFETY: - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
581                let arg0 = arg0.as_ref().map(|arg0| unsafe {
582                    proxy::low_level::from_untyped_borrowed::<WlDataOfferRef>(arg0)
583                });
584                self.0.selection(slf, arg0);
585            }
586            _ => {
587                invalid_opcode("wl_data_device", opcode);
588            }
589        }
590    }
591}
592
593impl<H> CreateEventHandler<H> for private::ProxyApi
594where
595    H: WlDataDeviceEventHandler,
596{
597    type EventHandler = private::EventHandler<H>;
598
599    #[inline]
600    fn create_event_handler(handler: H) -> Self::EventHandler {
601        private::EventHandler(handler)
602    }
603}
604
605impl WlDataDevice {
606    /// Since when the error.role enum variant is available.
607    #[allow(dead_code)]
608    pub const ENM__ERROR_ROLE__SINCE: u32 = 1;
609    /// Since when the error.used_source enum variant is available.
610    #[allow(dead_code)]
611    pub const ENM__ERROR_USED_SOURCE__SINCE: u32 = 1;
612}
613
614#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
615#[allow(dead_code)]
616pub struct WlDataDeviceError(pub u32);
617
618impl WlDataDeviceError {
619    /// given wl_surface has another role
620    #[allow(dead_code)]
621    pub const ROLE: Self = Self(0);
622
623    /// source has already been used
624    #[allow(dead_code)]
625    pub const USED_SOURCE: Self = Self(1);
626}
627
628impl Debug for WlDataDeviceError {
629    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
630        let name = match *self {
631            Self::ROLE => "ROLE",
632            Self::USED_SOURCE => "USED_SOURCE",
633            _ => return Debug::fmt(&self.0, f),
634        };
635        f.write_str(name)
636    }
637}
638
639/// Functional event handlers.
640pub mod event_handlers {
641    use super::*;
642
643    /// Event handler for data_offer events.
644    pub struct DataOffer<F>(F);
645    impl<F> WlDataDeviceEventHandler for DataOffer<F>
646    where
647        F: Fn(&WlDataDeviceRef, WlDataOffer),
648    {
649        #[inline]
650        fn data_offer(&self, _slf: &WlDataDeviceRef, id: WlDataOffer) {
651            self.0(_slf, id)
652        }
653    }
654
655    /// Event handler for enter events.
656    pub struct Enter<F>(F);
657    impl<F> WlDataDeviceEventHandler for Enter<F>
658    where
659        F: Fn(&WlDataDeviceRef, u32, Option<&WlSurfaceRef>, Fixed, Fixed, Option<&WlDataOfferRef>),
660    {
661        #[inline]
662        fn enter(
663            &self,
664            _slf: &WlDataDeviceRef,
665            serial: u32,
666            surface: Option<&WlSurfaceRef>,
667            x: Fixed,
668            y: Fixed,
669            id: Option<&WlDataOfferRef>,
670        ) {
671            self.0(_slf, serial, surface, x, y, id)
672        }
673    }
674
675    /// Event handler for leave events.
676    pub struct Leave<F>(F);
677    impl<F> WlDataDeviceEventHandler for Leave<F>
678    where
679        F: Fn(&WlDataDeviceRef),
680    {
681        #[inline]
682        fn leave(&self, _slf: &WlDataDeviceRef) {
683            self.0(_slf)
684        }
685    }
686
687    /// Event handler for motion events.
688    pub struct Motion<F>(F);
689    impl<F> WlDataDeviceEventHandler for Motion<F>
690    where
691        F: Fn(&WlDataDeviceRef, u32, Fixed, Fixed),
692    {
693        #[inline]
694        fn motion(&self, _slf: &WlDataDeviceRef, time: u32, x: Fixed, y: Fixed) {
695            self.0(_slf, time, x, y)
696        }
697    }
698
699    /// Event handler for drop events.
700    pub struct Drop<F>(F);
701    impl<F> WlDataDeviceEventHandler for Drop<F>
702    where
703        F: Fn(&WlDataDeviceRef),
704    {
705        #[inline]
706        fn drop(&self, _slf: &WlDataDeviceRef) {
707            self.0(_slf)
708        }
709    }
710
711    /// Event handler for selection events.
712    pub struct Selection<F>(F);
713    impl<F> WlDataDeviceEventHandler for Selection<F>
714    where
715        F: Fn(&WlDataDeviceRef, Option<&WlDataOfferRef>),
716    {
717        #[inline]
718        fn selection(&self, _slf: &WlDataDeviceRef, id: Option<&WlDataOfferRef>) {
719            self.0(_slf, id)
720        }
721    }
722
723    impl WlDataDevice {
724        /// Creates an event handler for data_offer events.
725        ///
726        /// The event handler ignores all other events.
727        #[allow(dead_code)]
728        pub fn on_data_offer<F>(f: F) -> DataOffer<F>
729        where
730            F: Fn(&WlDataDeviceRef, WlDataOffer),
731        {
732            DataOffer(f)
733        }
734
735        /// Creates an event handler for enter events.
736        ///
737        /// The event handler ignores all other events.
738        #[allow(dead_code)]
739        pub fn on_enter<F>(f: F) -> Enter<F>
740        where
741            F: Fn(
742                &WlDataDeviceRef,
743                u32,
744                Option<&WlSurfaceRef>,
745                Fixed,
746                Fixed,
747                Option<&WlDataOfferRef>,
748            ),
749        {
750            Enter(f)
751        }
752
753        /// Creates an event handler for leave events.
754        ///
755        /// The event handler ignores all other events.
756        #[allow(dead_code)]
757        pub fn on_leave<F>(f: F) -> Leave<F>
758        where
759            F: Fn(&WlDataDeviceRef),
760        {
761            Leave(f)
762        }
763
764        /// Creates an event handler for motion events.
765        ///
766        /// The event handler ignores all other events.
767        #[allow(dead_code)]
768        pub fn on_motion<F>(f: F) -> Motion<F>
769        where
770            F: Fn(&WlDataDeviceRef, u32, Fixed, Fixed),
771        {
772            Motion(f)
773        }
774
775        /// Creates an event handler for drop events.
776        ///
777        /// The event handler ignores all other events.
778        #[allow(dead_code)]
779        pub fn on_drop<F>(f: F) -> Drop<F>
780        where
781            F: Fn(&WlDataDeviceRef),
782        {
783            Drop(f)
784        }
785
786        /// Creates an event handler for selection events.
787        ///
788        /// The event handler ignores all other events.
789        #[allow(dead_code)]
790        pub fn on_selection<F>(f: F) -> Selection<F>
791        where
792            F: Fn(&WlDataDeviceRef, Option<&WlDataOfferRef>),
793        {
794            Selection(f)
795        }
796    }
797}