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