async_roundtrip/common/protocols_data/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 type Data: 'static;
357
358 /// introduce a new wl_data_offer
359 ///
360 /// The data_offer event introduces a new wl_data_offer object,
361 /// which will subsequently be used in either the
362 /// data_device.enter event (for drag-and-drop) or the
363 /// data_device.selection event (for selections). Immediately
364 /// following the data_device.data_offer event, the new data_offer
365 /// object will send out data_offer.offer events to describe the
366 /// mime types it offers.
367 ///
368 /// # Arguments
369 ///
370 /// - `id`: the new data_offer object
371 #[inline]
372 fn data_offer(&self, _data: &mut Self::Data, _slf: &WlDataDeviceRef, id: WlDataOffer) {
373 let _ = id;
374 }
375
376 /// initiate drag-and-drop session
377 ///
378 /// This event is sent when an active drag-and-drop pointer enters
379 /// a surface owned by the client. The position of the pointer at
380 /// enter time is provided by the x and y arguments, in surface-local
381 /// coordinates.
382 ///
383 /// # Arguments
384 ///
385 /// - `serial`: serial number of the enter event
386 /// - `surface`: client surface entered
387 /// - `x`: surface-local x coordinate
388 /// - `y`: surface-local y coordinate
389 /// - `id`: source data_offer object
390 ///
391 /// All borrowed proxies passed to this function are guaranteed to be
392 /// immutable and non-null.
393 #[inline]
394 fn enter(
395 &self,
396 _data: &mut Self::Data,
397 _slf: &WlDataDeviceRef,
398 serial: u32,
399 surface: Option<&WlSurfaceRef>,
400 x: Fixed,
401 y: Fixed,
402 id: Option<&WlDataOfferRef>,
403 ) {
404 let _ = serial;
405 let _ = surface;
406 let _ = x;
407 let _ = y;
408 let _ = id;
409 }
410
411 /// end drag-and-drop session
412 ///
413 /// This event is sent when the drag-and-drop pointer leaves the
414 /// surface and the session ends. The client must destroy the
415 /// wl_data_offer introduced at enter time at this point.
416 #[inline]
417 fn leave(&self, _data: &mut Self::Data, _slf: &WlDataDeviceRef) {}
418
419 /// drag-and-drop session motion
420 ///
421 /// This event is sent when the drag-and-drop pointer moves within
422 /// the currently focused surface. The new position of the pointer
423 /// is provided by the x and y arguments, in surface-local
424 /// coordinates.
425 ///
426 /// # Arguments
427 ///
428 /// - `time`: timestamp with millisecond granularity
429 /// - `x`: surface-local x coordinate
430 /// - `y`: surface-local y coordinate
431 #[inline]
432 fn motion(
433 &self,
434 _data: &mut Self::Data,
435 _slf: &WlDataDeviceRef,
436 time: u32,
437 x: Fixed,
438 y: Fixed,
439 ) {
440 let _ = time;
441 let _ = x;
442 let _ = y;
443 }
444
445 /// end drag-and-drop session successfully
446 ///
447 /// The event is sent when a drag-and-drop operation is ended
448 /// because the implicit grab is removed.
449 ///
450 /// The drag-and-drop destination is expected to honor the last action
451 /// received through wl_data_offer.action, if the resulting action is
452 /// "copy" or "move", the destination can still perform
453 /// wl_data_offer.receive requests, and is expected to end all
454 /// transfers with a wl_data_offer.finish request.
455 ///
456 /// If the resulting action is "ask", the action will not be considered
457 /// final. The drag-and-drop destination is expected to perform one last
458 /// wl_data_offer.set_actions request, or wl_data_offer.destroy in order
459 /// to cancel the operation.
460 #[inline]
461 fn drop(&self, _data: &mut Self::Data, _slf: &WlDataDeviceRef) {}
462
463 /// advertise new selection
464 ///
465 /// The selection event is sent out to notify the client of a new
466 /// wl_data_offer for the selection for this device. The
467 /// data_device.data_offer and the data_offer.offer events are
468 /// sent out immediately before this event to introduce the data
469 /// offer object. The selection event is sent to a client
470 /// immediately before receiving keyboard focus and when a new
471 /// selection is set while the client has keyboard focus. The
472 /// data_offer is valid until a new data_offer or NULL is received
473 /// or until the client loses keyboard focus. Switching surface with
474 /// keyboard focus within the same client doesn't mean a new selection
475 /// will be sent. The client must destroy the previous selection
476 /// data_offer, if any, upon receiving this event.
477 ///
478 /// # Arguments
479 ///
480 /// - `id`: selection data_offer object
481 ///
482 /// All borrowed proxies passed to this function are guaranteed to be
483 /// immutable and non-null.
484 #[inline]
485 fn selection(
486 &self,
487 _data: &mut Self::Data,
488 _slf: &WlDataDeviceRef,
489 id: Option<&WlDataOfferRef>,
490 ) {
491 let _ = id;
492 }
493}
494
495impl WlDataDeviceEventHandler for private::NoOpEventHandler {
496 type Data = ();
497}
498
499// SAFETY: - INTERFACE is a valid wl_interface
500// - mutable_type always returns the same value
501unsafe impl<H> EventHandler for private::EventHandler<H>
502where
503 H: WlDataDeviceEventHandler,
504{
505 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
506
507 #[inline]
508 fn mutable_type() -> Option<(TypeId, &'static str)> {
509 let id = TypeId::of::<H::Data>();
510 let name = std::any::type_name::<H::Data>();
511 Some((id, name))
512 }
513
514 #[allow(unused_variables)]
515 unsafe fn handle_event(
516 &self,
517 queue: &Queue,
518 data: *mut u8,
519 slf: &UntypedBorrowedProxy,
520 opcode: u32,
521 args: *mut wl_argument,
522 ) {
523 // SAFETY: This function requires that slf has the interface INTERFACE
524 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlDataDeviceRef>(slf) };
525 // SAFETY: This function requires that data is `&mut T` where `T`
526 // has the type id returned by `Self::mutable_type`, i.e.,
527 // `T = H::Data`.
528 let data: &mut H::Data = unsafe { &mut *data.cast() };
529 match opcode {
530 0 => {
531 // SAFETY: INTERFACE requires that there are 1 arguments
532 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
533 // SAFETY: - INTERFACE requires that args[0] contains an object
534 // - ownership is transferred to this function
535 // - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
536 let arg0 = unsafe {
537 UntypedOwnedProxy::from_plain_wl_proxy(
538 queue,
539 NonNull::new_unchecked(args[0].o.cast()),
540 WlDataOffer::WL_INTERFACE,
541 )
542 };
543 // SAFETY: - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
544 let arg0 = unsafe { proxy::low_level::from_untyped_owned::<WlDataOffer>(arg0) };
545 self.0.data_offer(data, slf, arg0);
546 }
547 1 => {
548 // SAFETY: INTERFACE requires that there are 5 arguments
549 let args = unsafe { &*args.cast::<[wl_argument; 5]>() };
550 // SAFETY: - INTERFACE requires that args[0] contains a uint
551 let arg0 = unsafe { args[0].u };
552 // SAFETY: - INTERFACE requires that args[1] contains an object
553 let arg1 = unsafe {
554 if let Some(p) = NonNull::new(args[1].o.cast()) {
555 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
556 } else {
557 None
558 }
559 };
560 // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
561 let arg1 = arg1.as_ref().map(|arg1| unsafe {
562 proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
563 });
564 // SAFETY: - INTERFACE requires that args[2] contains a fixed
565 let arg2 = unsafe { Fixed::from_wire(args[2].f) };
566 // SAFETY: - INTERFACE requires that args[3] contains a fixed
567 let arg3 = unsafe { Fixed::from_wire(args[3].f) };
568 // SAFETY: - INTERFACE requires that args[4] contains an object
569 let arg4 = unsafe {
570 if let Some(p) = NonNull::new(args[4].o.cast()) {
571 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
572 } else {
573 None
574 }
575 };
576 // SAFETY: - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
577 let arg4 = arg4.as_ref().map(|arg4| unsafe {
578 proxy::low_level::from_untyped_borrowed::<WlDataOfferRef>(arg4)
579 });
580 self.0.enter(data, slf, arg0, arg1, arg2, arg3, arg4);
581 }
582 2 => {
583 self.0.leave(data, slf);
584 }
585 3 => {
586 // SAFETY: INTERFACE requires that there are 3 arguments
587 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
588 // SAFETY: - INTERFACE requires that args[0] contains a uint
589 let arg0 = unsafe { args[0].u };
590 // SAFETY: - INTERFACE requires that args[1] contains a fixed
591 let arg1 = unsafe { Fixed::from_wire(args[1].f) };
592 // SAFETY: - INTERFACE requires that args[2] contains a fixed
593 let arg2 = unsafe { Fixed::from_wire(args[2].f) };
594 self.0.motion(data, slf, arg0, arg1, arg2);
595 }
596 4 => {
597 self.0.drop(data, slf);
598 }
599 5 => {
600 // SAFETY: INTERFACE requires that there are 1 arguments
601 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
602 // SAFETY: - INTERFACE requires that args[0] contains an object
603 let arg0 = unsafe {
604 if let Some(p) = NonNull::new(args[0].o.cast()) {
605 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
606 } else {
607 None
608 }
609 };
610 // SAFETY: - INTERFACE requires that the object has the interface WlDataOffer::WL_INTERFACE
611 let arg0 = arg0.as_ref().map(|arg0| unsafe {
612 proxy::low_level::from_untyped_borrowed::<WlDataOfferRef>(arg0)
613 });
614 self.0.selection(data, slf, arg0);
615 }
616 _ => {
617 invalid_opcode("wl_data_device", opcode);
618 }
619 }
620 }
621}
622
623impl<H> CreateEventHandler<H> for private::ProxyApi
624where
625 H: WlDataDeviceEventHandler,
626{
627 type EventHandler = private::EventHandler<H>;
628
629 #[inline]
630 fn create_event_handler(handler: H) -> Self::EventHandler {
631 private::EventHandler(handler)
632 }
633}
634
635impl WlDataDevice {
636 /// Since when the error.role enum variant is available.
637 #[allow(dead_code)]
638 pub const ENM__ERROR_ROLE__SINCE: u32 = 1;
639 /// Since when the error.used_source enum variant is available.
640 #[allow(dead_code)]
641 pub const ENM__ERROR_USED_SOURCE__SINCE: u32 = 1;
642}
643
644#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
645#[allow(dead_code)]
646pub struct WlDataDeviceError(pub u32);
647
648impl WlDataDeviceError {
649 /// given wl_surface has another role
650 #[allow(dead_code)]
651 pub const ROLE: Self = Self(0);
652
653 /// source has already been used
654 #[allow(dead_code)]
655 pub const USED_SOURCE: Self = Self(1);
656}
657
658impl Debug for WlDataDeviceError {
659 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
660 let name = match *self {
661 Self::ROLE => "ROLE",
662 Self::USED_SOURCE => "USED_SOURCE",
663 _ => return Debug::fmt(&self.0, f),
664 };
665 f.write_str(name)
666 }
667}
668
669/// Functional event handlers.
670pub mod event_handlers {
671 use super::*;
672
673 /// Event handler for data_offer events.
674 pub struct DataOffer<T, F>(F, PhantomData<fn(&mut T)>);
675 impl<T, F> WlDataDeviceEventHandler for DataOffer<T, F>
676 where
677 T: 'static,
678 F: Fn(&mut T, &WlDataDeviceRef, WlDataOffer),
679 {
680 type Data = T;
681
682 #[inline]
683 fn data_offer(&self, _data: &mut T, _slf: &WlDataDeviceRef, id: WlDataOffer) {
684 self.0(_data, _slf, id)
685 }
686 }
687
688 /// Event handler for enter events.
689 pub struct Enter<T, F>(F, PhantomData<fn(&mut T)>);
690 impl<T, F> WlDataDeviceEventHandler for Enter<T, F>
691 where
692 T: 'static,
693 F: Fn(
694 &mut T,
695 &WlDataDeviceRef,
696 u32,
697 Option<&WlSurfaceRef>,
698 Fixed,
699 Fixed,
700 Option<&WlDataOfferRef>,
701 ),
702 {
703 type Data = T;
704
705 #[inline]
706 fn enter(
707 &self,
708 _data: &mut T,
709 _slf: &WlDataDeviceRef,
710 serial: u32,
711 surface: Option<&WlSurfaceRef>,
712 x: Fixed,
713 y: Fixed,
714 id: Option<&WlDataOfferRef>,
715 ) {
716 self.0(_data, _slf, serial, surface, x, y, id)
717 }
718 }
719
720 /// Event handler for leave events.
721 pub struct Leave<T, F>(F, PhantomData<fn(&mut T)>);
722 impl<T, F> WlDataDeviceEventHandler for Leave<T, F>
723 where
724 T: 'static,
725 F: Fn(&mut T, &WlDataDeviceRef),
726 {
727 type Data = T;
728
729 #[inline]
730 fn leave(&self, _data: &mut T, _slf: &WlDataDeviceRef) {
731 self.0(_data, _slf)
732 }
733 }
734
735 /// Event handler for motion events.
736 pub struct Motion<T, F>(F, PhantomData<fn(&mut T)>);
737 impl<T, F> WlDataDeviceEventHandler for Motion<T, F>
738 where
739 T: 'static,
740 F: Fn(&mut T, &WlDataDeviceRef, u32, Fixed, Fixed),
741 {
742 type Data = T;
743
744 #[inline]
745 fn motion(&self, _data: &mut T, _slf: &WlDataDeviceRef, time: u32, x: Fixed, y: Fixed) {
746 self.0(_data, _slf, time, x, y)
747 }
748 }
749
750 /// Event handler for drop events.
751 pub struct Drop<T, F>(F, PhantomData<fn(&mut T)>);
752 impl<T, F> WlDataDeviceEventHandler for Drop<T, F>
753 where
754 T: 'static,
755 F: Fn(&mut T, &WlDataDeviceRef),
756 {
757 type Data = T;
758
759 #[inline]
760 fn drop(&self, _data: &mut T, _slf: &WlDataDeviceRef) {
761 self.0(_data, _slf)
762 }
763 }
764
765 /// Event handler for selection events.
766 pub struct Selection<T, F>(F, PhantomData<fn(&mut T)>);
767 impl<T, F> WlDataDeviceEventHandler for Selection<T, F>
768 where
769 T: 'static,
770 F: Fn(&mut T, &WlDataDeviceRef, Option<&WlDataOfferRef>),
771 {
772 type Data = T;
773
774 #[inline]
775 fn selection(&self, _data: &mut T, _slf: &WlDataDeviceRef, id: Option<&WlDataOfferRef>) {
776 self.0(_data, _slf, id)
777 }
778 }
779
780 impl WlDataDevice {
781 /// Creates an event handler for data_offer events.
782 ///
783 /// The event handler ignores all other events.
784 #[allow(dead_code)]
785 pub fn on_data_offer<T, F>(f: F) -> DataOffer<T, F>
786 where
787 T: 'static,
788 F: Fn(&mut T, &WlDataDeviceRef, WlDataOffer),
789 {
790 DataOffer(f, PhantomData)
791 }
792
793 /// Creates an event handler for enter events.
794 ///
795 /// The event handler ignores all other events.
796 #[allow(dead_code)]
797 pub fn on_enter<T, F>(f: F) -> Enter<T, F>
798 where
799 T: 'static,
800 F: Fn(
801 &mut T,
802 &WlDataDeviceRef,
803 u32,
804 Option<&WlSurfaceRef>,
805 Fixed,
806 Fixed,
807 Option<&WlDataOfferRef>,
808 ),
809 {
810 Enter(f, PhantomData)
811 }
812
813 /// Creates an event handler for leave events.
814 ///
815 /// The event handler ignores all other events.
816 #[allow(dead_code)]
817 pub fn on_leave<T, F>(f: F) -> Leave<T, F>
818 where
819 T: 'static,
820 F: Fn(&mut T, &WlDataDeviceRef),
821 {
822 Leave(f, PhantomData)
823 }
824
825 /// Creates an event handler for motion events.
826 ///
827 /// The event handler ignores all other events.
828 #[allow(dead_code)]
829 pub fn on_motion<T, F>(f: F) -> Motion<T, F>
830 where
831 T: 'static,
832 F: Fn(&mut T, &WlDataDeviceRef, u32, Fixed, Fixed),
833 {
834 Motion(f, PhantomData)
835 }
836
837 /// Creates an event handler for drop events.
838 ///
839 /// The event handler ignores all other events.
840 #[allow(dead_code)]
841 pub fn on_drop<T, F>(f: F) -> Drop<T, F>
842 where
843 T: 'static,
844 F: Fn(&mut T, &WlDataDeviceRef),
845 {
846 Drop(f, PhantomData)
847 }
848
849 /// Creates an event handler for selection events.
850 ///
851 /// The event handler ignores all other events.
852 #[allow(dead_code)]
853 pub fn on_selection<T, F>(f: F) -> Selection<T, F>
854 where
855 T: 'static,
856 F: Fn(&mut T, &WlDataDeviceRef, Option<&WlDataOfferRef>),
857 {
858 Selection(f, PhantomData)
859 }
860 }
861}