Skip to main content

get_registry/common/protocols/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
247impl WlDataDeviceManagerEventHandler for private::NoOpEventHandler {}
248
249// SAFETY: - INTERFACE is a valid wl_interface
250unsafe impl<H> EventHandler for private::EventHandler<H>
251where
252    H: WlDataDeviceManagerEventHandler,
253{
254    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
255
256    #[allow(unused_variables)]
257    unsafe fn handle_event(
258        &self,
259        queue: &Queue,
260        data: *mut u8,
261        slf: &UntypedBorrowedProxy,
262        opcode: u32,
263        args: *mut wl_argument,
264    ) {
265        invalid_opcode("wl_data_device_manager", opcode);
266    }
267}
268
269impl<H> CreateEventHandler<H> for private::ProxyApi
270where
271    H: WlDataDeviceManagerEventHandler,
272{
273    type EventHandler = private::EventHandler<H>;
274
275    #[inline]
276    fn create_event_handler(handler: H) -> Self::EventHandler {
277        private::EventHandler(handler)
278    }
279}
280
281impl WlDataDeviceManager {
282    /// Since when the dnd_action.none enum variant is available.
283    #[allow(dead_code)]
284    pub const ENM__DND_ACTION_NONE__SINCE: u32 = 1;
285    /// Since when the dnd_action.copy enum variant is available.
286    #[allow(dead_code)]
287    pub const ENM__DND_ACTION_COPY__SINCE: u32 = 1;
288    /// Since when the dnd_action.move enum variant is available.
289    #[allow(dead_code)]
290    pub const ENM__DND_ACTION_MOVE__SINCE: u32 = 1;
291    /// Since when the dnd_action.ask enum variant is available.
292    #[allow(dead_code)]
293    pub const ENM__DND_ACTION_ASK__SINCE: u32 = 1;
294}
295
296/// drag and drop actions
297///
298/// This is a bitmask of the available/preferred actions in a
299/// drag-and-drop operation.
300///
301/// In the compositor, the selected action is a result of matching the
302/// actions offered by the source and destination sides.  "action" events
303/// with a "none" action will be sent to both source and destination if
304/// there is no match. All further checks will effectively happen on
305/// (source actions ∩ destination actions).
306///
307/// In addition, compositors may also pick different actions in
308/// reaction to key modifiers being pressed. One common design that
309/// is used in major toolkits (and the behavior recommended for
310/// compositors) is:
311///
312/// - If no modifiers are pressed, the first match (in bit order)
313///   will be used.
314/// - Pressing Shift selects "move", if enabled in the mask.
315/// - Pressing Control selects "copy", if enabled in the mask.
316///
317/// Behavior beyond that is considered implementation-dependent.
318/// Compositors may for example bind other modifiers (like Alt/Meta)
319/// or drags initiated with other buttons than BTN_LEFT to specific
320/// actions (e.g. "ask").
321#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
322#[allow(dead_code)]
323pub struct WlDataDeviceManagerDndAction(pub u32);
324
325/// An iterator over the set bits in a [WlDataDeviceManagerDndAction].
326///
327/// You can construct this with the `IntoIterator` implementation of `WlDataDeviceManagerDndAction`.
328#[derive(Clone, Debug)]
329#[allow(dead_code)]
330pub struct WlDataDeviceManagerDndActionIter(pub u32);
331
332impl WlDataDeviceManagerDndAction {
333    /// no action
334    #[allow(dead_code)]
335    pub const NONE: Self = Self(0);
336
337    /// copy action
338    #[allow(dead_code)]
339    pub const COPY: Self = Self(1);
340
341    /// move action
342    #[allow(dead_code)]
343    pub const MOVE: Self = Self(2);
344
345    /// ask action
346    #[allow(dead_code)]
347    pub const ASK: Self = Self(4);
348}
349
350#[allow(dead_code)]
351impl WlDataDeviceManagerDndAction {
352    #[inline]
353    pub const fn empty() -> Self {
354        Self(0)
355    }
356
357    #[inline]
358    #[must_use]
359    pub const fn is_empty(self) -> bool {
360        self.0 == 0
361    }
362
363    #[inline]
364    #[must_use]
365    pub const fn contains(self, other: Self) -> bool {
366        self.0 & other.0 == other.0
367    }
368
369    #[inline]
370    #[must_use]
371    pub const fn intersects(self, other: Self) -> bool {
372        self.0 & other.0 != 0
373    }
374
375    #[inline]
376    pub const fn insert(&mut self, other: Self) {
377        *self = self.union(other);
378    }
379
380    #[inline]
381    pub const fn remove(&mut self, other: Self) {
382        *self = self.difference(other);
383    }
384
385    #[inline]
386    pub const fn toggle(&mut self, other: Self) {
387        *self = self.symmetric_difference(other);
388    }
389
390    #[inline]
391    pub const fn set(&mut self, other: Self, value: bool) {
392        if value {
393            self.insert(other);
394        } else {
395            self.remove(other);
396        }
397    }
398
399    #[inline]
400    #[must_use]
401    pub const fn intersection(self, other: Self) -> Self {
402        Self(self.0 & other.0)
403    }
404
405    #[inline]
406    #[must_use]
407    pub const fn union(self, other: Self) -> Self {
408        Self(self.0 | other.0)
409    }
410
411    #[inline]
412    #[must_use]
413    pub const fn difference(self, other: Self) -> Self {
414        Self(self.0 & !other.0)
415    }
416
417    #[inline]
418    #[must_use]
419    pub const fn complement(self) -> Self {
420        Self(!self.0)
421    }
422
423    #[inline]
424    #[must_use]
425    pub const fn symmetric_difference(self, other: Self) -> Self {
426        Self(self.0 ^ other.0)
427    }
428
429    #[inline]
430    pub const fn all_known() -> Self {
431        #[allow(clippy::eq_op, clippy::identity_op)]
432        Self(0 | 0 | 1 | 2 | 4)
433    }
434}
435
436impl Iterator for WlDataDeviceManagerDndActionIter {
437    type Item = WlDataDeviceManagerDndAction;
438
439    fn next(&mut self) -> Option<Self::Item> {
440        if self.0 == 0 {
441            return None;
442        }
443        let bit = 1 << self.0.trailing_zeros();
444        self.0 &= !bit;
445        Some(WlDataDeviceManagerDndAction(bit))
446    }
447}
448
449impl IntoIterator for WlDataDeviceManagerDndAction {
450    type Item = WlDataDeviceManagerDndAction;
451    type IntoIter = WlDataDeviceManagerDndActionIter;
452
453    fn into_iter(self) -> Self::IntoIter {
454        WlDataDeviceManagerDndActionIter(self.0)
455    }
456}
457
458impl BitAnd for WlDataDeviceManagerDndAction {
459    type Output = Self;
460
461    fn bitand(self, rhs: Self) -> Self::Output {
462        self.intersection(rhs)
463    }
464}
465
466impl BitAndAssign for WlDataDeviceManagerDndAction {
467    fn bitand_assign(&mut self, rhs: Self) {
468        *self = self.intersection(rhs);
469    }
470}
471
472impl BitOr for WlDataDeviceManagerDndAction {
473    type Output = Self;
474
475    fn bitor(self, rhs: Self) -> Self::Output {
476        self.union(rhs)
477    }
478}
479
480impl BitOrAssign for WlDataDeviceManagerDndAction {
481    fn bitor_assign(&mut self, rhs: Self) {
482        *self = self.union(rhs);
483    }
484}
485
486impl BitXor for WlDataDeviceManagerDndAction {
487    type Output = Self;
488
489    fn bitxor(self, rhs: Self) -> Self::Output {
490        self.symmetric_difference(rhs)
491    }
492}
493
494impl BitXorAssign for WlDataDeviceManagerDndAction {
495    fn bitxor_assign(&mut self, rhs: Self) {
496        *self = self.symmetric_difference(rhs);
497    }
498}
499
500impl Sub for WlDataDeviceManagerDndAction {
501    type Output = Self;
502
503    fn sub(self, rhs: Self) -> Self::Output {
504        self.difference(rhs)
505    }
506}
507
508impl SubAssign for WlDataDeviceManagerDndAction {
509    fn sub_assign(&mut self, rhs: Self) {
510        *self = self.difference(rhs);
511    }
512}
513
514impl Not for WlDataDeviceManagerDndAction {
515    type Output = Self;
516
517    fn not(self) -> Self::Output {
518        self.complement()
519    }
520}
521
522impl Debug for WlDataDeviceManagerDndAction {
523    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
524        let mut v = self.0;
525        let mut first = true;
526        if v & 1 == 1 {
527            v &= !1;
528            if first {
529                first = false;
530            } else {
531                f.write_str(" | ")?;
532            }
533            f.write_str("COPY")?;
534        }
535        if v & 2 == 2 {
536            v &= !2;
537            if first {
538                first = false;
539            } else {
540                f.write_str(" | ")?;
541            }
542            f.write_str("MOVE")?;
543        }
544        if v & 4 == 4 {
545            v &= !4;
546            if first {
547                first = false;
548            } else {
549                f.write_str(" | ")?;
550            }
551            f.write_str("ASK")?;
552        }
553        if v != 0 {
554            if first {
555                first = false;
556            } else {
557                f.write_str(" | ")?;
558            }
559            write!(f, "0x{v:032x}")?;
560        }
561        if first {
562            f.write_str("NONE")?;
563        }
564        Ok(())
565    }
566}
567
568/// Functional event handlers.
569pub mod event_handlers {
570    use super::*;
571
572    impl WlDataDeviceManager {}
573}