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