Skip to main content

get_registry/common/protocols_data/tablet_v2/
zwp_tablet_seat_v2.rs

1//! controller object for graphic tablet devices of a seat
2//!
3//! An object that provides access to the graphics tablets available on this
4//! seat. After binding to this interface, the compositor sends a set of
5//! wp_tablet_seat.tablet_added and wp_tablet_seat.tool_added events.
6
7use super::super::all_types::*;
8use ::wl_client::builder::prelude::*;
9
10static INTERFACE: wl_interface = wl_interface {
11    name: c"zwp_tablet_seat_v2".as_ptr(),
12    version: 1,
13    method_count: 1,
14    methods: {
15        static MESSAGES: [wl_message; 1] = [wl_message {
16            name: c"destroy".as_ptr(),
17            signature: c"".as_ptr(),
18            types: {
19                static TYPES: [Option<&'static wl_interface>; 0] = [];
20                TYPES.as_ptr().cast()
21            },
22        }];
23        MESSAGES.as_ptr()
24    },
25    event_count: 3,
26    events: {
27        static MESSAGES: [wl_message; 3] = [
28            wl_message {
29                name: c"tablet_added".as_ptr(),
30                signature: c"n".as_ptr(),
31                types: {
32                    static TYPES: [Option<&'static wl_interface>; 1] =
33                        [Some(ZwpTabletV2::WL_INTERFACE)];
34                    TYPES.as_ptr().cast()
35                },
36            },
37            wl_message {
38                name: c"tool_added".as_ptr(),
39                signature: c"n".as_ptr(),
40                types: {
41                    static TYPES: [Option<&'static wl_interface>; 1] =
42                        [Some(ZwpTabletToolV2::WL_INTERFACE)];
43                    TYPES.as_ptr().cast()
44                },
45            },
46            wl_message {
47                name: c"pad_added".as_ptr(),
48                signature: c"n".as_ptr(),
49                types: {
50                    static TYPES: [Option<&'static wl_interface>; 1] =
51                        [Some(ZwpTabletPadV2::WL_INTERFACE)];
52                    TYPES.as_ptr().cast()
53                },
54            },
55        ];
56        MESSAGES.as_ptr()
57    },
58};
59
60/// An owned zwp_tablet_seat_v2 proxy.
61///
62/// See the documentation of [the module][self] for the interface description.
63#[derive(Clone, Eq, PartialEq)]
64#[repr(transparent)]
65pub struct ZwpTabletSeatV2 {
66    /// This proxy has the interface INTERFACE.
67    proxy: UntypedOwnedProxy,
68}
69
70/// A borrowed zwp_tablet_seat_v2 proxy.
71///
72/// See the documentation of [the module][self] for the interface description.
73#[derive(Eq, PartialEq)]
74#[repr(transparent)]
75pub struct ZwpTabletSeatV2Ref {
76    /// This proxy has the interface INTERFACE.
77    proxy: UntypedBorrowedProxy,
78}
79
80// SAFETY: ZwpTabletSeatV2 is a transparent wrapper around UntypedOwnedProxy
81unsafe impl UntypedOwnedProxyWrapper for ZwpTabletSeatV2 {}
82
83// SAFETY: - INTERFACE is a valid wl_interface
84//         - The only invariant is that self.proxy has a compatible interface
85unsafe impl OwnedProxy for ZwpTabletSeatV2 {
86    const INTERFACE: &'static str = "zwp_tablet_seat_v2";
87    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
88    const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
89        private::EventHandler(private::NoOpEventHandler);
90    const MAX_VERSION: u32 = 1;
91
92    type Borrowed = ZwpTabletSeatV2Ref;
93    type Api = private::ProxyApi;
94    type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
95}
96
97// SAFETY: ZwpTabletSeatV2Ref is a transparent wrapper around UntypedBorrowedProxy
98unsafe impl UntypedBorrowedProxyWrapper for ZwpTabletSeatV2Ref {}
99
100// SAFETY: - The only invariant is that self.proxy has a compatible interface
101unsafe impl BorrowedProxy for ZwpTabletSeatV2Ref {
102    type Owned = ZwpTabletSeatV2;
103}
104
105impl Deref for ZwpTabletSeatV2 {
106    type Target = ZwpTabletSeatV2Ref;
107
108    fn deref(&self) -> &Self::Target {
109        proxy::low_level::deref(self)
110    }
111}
112
113mod private {
114    pub struct ProxyApi;
115
116    #[allow(dead_code)]
117    pub struct EventHandler<H>(pub(super) H);
118
119    #[allow(dead_code)]
120    pub struct NoOpEventHandler;
121}
122
123impl Debug for ZwpTabletSeatV2 {
124    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
125        write!(f, "zwp_tablet_seat_v2#{}", self.proxy.id())
126    }
127}
128
129impl Debug for ZwpTabletSeatV2Ref {
130    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
131        write!(f, "zwp_tablet_seat_v2#{}", self.proxy.id())
132    }
133}
134
135impl PartialEq<ZwpTabletSeatV2Ref> for ZwpTabletSeatV2 {
136    fn eq(&self, other: &ZwpTabletSeatV2Ref) -> bool {
137        self.proxy == other.proxy
138    }
139}
140
141impl PartialEq<ZwpTabletSeatV2> for ZwpTabletSeatV2Ref {
142    fn eq(&self, other: &ZwpTabletSeatV2) -> bool {
143        self.proxy == other.proxy
144    }
145}
146
147#[allow(dead_code)]
148impl ZwpTabletSeatV2 {
149    /// Since when the destroy request is available.
150    #[allow(dead_code)]
151    pub const REQ__DESTROY__SINCE: u32 = 1;
152}
153
154#[allow(dead_code)]
155impl ZwpTabletSeatV2 {
156    /// release the memory for the tablet seat object
157    ///
158    /// Destroy the wp_tablet_seat object. Objects created from this
159    /// object are unaffected and should be destroyed separately.
160    #[inline]
161    pub fn destroy(&self) {
162        let mut args = [];
163        // SAFETY: - self.proxy has the interface INTERFACE
164        //         - 0 < INTERFACE.method_count = 1
165        //         - the request signature is ``
166        unsafe {
167            self.proxy.send_destructor(0, &mut args);
168        }
169    }
170}
171
172impl ZwpTabletSeatV2 {
173    /// Since when the tablet_added event is available.
174    #[allow(dead_code)]
175    pub const EVT__TABLET_ADDED__SINCE: u32 = 1;
176
177    /// Since when the tool_added event is available.
178    #[allow(dead_code)]
179    pub const EVT__TOOL_ADDED__SINCE: u32 = 1;
180
181    /// Since when the pad_added event is available.
182    #[allow(dead_code)]
183    pub const EVT__PAD_ADDED__SINCE: u32 = 1;
184}
185
186/// An event handler for [ZwpTabletSeatV2] proxies.
187#[allow(dead_code)]
188pub trait ZwpTabletSeatV2EventHandler {
189    type Data: 'static;
190
191    /// new device notification
192    ///
193    /// This event is sent whenever a new tablet becomes available on this
194    /// seat. This event only provides the object id of the tablet, any
195    /// static information about the tablet (device name, vid/pid, etc.) is
196    /// sent through the wp_tablet interface.
197    ///
198    /// # Arguments
199    ///
200    /// - `id`: the newly added graphics tablet
201    #[inline]
202    fn tablet_added(&self, _data: &mut Self::Data, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletV2) {
203        let _ = id;
204    }
205
206    /// a new tool has been used with a tablet
207    ///
208    /// This event is sent whenever a tool that has not previously been used
209    /// with a tablet comes into use. This event only provides the object id
210    /// of the tool; any static information about the tool (capabilities,
211    /// type, etc.) is sent through the wp_tablet_tool interface.
212    ///
213    /// # Arguments
214    ///
215    /// - `id`: the newly added tablet tool
216    #[inline]
217    fn tool_added(&self, _data: &mut Self::Data, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletToolV2) {
218        let _ = id;
219    }
220
221    /// new pad notification
222    ///
223    /// This event is sent whenever a new pad is known to the system. Typically,
224    /// pads are physically attached to tablets and a pad_added event is
225    /// sent immediately after the wp_tablet_seat.tablet_added.
226    /// However, some standalone pad devices logically attach to tablets at
227    /// runtime, and the client must wait for wp_tablet_pad.enter to know
228    /// the tablet a pad is attached to.
229    ///
230    /// This event only provides the object id of the pad. All further
231    /// features (buttons, strips, rings) are sent through the wp_tablet_pad
232    /// interface.
233    ///
234    /// # Arguments
235    ///
236    /// - `id`: the newly added pad
237    #[inline]
238    fn pad_added(&self, _data: &mut Self::Data, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletPadV2) {
239        let _ = id;
240    }
241}
242
243impl ZwpTabletSeatV2EventHandler for private::NoOpEventHandler {
244    type Data = ();
245}
246
247// SAFETY: - INTERFACE is a valid wl_interface
248//         - mutable_type always returns the same value
249unsafe impl<H> EventHandler for private::EventHandler<H>
250where
251    H: ZwpTabletSeatV2EventHandler,
252{
253    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
254
255    #[inline]
256    fn mutable_type() -> Option<(TypeId, &'static str)> {
257        let id = TypeId::of::<H::Data>();
258        let name = std::any::type_name::<H::Data>();
259        Some((id, name))
260    }
261
262    #[allow(unused_variables)]
263    unsafe fn handle_event(
264        &self,
265        queue: &Queue,
266        data: *mut u8,
267        slf: &UntypedBorrowedProxy,
268        opcode: u32,
269        args: *mut wl_argument,
270    ) {
271        // SAFETY: This function requires that slf has the interface INTERFACE
272        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<ZwpTabletSeatV2Ref>(slf) };
273        // SAFETY: This function requires that data is `&mut T` where `T`
274        //         has the type id returned by `Self::mutable_type`, i.e.,
275        //         `T = H::Data`.
276        let data: &mut H::Data = unsafe { &mut *data.cast() };
277        match opcode {
278            0 => {
279                // SAFETY: INTERFACE requires that there are 1 arguments
280                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
281                // SAFETY: - INTERFACE requires that args[0] contains an object
282                //         - ownership is transferred to this function
283                //         - INTERFACE requires that the object has the interface ZwpTabletV2::WL_INTERFACE
284                let arg0 = unsafe {
285                    UntypedOwnedProxy::from_plain_wl_proxy(
286                        queue,
287                        NonNull::new_unchecked(args[0].o.cast()),
288                        ZwpTabletV2::WL_INTERFACE,
289                    )
290                };
291                // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletV2::WL_INTERFACE
292                let arg0 = unsafe { proxy::low_level::from_untyped_owned::<ZwpTabletV2>(arg0) };
293                self.0.tablet_added(data, slf, arg0);
294            }
295            1 => {
296                // SAFETY: INTERFACE requires that there are 1 arguments
297                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
298                // SAFETY: - INTERFACE requires that args[0] contains an object
299                //         - ownership is transferred to this function
300                //         - INTERFACE requires that the object has the interface ZwpTabletToolV2::WL_INTERFACE
301                let arg0 = unsafe {
302                    UntypedOwnedProxy::from_plain_wl_proxy(
303                        queue,
304                        NonNull::new_unchecked(args[0].o.cast()),
305                        ZwpTabletToolV2::WL_INTERFACE,
306                    )
307                };
308                // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletToolV2::WL_INTERFACE
309                let arg0 = unsafe { proxy::low_level::from_untyped_owned::<ZwpTabletToolV2>(arg0) };
310                self.0.tool_added(data, slf, arg0);
311            }
312            2 => {
313                // SAFETY: INTERFACE requires that there are 1 arguments
314                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
315                // SAFETY: - INTERFACE requires that args[0] contains an object
316                //         - ownership is transferred to this function
317                //         - INTERFACE requires that the object has the interface ZwpTabletPadV2::WL_INTERFACE
318                let arg0 = unsafe {
319                    UntypedOwnedProxy::from_plain_wl_proxy(
320                        queue,
321                        NonNull::new_unchecked(args[0].o.cast()),
322                        ZwpTabletPadV2::WL_INTERFACE,
323                    )
324                };
325                // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletPadV2::WL_INTERFACE
326                let arg0 = unsafe { proxy::low_level::from_untyped_owned::<ZwpTabletPadV2>(arg0) };
327                self.0.pad_added(data, slf, arg0);
328            }
329            _ => {
330                invalid_opcode("zwp_tablet_seat_v2", opcode);
331            }
332        }
333    }
334}
335
336impl<H> CreateEventHandler<H> for private::ProxyApi
337where
338    H: ZwpTabletSeatV2EventHandler,
339{
340    type EventHandler = private::EventHandler<H>;
341
342    #[inline]
343    fn create_event_handler(handler: H) -> Self::EventHandler {
344        private::EventHandler(handler)
345    }
346}
347
348/// Functional event handlers.
349pub mod event_handlers {
350    use super::*;
351
352    /// Event handler for tablet_added events.
353    pub struct TabletAdded<T, F>(F, PhantomData<fn(&mut T)>);
354    impl<T, F> ZwpTabletSeatV2EventHandler for TabletAdded<T, F>
355    where
356        T: 'static,
357        F: Fn(&mut T, &ZwpTabletSeatV2Ref, ZwpTabletV2),
358    {
359        type Data = T;
360
361        #[inline]
362        fn tablet_added(&self, _data: &mut T, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletV2) {
363            self.0(_data, _slf, id)
364        }
365    }
366
367    /// Event handler for tool_added events.
368    pub struct ToolAdded<T, F>(F, PhantomData<fn(&mut T)>);
369    impl<T, F> ZwpTabletSeatV2EventHandler for ToolAdded<T, F>
370    where
371        T: 'static,
372        F: Fn(&mut T, &ZwpTabletSeatV2Ref, ZwpTabletToolV2),
373    {
374        type Data = T;
375
376        #[inline]
377        fn tool_added(&self, _data: &mut T, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletToolV2) {
378            self.0(_data, _slf, id)
379        }
380    }
381
382    /// Event handler for pad_added events.
383    pub struct PadAdded<T, F>(F, PhantomData<fn(&mut T)>);
384    impl<T, F> ZwpTabletSeatV2EventHandler for PadAdded<T, F>
385    where
386        T: 'static,
387        F: Fn(&mut T, &ZwpTabletSeatV2Ref, ZwpTabletPadV2),
388    {
389        type Data = T;
390
391        #[inline]
392        fn pad_added(&self, _data: &mut T, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletPadV2) {
393            self.0(_data, _slf, id)
394        }
395    }
396
397    impl ZwpTabletSeatV2 {
398        /// Creates an event handler for tablet_added events.
399        ///
400        /// The event handler ignores all other events.
401        #[allow(dead_code)]
402        pub fn on_tablet_added<T, F>(f: F) -> TabletAdded<T, F>
403        where
404            T: 'static,
405            F: Fn(&mut T, &ZwpTabletSeatV2Ref, ZwpTabletV2),
406        {
407            TabletAdded(f, PhantomData)
408        }
409
410        /// Creates an event handler for tool_added events.
411        ///
412        /// The event handler ignores all other events.
413        #[allow(dead_code)]
414        pub fn on_tool_added<T, F>(f: F) -> ToolAdded<T, F>
415        where
416            T: 'static,
417            F: Fn(&mut T, &ZwpTabletSeatV2Ref, ZwpTabletToolV2),
418        {
419            ToolAdded(f, PhantomData)
420        }
421
422        /// Creates an event handler for pad_added events.
423        ///
424        /// The event handler ignores all other events.
425        #[allow(dead_code)]
426        pub fn on_pad_added<T, F>(f: F) -> PadAdded<T, F>
427        where
428            T: 'static,
429            F: Fn(&mut T, &ZwpTabletSeatV2Ref, ZwpTabletPadV2),
430        {
431            PadAdded(f, PhantomData)
432        }
433    }
434}