wl-client 0.2.0

Safe client-side libwayland wrapper
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
//! offer to transfer data
//!
//! The wl_data_source object is the source side of a wl_data_offer.
//! It is created by the source client in a data transfer and
//! provides a way to describe the offered data and a way to respond
//! to requests to transfer the data.

use {super::super::all_types::*, ::wl_client::builder::prelude::*};

static INTERFACE: wl_interface = wl_interface {
    name: c"wl_data_source".as_ptr(),
    version: 3,
    method_count: 3,
    methods: {
        static MESSAGES: [wl_message; 3] = [
            wl_message {
                name: c"offer".as_ptr(),
                signature: c"s".as_ptr(),
                types: {
                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
                    TYPES.as_ptr().cast()
                },
            },
            wl_message {
                name: c"destroy".as_ptr(),
                signature: c"".as_ptr(),
                types: {
                    static TYPES: [Option<&'static wl_interface>; 0] = [];
                    TYPES.as_ptr().cast()
                },
            },
            wl_message {
                name: c"set_actions".as_ptr(),
                signature: c"u".as_ptr(),
                types: {
                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
                    TYPES.as_ptr().cast()
                },
            },
        ];
        MESSAGES.as_ptr()
    },
    event_count: 6,
    events: {
        static MESSAGES: [wl_message; 6] = [
            wl_message {
                name: c"target".as_ptr(),
                signature: c"?s".as_ptr(),
                types: {
                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
                    TYPES.as_ptr().cast()
                },
            },
            wl_message {
                name: c"send".as_ptr(),
                signature: c"sh".as_ptr(),
                types: {
                    static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
                    TYPES.as_ptr().cast()
                },
            },
            wl_message {
                name: c"cancelled".as_ptr(),
                signature: c"".as_ptr(),
                types: {
                    static TYPES: [Option<&'static wl_interface>; 0] = [];
                    TYPES.as_ptr().cast()
                },
            },
            wl_message {
                name: c"dnd_drop_performed".as_ptr(),
                signature: c"".as_ptr(),
                types: {
                    static TYPES: [Option<&'static wl_interface>; 0] = [];
                    TYPES.as_ptr().cast()
                },
            },
            wl_message {
                name: c"dnd_finished".as_ptr(),
                signature: c"".as_ptr(),
                types: {
                    static TYPES: [Option<&'static wl_interface>; 0] = [];
                    TYPES.as_ptr().cast()
                },
            },
            wl_message {
                name: c"action".as_ptr(),
                signature: c"u".as_ptr(),
                types: {
                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
                    TYPES.as_ptr().cast()
                },
            },
        ];
        MESSAGES.as_ptr()
    },
};

/// An owned wl_data_source proxy.
///
/// See the documentation of [the module][self] for the interface description.
#[derive(Clone, Eq, PartialEq)]
#[repr(transparent)]
pub struct WlDataSource {
    /// This proxy has the interface INTERFACE.
    proxy: UntypedOwnedProxy,
}

/// A borrowed wl_data_source proxy.
///
/// See the documentation of [the module][self] for the interface description.
#[derive(Eq, PartialEq)]
#[repr(transparent)]
pub struct WlDataSourceRef {
    /// This proxy has the interface INTERFACE.
    proxy: UntypedBorrowedProxy,
}

// SAFETY: WlDataSource is a transparent wrapper around UntypedOwnedProxy
unsafe impl UntypedOwnedProxyWrapper for WlDataSource {}

// SAFETY: - INTERFACE is a valid wl_interface
//         - The only invariant is that self.proxy has a compatible interface
unsafe impl OwnedProxy for WlDataSource {
    const INTERFACE: &'static str = "wl_data_source";
    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
        private::EventHandler(private::NoOpEventHandler);
    const MAX_VERSION: u32 = 3;

    type Borrowed = WlDataSourceRef;
    type Api = private::ProxyApi;
    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
}

// SAFETY: WlDataSourceRef is a transparent wrapper around UntypedBorrowedProxy
unsafe impl UntypedBorrowedProxyWrapper for WlDataSourceRef {}

// SAFETY: - The only invariant is that self.proxy has a compatible interface
unsafe impl BorrowedProxy for WlDataSourceRef {
    type Owned = WlDataSource;
}

impl Deref for WlDataSource {
    type Target = WlDataSourceRef;

    fn deref(&self) -> &Self::Target {
        proxy::low_level::deref(self)
    }
}

mod private {
    pub struct ProxyApi;

    #[allow(dead_code)]
    pub struct EventHandler<H>(pub(super) H);

    #[allow(dead_code)]
    pub struct NoOpEventHandler;
}

impl Debug for WlDataSource {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "wl_data_source#{}", self.proxy.id())
    }
}

impl Debug for WlDataSourceRef {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        write!(f, "wl_data_source#{}", self.proxy.id())
    }
}

impl PartialEq<WlDataSourceRef> for WlDataSource {
    fn eq(&self, other: &WlDataSourceRef) -> bool {
        self.proxy == other.proxy
    }
}

impl PartialEq<WlDataSource> for WlDataSourceRef {
    fn eq(&self, other: &WlDataSource) -> bool {
        self.proxy == other.proxy
    }
}

#[allow(dead_code)]
impl WlDataSource {
    /// Since when the destroy request is available.
    #[allow(dead_code)]
    pub const REQ__DESTROY__SINCE: u32 = 1;

    /// destroy the data source
    ///
    /// Destroy the data source.
    #[inline]
    pub fn destroy(&self) {
        let mut args = [];
        // SAFETY: - self.proxy has the interface INTERFACE
        //         - 1 < INTERFACE.method_count = 3
        //         - the request signature is ``
        unsafe {
            self.proxy.send_destructor(1, &mut args);
        }
    }
}

#[allow(dead_code)]
impl WlDataSourceRef {
    /// add an offered mime type
    ///
    /// This request adds a mime type to the set of mime types
    /// advertised to targets.  Can be called several times to offer
    /// multiple types.
    ///
    /// # Arguments
    ///
    /// - `mime_type`: mime type offered by the data source
    #[inline]
    pub fn offer(&self, mime_type: &str) {
        let (arg0,) = (mime_type,);
        with_cstr_cache(|cache| {
            let str0_offset = cache.len();
            cache.extend_from_slice(arg0.as_bytes());
            cache.push(0);
            let str0 = cache[str0_offset..].as_ptr().cast();
            let mut args = [wl_argument { s: str0 }];
            // SAFETY: - self.proxy has the interface INTERFACE
            //         - 0 < INTERFACE.method_count = 3
            //         - the request signature is `s`
            unsafe {
                self.proxy.send_request(0, &mut args);
            }
        })
    }

    /// set the available drag-and-drop actions
    ///
    /// Sets the actions that the source side client supports for this
    /// operation. This request may trigger wl_data_source.action and
    /// wl_data_offer.action events if the compositor needs to change the
    /// selected action.
    ///
    /// The dnd_actions argument must contain only values expressed in the
    /// wl_data_device_manager.dnd_actions enum, otherwise it will result
    /// in a protocol error.
    ///
    /// This request must be made once only, and can only be made on sources
    /// used in drag-and-drop, so it must be performed before
    /// wl_data_device.start_drag. Attempting to use the source other than
    /// for drag-and-drop will raise a protocol error.
    ///
    /// # Arguments
    ///
    /// - `dnd_actions`: actions supported by the data source
    #[inline]
    pub fn set_actions(&self, dnd_actions: WlDataDeviceManagerDndAction) {
        let (arg0,) = (dnd_actions,);
        let mut args = [wl_argument { u: arg0.0 }];
        // SAFETY: - self.proxy has the interface INTERFACE
        //         - 2 < INTERFACE.method_count = 3
        //         - the request signature is `u`
        unsafe {
            self.proxy.send_request(2, &mut args);
        }
    }
}

impl WlDataSource {
    /// Since when the target event is available.
    #[allow(dead_code)]
    pub const EVT__TARGET__SINCE: u32 = 1;

    /// Since when the send event is available.
    #[allow(dead_code)]
    pub const EVT__SEND__SINCE: u32 = 1;

    /// Since when the cancelled event is available.
    #[allow(dead_code)]
    pub const EVT__CANCELLED__SINCE: u32 = 1;

    /// Since when the dnd_drop_performed event is available.
    #[allow(dead_code)]
    pub const EVT__DND_DROP_PERFORMED__SINCE: u32 = 3;

    /// Since when the dnd_finished event is available.
    #[allow(dead_code)]
    pub const EVT__DND_FINISHED__SINCE: u32 = 3;

    /// Since when the action event is available.
    #[allow(dead_code)]
    pub const EVT__ACTION__SINCE: u32 = 3;
}

/// An event handler for [WlDataSource] proxies.
#[allow(dead_code)]
pub trait WlDataSourceEventHandler {
    type Data: 'static;

    /// a target accepts an offered mime type
    ///
    /// Sent when a target accepts pointer_focus or motion events.  If
    /// a target does not accept any of the offered types, type is NULL.
    ///
    /// Used for feedback during drag-and-drop.
    ///
    /// # Arguments
    ///
    /// - `mime_type`: mime type accepted by the target
    #[inline]
    fn target(&self, _data: &mut Self::Data, _slf: &WlDataSourceRef, mime_type: Option<&str>) {
        let _ = mime_type;
    }

    /// send the data
    ///
    /// Request for data from the client.  Send the data as the
    /// specified mime type over the passed file descriptor, then
    /// close it.
    ///
    /// # Arguments
    ///
    /// - `mime_type`: mime type for the data
    /// - `fd`: file descriptor for the data
    #[inline]
    fn send(&self, _data: &mut Self::Data, _slf: &WlDataSourceRef, mime_type: &str, fd: OwnedFd) {
        let _ = mime_type;
        let _ = fd;
    }

    /// selection was cancelled
    ///
    /// This data source is no longer valid. There are several reasons why
    /// this could happen:
    ///
    /// - The data source has been replaced by another data source.
    /// - The drag-and-drop operation was performed, but the drop destination
    ///   did not accept any of the mime types offered through
    ///   wl_data_source.target.
    /// - The drag-and-drop operation was performed, but the drop destination
    ///   did not select any of the actions present in the mask offered through
    ///   wl_data_source.action.
    /// - The drag-and-drop operation was performed but didn't happen over a
    ///   surface.
    /// - The compositor cancelled the drag-and-drop operation (e.g. compositor
    ///   dependent timeouts to avoid stale drag-and-drop transfers).
    ///
    /// The client should clean up and destroy this data source.
    ///
    /// For objects of version 2 or older, wl_data_source.cancelled will
    /// only be emitted if the data source was replaced by another data
    /// source.
    #[inline]
    fn cancelled(&self, _data: &mut Self::Data, _slf: &WlDataSourceRef) {}

    /// the drag-and-drop operation physically finished
    ///
    /// The user performed the drop action. This event does not indicate
    /// acceptance, wl_data_source.cancelled may still be emitted afterwards
    /// if the drop destination does not accept any mime type.
    ///
    /// However, this event might however not be received if the compositor
    /// cancelled the drag-and-drop operation before this event could happen.
    ///
    /// Note that the data_source may still be used in the future and should
    /// not be destroyed here.
    #[inline]
    fn dnd_drop_performed(&self, _data: &mut Self::Data, _slf: &WlDataSourceRef) {}

    /// the drag-and-drop operation concluded
    ///
    /// The drop destination finished interoperating with this data
    /// source, so the client is now free to destroy this data source and
    /// free all associated data.
    ///
    /// If the action used to perform the operation was "move", the
    /// source can now delete the transferred data.
    #[inline]
    fn dnd_finished(&self, _data: &mut Self::Data, _slf: &WlDataSourceRef) {}

    /// notify the selected action
    ///
    /// This event indicates the action selected by the compositor after
    /// matching the source/destination side actions. Only one action (or
    /// none) will be offered here.
    ///
    /// This event can be emitted multiple times during the drag-and-drop
    /// operation, mainly in response to destination side changes through
    /// wl_data_offer.set_actions, and as the data device enters/leaves
    /// surfaces.
    ///
    /// It is only possible to receive this event after
    /// wl_data_source.dnd_drop_performed if the drag-and-drop operation
    /// ended in an "ask" action, in which case the final wl_data_source.action
    /// event will happen immediately before wl_data_source.dnd_finished.
    ///
    /// Compositors may also change the selected action on the fly, mainly
    /// in response to keyboard modifier changes during the drag-and-drop
    /// operation.
    ///
    /// The most recent action received is always the valid one. The chosen
    /// action may change alongside negotiation (e.g. an "ask" action can turn
    /// into a "move" operation), so the effects of the final action must
    /// always be applied in wl_data_offer.dnd_finished.
    ///
    /// Clients can trigger cursor surface changes from this point, so
    /// they reflect the current action.
    ///
    /// # Arguments
    ///
    /// - `dnd_action`: action selected by the compositor
    #[inline]
    fn action(
        &self,
        _data: &mut Self::Data,
        _slf: &WlDataSourceRef,
        dnd_action: WlDataDeviceManagerDndAction,
    ) {
        let _ = dnd_action;
    }
}

impl WlDataSourceEventHandler for private::NoOpEventHandler {
    type Data = ();
}

// SAFETY: - INTERFACE is a valid wl_interface
//         - mutable_type always returns the same value
unsafe impl<H> EventHandler for private::EventHandler<H>
where
    H: WlDataSourceEventHandler,
{
    const WL_INTERFACE: &'static wl_interface = &INTERFACE;

    #[inline]
    fn mutable_type() -> Option<(TypeId, &'static str)> {
        let id = TypeId::of::<H::Data>();
        let name = std::any::type_name::<H::Data>();
        Some((id, name))
    }

    #[allow(unused_variables)]
    unsafe fn handle_event(
        &self,
        queue: &Queue,
        data: *mut u8,
        slf: &UntypedBorrowedProxy,
        opcode: u32,
        args: *mut wl_argument,
    ) {
        // SAFETY: This function requires that slf has the interface INTERFACE
        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlDataSourceRef>(slf) };
        // SAFETY: This function requires that data is `&mut T` where `T`
        //         has the type id returned by `Self::mutable_type`, i.e.,
        //         `T = H::Data`.
        let data: &mut H::Data = unsafe { &mut *data.cast() };
        match opcode {
            0 => {
                // SAFETY: INTERFACE requires that there are 1 arguments
                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
                // SAFETY: - INTERFACE requires that args[0] contains a string
                //         - if the pointer is not null, then it is a c string
                let arg0 = unsafe {
                    convert_optional_string_arg("wl_data_source", "mime_type", args[0].s)
                };
                self.0.target(data, slf, arg0);
            }
            1 => {
                // SAFETY: INTERFACE requires that there are 2 arguments
                let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
                // SAFETY: - INTERFACE requires that args[0] contains a string
                //         - if the pointer is not null, then it is a c string
                let arg0 = unsafe { convert_string_arg("wl_data_source", "mime_type", args[0].s) };
                // SAFETY: - INTERFACE requires that args[1] contains a file descriptor
                let arg1 = unsafe { OwnedFd::from_raw_fd(args[1].h) };
                self.0.send(data, slf, arg0, arg1);
            }
            2 => {
                self.0.cancelled(data, slf);
            }
            3 => {
                self.0.dnd_drop_performed(data, slf);
            }
            4 => {
                self.0.dnd_finished(data, slf);
            }
            5 => {
                // SAFETY: INTERFACE requires that there are 1 arguments
                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
                // SAFETY: - INTERFACE requires that args[0] contains a uint
                let arg0 = unsafe { WlDataDeviceManagerDndAction(args[0].u) };
                self.0.action(data, slf, arg0);
            }
            _ => {
                invalid_opcode("wl_data_source", opcode);
            }
        }
    }
}

impl<H> CreateEventHandler<H> for private::ProxyApi
where
    H: WlDataSourceEventHandler,
{
    type EventHandler = private::EventHandler<H>;

    #[inline]
    fn create_event_handler(handler: H) -> Self::EventHandler {
        private::EventHandler(handler)
    }
}

impl WlDataSource {
    /// Since when the error.invalid_action_mask enum variant is available.
    #[allow(dead_code)]
    pub const ENM__ERROR_INVALID_ACTION_MASK__SINCE: u32 = 1;
    /// Since when the error.invalid_source enum variant is available.
    #[allow(dead_code)]
    pub const ENM__ERROR_INVALID_SOURCE__SINCE: u32 = 1;
}

#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[allow(dead_code)]
pub struct WlDataSourceError(pub u32);

impl WlDataSourceError {
    /// action mask contains invalid values
    #[allow(dead_code)]
    pub const INVALID_ACTION_MASK: Self = Self(0);

    /// source doesn't accept this request
    #[allow(dead_code)]
    pub const INVALID_SOURCE: Self = Self(1);
}

impl Debug for WlDataSourceError {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        let name = match *self {
            Self::INVALID_ACTION_MASK => "INVALID_ACTION_MASK",
            Self::INVALID_SOURCE => "INVALID_SOURCE",
            _ => return Debug::fmt(&self.0, f),
        };
        f.write_str(name)
    }
}

/// Functional event handlers.
pub mod event_handlers {
    use super::*;

    /// Event handler for target events.
    pub struct Target<T, F>(F, PhantomData<fn(&mut T)>);
    impl<T, F> WlDataSourceEventHandler for Target<T, F>
    where
        T: 'static,
        F: Fn(&mut T, &WlDataSourceRef, Option<&str>),
    {
        type Data = T;

        #[inline]
        fn target(&self, _data: &mut T, _slf: &WlDataSourceRef, mime_type: Option<&str>) {
            self.0(_data, _slf, mime_type)
        }
    }

    /// Event handler for send events.
    pub struct Send<T, F>(F, PhantomData<fn(&mut T)>);
    impl<T, F> WlDataSourceEventHandler for Send<T, F>
    where
        T: 'static,
        F: Fn(&mut T, &WlDataSourceRef, &str, OwnedFd),
    {
        type Data = T;

        #[inline]
        fn send(&self, _data: &mut T, _slf: &WlDataSourceRef, mime_type: &str, fd: OwnedFd) {
            self.0(_data, _slf, mime_type, fd)
        }
    }

    /// Event handler for cancelled events.
    pub struct Cancelled<T, F>(F, PhantomData<fn(&mut T)>);
    impl<T, F> WlDataSourceEventHandler for Cancelled<T, F>
    where
        T: 'static,
        F: Fn(&mut T, &WlDataSourceRef),
    {
        type Data = T;

        #[inline]
        fn cancelled(&self, _data: &mut T, _slf: &WlDataSourceRef) {
            self.0(_data, _slf)
        }
    }

    /// Event handler for dnd_drop_performed events.
    pub struct DndDropPerformed<T, F>(F, PhantomData<fn(&mut T)>);
    impl<T, F> WlDataSourceEventHandler for DndDropPerformed<T, F>
    where
        T: 'static,
        F: Fn(&mut T, &WlDataSourceRef),
    {
        type Data = T;

        #[inline]
        fn dnd_drop_performed(&self, _data: &mut T, _slf: &WlDataSourceRef) {
            self.0(_data, _slf)
        }
    }

    /// Event handler for dnd_finished events.
    pub struct DndFinished<T, F>(F, PhantomData<fn(&mut T)>);
    impl<T, F> WlDataSourceEventHandler for DndFinished<T, F>
    where
        T: 'static,
        F: Fn(&mut T, &WlDataSourceRef),
    {
        type Data = T;

        #[inline]
        fn dnd_finished(&self, _data: &mut T, _slf: &WlDataSourceRef) {
            self.0(_data, _slf)
        }
    }

    /// Event handler for action events.
    pub struct Action<T, F>(F, PhantomData<fn(&mut T)>);
    impl<T, F> WlDataSourceEventHandler for Action<T, F>
    where
        T: 'static,
        F: Fn(&mut T, &WlDataSourceRef, WlDataDeviceManagerDndAction),
    {
        type Data = T;

        #[inline]
        fn action(
            &self,
            _data: &mut T,
            _slf: &WlDataSourceRef,
            dnd_action: WlDataDeviceManagerDndAction,
        ) {
            self.0(_data, _slf, dnd_action)
        }
    }

    impl WlDataSource {
        /// Creates an event handler for target events.
        ///
        /// The event handler ignores all other events.
        #[allow(dead_code)]
        pub fn on_target<T, F>(f: F) -> Target<T, F>
        where
            T: 'static,
            F: Fn(&mut T, &WlDataSourceRef, Option<&str>),
        {
            Target(f, PhantomData)
        }

        /// Creates an event handler for send events.
        ///
        /// The event handler ignores all other events.
        #[allow(dead_code)]
        pub fn on_send<T, F>(f: F) -> Send<T, F>
        where
            T: 'static,
            F: Fn(&mut T, &WlDataSourceRef, &str, OwnedFd),
        {
            Send(f, PhantomData)
        }

        /// Creates an event handler for cancelled events.
        ///
        /// The event handler ignores all other events.
        #[allow(dead_code)]
        pub fn on_cancelled<T, F>(f: F) -> Cancelled<T, F>
        where
            T: 'static,
            F: Fn(&mut T, &WlDataSourceRef),
        {
            Cancelled(f, PhantomData)
        }

        /// Creates an event handler for dnd_drop_performed events.
        ///
        /// The event handler ignores all other events.
        #[allow(dead_code)]
        pub fn on_dnd_drop_performed<T, F>(f: F) -> DndDropPerformed<T, F>
        where
            T: 'static,
            F: Fn(&mut T, &WlDataSourceRef),
        {
            DndDropPerformed(f, PhantomData)
        }

        /// Creates an event handler for dnd_finished events.
        ///
        /// The event handler ignores all other events.
        #[allow(dead_code)]
        pub fn on_dnd_finished<T, F>(f: F) -> DndFinished<T, F>
        where
            T: 'static,
            F: Fn(&mut T, &WlDataSourceRef),
        {
            DndFinished(f, PhantomData)
        }

        /// Creates an event handler for action events.
        ///
        /// The event handler ignores all other events.
        #[allow(dead_code)]
        pub fn on_action<T, F>(f: F) -> Action<T, F>
        where
            T: 'static,
            F: Fn(&mut T, &WlDataSourceRef, WlDataDeviceManagerDndAction),
        {
            Action(f, PhantomData)
        }
    }
}