get_registry/common/protocols/tablet_v2/zwp_tablet_pad_group_v2.rs
1//! a set of buttons, rings and strips
2//!
3//! A pad group describes a distinct (sub)set of buttons, rings and strips
4//! present in the tablet. The criteria of this grouping is usually positional,
5//! eg. if a tablet has buttons on the left and right side, 2 groups will be
6//! presented. The physical arrangement of groups is undisclosed and may
7//! change on the fly.
8//!
9//! Pad groups will announce their features during pad initialization. Between
10//! the corresponding wp_tablet_pad.group event and wp_tablet_pad_group.done, the
11//! pad group will announce the buttons, rings and strips contained in it,
12//! plus the number of supported modes.
13//!
14//! Modes are a mechanism to allow multiple groups of actions for every element
15//! in the pad group. The number of groups and available modes in each is
16//! persistent across device plugs. The current mode is user-switchable, it
17//! will be announced through the wp_tablet_pad_group.mode_switch event both
18//! whenever it is switched, and after wp_tablet_pad.enter.
19//!
20//! The current mode logically applies to all elements in the pad group,
21//! although it is at clients' discretion whether to actually perform different
22//! actions, and/or issue the respective .set_feedback requests to notify the
23//! compositor. See the wp_tablet_pad_group.mode_switch event for more details.
24
25use super::super::all_types::*;
26use ::wl_client::builder::prelude::*;
27
28static INTERFACE: wl_interface = wl_interface {
29 name: c"zwp_tablet_pad_group_v2".as_ptr(),
30 version: 1,
31 method_count: 1,
32 methods: {
33 static MESSAGES: [wl_message; 1] = [wl_message {
34 name: c"destroy".as_ptr(),
35 signature: c"".as_ptr(),
36 types: {
37 static TYPES: [Option<&'static wl_interface>; 0] = [];
38 TYPES.as_ptr().cast()
39 },
40 }];
41 MESSAGES.as_ptr()
42 },
43 event_count: 6,
44 events: {
45 static MESSAGES: [wl_message; 6] = [
46 wl_message {
47 name: c"buttons".as_ptr(),
48 signature: c"a".as_ptr(),
49 types: {
50 static TYPES: [Option<&'static wl_interface>; 1] = [None];
51 TYPES.as_ptr().cast()
52 },
53 },
54 wl_message {
55 name: c"ring".as_ptr(),
56 signature: c"n".as_ptr(),
57 types: {
58 static TYPES: [Option<&'static wl_interface>; 1] =
59 [Some(ZwpTabletPadRingV2::WL_INTERFACE)];
60 TYPES.as_ptr().cast()
61 },
62 },
63 wl_message {
64 name: c"strip".as_ptr(),
65 signature: c"n".as_ptr(),
66 types: {
67 static TYPES: [Option<&'static wl_interface>; 1] =
68 [Some(ZwpTabletPadStripV2::WL_INTERFACE)];
69 TYPES.as_ptr().cast()
70 },
71 },
72 wl_message {
73 name: c"modes".as_ptr(),
74 signature: c"u".as_ptr(),
75 types: {
76 static TYPES: [Option<&'static wl_interface>; 1] = [None];
77 TYPES.as_ptr().cast()
78 },
79 },
80 wl_message {
81 name: c"done".as_ptr(),
82 signature: c"".as_ptr(),
83 types: {
84 static TYPES: [Option<&'static wl_interface>; 0] = [];
85 TYPES.as_ptr().cast()
86 },
87 },
88 wl_message {
89 name: c"mode_switch".as_ptr(),
90 signature: c"uuu".as_ptr(),
91 types: {
92 static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
93 TYPES.as_ptr().cast()
94 },
95 },
96 ];
97 MESSAGES.as_ptr()
98 },
99};
100
101/// An owned zwp_tablet_pad_group_v2 proxy.
102///
103/// See the documentation of [the module][self] for the interface description.
104#[derive(Clone, Eq, PartialEq)]
105#[repr(transparent)]
106pub struct ZwpTabletPadGroupV2 {
107 /// This proxy has the interface INTERFACE.
108 proxy: UntypedOwnedProxy,
109}
110
111/// A borrowed zwp_tablet_pad_group_v2 proxy.
112///
113/// See the documentation of [the module][self] for the interface description.
114#[derive(Eq, PartialEq)]
115#[repr(transparent)]
116pub struct ZwpTabletPadGroupV2Ref {
117 /// This proxy has the interface INTERFACE.
118 proxy: UntypedBorrowedProxy,
119}
120
121// SAFETY: ZwpTabletPadGroupV2 is a transparent wrapper around UntypedOwnedProxy
122unsafe impl UntypedOwnedProxyWrapper for ZwpTabletPadGroupV2 {}
123
124// SAFETY: - INTERFACE is a valid wl_interface
125// - The only invariant is that self.proxy has a compatible interface
126unsafe impl OwnedProxy for ZwpTabletPadGroupV2 {
127 const INTERFACE: &'static str = "zwp_tablet_pad_group_v2";
128 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
129 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
130 private::EventHandler(private::NoOpEventHandler);
131 const MAX_VERSION: u32 = 1;
132
133 type Borrowed = ZwpTabletPadGroupV2Ref;
134 type Api = private::ProxyApi;
135 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
136}
137
138// SAFETY: ZwpTabletPadGroupV2Ref is a transparent wrapper around UntypedBorrowedProxy
139unsafe impl UntypedBorrowedProxyWrapper for ZwpTabletPadGroupV2Ref {}
140
141// SAFETY: - The only invariant is that self.proxy has a compatible interface
142unsafe impl BorrowedProxy for ZwpTabletPadGroupV2Ref {
143 type Owned = ZwpTabletPadGroupV2;
144}
145
146impl Deref for ZwpTabletPadGroupV2 {
147 type Target = ZwpTabletPadGroupV2Ref;
148
149 fn deref(&self) -> &Self::Target {
150 proxy::low_level::deref(self)
151 }
152}
153
154mod private {
155 pub struct ProxyApi;
156
157 #[allow(dead_code)]
158 pub struct EventHandler<H>(pub(super) H);
159
160 #[allow(dead_code)]
161 pub struct NoOpEventHandler;
162}
163
164impl Debug for ZwpTabletPadGroupV2 {
165 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
166 write!(f, "zwp_tablet_pad_group_v2#{}", self.proxy.id())
167 }
168}
169
170impl Debug for ZwpTabletPadGroupV2Ref {
171 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
172 write!(f, "zwp_tablet_pad_group_v2#{}", self.proxy.id())
173 }
174}
175
176impl PartialEq<ZwpTabletPadGroupV2Ref> for ZwpTabletPadGroupV2 {
177 fn eq(&self, other: &ZwpTabletPadGroupV2Ref) -> bool {
178 self.proxy == other.proxy
179 }
180}
181
182impl PartialEq<ZwpTabletPadGroupV2> for ZwpTabletPadGroupV2Ref {
183 fn eq(&self, other: &ZwpTabletPadGroupV2) -> bool {
184 self.proxy == other.proxy
185 }
186}
187
188#[allow(dead_code)]
189impl ZwpTabletPadGroupV2 {
190 /// Since when the destroy request is available.
191 #[allow(dead_code)]
192 pub const REQ__DESTROY__SINCE: u32 = 1;
193}
194
195#[allow(dead_code)]
196impl ZwpTabletPadGroupV2 {
197 /// destroy the pad object
198 ///
199 /// Destroy the wp_tablet_pad_group object. Objects created from this object
200 /// are unaffected and should be destroyed separately.
201 #[inline]
202 pub fn destroy(&self) {
203 let mut args = [];
204 // SAFETY: - self.proxy has the interface INTERFACE
205 // - 0 < INTERFACE.method_count = 1
206 // - the request signature is ``
207 unsafe {
208 self.proxy.send_destructor(0, &mut args);
209 }
210 }
211}
212
213impl ZwpTabletPadGroupV2 {
214 /// Since when the buttons event is available.
215 #[allow(dead_code)]
216 pub const EVT__BUTTONS__SINCE: u32 = 1;
217
218 /// Since when the ring event is available.
219 #[allow(dead_code)]
220 pub const EVT__RING__SINCE: u32 = 1;
221
222 /// Since when the strip event is available.
223 #[allow(dead_code)]
224 pub const EVT__STRIP__SINCE: u32 = 1;
225
226 /// Since when the modes event is available.
227 #[allow(dead_code)]
228 pub const EVT__MODES__SINCE: u32 = 1;
229
230 /// Since when the done event is available.
231 #[allow(dead_code)]
232 pub const EVT__DONE__SINCE: u32 = 1;
233
234 /// Since when the mode_switch event is available.
235 #[allow(dead_code)]
236 pub const EVT__MODE_SWITCH__SINCE: u32 = 1;
237}
238
239/// An event handler for [ZwpTabletPadGroupV2] proxies.
240#[allow(dead_code)]
241pub trait ZwpTabletPadGroupV2EventHandler {
242 /// buttons announced
243 ///
244 /// Sent on wp_tablet_pad_group initialization to announce the available
245 /// buttons in the group. Button indices start at 0, a button may only be
246 /// in one group at a time.
247 ///
248 /// This event is first sent in the initial burst of events before the
249 /// wp_tablet_pad_group.done event.
250 ///
251 /// Some buttons are reserved by the compositor. These buttons may not be
252 /// assigned to any wp_tablet_pad_group. Compositors may broadcast this
253 /// event in the case of changes to the mapping of these reserved buttons.
254 /// If the compositor happens to reserve all buttons in a group, this event
255 /// will be sent with an empty array.
256 ///
257 /// # Arguments
258 ///
259 /// - `buttons`: buttons in this group
260 #[inline]
261 fn buttons(&self, _slf: &ZwpTabletPadGroupV2Ref, buttons: &[u8]) {
262 let _ = buttons;
263 }
264
265 /// ring announced
266 ///
267 /// Sent on wp_tablet_pad_group initialization to announce available rings.
268 /// One event is sent for each ring available on this pad group.
269 ///
270 /// This event is sent in the initial burst of events before the
271 /// wp_tablet_pad_group.done event.
272 ///
273 /// # Arguments
274 ///
275 /// - `ring`:
276 #[inline]
277 fn ring(&self, _slf: &ZwpTabletPadGroupV2Ref, ring: ZwpTabletPadRingV2) {
278 let _ = ring;
279 }
280
281 /// strip announced
282 ///
283 /// Sent on wp_tablet_pad initialization to announce available strips.
284 /// One event is sent for each strip available on this pad group.
285 ///
286 /// This event is sent in the initial burst of events before the
287 /// wp_tablet_pad_group.done event.
288 ///
289 /// # Arguments
290 ///
291 /// - `strip`:
292 #[inline]
293 fn strip(&self, _slf: &ZwpTabletPadGroupV2Ref, strip: ZwpTabletPadStripV2) {
294 let _ = strip;
295 }
296
297 /// mode-switch ability announced
298 ///
299 /// Sent on wp_tablet_pad_group initialization to announce that the pad
300 /// group may switch between modes. A client may use a mode to store a
301 /// specific configuration for buttons, rings and strips and use the
302 /// wl_tablet_pad_group.mode_switch event to toggle between these
303 /// configurations. Mode indices start at 0.
304 ///
305 /// Switching modes is compositor-dependent. See the
306 /// wp_tablet_pad_group.mode_switch event for more details.
307 ///
308 /// This event is sent in the initial burst of events before the
309 /// wp_tablet_pad_group.done event. This event is only sent when more than
310 /// more than one mode is available.
311 ///
312 /// # Arguments
313 ///
314 /// - `modes`: the number of modes
315 #[inline]
316 fn modes(&self, _slf: &ZwpTabletPadGroupV2Ref, modes: u32) {
317 let _ = modes;
318 }
319
320 /// tablet group description events sequence complete
321 ///
322 /// This event is sent immediately to signal the end of the initial
323 /// burst of descriptive events. A client may consider the static
324 /// description of the tablet to be complete and finalize initialization
325 /// of the tablet group.
326 #[inline]
327 fn done(&self, _slf: &ZwpTabletPadGroupV2Ref) {}
328
329 /// mode switch event
330 ///
331 /// Notification that the mode was switched.
332 ///
333 /// A mode applies to all buttons, rings and strips in a group
334 /// simultaneously, but a client is not required to assign different actions
335 /// for each mode. For example, a client may have mode-specific button
336 /// mappings but map the ring to vertical scrolling in all modes. Mode
337 /// indices start at 0.
338 ///
339 /// Switching modes is compositor-dependent. The compositor may provide
340 /// visual cues to the user about the mode, e.g. by toggling LEDs on
341 /// the tablet device. Mode-switching may be software-controlled or
342 /// controlled by one or more physical buttons. For example, on a Wacom
343 /// Intuos Pro, the button inside the ring may be assigned to switch
344 /// between modes.
345 ///
346 /// The compositor will also send this event after wp_tablet_pad.enter on
347 /// each group in order to notify of the current mode. Groups that only
348 /// feature one mode will use mode=0 when emitting this event.
349 ///
350 /// If a button action in the new mode differs from the action in the
351 /// previous mode, the client should immediately issue a
352 /// wp_tablet_pad.set_feedback request for each changed button.
353 ///
354 /// If a ring or strip action in the new mode differs from the action
355 /// in the previous mode, the client should immediately issue a
356 /// wp_tablet_ring.set_feedback or wp_tablet_strip.set_feedback request
357 /// for each changed ring or strip.
358 ///
359 /// # Arguments
360 ///
361 /// - `time`: the time of the event with millisecond granularity
362 /// - `serial`:
363 /// - `mode`: the new mode of the pad
364 #[inline]
365 fn mode_switch(&self, _slf: &ZwpTabletPadGroupV2Ref, time: u32, serial: u32, mode: u32) {
366 let _ = time;
367 let _ = serial;
368 let _ = mode;
369 }
370}
371
372impl ZwpTabletPadGroupV2EventHandler for private::NoOpEventHandler {}
373
374// SAFETY: - INTERFACE is a valid wl_interface
375unsafe impl<H> EventHandler for private::EventHandler<H>
376where
377 H: ZwpTabletPadGroupV2EventHandler,
378{
379 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
380
381 #[allow(unused_variables)]
382 unsafe fn handle_event(
383 &self,
384 queue: &Queue,
385 data: *mut u8,
386 slf: &UntypedBorrowedProxy,
387 opcode: u32,
388 args: *mut wl_argument,
389 ) {
390 // SAFETY: This function requires that slf has the interface INTERFACE
391 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<ZwpTabletPadGroupV2Ref>(slf) };
392 match opcode {
393 0 => {
394 // SAFETY: INTERFACE requires that there are 1 arguments
395 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
396 // SAFETY: - INTERFACE requires that args[0] contains an array
397 let arg0 = unsafe {
398 let a = &*args[0].a;
399 std::slice::from_raw_parts(a.data.cast(), a.size)
400 };
401 self.0.buttons(slf, arg0);
402 }
403 1 => {
404 // SAFETY: INTERFACE requires that there are 1 arguments
405 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
406 // SAFETY: - INTERFACE requires that args[0] contains an object
407 // - ownership is transferred to this function
408 // - INTERFACE requires that the object has the interface ZwpTabletPadRingV2::WL_INTERFACE
409 let arg0 = unsafe {
410 UntypedOwnedProxy::from_plain_wl_proxy(
411 queue,
412 NonNull::new_unchecked(args[0].o.cast()),
413 ZwpTabletPadRingV2::WL_INTERFACE,
414 )
415 };
416 // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletPadRingV2::WL_INTERFACE
417 let arg0 =
418 unsafe { proxy::low_level::from_untyped_owned::<ZwpTabletPadRingV2>(arg0) };
419 self.0.ring(slf, arg0);
420 }
421 2 => {
422 // SAFETY: INTERFACE requires that there are 1 arguments
423 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
424 // SAFETY: - INTERFACE requires that args[0] contains an object
425 // - ownership is transferred to this function
426 // - INTERFACE requires that the object has the interface ZwpTabletPadStripV2::WL_INTERFACE
427 let arg0 = unsafe {
428 UntypedOwnedProxy::from_plain_wl_proxy(
429 queue,
430 NonNull::new_unchecked(args[0].o.cast()),
431 ZwpTabletPadStripV2::WL_INTERFACE,
432 )
433 };
434 // SAFETY: - INTERFACE requires that the object has the interface ZwpTabletPadStripV2::WL_INTERFACE
435 let arg0 =
436 unsafe { proxy::low_level::from_untyped_owned::<ZwpTabletPadStripV2>(arg0) };
437 self.0.strip(slf, arg0);
438 }
439 3 => {
440 // SAFETY: INTERFACE requires that there are 1 arguments
441 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
442 // SAFETY: - INTERFACE requires that args[0] contains a uint
443 let arg0 = unsafe { args[0].u };
444 self.0.modes(slf, arg0);
445 }
446 4 => {
447 self.0.done(slf);
448 }
449 5 => {
450 // SAFETY: INTERFACE requires that there are 3 arguments
451 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
452 // SAFETY: - INTERFACE requires that args[0] contains a uint
453 let arg0 = unsafe { args[0].u };
454 // SAFETY: - INTERFACE requires that args[1] contains a uint
455 let arg1 = unsafe { args[1].u };
456 // SAFETY: - INTERFACE requires that args[2] contains a uint
457 let arg2 = unsafe { args[2].u };
458 self.0.mode_switch(slf, arg0, arg1, arg2);
459 }
460 _ => {
461 invalid_opcode("zwp_tablet_pad_group_v2", opcode);
462 }
463 }
464 }
465}
466
467impl<H> CreateEventHandler<H> for private::ProxyApi
468where
469 H: ZwpTabletPadGroupV2EventHandler,
470{
471 type EventHandler = private::EventHandler<H>;
472
473 #[inline]
474 fn create_event_handler(handler: H) -> Self::EventHandler {
475 private::EventHandler(handler)
476 }
477}
478
479/// Functional event handlers.
480pub mod event_handlers {
481 use super::*;
482
483 /// Event handler for buttons events.
484 pub struct Buttons<F>(F);
485 impl<F> ZwpTabletPadGroupV2EventHandler for Buttons<F>
486 where
487 F: Fn(&ZwpTabletPadGroupV2Ref, &[u8]),
488 {
489 #[inline]
490 fn buttons(&self, _slf: &ZwpTabletPadGroupV2Ref, buttons: &[u8]) {
491 self.0(_slf, buttons)
492 }
493 }
494
495 /// Event handler for ring events.
496 pub struct Ring<F>(F);
497 impl<F> ZwpTabletPadGroupV2EventHandler for Ring<F>
498 where
499 F: Fn(&ZwpTabletPadGroupV2Ref, ZwpTabletPadRingV2),
500 {
501 #[inline]
502 fn ring(&self, _slf: &ZwpTabletPadGroupV2Ref, ring: ZwpTabletPadRingV2) {
503 self.0(_slf, ring)
504 }
505 }
506
507 /// Event handler for strip events.
508 pub struct Strip<F>(F);
509 impl<F> ZwpTabletPadGroupV2EventHandler for Strip<F>
510 where
511 F: Fn(&ZwpTabletPadGroupV2Ref, ZwpTabletPadStripV2),
512 {
513 #[inline]
514 fn strip(&self, _slf: &ZwpTabletPadGroupV2Ref, strip: ZwpTabletPadStripV2) {
515 self.0(_slf, strip)
516 }
517 }
518
519 /// Event handler for modes events.
520 pub struct Modes<F>(F);
521 impl<F> ZwpTabletPadGroupV2EventHandler for Modes<F>
522 where
523 F: Fn(&ZwpTabletPadGroupV2Ref, u32),
524 {
525 #[inline]
526 fn modes(&self, _slf: &ZwpTabletPadGroupV2Ref, modes: u32) {
527 self.0(_slf, modes)
528 }
529 }
530
531 /// Event handler for done events.
532 pub struct Done<F>(F);
533 impl<F> ZwpTabletPadGroupV2EventHandler for Done<F>
534 where
535 F: Fn(&ZwpTabletPadGroupV2Ref),
536 {
537 #[inline]
538 fn done(&self, _slf: &ZwpTabletPadGroupV2Ref) {
539 self.0(_slf)
540 }
541 }
542
543 /// Event handler for mode_switch events.
544 pub struct ModeSwitch<F>(F);
545 impl<F> ZwpTabletPadGroupV2EventHandler for ModeSwitch<F>
546 where
547 F: Fn(&ZwpTabletPadGroupV2Ref, u32, u32, u32),
548 {
549 #[inline]
550 fn mode_switch(&self, _slf: &ZwpTabletPadGroupV2Ref, time: u32, serial: u32, mode: u32) {
551 self.0(_slf, time, serial, mode)
552 }
553 }
554
555 impl ZwpTabletPadGroupV2 {
556 /// Creates an event handler for buttons events.
557 ///
558 /// The event handler ignores all other events.
559 #[allow(dead_code)]
560 pub fn on_buttons<F>(f: F) -> Buttons<F>
561 where
562 F: Fn(&ZwpTabletPadGroupV2Ref, &[u8]),
563 {
564 Buttons(f)
565 }
566
567 /// Creates an event handler for ring events.
568 ///
569 /// The event handler ignores all other events.
570 #[allow(dead_code)]
571 pub fn on_ring<F>(f: F) -> Ring<F>
572 where
573 F: Fn(&ZwpTabletPadGroupV2Ref, ZwpTabletPadRingV2),
574 {
575 Ring(f)
576 }
577
578 /// Creates an event handler for strip events.
579 ///
580 /// The event handler ignores all other events.
581 #[allow(dead_code)]
582 pub fn on_strip<F>(f: F) -> Strip<F>
583 where
584 F: Fn(&ZwpTabletPadGroupV2Ref, ZwpTabletPadStripV2),
585 {
586 Strip(f)
587 }
588
589 /// Creates an event handler for modes events.
590 ///
591 /// The event handler ignores all other events.
592 #[allow(dead_code)]
593 pub fn on_modes<F>(f: F) -> Modes<F>
594 where
595 F: Fn(&ZwpTabletPadGroupV2Ref, u32),
596 {
597 Modes(f)
598 }
599
600 /// Creates an event handler for done events.
601 ///
602 /// The event handler ignores all other events.
603 #[allow(dead_code)]
604 pub fn on_done<F>(f: F) -> Done<F>
605 where
606 F: Fn(&ZwpTabletPadGroupV2Ref),
607 {
608 Done(f)
609 }
610
611 /// Creates an event handler for mode_switch events.
612 ///
613 /// The event handler ignores all other events.
614 #[allow(dead_code)]
615 pub fn on_mode_switch<F>(f: F) -> ModeSwitch<F>
616 where
617 F: Fn(&ZwpTabletPadGroupV2Ref, u32, u32, u32),
618 {
619 ModeSwitch(f)
620 }
621 }
622}