Skip to main content

get_registry/common/protocols/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    /// new device notification
190    ///
191    /// This event is sent whenever a new tablet becomes available on this
192    /// seat. This event only provides the object id of the tablet, any
193    /// static information about the tablet (device name, vid/pid, etc.) is
194    /// sent through the wp_tablet interface.
195    ///
196    /// # Arguments
197    ///
198    /// - `id`: the newly added graphics tablet
199    #[inline]
200    fn tablet_added(&self, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletV2) {
201        let _ = id;
202    }
203
204    /// a new tool has been used with a tablet
205    ///
206    /// This event is sent whenever a tool that has not previously been used
207    /// with a tablet comes into use. This event only provides the object id
208    /// of the tool; any static information about the tool (capabilities,
209    /// type, etc.) is sent through the wp_tablet_tool interface.
210    ///
211    /// # Arguments
212    ///
213    /// - `id`: the newly added tablet tool
214    #[inline]
215    fn tool_added(&self, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletToolV2) {
216        let _ = id;
217    }
218
219    /// new pad notification
220    ///
221    /// This event is sent whenever a new pad is known to the system. Typically,
222    /// pads are physically attached to tablets and a pad_added event is
223    /// sent immediately after the wp_tablet_seat.tablet_added.
224    /// However, some standalone pad devices logically attach to tablets at
225    /// runtime, and the client must wait for wp_tablet_pad.enter to know
226    /// the tablet a pad is attached to.
227    ///
228    /// This event only provides the object id of the pad. All further
229    /// features (buttons, strips, rings) are sent through the wp_tablet_pad
230    /// interface.
231    ///
232    /// # Arguments
233    ///
234    /// - `id`: the newly added pad
235    #[inline]
236    fn pad_added(&self, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletPadV2) {
237        let _ = id;
238    }
239}
240
241impl ZwpTabletSeatV2EventHandler for private::NoOpEventHandler {}
242
243// SAFETY: - INTERFACE is a valid wl_interface
244unsafe impl<H> EventHandler for private::EventHandler<H>
245where
246    H: ZwpTabletSeatV2EventHandler,
247{
248    const WL_INTERFACE: &'static wl_interface = &INTERFACE;
249
250    #[allow(unused_variables)]
251    unsafe fn handle_event(
252        &self,
253        queue: &Queue,
254        data: *mut u8,
255        slf: &UntypedBorrowedProxy,
256        opcode: u32,
257        args: *mut wl_argument,
258    ) {
259        // SAFETY: This function requires that slf has the interface INTERFACE
260        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<ZwpTabletSeatV2Ref>(slf) };
261        match opcode {
262            0 => {
263                // SAFETY: INTERFACE requires that there are 1 arguments
264                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
265                // SAFETY: - INTERFACE requires that args[0] contains an object
266                //         - ownership is transferred to this function
267                //         - INTERFACE requires that the object has the interface ZwpTabletV2::WL_INTERFACE
268                let arg0 = unsafe {
269                    UntypedOwnedProxy::from_plain_wl_proxy(
270                        queue,
271                        NonNull::new_unchecked(args[0].o.cast()),
272                        ZwpTabletV2::WL_INTERFACE,
273                    )
274                };
275                // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletV2::WL_INTERFACE
276                let arg0 = unsafe { proxy::low_level::from_untyped_owned::<ZwpTabletV2>(arg0) };
277                self.0.tablet_added(slf, arg0);
278            }
279            1 => {
280                // SAFETY: INTERFACE requires that there are 1 arguments
281                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
282                // SAFETY: - INTERFACE requires that args[0] contains an object
283                //         - ownership is transferred to this function
284                //         - INTERFACE requires that the object has the interface ZwpTabletToolV2::WL_INTERFACE
285                let arg0 = unsafe {
286                    UntypedOwnedProxy::from_plain_wl_proxy(
287                        queue,
288                        NonNull::new_unchecked(args[0].o.cast()),
289                        ZwpTabletToolV2::WL_INTERFACE,
290                    )
291                };
292                // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletToolV2::WL_INTERFACE
293                let arg0 = unsafe { proxy::low_level::from_untyped_owned::<ZwpTabletToolV2>(arg0) };
294                self.0.tool_added(slf, arg0);
295            }
296            2 => {
297                // SAFETY: INTERFACE requires that there are 1 arguments
298                let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
299                // SAFETY: - INTERFACE requires that args[0] contains an object
300                //         - ownership is transferred to this function
301                //         - INTERFACE requires that the object has the interface ZwpTabletPadV2::WL_INTERFACE
302                let arg0 = unsafe {
303                    UntypedOwnedProxy::from_plain_wl_proxy(
304                        queue,
305                        NonNull::new_unchecked(args[0].o.cast()),
306                        ZwpTabletPadV2::WL_INTERFACE,
307                    )
308                };
309                // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletPadV2::WL_INTERFACE
310                let arg0 = unsafe { proxy::low_level::from_untyped_owned::<ZwpTabletPadV2>(arg0) };
311                self.0.pad_added(slf, arg0);
312            }
313            _ => {
314                invalid_opcode("zwp_tablet_seat_v2", opcode);
315            }
316        }
317    }
318}
319
320impl<H> CreateEventHandler<H> for private::ProxyApi
321where
322    H: ZwpTabletSeatV2EventHandler,
323{
324    type EventHandler = private::EventHandler<H>;
325
326    #[inline]
327    fn create_event_handler(handler: H) -> Self::EventHandler {
328        private::EventHandler(handler)
329    }
330}
331
332/// Functional event handlers.
333pub mod event_handlers {
334    use super::*;
335
336    /// Event handler for tablet_added events.
337    pub struct TabletAdded<F>(F);
338    impl<F> ZwpTabletSeatV2EventHandler for TabletAdded<F>
339    where
340        F: Fn(&ZwpTabletSeatV2Ref, ZwpTabletV2),
341    {
342        #[inline]
343        fn tablet_added(&self, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletV2) {
344            self.0(_slf, id)
345        }
346    }
347
348    /// Event handler for tool_added events.
349    pub struct ToolAdded<F>(F);
350    impl<F> ZwpTabletSeatV2EventHandler for ToolAdded<F>
351    where
352        F: Fn(&ZwpTabletSeatV2Ref, ZwpTabletToolV2),
353    {
354        #[inline]
355        fn tool_added(&self, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletToolV2) {
356            self.0(_slf, id)
357        }
358    }
359
360    /// Event handler for pad_added events.
361    pub struct PadAdded<F>(F);
362    impl<F> ZwpTabletSeatV2EventHandler for PadAdded<F>
363    where
364        F: Fn(&ZwpTabletSeatV2Ref, ZwpTabletPadV2),
365    {
366        #[inline]
367        fn pad_added(&self, _slf: &ZwpTabletSeatV2Ref, id: ZwpTabletPadV2) {
368            self.0(_slf, id)
369        }
370    }
371
372    impl ZwpTabletSeatV2 {
373        /// Creates an event handler for tablet_added events.
374        ///
375        /// The event handler ignores all other events.
376        #[allow(dead_code)]
377        pub fn on_tablet_added<F>(f: F) -> TabletAdded<F>
378        where
379            F: Fn(&ZwpTabletSeatV2Ref, ZwpTabletV2),
380        {
381            TabletAdded(f)
382        }
383
384        /// Creates an event handler for tool_added events.
385        ///
386        /// The event handler ignores all other events.
387        #[allow(dead_code)]
388        pub fn on_tool_added<F>(f: F) -> ToolAdded<F>
389        where
390            F: Fn(&ZwpTabletSeatV2Ref, ZwpTabletToolV2),
391        {
392            ToolAdded(f)
393        }
394
395        /// Creates an event handler for pad_added events.
396        ///
397        /// The event handler ignores all other events.
398        #[allow(dead_code)]
399        pub fn on_pad_added<F>(f: F) -> PadAdded<F>
400        where
401            F: Fn(&ZwpTabletSeatV2Ref, ZwpTabletPadV2),
402        {
403            PadAdded(f)
404        }
405    }
406}