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