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