Skip to main content

get_registry/common/protocols_data/wayland/
wl_data_offer.rs

1//! offer to transfer data
2//!
3//! A wl_data_offer represents a piece of data offered for transfer
4//! by another client (the source client).  It is used by the
5//! copy-and-paste and drag-and-drop mechanisms.  The offer
6//! describes the different mime types that the data can be
7//! converted to and provides the mechanism for transferring the
8//! data directly from the source client.
9
10use super::super::all_types::*;
11use ::wl_client::builder::prelude::*;
12
13static INTERFACE: wl_interface = wl_interface {
14    name: c"wl_data_offer".as_ptr(),
15    version: 3,
16    method_count: 5,
17    methods: {
18        static MESSAGES: [wl_message; 5] = [
19            wl_message {
20                name: c"accept".as_ptr(),
21                signature: c"u?s".as_ptr(),
22                types: {
23                    static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
24                    TYPES.as_ptr().cast()
25                },
26            },
27            wl_message {
28                name: c"receive".as_ptr(),
29                signature: c"sh".as_ptr(),
30                types: {
31                    static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
32                    TYPES.as_ptr().cast()
33                },
34            },
35            wl_message {
36                name: c"destroy".as_ptr(),
37                signature: c"".as_ptr(),
38                types: {
39                    static TYPES: [Option<&'static wl_interface>; 0] = [];
40                    TYPES.as_ptr().cast()
41                },
42            },
43            wl_message {
44                name: c"finish".as_ptr(),
45                signature: c"".as_ptr(),
46                types: {
47                    static TYPES: [Option<&'static wl_interface>; 0] = [];
48                    TYPES.as_ptr().cast()
49                },
50            },
51            wl_message {
52                name: c"set_actions".as_ptr(),
53                signature: c"uu".as_ptr(),
54                types: {
55                    static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
56                    TYPES.as_ptr().cast()
57                },
58            },
59        ];
60        MESSAGES.as_ptr()
61    },
62    event_count: 3,
63    events: {
64        static MESSAGES: [wl_message; 3] = [
65            wl_message {
66                name: c"offer".as_ptr(),
67                signature: c"s".as_ptr(),
68                types: {
69                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
70                    TYPES.as_ptr().cast()
71                },
72            },
73            wl_message {
74                name: c"source_actions".as_ptr(),
75                signature: c"u".as_ptr(),
76                types: {
77                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
78                    TYPES.as_ptr().cast()
79                },
80            },
81            wl_message {
82                name: c"action".as_ptr(),
83                signature: c"u".as_ptr(),
84                types: {
85                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
86                    TYPES.as_ptr().cast()
87                },
88            },
89        ];
90        MESSAGES.as_ptr()
91    },
92};
93
94/// An owned wl_data_offer proxy.
95///
96/// See the documentation of [the module][self] for the interface description.
97#[derive(Clone, Eq, PartialEq)]
98#[repr(transparent)]
99pub struct WlDataOffer {
100    /// This proxy has the interface INTERFACE.
101    proxy: UntypedOwnedProxy,
102}
103
104/// A borrowed wl_data_offer proxy.
105///
106/// See the documentation of [the module][self] for the interface description.
107#[derive(Eq, PartialEq)]
108#[repr(transparent)]
109pub struct WlDataOfferRef {
110    /// This proxy has the interface INTERFACE.
111    proxy: UntypedBorrowedProxy,
112}
113
114// SAFETY: WlDataOffer is a transparent wrapper around UntypedOwnedProxy
115unsafe impl UntypedOwnedProxyWrapper for WlDataOffer {}
116
117// SAFETY: - INTERFACE is a valid wl_interface
118//         - The only invariant is that self.proxy has a compatible interface
119unsafe impl OwnedProxy for WlDataOffer {
120    const INTERFACE: &'static str = "wl_data_offer";
121    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
122    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
123        private::EventHandler(private::NoOpEventHandler);
124    const MAX_VERSION: u32 = 3;
125
126    type Borrowed = WlDataOfferRef;
127    type Api = private::ProxyApi;
128    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
129}
130
131// SAFETY: WlDataOfferRef is a transparent wrapper around UntypedBorrowedProxy
132unsafe impl UntypedBorrowedProxyWrapper for WlDataOfferRef {}
133
134// SAFETY: - The only invariant is that self.proxy has a compatible interface
135unsafe impl BorrowedProxy for WlDataOfferRef {
136    type Owned = WlDataOffer;
137}
138
139impl Deref for WlDataOffer {
140    type Target = WlDataOfferRef;
141
142    fn deref(&self) -> &Self::Target {
143        proxy::low_level::deref(self)
144    }
145}
146
147mod private {
148    pub struct ProxyApi;
149
150    #[allow(dead_code)]
151    pub struct EventHandler<H>(pub(super) H);
152
153    #[allow(dead_code)]
154    pub struct NoOpEventHandler;
155}
156
157impl Debug for WlDataOffer {
158    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
159        write!(f, "wl_data_offer#{}", self.proxy.id())
160    }
161}
162
163impl Debug for WlDataOfferRef {
164    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
165        write!(f, "wl_data_offer#{}", self.proxy.id())
166    }
167}
168
169impl PartialEq<WlDataOfferRef> for WlDataOffer {
170    fn eq(&self, other: &WlDataOfferRef) -> bool {
171        self.proxy == other.proxy
172    }
173}
174
175impl PartialEq<WlDataOffer> for WlDataOfferRef {
176    fn eq(&self, other: &WlDataOffer) -> bool {
177        self.proxy == other.proxy
178    }
179}
180
181#[allow(dead_code)]
182impl WlDataOffer {
183    /// Since when the accept request is available.
184    #[allow(dead_code)]
185    pub const REQ__ACCEPT__SINCE: u32 = 1;
186
187    /// Since when the receive request is available.
188    #[allow(dead_code)]
189    pub const REQ__RECEIVE__SINCE: u32 = 1;
190
191    /// Since when the destroy request is available.
192    #[allow(dead_code)]
193    pub const REQ__DESTROY__SINCE: u32 = 1;
194
195    /// Since when the finish request is available.
196    #[allow(dead_code)]
197    pub const REQ__FINISH__SINCE: u32 = 3;
198
199    /// Since when the set_actions request is available.
200    #[allow(dead_code)]
201    pub const REQ__SET_ACTIONS__SINCE: u32 = 3;
202}
203
204#[allow(dead_code)]
205impl WlDataOffer {
206    /// destroy data offer
207    ///
208    /// Destroy the data offer.
209    #[inline]
210    pub fn destroy(&self) {
211        let mut args = [];
212        // SAFETY: - self.proxy has the interface INTERFACE
213        //         - 2 < INTERFACE.method_count = 5
214        //         - the request signature is ``
215        unsafe {
216            self.proxy.send_destructor(2, &mut args);
217        }
218    }
219}
220
221#[allow(dead_code)]
222impl WlDataOfferRef {
223    /// accept one of the offered mime types
224    ///
225    /// Indicate that the client can accept the given mime type, or
226    /// NULL for not accepted.
227    ///
228    /// For objects of version 2 or older, this request is used by the
229    /// client to give feedback whether the client can receive the given
230    /// mime type, or NULL if none is accepted; the feedback does not
231    /// determine whether the drag-and-drop operation succeeds or not.
232    ///
233    /// For objects of version 3 or newer, this request determines the
234    /// final result of the drag-and-drop operation. If the end result
235    /// is that no mime types were accepted, the drag-and-drop operation
236    /// will be cancelled and the corresponding drag source will receive
237    /// wl_data_source.cancelled. Clients may still use this event in
238    /// conjunction with wl_data_source.action for feedback.
239    ///
240    /// # Arguments
241    ///
242    /// - `serial`: serial number of the accept request
243    /// - `mime_type`: mime type accepted by the client
244    #[inline]
245    pub fn accept(&self, serial: u32, mime_type: Option<&str>) {
246        let (arg0, arg1) = (serial, mime_type);
247        with_cstr_cache(|cache| {
248            let str1_offset = cache.len();
249            if let Some(arg1) = arg1 {
250                cache.extend_from_slice(arg1.as_bytes());
251                cache.push(0);
252            }
253            let mut str1 = ptr::null();
254            if arg1.is_some() {
255                str1 = cache[str1_offset..].as_ptr().cast();
256            }
257            let mut args = [wl_argument { u: arg0 }, wl_argument { s: str1 }];
258            // SAFETY: - self.proxy has the interface INTERFACE
259            //         - 0 < INTERFACE.method_count = 5
260            //         - the request signature is `u?s`
261            unsafe {
262                self.proxy.send_request(0, &mut args);
263            }
264        })
265    }
266
267    /// request that the data is transferred
268    ///
269    /// To transfer the offered data, the client issues this request
270    /// and indicates the mime type it wants to receive.  The transfer
271    /// happens through the passed file descriptor (typically created
272    /// with the pipe system call).  The source client writes the data
273    /// in the mime type representation requested and then closes the
274    /// file descriptor.
275    ///
276    /// The receiving client reads from the read end of the pipe until
277    /// EOF and then closes its end, at which point the transfer is
278    /// complete.
279    ///
280    /// This request may happen multiple times for different mime types,
281    /// both before and after wl_data_device.drop. Drag-and-drop destination
282    /// clients may preemptively fetch data or examine it more closely to
283    /// determine acceptance.
284    ///
285    /// # Arguments
286    ///
287    /// - `mime_type`: mime type desired by receiver
288    /// - `fd`: file descriptor for data transfer
289    #[inline]
290    pub fn receive(&self, mime_type: &str, fd: BorrowedFd<'_>) {
291        let (arg0, arg1) = (mime_type, fd);
292        with_cstr_cache(|cache| {
293            let str0_offset = cache.len();
294            cache.extend_from_slice(arg0.as_bytes());
295            cache.push(0);
296            let str0 = cache[str0_offset..].as_ptr().cast();
297            let mut args = [
298                wl_argument { s: str0 },
299                wl_argument {
300                    h: arg1.as_raw_fd(),
301                },
302            ];
303            // SAFETY: - self.proxy has the interface INTERFACE
304            //         - 1 < INTERFACE.method_count = 5
305            //         - the request signature is `sh`
306            unsafe {
307                self.proxy.send_request(1, &mut args);
308            }
309        })
310    }
311
312    /// the offer will no longer be used
313    ///
314    /// Notifies the compositor that the drag destination successfully
315    /// finished the drag-and-drop operation.
316    ///
317    /// Upon receiving this request, the compositor will emit
318    /// wl_data_source.dnd_finished on the drag source client.
319    ///
320    /// It is a client error to perform other requests than
321    /// wl_data_offer.destroy after this one. It is also an error to perform
322    /// this request after a NULL mime type has been set in
323    /// wl_data_offer.accept or no action was received through
324    /// wl_data_offer.action.
325    ///
326    /// If wl_data_offer.finish request is received for a non drag and drop
327    /// operation, the invalid_finish protocol error is raised.
328    #[inline]
329    pub fn finish(&self) {
330        let mut args = [];
331        // SAFETY: - self.proxy has the interface INTERFACE
332        //         - 3 < INTERFACE.method_count = 5
333        //         - the request signature is ``
334        unsafe {
335            self.proxy.send_request(3, &mut args);
336        }
337    }
338
339    /// set the available/preferred drag-and-drop actions
340    ///
341    /// Sets the actions that the destination side client supports for
342    /// this operation. This request may trigger the emission of
343    /// wl_data_source.action and wl_data_offer.action events if the compositor
344    /// needs to change the selected action.
345    ///
346    /// This request can be called multiple times throughout the
347    /// drag-and-drop operation, typically in response to wl_data_device.enter
348    /// or wl_data_device.motion events.
349    ///
350    /// This request determines the final result of the drag-and-drop
351    /// operation. If the end result is that no action is accepted,
352    /// the drag source will receive wl_data_source.cancelled.
353    ///
354    /// The dnd_actions argument must contain only values expressed in the
355    /// wl_data_device_manager.dnd_actions enum, and the preferred_action
356    /// argument must only contain one of those values set, otherwise it
357    /// will result in a protocol error.
358    ///
359    /// While managing an "ask" action, the destination drag-and-drop client
360    /// may perform further wl_data_offer.receive requests, and is expected
361    /// to perform one last wl_data_offer.set_actions request with a preferred
362    /// action other than "ask" (and optionally wl_data_offer.accept) before
363    /// requesting wl_data_offer.finish, in order to convey the action selected
364    /// by the user. If the preferred action is not in the
365    /// wl_data_offer.source_actions mask, an error will be raised.
366    ///
367    /// If the "ask" action is dismissed (e.g. user cancellation), the client
368    /// is expected to perform wl_data_offer.destroy right away.
369    ///
370    /// This request can only be made on drag-and-drop offers, a protocol error
371    /// will be raised otherwise.
372    ///
373    /// # Arguments
374    ///
375    /// - `dnd_actions`: actions supported by the destination client
376    /// - `preferred_action`: action preferred by the destination client
377    #[inline]
378    pub fn set_actions(
379        &self,
380        dnd_actions: WlDataDeviceManagerDndAction,
381        preferred_action: WlDataDeviceManagerDndAction,
382    ) {
383        let (arg0, arg1) = (dnd_actions, preferred_action);
384        let mut args = [wl_argument { u: arg0.0 }, wl_argument { u: arg1.0 }];
385        // SAFETY: - self.proxy has the interface INTERFACE
386        //         - 4 < INTERFACE.method_count = 5
387        //         - the request signature is `uu`
388        unsafe {
389            self.proxy.send_request(4, &mut args);
390        }
391    }
392}
393
394impl WlDataOffer {
395    /// Since when the offer event is available.
396    #[allow(dead_code)]
397    pub const EVT__OFFER__SINCE: u32 = 1;
398
399    /// Since when the source_actions event is available.
400    #[allow(dead_code)]
401    pub const EVT__SOURCE_ACTIONS__SINCE: u32 = 3;
402
403    /// Since when the action event is available.
404    #[allow(dead_code)]
405    pub const EVT__ACTION__SINCE: u32 = 3;
406}
407
408/// An event handler for [WlDataOffer] proxies.
409#[allow(dead_code)]
410pub trait WlDataOfferEventHandler {
411    type Data: 'static;
412
413    /// advertise offered mime type
414    ///
415    /// Sent immediately after creating the wl_data_offer object.  One
416    /// event per offered mime type.
417    ///
418    /// # Arguments
419    ///
420    /// - `mime_type`: offered mime type
421    #[inline]
422    fn offer(&self, _data: &mut Self::Data, _slf: &WlDataOfferRef, mime_type: &str) {
423        let _ = mime_type;
424    }
425
426    /// notify the source-side available actions
427    ///
428    /// This event indicates the actions offered by the data source. It
429    /// will be sent immediately after creating the wl_data_offer object,
430    /// or anytime the source side changes its offered actions through
431    /// wl_data_source.set_actions.
432    ///
433    /// # Arguments
434    ///
435    /// - `source_actions`: actions offered by the data source
436    #[inline]
437    fn source_actions(
438        &self,
439        _data: &mut Self::Data,
440        _slf: &WlDataOfferRef,
441        source_actions: WlDataDeviceManagerDndAction,
442    ) {
443        let _ = source_actions;
444    }
445
446    /// notify the selected action
447    ///
448    /// This event indicates the action selected by the compositor after
449    /// matching the source/destination side actions. Only one action (or
450    /// none) will be offered here.
451    ///
452    /// This event can be emitted multiple times during the drag-and-drop
453    /// operation in response to destination side action changes through
454    /// wl_data_offer.set_actions.
455    ///
456    /// This event will no longer be emitted after wl_data_device.drop
457    /// happened on the drag-and-drop destination, the client must
458    /// honor the last action received, or the last preferred one set
459    /// through wl_data_offer.set_actions when handling an "ask" action.
460    ///
461    /// Compositors may also change the selected action on the fly, mainly
462    /// in response to keyboard modifier changes during the drag-and-drop
463    /// operation.
464    ///
465    /// The most recent action received is always the valid one. Prior to
466    /// receiving wl_data_device.drop, the chosen action may change (e.g.
467    /// due to keyboard modifiers being pressed). At the time of receiving
468    /// wl_data_device.drop the drag-and-drop destination must honor the
469    /// last action received.
470    ///
471    /// Action changes may still happen after wl_data_device.drop,
472    /// especially on "ask" actions, where the drag-and-drop destination
473    /// may choose another action afterwards. Action changes happening
474    /// at this stage are always the result of inter-client negotiation, the
475    /// compositor shall no longer be able to induce a different action.
476    ///
477    /// Upon "ask" actions, it is expected that the drag-and-drop destination
478    /// may potentially choose a different action and/or mime type,
479    /// based on wl_data_offer.source_actions and finally chosen by the
480    /// user (e.g. popping up a menu with the available options). The
481    /// final wl_data_offer.set_actions and wl_data_offer.accept requests
482    /// must happen before the call to wl_data_offer.finish.
483    ///
484    /// # Arguments
485    ///
486    /// - `dnd_action`: action selected by the compositor
487    #[inline]
488    fn action(
489        &self,
490        _data: &mut Self::Data,
491        _slf: &WlDataOfferRef,
492        dnd_action: WlDataDeviceManagerDndAction,
493    ) {
494        let _ = dnd_action;
495    }
496}
497
498impl WlDataOfferEventHandler for private::NoOpEventHandler {
499    type Data = ();
500}
501
502// SAFETY: - INTERFACE is a valid wl_interface
503//         - mutable_type always returns the same value
504unsafe impl<H> EventHandler for private::EventHandler<H>
505where
506    H: WlDataOfferEventHandler,
507{
508    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
509
510    #[inline]
511    fn mutable_type() -> Option<(TypeId, &'static str)> {
512        let id = TypeId::of::<H::Data>();
513        let name = std::any::type_name::<H::Data>();
514        Some((id, name))
515    }
516
517    #[allow(unused_variables)]
518    unsafe fn handle_event(
519        &self,
520        queue: &Queue,
521        data: *mut u8,
522        slf: &UntypedBorrowedProxy,
523        opcode: u32,
524        args: *mut wl_argument,
525    ) {
526        // SAFETY: This function requires that slf has the interface INTERFACE
527        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlDataOfferRef>(slf) };
528        // SAFETY: This function requires that data is `&mut T` where `T`
529        //         has the type id returned by `Self::mutable_type`, i.e.,
530        //         `T = H::Data`.
531        let data: &mut H::Data = unsafe { &mut *data.cast() };
532        match opcode {
533            0 => {
534                // SAFETY: INTERFACE requires that there are 1 arguments
535                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
536                // SAFETY: - INTERFACE requires that args[0] contains a string
537                //         - if the pointer is not null, then it is a c string
538                let arg0 = unsafe { convert_string_arg("wl_data_offer", "mime_type", args[0].s) };
539                self.0.offer(data, slf, arg0);
540            }
541            1 => {
542                // SAFETY: INTERFACE requires that there are 1 arguments
543                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
544                // SAFETY: - INTERFACE requires that args[0] contains a uint
545                let arg0 = unsafe { WlDataDeviceManagerDndAction(args[0].u) };
546                self.0.source_actions(data, slf, arg0);
547            }
548            2 => {
549                // SAFETY: INTERFACE requires that there are 1 arguments
550                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
551                // SAFETY: - INTERFACE requires that args[0] contains a uint
552                let arg0 = unsafe { WlDataDeviceManagerDndAction(args[0].u) };
553                self.0.action(data, slf, arg0);
554            }
555            _ => {
556                invalid_opcode("wl_data_offer", opcode);
557            }
558        }
559    }
560}
561
562impl<H> CreateEventHandler<H> for private::ProxyApi
563where
564    H: WlDataOfferEventHandler,
565{
566    type EventHandler = private::EventHandler<H>;
567
568    #[inline]
569    fn create_event_handler(handler: H) -> Self::EventHandler {
570        private::EventHandler(handler)
571    }
572}
573
574impl WlDataOffer {
575    /// Since when the error.invalid_finish enum variant is available.
576    #[allow(dead_code)]
577    pub const ENM__ERROR_INVALID_FINISH__SINCE: u32 = 1;
578    /// Since when the error.invalid_action_mask enum variant is available.
579    #[allow(dead_code)]
580    pub const ENM__ERROR_INVALID_ACTION_MASK__SINCE: u32 = 1;
581    /// Since when the error.invalid_action enum variant is available.
582    #[allow(dead_code)]
583    pub const ENM__ERROR_INVALID_ACTION__SINCE: u32 = 1;
584    /// Since when the error.invalid_offer enum variant is available.
585    #[allow(dead_code)]
586    pub const ENM__ERROR_INVALID_OFFER__SINCE: u32 = 1;
587}
588
589#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
590#[allow(dead_code)]
591pub struct WlDataOfferError(pub u32);
592
593impl WlDataOfferError {
594    /// finish request was called untimely
595    #[allow(dead_code)]
596    pub const INVALID_FINISH: Self = Self(0);
597
598    /// action mask contains invalid values
599    #[allow(dead_code)]
600    pub const INVALID_ACTION_MASK: Self = Self(1);
601
602    /// action argument has an invalid value
603    #[allow(dead_code)]
604    pub const INVALID_ACTION: Self = Self(2);
605
606    /// offer doesn't accept this request
607    #[allow(dead_code)]
608    pub const INVALID_OFFER: Self = Self(3);
609}
610
611impl Debug for WlDataOfferError {
612    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
613        let name = match *self {
614            Self::INVALID_FINISH => "INVALID_FINISH",
615            Self::INVALID_ACTION_MASK => "INVALID_ACTION_MASK",
616            Self::INVALID_ACTION => "INVALID_ACTION",
617            Self::INVALID_OFFER => "INVALID_OFFER",
618            _ => return Debug::fmt(&self.0, f),
619        };
620        f.write_str(name)
621    }
622}
623
624/// Functional event handlers.
625pub mod event_handlers {
626    use super::*;
627
628    /// Event handler for offer events.
629    pub struct Offer<T, F>(F, PhantomData<fn(&mut T)>);
630    impl<T, F> WlDataOfferEventHandler for Offer<T, F>
631    where
632        T: 'static,
633        F: Fn(&mut T, &WlDataOfferRef, &str),
634    {
635        type Data = T;
636
637        #[inline]
638        fn offer(&self, _data: &mut T, _slf: &WlDataOfferRef, mime_type: &str) {
639            self.0(_data, _slf, mime_type)
640        }
641    }
642
643    /// Event handler for source_actions events.
644    pub struct SourceActions<T, F>(F, PhantomData<fn(&mut T)>);
645    impl<T, F> WlDataOfferEventHandler for SourceActions<T, F>
646    where
647        T: 'static,
648        F: Fn(&mut T, &WlDataOfferRef, WlDataDeviceManagerDndAction),
649    {
650        type Data = T;
651
652        #[inline]
653        fn source_actions(
654            &self,
655            _data: &mut T,
656            _slf: &WlDataOfferRef,
657            source_actions: WlDataDeviceManagerDndAction,
658        ) {
659            self.0(_data, _slf, source_actions)
660        }
661    }
662
663    /// Event handler for action events.
664    pub struct Action<T, F>(F, PhantomData<fn(&mut T)>);
665    impl<T, F> WlDataOfferEventHandler for Action<T, F>
666    where
667        T: 'static,
668        F: Fn(&mut T, &WlDataOfferRef, WlDataDeviceManagerDndAction),
669    {
670        type Data = T;
671
672        #[inline]
673        fn action(
674            &self,
675            _data: &mut T,
676            _slf: &WlDataOfferRef,
677            dnd_action: WlDataDeviceManagerDndAction,
678        ) {
679            self.0(_data, _slf, dnd_action)
680        }
681    }
682
683    impl WlDataOffer {
684        /// Creates an event handler for offer events.
685        ///
686        /// The event handler ignores all other events.
687        #[allow(dead_code)]
688        pub fn on_offer<T, F>(f: F) -> Offer<T, F>
689        where
690            T: 'static,
691            F: Fn(&mut T, &WlDataOfferRef, &str),
692        {
693            Offer(f, PhantomData)
694        }
695
696        /// Creates an event handler for source_actions events.
697        ///
698        /// The event handler ignores all other events.
699        #[allow(dead_code)]
700        pub fn on_source_actions<T, F>(f: F) -> SourceActions<T, F>
701        where
702            T: 'static,
703            F: Fn(&mut T, &WlDataOfferRef, WlDataDeviceManagerDndAction),
704        {
705            SourceActions(f, PhantomData)
706        }
707
708        /// Creates an event handler for action events.
709        ///
710        /// The event handler ignores all other events.
711        #[allow(dead_code)]
712        pub fn on_action<T, F>(f: F) -> Action<T, F>
713        where
714            T: 'static,
715            F: Fn(&mut T, &WlDataOfferRef, WlDataDeviceManagerDndAction),
716        {
717            Action(f, PhantomData)
718        }
719    }
720}