Skip to main content

get_registry/common/protocols/tablet_v2/
zwp_tablet_v2.rs

1//! graphics tablet device
2//!
3//! The wp_tablet interface represents one graphics tablet device. The
4//! tablet interface itself does not generate events; all events are
5//! generated by wp_tablet_tool objects when in proximity above a tablet.
6//!
7//! A tablet has a number of static characteristics, e.g. device name and
8//! pid/vid. These capabilities are sent in an event sequence after the
9//! wp_tablet_seat.tablet_added event. This initial event sequence is
10//! terminated by a wp_tablet.done event.
11
12use super::super::all_types::*;
13use ::wl_client::builder::prelude::*;
14
15static INTERFACE: wl_interface = wl_interface {
16    name: c"zwp_tablet_v2".as_ptr(),
17    version: 1,
18    method_count: 1,
19    methods: {
20        static MESSAGES: [wl_message; 1] = [wl_message {
21            name: c"destroy".as_ptr(),
22            signature: c"".as_ptr(),
23            types: {
24                static TYPES: [Option<&'static wl_interface>; 0] = [];
25                TYPES.as_ptr().cast()
26            },
27        }];
28        MESSAGES.as_ptr()
29    },
30    event_count: 5,
31    events: {
32        static MESSAGES: [wl_message; 5] = [
33            wl_message {
34                name: c"name".as_ptr(),
35                signature: c"s".as_ptr(),
36                types: {
37                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
38                    TYPES.as_ptr().cast()
39                },
40            },
41            wl_message {
42                name: c"id".as_ptr(),
43                signature: c"uu".as_ptr(),
44                types: {
45                    static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
46                    TYPES.as_ptr().cast()
47                },
48            },
49            wl_message {
50                name: c"path".as_ptr(),
51                signature: c"s".as_ptr(),
52                types: {
53                    static TYPES: [Option<&'static wl_interface>; 1] = [None];
54                    TYPES.as_ptr().cast()
55                },
56            },
57            wl_message {
58                name: c"done".as_ptr(),
59                signature: c"".as_ptr(),
60                types: {
61                    static TYPES: [Option<&'static wl_interface>; 0] = [];
62                    TYPES.as_ptr().cast()
63                },
64            },
65            wl_message {
66                name: c"removed".as_ptr(),
67                signature: c"".as_ptr(),
68                types: {
69                    static TYPES: [Option<&'static wl_interface>; 0] = [];
70                    TYPES.as_ptr().cast()
71                },
72            },
73        ];
74        MESSAGES.as_ptr()
75    },
76};
77
78/// An owned zwp_tablet_v2 proxy.
79///
80/// See the documentation of [the module][self] for the interface description.
81#[derive(Clone, Eq, PartialEq)]
82#[repr(transparent)]
83pub struct ZwpTabletV2 {
84    /// This proxy has the interface INTERFACE.
85    proxy: UntypedOwnedProxy,
86}
87
88/// A borrowed zwp_tablet_v2 proxy.
89///
90/// See the documentation of [the module][self] for the interface description.
91#[derive(Eq, PartialEq)]
92#[repr(transparent)]
93pub struct ZwpTabletV2Ref {
94    /// This proxy has the interface INTERFACE.
95    proxy: UntypedBorrowedProxy,
96}
97
98// SAFETY: ZwpTabletV2 is a transparent wrapper around UntypedOwnedProxy
99unsafe impl UntypedOwnedProxyWrapper for ZwpTabletV2 {}
100
101// SAFETY: - INTERFACE is a valid wl_interface
102//         - The only invariant is that self.proxy has a compatible interface
103unsafe impl OwnedProxy for ZwpTabletV2 {
104    const INTERFACE: &'static str = "zwp_tablet_v2";
105    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
106    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
107        private::EventHandler(private::NoOpEventHandler);
108    const MAX_VERSION: u32 = 1;
109
110    type Borrowed = ZwpTabletV2Ref;
111    type Api = private::ProxyApi;
112    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
113}
114
115// SAFETY: ZwpTabletV2Ref is a transparent wrapper around UntypedBorrowedProxy
116unsafe impl UntypedBorrowedProxyWrapper for ZwpTabletV2Ref {}
117
118// SAFETY: - The only invariant is that self.proxy has a compatible interface
119unsafe impl BorrowedProxy for ZwpTabletV2Ref {
120    type Owned = ZwpTabletV2;
121}
122
123impl Deref for ZwpTabletV2 {
124    type Target = ZwpTabletV2Ref;
125
126    fn deref(&self) -> &Self::Target {
127        proxy::low_level::deref(self)
128    }
129}
130
131mod private {
132    pub struct ProxyApi;
133
134    #[allow(dead_code)]
135    pub struct EventHandler<H>(pub(super) H);
136
137    #[allow(dead_code)]
138    pub struct NoOpEventHandler;
139}
140
141impl Debug for ZwpTabletV2 {
142    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
143        write!(f, "zwp_tablet_v2#{}", self.proxy.id())
144    }
145}
146
147impl Debug for ZwpTabletV2Ref {
148    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
149        write!(f, "zwp_tablet_v2#{}", self.proxy.id())
150    }
151}
152
153impl PartialEq<ZwpTabletV2Ref> for ZwpTabletV2 {
154    fn eq(&self, other: &ZwpTabletV2Ref) -> bool {
155        self.proxy == other.proxy
156    }
157}
158
159impl PartialEq<ZwpTabletV2> for ZwpTabletV2Ref {
160    fn eq(&self, other: &ZwpTabletV2) -> bool {
161        self.proxy == other.proxy
162    }
163}
164
165#[allow(dead_code)]
166impl ZwpTabletV2 {
167    /// Since when the destroy request is available.
168    #[allow(dead_code)]
169    pub const REQ__DESTROY__SINCE: u32 = 1;
170}
171
172#[allow(dead_code)]
173impl ZwpTabletV2 {
174    /// destroy the tablet object
175    ///
176    /// This destroys the client's resource for this tablet object.
177    #[inline]
178    pub fn destroy(&self) {
179        let mut args = [];
180        // SAFETY: - self.proxy has the interface INTERFACE
181        //         - 0 < INTERFACE.method_count = 1
182        //         - the request signature is ``
183        unsafe {
184            self.proxy.send_destructor(0, &mut args);
185        }
186    }
187}
188
189impl ZwpTabletV2 {
190    /// Since when the name event is available.
191    #[allow(dead_code)]
192    pub const EVT__NAME__SINCE: u32 = 1;
193
194    /// Since when the id event is available.
195    #[allow(dead_code)]
196    pub const EVT__ID__SINCE: u32 = 1;
197
198    /// Since when the path event is available.
199    #[allow(dead_code)]
200    pub const EVT__PATH__SINCE: u32 = 1;
201
202    /// Since when the done event is available.
203    #[allow(dead_code)]
204    pub const EVT__DONE__SINCE: u32 = 1;
205
206    /// Since when the removed event is available.
207    #[allow(dead_code)]
208    pub const EVT__REMOVED__SINCE: u32 = 1;
209}
210
211/// An event handler for [ZwpTabletV2] proxies.
212#[allow(dead_code)]
213pub trait ZwpTabletV2EventHandler {
214    /// tablet device name
215    ///
216    /// A descriptive name for the tablet device.
217    ///
218    /// 	If the device has no descriptive name, this event is not sent.
219    ///
220    /// 	This event is sent in the initial burst of events before the
221    /// wp_tablet.done event.
222    ///
223    /// # Arguments
224    ///
225    /// - `name`: the device name
226    #[inline]
227    fn name(&self, _slf: &ZwpTabletV2Ref, name: &str) {
228        let _ = name;
229    }
230
231    /// tablet device USB vendor/product id
232    ///
233    /// The USB vendor and product IDs for the tablet device.
234    ///
235    /// If the device has no USB vendor/product ID, this event is not sent.
236    /// This can happen for virtual devices or non-USB devices, for instance.
237    ///
238    /// This event is sent in the initial burst of events before the
239    /// wp_tablet.done event.
240    ///
241    /// # Arguments
242    ///
243    /// - `vid`: USB vendor id
244    /// - `pid`: USB product id
245    #[inline]
246    fn id(&self, _slf: &ZwpTabletV2Ref, vid: u32, pid: u32) {
247        let _ = vid;
248        let _ = pid;
249    }
250
251    /// path to the device
252    ///
253    /// A system-specific device path that indicates which device is behind
254    /// this wp_tablet. This information may be used to gather additional
255    /// information about the device, e.g. through libwacom.
256    ///
257    /// A device may have more than one device path. If so, multiple
258    /// wp_tablet.path events are sent. A device may be emulated and not
259    /// have a device path, and in that case this event will not be sent.
260    ///
261    /// The format of the path is unspecified, it may be a device node, a
262    /// sysfs path, or some other identifier. It is up to the client to
263    /// identify the string provided.
264    ///
265    /// This event is sent in the initial burst of events before the
266    /// wp_tablet.done event.
267    ///
268    /// # Arguments
269    ///
270    /// - `path`: path to local device
271    #[inline]
272    fn path(&self, _slf: &ZwpTabletV2Ref, path: &str) {
273        let _ = path;
274    }
275
276    /// tablet description events sequence complete
277    ///
278    /// This event is sent immediately to signal the end of the initial
279    /// burst of descriptive events. A client may consider the static
280    /// description of the tablet to be complete and finalize initialization
281    /// of the tablet.
282    #[inline]
283    fn done(&self, _slf: &ZwpTabletV2Ref) {}
284
285    /// tablet removed event
286    ///
287    /// Sent when the tablet has been removed from the system. When a tablet
288    /// is removed, some tools may be removed.
289    ///
290    /// When this event is received, the client must wp_tablet.destroy
291    /// the object.
292    #[inline]
293    fn removed(&self, _slf: &ZwpTabletV2Ref) {}
294}
295
296impl ZwpTabletV2EventHandler for private::NoOpEventHandler {}
297
298// SAFETY: - INTERFACE is a valid wl_interface
299unsafe impl<H> EventHandler for private::EventHandler<H>
300where
301    H: ZwpTabletV2EventHandler,
302{
303    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
304
305    #[allow(unused_variables)]
306    unsafe fn handle_event(
307        &self,
308        queue: &Queue,
309        data: *mut u8,
310        slf: &UntypedBorrowedProxy,
311        opcode: u32,
312        args: *mut wl_argument,
313    ) {
314        // SAFETY: This function requires that slf has the interface INTERFACE
315        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<ZwpTabletV2Ref>(slf) };
316        match opcode {
317            0 => {
318                // SAFETY: INTERFACE requires that there are 1 arguments
319                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
320                // SAFETY: - INTERFACE requires that args[0] contains a string
321                //         - if the pointer is not null, then it is a c string
322                let arg0 = unsafe { convert_string_arg("zwp_tablet_v2", "name", args[0].s) };
323                self.0.name(slf, arg0);
324            }
325            1 => {
326                // SAFETY: INTERFACE requires that there are 2 arguments
327                let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
328                // SAFETY: - INTERFACE requires that args[0] contains a uint
329                let arg0 = unsafe { args[0].u };
330                // SAFETY: - INTERFACE requires that args[1] contains a uint
331                let arg1 = unsafe { args[1].u };
332                self.0.id(slf, arg0, arg1);
333            }
334            2 => {
335                // SAFETY: INTERFACE requires that there are 1 arguments
336                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
337                // SAFETY: - INTERFACE requires that args[0] contains a string
338                //         - if the pointer is not null, then it is a c string
339                let arg0 = unsafe { convert_string_arg("zwp_tablet_v2", "path", args[0].s) };
340                self.0.path(slf, arg0);
341            }
342            3 => {
343                self.0.done(slf);
344            }
345            4 => {
346                self.0.removed(slf);
347            }
348            _ => {
349                invalid_opcode("zwp_tablet_v2", opcode);
350            }
351        }
352    }
353}
354
355impl<H> CreateEventHandler<H> for private::ProxyApi
356where
357    H: ZwpTabletV2EventHandler,
358{
359    type EventHandler = private::EventHandler<H>;
360
361    #[inline]
362    fn create_event_handler(handler: H) -> Self::EventHandler {
363        private::EventHandler(handler)
364    }
365}
366
367/// Functional event handlers.
368pub mod event_handlers {
369    use super::*;
370
371    /// Event handler for name events.
372    pub struct Name<F>(F);
373    impl<F> ZwpTabletV2EventHandler for Name<F>
374    where
375        F: Fn(&ZwpTabletV2Ref, &str),
376    {
377        #[inline]
378        fn name(&self, _slf: &ZwpTabletV2Ref, name: &str) {
379            self.0(_slf, name)
380        }
381    }
382
383    /// Event handler for id events.
384    pub struct Id<F>(F);
385    impl<F> ZwpTabletV2EventHandler for Id<F>
386    where
387        F: Fn(&ZwpTabletV2Ref, u32, u32),
388    {
389        #[inline]
390        fn id(&self, _slf: &ZwpTabletV2Ref, vid: u32, pid: u32) {
391            self.0(_slf, vid, pid)
392        }
393    }
394
395    /// Event handler for path events.
396    pub struct Path<F>(F);
397    impl<F> ZwpTabletV2EventHandler for Path<F>
398    where
399        F: Fn(&ZwpTabletV2Ref, &str),
400    {
401        #[inline]
402        fn path(&self, _slf: &ZwpTabletV2Ref, path: &str) {
403            self.0(_slf, path)
404        }
405    }
406
407    /// Event handler for done events.
408    pub struct Done<F>(F);
409    impl<F> ZwpTabletV2EventHandler for Done<F>
410    where
411        F: Fn(&ZwpTabletV2Ref),
412    {
413        #[inline]
414        fn done(&self, _slf: &ZwpTabletV2Ref) {
415            self.0(_slf)
416        }
417    }
418
419    /// Event handler for removed events.
420    pub struct Removed<F>(F);
421    impl<F> ZwpTabletV2EventHandler for Removed<F>
422    where
423        F: Fn(&ZwpTabletV2Ref),
424    {
425        #[inline]
426        fn removed(&self, _slf: &ZwpTabletV2Ref) {
427            self.0(_slf)
428        }
429    }
430
431    impl ZwpTabletV2 {
432        /// Creates an event handler for name events.
433        ///
434        /// The event handler ignores all other events.
435        #[allow(dead_code)]
436        pub fn on_name<F>(f: F) -> Name<F>
437        where
438            F: Fn(&ZwpTabletV2Ref, &str),
439        {
440            Name(f)
441        }
442
443        /// Creates an event handler for id events.
444        ///
445        /// The event handler ignores all other events.
446        #[allow(dead_code)]
447        pub fn on_id<F>(f: F) -> Id<F>
448        where
449            F: Fn(&ZwpTabletV2Ref, u32, u32),
450        {
451            Id(f)
452        }
453
454        /// Creates an event handler for path events.
455        ///
456        /// The event handler ignores all other events.
457        #[allow(dead_code)]
458        pub fn on_path<F>(f: F) -> Path<F>
459        where
460            F: Fn(&ZwpTabletV2Ref, &str),
461        {
462            Path(f)
463        }
464
465        /// Creates an event handler for done events.
466        ///
467        /// The event handler ignores all other events.
468        #[allow(dead_code)]
469        pub fn on_done<F>(f: F) -> Done<F>
470        where
471            F: Fn(&ZwpTabletV2Ref),
472        {
473            Done(f)
474        }
475
476        /// Creates an event handler for removed events.
477        ///
478        /// The event handler ignores all other events.
479        #[allow(dead_code)]
480        pub fn on_removed<F>(f: F) -> Removed<F>
481        where
482            F: Fn(&ZwpTabletV2Ref),
483        {
484            Removed(f)
485        }
486    }
487}