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