simple_window/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 data: *mut u8,
306 slf: &UntypedBorrowedProxy,
307 opcode: u32,
308 args: *mut wl_argument,
309 ) {
310 // SAFETY: This function requires that slf has the interface INTERFACE
311 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<ZwpTabletV2Ref>(slf) };
312 match opcode {
313 0 => {
314 // SAFETY: INTERFACE requires that there are 1 arguments
315 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
316 // SAFETY: - INTERFACE requires that args[0] contains a string
317 // - if the pointer is not null, then it is a c string
318 let arg0 = unsafe { convert_string_arg("zwp_tablet_v2", "name", args[0].s) };
319 self.0.name(slf, arg0);
320 }
321 1 => {
322 // SAFETY: INTERFACE requires that there are 2 arguments
323 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
324 // SAFETY: - INTERFACE requires that args[0] contains a uint
325 let arg0 = unsafe { args[0].u };
326 // SAFETY: - INTERFACE requires that args[1] contains a uint
327 let arg1 = unsafe { args[1].u };
328 self.0.id(slf, arg0, arg1);
329 }
330 2 => {
331 // SAFETY: INTERFACE requires that there are 1 arguments
332 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
333 // SAFETY: - INTERFACE requires that args[0] contains a string
334 // - if the pointer is not null, then it is a c string
335 let arg0 = unsafe { convert_string_arg("zwp_tablet_v2", "path", args[0].s) };
336 self.0.path(slf, arg0);
337 }
338 3 => {
339 self.0.done(slf);
340 }
341 4 => {
342 self.0.removed(slf);
343 }
344 _ => {
345 invalid_opcode("zwp_tablet_v2", opcode);
346 }
347 }
348 }
349}
350
351impl<H> CreateEventHandler<H> for private::ProxyApi
352where
353 H: ZwpTabletV2EventHandler,
354{
355 type EventHandler = private::EventHandler<H>;
356
357 #[inline]
358 fn create_event_handler(handler: H) -> Self::EventHandler {
359 private::EventHandler(handler)
360 }
361}
362
363/// Functional event handlers.
364pub mod event_handlers {
365 use super::*;
366
367 /// Event handler for name events.
368 pub struct Name<F>(F);
369 impl<F> ZwpTabletV2EventHandler for Name<F>
370 where
371 F: Fn(&ZwpTabletV2Ref, &str),
372 {
373 #[inline]
374 fn name(&self, _slf: &ZwpTabletV2Ref, name: &str) {
375 self.0(_slf, name)
376 }
377 }
378
379 /// Event handler for id events.
380 pub struct Id<F>(F);
381 impl<F> ZwpTabletV2EventHandler for Id<F>
382 where
383 F: Fn(&ZwpTabletV2Ref, u32, u32),
384 {
385 #[inline]
386 fn id(&self, _slf: &ZwpTabletV2Ref, vid: u32, pid: u32) {
387 self.0(_slf, vid, pid)
388 }
389 }
390
391 /// Event handler for path events.
392 pub struct Path<F>(F);
393 impl<F> ZwpTabletV2EventHandler for Path<F>
394 where
395 F: Fn(&ZwpTabletV2Ref, &str),
396 {
397 #[inline]
398 fn path(&self, _slf: &ZwpTabletV2Ref, path: &str) {
399 self.0(_slf, path)
400 }
401 }
402
403 /// Event handler for done events.
404 pub struct Done<F>(F);
405 impl<F> ZwpTabletV2EventHandler for Done<F>
406 where
407 F: Fn(&ZwpTabletV2Ref),
408 {
409 #[inline]
410 fn done(&self, _slf: &ZwpTabletV2Ref) {
411 self.0(_slf)
412 }
413 }
414
415 /// Event handler for removed events.
416 pub struct Removed<F>(F);
417 impl<F> ZwpTabletV2EventHandler for Removed<F>
418 where
419 F: Fn(&ZwpTabletV2Ref),
420 {
421 #[inline]
422 fn removed(&self, _slf: &ZwpTabletV2Ref) {
423 self.0(_slf)
424 }
425 }
426
427 impl ZwpTabletV2 {
428 /// Creates an event handler for name events.
429 ///
430 /// The event handler ignores all other events.
431 #[allow(dead_code)]
432 pub fn on_name<F>(f: F) -> Name<F>
433 where
434 F: Fn(&ZwpTabletV2Ref, &str),
435 {
436 Name(f)
437 }
438
439 /// Creates an event handler for id events.
440 ///
441 /// The event handler ignores all other events.
442 #[allow(dead_code)]
443 pub fn on_id<F>(f: F) -> Id<F>
444 where
445 F: Fn(&ZwpTabletV2Ref, u32, u32),
446 {
447 Id(f)
448 }
449
450 /// Creates an event handler for path events.
451 ///
452 /// The event handler ignores all other events.
453 #[allow(dead_code)]
454 pub fn on_path<F>(f: F) -> Path<F>
455 where
456 F: Fn(&ZwpTabletV2Ref, &str),
457 {
458 Path(f)
459 }
460
461 /// Creates an event handler for done events.
462 ///
463 /// The event handler ignores all other events.
464 #[allow(dead_code)]
465 pub fn on_done<F>(f: F) -> Done<F>
466 where
467 F: Fn(&ZwpTabletV2Ref),
468 {
469 Done(f)
470 }
471
472 /// Creates an event handler for removed events.
473 ///
474 /// The event handler ignores all other events.
475 #[allow(dead_code)]
476 pub fn on_removed<F>(f: F) -> Removed<F>
477 where
478 F: Fn(&ZwpTabletV2Ref),
479 {
480 Removed(f)
481 }
482 }
483}