Skip to main content

get_registry/common/protocols_data/wayland/
wl_data_device_manager.rs

1//! data transfer interface
2//!
3//! The wl_data_device_manager is a singleton global object that
4//! provides access to inter-client data transfer mechanisms such as
5//! copy-and-paste and drag-and-drop.  These mechanisms are tied to
6//! a wl_seat and this interface lets a client get a wl_data_device
7//! corresponding to a wl_seat.
8//!
9//! Depending on the version bound, the objects created from the bound
10//! wl_data_device_manager object will have different requirements for
11//! functioning properly. See wl_data_source.set_actions,
12//! wl_data_offer.accept and wl_data_offer.finish for details.
13
14use super::super::all_types::*;
15use ::wl_client::builder::prelude::*;
16
17static INTERFACE: wl_interface = wl_interface {
18    name: c"wl_data_device_manager".as_ptr(),
19    version: 3,
20    method_count: 2,
21    methods: {
22        static MESSAGES: [wl_message; 2] = [
23            wl_message {
24                name: c"create_data_source".as_ptr(),
25                signature: c"n".as_ptr(),
26                types: {
27                    static TYPES: [Option<&'static wl_interface>; 1] =
28                        [Some(WlDataSource::WL_INTERFACE)];
29                    TYPES.as_ptr().cast()
30                },
31            },
32            wl_message {
33                name: c"get_data_device".as_ptr(),
34                signature: c"no".as_ptr(),
35                types: {
36                    static TYPES: [Option<&'static wl_interface>; 2] =
37                        [Some(WlDataDevice::WL_INTERFACE), Some(WlSeat::WL_INTERFACE)];
38                    TYPES.as_ptr().cast()
39                },
40            },
41        ];
42        MESSAGES.as_ptr()
43    },
44    event_count: 0,
45    events: ptr::null(),
46};
47
48/// An owned wl_data_device_manager proxy.
49///
50/// See the documentation of [the module][self] for the interface description.
51#[derive(Clone, Eq, PartialEq)]
52#[repr(transparent)]
53pub struct WlDataDeviceManager {
54    /// This proxy has the interface INTERFACE.
55    proxy: UntypedOwnedProxy,
56}
57
58/// A borrowed wl_data_device_manager proxy.
59///
60/// See the documentation of [the module][self] for the interface description.
61#[derive(Eq, PartialEq)]
62#[repr(transparent)]
63pub struct WlDataDeviceManagerRef {
64    /// This proxy has the interface INTERFACE.
65    proxy: UntypedBorrowedProxy,
66}
67
68// SAFETY: WlDataDeviceManager is a transparent wrapper around UntypedOwnedProxy
69unsafe impl UntypedOwnedProxyWrapper for WlDataDeviceManager {}
70
71// SAFETY: - INTERFACE is a valid wl_interface
72//         - The only invariant is that self.proxy has a compatible interface
73unsafe impl OwnedProxy for WlDataDeviceManager {
74    const INTERFACE: &'static str = "wl_data_device_manager";
75    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
76    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
77        private::EventHandler(private::NoOpEventHandler);
78    const MAX_VERSION: u32 = 3;
79
80    type Borrowed = WlDataDeviceManagerRef;
81    type Api = private::ProxyApi;
82    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
83}
84
85// SAFETY: WlDataDeviceManagerRef is a transparent wrapper around UntypedBorrowedProxy
86unsafe impl UntypedBorrowedProxyWrapper for WlDataDeviceManagerRef {}
87
88// SAFETY: - The only invariant is that self.proxy has a compatible interface
89unsafe impl BorrowedProxy for WlDataDeviceManagerRef {
90    type Owned = WlDataDeviceManager;
91}
92
93impl Deref for WlDataDeviceManager {
94    type Target = WlDataDeviceManagerRef;
95
96    fn deref(&self) -> &Self::Target {
97        proxy::low_level::deref(self)
98    }
99}
100
101mod private {
102    pub struct ProxyApi;
103
104    #[allow(dead_code)]
105    pub struct EventHandler<H>(pub(super) H);
106
107    #[allow(dead_code)]
108    pub struct NoOpEventHandler;
109}
110
111impl Debug for WlDataDeviceManager {
112    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
113        write!(f, "wl_data_device_manager#{}", self.proxy.id())
114    }
115}
116
117impl Debug for WlDataDeviceManagerRef {
118    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
119        write!(f, "wl_data_device_manager#{}", self.proxy.id())
120    }
121}
122
123impl PartialEq<WlDataDeviceManagerRef> for WlDataDeviceManager {
124    fn eq(&self, other: &WlDataDeviceManagerRef) -> bool {
125        self.proxy == other.proxy
126    }
127}
128
129impl PartialEq<WlDataDeviceManager> for WlDataDeviceManagerRef {
130    fn eq(&self, other: &WlDataDeviceManager) -> bool {
131        self.proxy == other.proxy
132    }
133}
134
135#[allow(dead_code)]
136impl WlDataDeviceManager {
137    /// Since when the create_data_source request is available.
138    #[allow(dead_code)]
139    pub const REQ__CREATE_DATA_SOURCE__SINCE: u32 = 1;
140
141    /// Since when the get_data_device request is available.
142    #[allow(dead_code)]
143    pub const REQ__GET_DATA_DEVICE__SINCE: u32 = 1;
144}
145
146#[allow(dead_code)]
147impl WlDataDeviceManager {
148    /// create a new data source
149    ///
150    /// Create a new data source.
151    #[inline]
152    pub fn create_data_source(&self) -> WlDataSource {
153        let mut args = [wl_argument { n: 0 }];
154        // SAFETY: - self.proxy has the interface INTERFACE
155        //         - 0 < INTERFACE.method_count = 2
156        //         - the request signature is `n`
157        //         - OwnedProxy::WL_INTERFACE is always a valid interface
158        let data = unsafe {
159            self.proxy
160                .send_constructor::<false>(0, &mut args, WlDataSource::WL_INTERFACE, None)
161        };
162        // SAFETY: data has the interface WlDataSource::WL_INTERFACE
163        unsafe { proxy::low_level::from_untyped_owned(data) }
164    }
165
166    /// create a new data device
167    ///
168    /// Create a new data device for a given seat.
169    ///
170    /// # Arguments
171    ///
172    /// - `seat`: seat associated with the data device
173    #[inline]
174    pub fn get_data_device(&self, seat: &WlSeatRef) -> WlDataDevice {
175        let (arg1,) = (seat,);
176        let obj1_lock = proxy::lock(arg1);
177        let obj1 = check_argument_proxy("seat", obj1_lock.wl_proxy());
178        let mut args = [wl_argument { n: 0 }, wl_argument { o: obj1 }];
179        // SAFETY: - self.proxy has the interface INTERFACE
180        //         - 1 < INTERFACE.method_count = 2
181        //         - the request signature is `no`
182        //         - OwnedProxy::WL_INTERFACE is always a valid interface
183        let data = unsafe {
184            self.proxy
185                .send_constructor::<false>(1, &mut args, WlDataDevice::WL_INTERFACE, None)
186        };
187        // SAFETY: data has the interface WlDataDevice::WL_INTERFACE
188        unsafe { proxy::low_level::from_untyped_owned(data) }
189    }
190}
191
192#[allow(dead_code)]
193impl WlDataDeviceManagerRef {
194    /// create a new data source
195    ///
196    /// Create a new data source.
197    ///
198    /// # Arguments
199    ///
200    /// - `_queue`: The queue that the returned proxy is assigned to.
201    #[inline]
202    pub fn create_data_source(&self, _queue: &Queue) -> WlDataSource {
203        let mut args = [wl_argument { n: 0 }];
204        // SAFETY: - self.proxy has the interface INTERFACE
205        //         - 0 < INTERFACE.method_count = 2
206        //         - the request signature is `n`
207        //         - OwnedProxy::WL_INTERFACE is always a valid interface
208        let data = unsafe {
209            self.proxy
210                .send_constructor(_queue, 0, &mut args, WlDataSource::WL_INTERFACE, None)
211        };
212        // SAFETY: data has the interface WlDataSource::WL_INTERFACE
213        unsafe { proxy::low_level::from_untyped_owned(data) }
214    }
215
216    /// create a new data device
217    ///
218    /// Create a new data device for a given seat.
219    ///
220    /// # Arguments
221    ///
222    /// - `_queue`: The queue that the returned proxy is assigned to.
223    /// - `seat`: seat associated with the data device
224    #[inline]
225    pub fn get_data_device(&self, _queue: &Queue, seat: &WlSeatRef) -> WlDataDevice {
226        let (arg1,) = (seat,);
227        let obj1_lock = proxy::lock(arg1);
228        let obj1 = check_argument_proxy("seat", obj1_lock.wl_proxy());
229        let mut args = [wl_argument { n: 0 }, wl_argument { o: obj1 }];
230        // SAFETY: - self.proxy has the interface INTERFACE
231        //         - 1 < INTERFACE.method_count = 2
232        //         - the request signature is `no`
233        //         - OwnedProxy::WL_INTERFACE is always a valid interface
234        let data = unsafe {
235            self.proxy
236                .send_constructor(_queue, 1, &mut args, WlDataDevice::WL_INTERFACE, None)
237        };
238        // SAFETY: data has the interface WlDataDevice::WL_INTERFACE
239        unsafe { proxy::low_level::from_untyped_owned(data) }
240    }
241}
242
243/// An event handler for [WlDataDeviceManager] proxies.
244#[allow(dead_code)]
245pub trait WlDataDeviceManagerEventHandler {
246    type Data: 'static;
247}
248
249impl WlDataDeviceManagerEventHandler for private::NoOpEventHandler {
250    type Data = ();
251}
252
253// SAFETY: - INTERFACE is a valid wl_interface
254//         - mutable_type always returns the same value
255unsafe impl<H> EventHandler for private::EventHandler<H>
256where
257    H: WlDataDeviceManagerEventHandler,
258{
259    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
260
261    #[inline]
262    fn mutable_type() -> Option<(TypeId, &'static str)> {
263        let id = TypeId::of::<H::Data>();
264        let name = std::any::type_name::<H::Data>();
265        Some((id, name))
266    }
267
268    #[allow(unused_variables)]
269    unsafe fn handle_event(
270        &self,
271        queue: &Queue,
272        data: *mut u8,
273        slf: &UntypedBorrowedProxy,
274        opcode: u32,
275        args: *mut wl_argument,
276    ) {
277        invalid_opcode("wl_data_device_manager", opcode);
278    }
279}
280
281impl<H> CreateEventHandler<H> for private::ProxyApi
282where
283    H: WlDataDeviceManagerEventHandler,
284{
285    type EventHandler = private::EventHandler<H>;
286
287    #[inline]
288    fn create_event_handler(handler: H) -> Self::EventHandler {
289        private::EventHandler(handler)
290    }
291}
292
293impl WlDataDeviceManager {
294    /// Since when the dnd_action.none enum variant is available.
295    #[allow(dead_code)]
296    pub const ENM__DND_ACTION_NONE__SINCE: u32 = 1;
297    /// Since when the dnd_action.copy enum variant is available.
298    #[allow(dead_code)]
299    pub const ENM__DND_ACTION_COPY__SINCE: u32 = 1;
300    /// Since when the dnd_action.move enum variant is available.
301    #[allow(dead_code)]
302    pub const ENM__DND_ACTION_MOVE__SINCE: u32 = 1;
303    /// Since when the dnd_action.ask enum variant is available.
304    #[allow(dead_code)]
305    pub const ENM__DND_ACTION_ASK__SINCE: u32 = 1;
306}
307
308/// drag and drop actions
309///
310/// This is a bitmask of the available/preferred actions in a
311/// drag-and-drop operation.
312///
313/// In the compositor, the selected action is a result of matching the
314/// actions offered by the source and destination sides.  "action" events
315/// with a "none" action will be sent to both source and destination if
316/// there is no match. All further checks will effectively happen on
317/// (source actions ∩ destination actions).
318///
319/// In addition, compositors may also pick different actions in
320/// reaction to key modifiers being pressed. One common design that
321/// is used in major toolkits (and the behavior recommended for
322/// compositors) is:
323///
324/// - If no modifiers are pressed, the first match (in bit order)
325///   will be used.
326/// - Pressing Shift selects "move", if enabled in the mask.
327/// - Pressing Control selects "copy", if enabled in the mask.
328///
329/// Behavior beyond that is considered implementation-dependent.
330/// Compositors may for example bind other modifiers (like Alt/Meta)
331/// or drags initiated with other buttons than BTN_LEFT to specific
332/// actions (e.g. "ask").
333#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
334#[allow(dead_code)]
335pub struct WlDataDeviceManagerDndAction(pub u32);
336
337/// An iterator over the set bits in a [WlDataDeviceManagerDndAction].
338///
339/// You can construct this with the `IntoIterator` implementation of `WlDataDeviceManagerDndAction`.
340#[derive(Clone, Debug)]
341#[allow(dead_code)]
342pub struct WlDataDeviceManagerDndActionIter(pub u32);
343
344impl WlDataDeviceManagerDndAction {
345    /// no action
346    #[allow(dead_code)]
347    pub const NONE: Self = Self(0);
348
349    /// copy action
350    #[allow(dead_code)]
351    pub const COPY: Self = Self(1);
352
353    /// move action
354    #[allow(dead_code)]
355    pub const MOVE: Self = Self(2);
356
357    /// ask action
358    #[allow(dead_code)]
359    pub const ASK: Self = Self(4);
360}
361
362#[allow(dead_code)]
363impl WlDataDeviceManagerDndAction {
364    #[inline]
365    pub const fn empty() -> Self {
366        Self(0)
367    }
368
369    #[inline]
370    #[must_use]
371    pub const fn is_empty(self) -> bool {
372        self.0 == 0
373    }
374
375    #[inline]
376    #[must_use]
377    pub const fn contains(self, other: Self) -> bool {
378        self.0 & other.0 == other.0
379    }
380
381    #[inline]
382    #[must_use]
383    pub const fn intersects(self, other: Self) -> bool {
384        self.0 & other.0 != 0
385    }
386
387    #[inline]
388    pub const fn insert(&mut self, other: Self) {
389        *self = self.union(other);
390    }
391
392    #[inline]
393    pub const fn remove(&mut self, other: Self) {
394        *self = self.difference(other);
395    }
396
397    #[inline]
398    pub const fn toggle(&mut self, other: Self) {
399        *self = self.symmetric_difference(other);
400    }
401
402    #[inline]
403    pub const fn set(&mut self, other: Self, value: bool) {
404        if value {
405            self.insert(other);
406        } else {
407            self.remove(other);
408        }
409    }
410
411    #[inline]
412    #[must_use]
413    pub const fn intersection(self, other: Self) -> Self {
414        Self(self.0 & other.0)
415    }
416
417    #[inline]
418    #[must_use]
419    pub const fn union(self, other: Self) -> Self {
420        Self(self.0 | other.0)
421    }
422
423    #[inline]
424    #[must_use]
425    pub const fn difference(self, other: Self) -> Self {
426        Self(self.0 & !other.0)
427    }
428
429    #[inline]
430    #[must_use]
431    pub const fn complement(self) -> Self {
432        Self(!self.0)
433    }
434
435    #[inline]
436    #[must_use]
437    pub const fn symmetric_difference(self, other: Self) -> Self {
438        Self(self.0 ^ other.0)
439    }
440
441    #[inline]
442    pub const fn all_known() -> Self {
443        #[allow(clippy::eq_op, clippy::identity_op)]
444        Self(0 | 0 | 1 | 2 | 4)
445    }
446}
447
448impl Iterator for WlDataDeviceManagerDndActionIter {
449    type Item = WlDataDeviceManagerDndAction;
450
451    fn next(&mut self) -> Option<Self::Item> {
452        if self.0 == 0 {
453            return None;
454        }
455        let bit = 1 << self.0.trailing_zeros();
456        self.0 &= !bit;
457        Some(WlDataDeviceManagerDndAction(bit))
458    }
459}
460
461impl IntoIterator for WlDataDeviceManagerDndAction {
462    type Item = WlDataDeviceManagerDndAction;
463    type IntoIter = WlDataDeviceManagerDndActionIter;
464
465    fn into_iter(self) -> Self::IntoIter {
466        WlDataDeviceManagerDndActionIter(self.0)
467    }
468}
469
470impl BitAnd for WlDataDeviceManagerDndAction {
471    type Output = Self;
472
473    fn bitand(self, rhs: Self) -> Self::Output {
474        self.intersection(rhs)
475    }
476}
477
478impl BitAndAssign for WlDataDeviceManagerDndAction {
479    fn bitand_assign(&mut self, rhs: Self) {
480        *self = self.intersection(rhs);
481    }
482}
483
484impl BitOr for WlDataDeviceManagerDndAction {
485    type Output = Self;
486
487    fn bitor(self, rhs: Self) -> Self::Output {
488        self.union(rhs)
489    }
490}
491
492impl BitOrAssign for WlDataDeviceManagerDndAction {
493    fn bitor_assign(&mut self, rhs: Self) {
494        *self = self.union(rhs);
495    }
496}
497
498impl BitXor for WlDataDeviceManagerDndAction {
499    type Output = Self;
500
501    fn bitxor(self, rhs: Self) -> Self::Output {
502        self.symmetric_difference(rhs)
503    }
504}
505
506impl BitXorAssign for WlDataDeviceManagerDndAction {
507    fn bitxor_assign(&mut self, rhs: Self) {
508        *self = self.symmetric_difference(rhs);
509    }
510}
511
512impl Sub for WlDataDeviceManagerDndAction {
513    type Output = Self;
514
515    fn sub(self, rhs: Self) -> Self::Output {
516        self.difference(rhs)
517    }
518}
519
520impl SubAssign for WlDataDeviceManagerDndAction {
521    fn sub_assign(&mut self, rhs: Self) {
522        *self = self.difference(rhs);
523    }
524}
525
526impl Not for WlDataDeviceManagerDndAction {
527    type Output = Self;
528
529    fn not(self) -> Self::Output {
530        self.complement()
531    }
532}
533
534impl Debug for WlDataDeviceManagerDndAction {
535    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
536        let mut v = self.0;
537        let mut first = true;
538        if v & 1 == 1 {
539            v &= !1;
540            if first {
541                first = false;
542            } else {
543                f.write_str(" | ")?;
544            }
545            f.write_str("COPY")?;
546        }
547        if v & 2 == 2 {
548            v &= !2;
549            if first {
550                first = false;
551            } else {
552                f.write_str(" | ")?;
553            }
554            f.write_str("MOVE")?;
555        }
556        if v & 4 == 4 {
557            v &= !4;
558            if first {
559                first = false;
560            } else {
561                f.write_str(" | ")?;
562            }
563            f.write_str("ASK")?;
564        }
565        if v != 0 {
566            if first {
567                first = false;
568            } else {
569                f.write_str(" | ")?;
570            }
571            write!(f, "0x{v:032x}")?;
572        }
573        if first {
574            f.write_str("NONE")?;
575        }
576        Ok(())
577    }
578}
579
580/// Functional event handlers.
581pub mod event_handlers {
582    use super::*;
583
584    impl WlDataDeviceManager {}
585}