simple_window/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        data: *mut u8,
494        slf: &UntypedBorrowedProxy,
495        opcode: u32,
496        args: *mut wl_argument,
497    ) {
498        // SAFETY: This function requires that slf has the interface INTERFACE
499        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlDataDeviceRef>(slf) };
500        match opcode {
501            0 => {
502                // SAFETY: INTERFACE requires that there are 1 arguments
503                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
504                // SAFETY: - INTERFACE requires that args[0] contains an object
505                //         - ownership is transferred to this function
506                //         - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
507                let arg0 = unsafe {
508                    UntypedOwnedProxy::from_plain_wl_proxy(
509                        queue,
510                        NonNull::new_unchecked(args[0].o.cast()),
511                        WlDataOffer::WL_INTERFACE,
512                    )
513                };
514                // SAFETY: - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
515                let arg0 = unsafe { proxy::low_level::from_untyped_owned::<WlDataOffer>(arg0) };
516                self.0.data_offer(slf, arg0);
517            }
518            1 => {
519                // SAFETY: INTERFACE requires that there are 5 arguments
520                let args = unsafe { &*args.cast::<[wl_argument; 5]>() };
521                // SAFETY: - INTERFACE requires that args[0] contains a uint
522                let arg0 = unsafe { args[0].u };
523                // SAFETY: - INTERFACE requires that args[1] contains an object
524                let arg1 = unsafe {
525                    if let Some(p) = NonNull::new(args[1].o.cast()) {
526                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
527                    } else {
528                        None
529                    }
530                };
531                // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
532                let arg1 = arg1.as_ref().map(|arg1| unsafe {
533                    proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
534                });
535                // SAFETY: - INTERFACE requires that args[2] contains a fixed
536                let arg2 = unsafe { Fixed::from_wire(args[2].f) };
537                // SAFETY: - INTERFACE requires that args[3] contains a fixed
538                let arg3 = unsafe { Fixed::from_wire(args[3].f) };
539                // SAFETY: - INTERFACE requires that args[4] contains an object
540                let arg4 = unsafe {
541                    if let Some(p) = NonNull::new(args[4].o.cast()) {
542                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
543                    } else {
544                        None
545                    }
546                };
547                // SAFETY: - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
548                let arg4 = arg4.as_ref().map(|arg4| unsafe {
549                    proxy::low_level::from_untyped_borrowed::<WlDataOfferRef>(arg4)
550                });
551                self.0.enter(slf, arg0, arg1, arg2, arg3, arg4);
552            }
553            2 => {
554                self.0.leave(slf);
555            }
556            3 => {
557                // SAFETY: INTERFACE requires that there are 3 arguments
558                let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
559                // SAFETY: - INTERFACE requires that args[0] contains a uint
560                let arg0 = unsafe { args[0].u };
561                // SAFETY: - INTERFACE requires that args[1] contains a fixed
562                let arg1 = unsafe { Fixed::from_wire(args[1].f) };
563                // SAFETY: - INTERFACE requires that args[2] contains a fixed
564                let arg2 = unsafe { Fixed::from_wire(args[2].f) };
565                self.0.motion(slf, arg0, arg1, arg2);
566            }
567            4 => {
568                self.0.drop(slf);
569            }
570            5 => {
571                // SAFETY: INTERFACE requires that there are 1 arguments
572                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
573                // SAFETY: - INTERFACE requires that args[0] contains an object
574                let arg0 = unsafe {
575                    if let Some(p) = NonNull::new(args[0].o.cast()) {
576                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
577                    } else {
578                        None
579                    }
580                };
581                // SAFETY: - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
582                let arg0 = arg0.as_ref().map(|arg0| unsafe {
583                    proxy::low_level::from_untyped_borrowed::<WlDataOfferRef>(arg0)
584                });
585                self.0.selection(slf, arg0);
586            }
587            _ => {
588                invalid_opcode("wl_data_device", opcode);
589            }
590        }
591    }
592}
593
594impl<H> CreateEventHandler<H> for private::ProxyApi
595where
596    H: WlDataDeviceEventHandler,
597{
598    type EventHandler = private::EventHandler<H>;
599
600    #[inline]
601    fn create_event_handler(handler: H) -> Self::EventHandler {
602        private::EventHandler(handler)
603    }
604}
605
606impl WlDataDevice {
607    /// Since when the error.role enum variant is available.
608    #[allow(dead_code)]
609    pub const ENM__ERROR_ROLE__SINCE: u32 = 1;
610    /// Since when the error.used_source enum variant is available.
611    #[allow(dead_code)]
612    pub const ENM__ERROR_USED_SOURCE__SINCE: u32 = 1;
613}
614
615#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
616#[allow(dead_code)]
617pub struct WlDataDeviceError(pub u32);
618
619impl WlDataDeviceError {
620    /// given wl_surface has another role
621    #[allow(dead_code)]
622    pub const ROLE: Self = Self(0);
623
624    /// source has already been used
625    #[allow(dead_code)]
626    pub const USED_SOURCE: Self = Self(1);
627}
628
629impl Debug for WlDataDeviceError {
630    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
631        let name = match *self {
632            Self::ROLE => "ROLE",
633            Self::USED_SOURCE => "USED_SOURCE",
634            _ => return Debug::fmt(&self.0, f),
635        };
636        f.write_str(name)
637    }
638}
639
640/// Functional event handlers.
641pub mod event_handlers {
642    use super::*;
643
644    /// Event handler for data_offer events.
645    pub struct DataOffer<F>(F);
646    impl<F> WlDataDeviceEventHandler for DataOffer<F>
647    where
648        F: Fn(&WlDataDeviceRef, WlDataOffer),
649    {
650        #[inline]
651        fn data_offer(&self, _slf: &WlDataDeviceRef, id: WlDataOffer) {
652            self.0(_slf, id)
653        }
654    }
655
656    /// Event handler for enter events.
657    pub struct Enter<F>(F);
658    impl<F> WlDataDeviceEventHandler for Enter<F>
659    where
660        F: Fn(&WlDataDeviceRef, u32, Option<&WlSurfaceRef>, Fixed, Fixed, Option<&WlDataOfferRef>),
661    {
662        #[inline]
663        fn enter(
664            &self,
665            _slf: &WlDataDeviceRef,
666            serial: u32,
667            surface: Option<&WlSurfaceRef>,
668            x: Fixed,
669            y: Fixed,
670            id: Option<&WlDataOfferRef>,
671        ) {
672            self.0(_slf, serial, surface, x, y, id)
673        }
674    }
675
676    /// Event handler for leave events.
677    pub struct Leave<F>(F);
678    impl<F> WlDataDeviceEventHandler for Leave<F>
679    where
680        F: Fn(&WlDataDeviceRef),
681    {
682        #[inline]
683        fn leave(&self, _slf: &WlDataDeviceRef) {
684            self.0(_slf)
685        }
686    }
687
688    /// Event handler for motion events.
689    pub struct Motion<F>(F);
690    impl<F> WlDataDeviceEventHandler for Motion<F>
691    where
692        F: Fn(&WlDataDeviceRef, u32, Fixed, Fixed),
693    {
694        #[inline]
695        fn motion(&self, _slf: &WlDataDeviceRef, time: u32, x: Fixed, y: Fixed) {
696            self.0(_slf, time, x, y)
697        }
698    }
699
700    /// Event handler for drop events.
701    pub struct Drop<F>(F);
702    impl<F> WlDataDeviceEventHandler for Drop<F>
703    where
704        F: Fn(&WlDataDeviceRef),
705    {
706        #[inline]
707        fn drop(&self, _slf: &WlDataDeviceRef) {
708            self.0(_slf)
709        }
710    }
711
712    /// Event handler for selection events.
713    pub struct Selection<F>(F);
714    impl<F> WlDataDeviceEventHandler for Selection<F>
715    where
716        F: Fn(&WlDataDeviceRef, Option<&WlDataOfferRef>),
717    {
718        #[inline]
719        fn selection(&self, _slf: &WlDataDeviceRef, id: Option<&WlDataOfferRef>) {
720            self.0(_slf, id)
721        }
722    }
723
724    impl WlDataDevice {
725        /// Creates an event handler for data_offer events.
726        ///
727        /// The event handler ignores all other events.
728        #[allow(dead_code)]
729        pub fn on_data_offer<F>(f: F) -> DataOffer<F>
730        where
731            F: Fn(&WlDataDeviceRef, WlDataOffer),
732        {
733            DataOffer(f)
734        }
735
736        /// Creates an event handler for enter events.
737        ///
738        /// The event handler ignores all other events.
739        #[allow(dead_code)]
740        pub fn on_enter<F>(f: F) -> Enter<F>
741        where
742            F: Fn(
743                &WlDataDeviceRef,
744                u32,
745                Option<&WlSurfaceRef>,
746                Fixed,
747                Fixed,
748                Option<&WlDataOfferRef>,
749            ),
750        {
751            Enter(f)
752        }
753
754        /// Creates an event handler for leave events.
755        ///
756        /// The event handler ignores all other events.
757        #[allow(dead_code)]
758        pub fn on_leave<F>(f: F) -> Leave<F>
759        where
760            F: Fn(&WlDataDeviceRef),
761        {
762            Leave(f)
763        }
764
765        /// Creates an event handler for motion events.
766        ///
767        /// The event handler ignores all other events.
768        #[allow(dead_code)]
769        pub fn on_motion<F>(f: F) -> Motion<F>
770        where
771            F: Fn(&WlDataDeviceRef, u32, Fixed, Fixed),
772        {
773            Motion(f)
774        }
775
776        /// Creates an event handler for drop events.
777        ///
778        /// The event handler ignores all other events.
779        #[allow(dead_code)]
780        pub fn on_drop<F>(f: F) -> Drop<F>
781        where
782            F: Fn(&WlDataDeviceRef),
783        {
784            Drop(f)
785        }
786
787        /// Creates an event handler for selection events.
788        ///
789        /// The event handler ignores all other events.
790        #[allow(dead_code)]
791        pub fn on_selection<F>(f: F) -> Selection<F>
792        where
793            F: Fn(&WlDataDeviceRef, Option<&WlDataOfferRef>),
794        {
795            Selection(f)
796        }
797    }
798}