get_registry/common/protocols/tablet_v2/zwp_tablet_pad_ring_v2.rs
1//! pad ring
2//!
3//! A circular interaction area, such as the touch ring on the Wacom Intuos
4//! Pro series tablets.
5//!
6//! Events on a ring are logically grouped by the wl_tablet_pad_ring.frame
7//! event.
8
9use super::super::all_types::*;
10use ::wl_client::builder::prelude::*;
11
12static INTERFACE: wl_interface = wl_interface {
13 name: c"zwp_tablet_pad_ring_v2".as_ptr(),
14 version: 1,
15 method_count: 2,
16 methods: {
17 static MESSAGES: [wl_message; 2] = [
18 wl_message {
19 name: c"set_feedback".as_ptr(),
20 signature: c"su".as_ptr(),
21 types: {
22 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
23 TYPES.as_ptr().cast()
24 },
25 },
26 wl_message {
27 name: c"destroy".as_ptr(),
28 signature: c"".as_ptr(),
29 types: {
30 static TYPES: [Option<&'static wl_interface>; 0] = [];
31 TYPES.as_ptr().cast()
32 },
33 },
34 ];
35 MESSAGES.as_ptr()
36 },
37 event_count: 4,
38 events: {
39 static MESSAGES: [wl_message; 4] = [
40 wl_message {
41 name: c"source".as_ptr(),
42 signature: c"u".as_ptr(),
43 types: {
44 static TYPES: [Option<&'static wl_interface>; 1] = [None];
45 TYPES.as_ptr().cast()
46 },
47 },
48 wl_message {
49 name: c"angle".as_ptr(),
50 signature: c"f".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"stop".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"frame".as_ptr(),
66 signature: c"u".as_ptr(),
67 types: {
68 static TYPES: [Option<&'static wl_interface>; 1] = [None];
69 TYPES.as_ptr().cast()
70 },
71 },
72 ];
73 MESSAGES.as_ptr()
74 },
75};
76
77/// An owned zwp_tablet_pad_ring_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 ZwpTabletPadRingV2 {
83 /// This proxy has the interface INTERFACE.
84 proxy: UntypedOwnedProxy,
85}
86
87/// A borrowed zwp_tablet_pad_ring_v2 proxy.
88///
89/// See the documentation of [the module][self] for the interface description.
90#[derive(Eq, PartialEq)]
91#[repr(transparent)]
92pub struct ZwpTabletPadRingV2Ref {
93 /// This proxy has the interface INTERFACE.
94 proxy: UntypedBorrowedProxy,
95}
96
97// SAFETY: ZwpTabletPadRingV2 is a transparent wrapper around UntypedOwnedProxy
98unsafe impl UntypedOwnedProxyWrapper for ZwpTabletPadRingV2 {}
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 ZwpTabletPadRingV2 {
103 const INTERFACE: &'static str = "zwp_tablet_pad_ring_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 = ZwpTabletPadRingV2Ref;
110 type Api = private::ProxyApi;
111 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
112}
113
114// SAFETY: ZwpTabletPadRingV2Ref is a transparent wrapper around UntypedBorrowedProxy
115unsafe impl UntypedBorrowedProxyWrapper for ZwpTabletPadRingV2Ref {}
116
117// SAFETY: - The only invariant is that self.proxy has a compatible interface
118unsafe impl BorrowedProxy for ZwpTabletPadRingV2Ref {
119 type Owned = ZwpTabletPadRingV2;
120}
121
122impl Deref for ZwpTabletPadRingV2 {
123 type Target = ZwpTabletPadRingV2Ref;
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 ZwpTabletPadRingV2 {
141 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
142 write!(f, "zwp_tablet_pad_ring_v2#{}", self.proxy.id())
143 }
144}
145
146impl Debug for ZwpTabletPadRingV2Ref {
147 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
148 write!(f, "zwp_tablet_pad_ring_v2#{}", self.proxy.id())
149 }
150}
151
152impl PartialEq<ZwpTabletPadRingV2Ref> for ZwpTabletPadRingV2 {
153 fn eq(&self, other: &ZwpTabletPadRingV2Ref) -> bool {
154 self.proxy == other.proxy
155 }
156}
157
158impl PartialEq<ZwpTabletPadRingV2> for ZwpTabletPadRingV2Ref {
159 fn eq(&self, other: &ZwpTabletPadRingV2) -> bool {
160 self.proxy == other.proxy
161 }
162}
163
164#[allow(dead_code)]
165impl ZwpTabletPadRingV2 {
166 /// Since when the set_feedback request is available.
167 #[allow(dead_code)]
168 pub const REQ__SET_FEEDBACK__SINCE: u32 = 1;
169
170 /// Since when the destroy request is available.
171 #[allow(dead_code)]
172 pub const REQ__DESTROY__SINCE: u32 = 1;
173}
174
175#[allow(dead_code)]
176impl ZwpTabletPadRingV2 {
177 /// destroy the ring object
178 ///
179 /// This destroys the client's resource for this ring object.
180 #[inline]
181 pub fn destroy(&self) {
182 let mut args = [];
183 // SAFETY: - self.proxy has the interface INTERFACE
184 // - 1 < INTERFACE.method_count = 2
185 // - the request signature is ``
186 unsafe {
187 self.proxy.send_destructor(1, &mut args);
188 }
189 }
190}
191
192#[allow(dead_code)]
193impl ZwpTabletPadRingV2Ref {
194 /// set compositor feedback
195 ///
196 /// Request that the compositor use the provided feedback string
197 /// associated with this ring. This request should be issued immediately
198 /// after a wp_tablet_pad_group.mode_switch event from the corresponding
199 /// group is received, or whenever the ring is mapped to a different
200 /// action. See wp_tablet_pad_group.mode_switch for more details.
201 ///
202 /// Clients are encouraged to provide context-aware descriptions for
203 /// the actions associated with the ring; compositors may use this
204 /// information to offer visual feedback about the button layout
205 /// (eg. on-screen displays).
206 ///
207 /// The provided string 'description' is a UTF-8 encoded string to be
208 /// associated with this ring, and is considered user-visible; general
209 /// internationalization rules apply.
210 ///
211 /// The serial argument will be that of the last
212 /// wp_tablet_pad_group.mode_switch event received for the group of this
213 /// ring. Requests providing other serials than the most recent one will be
214 /// ignored.
215 ///
216 /// # Arguments
217 ///
218 /// - `description`: ring description
219 /// - `serial`: serial of the mode switch event
220 #[inline]
221 pub fn set_feedback(&self, description: &str, serial: u32) {
222 let (arg0, arg1) = (description, serial);
223 with_cstr_cache(|cache| {
224 let str0_offset = cache.len();
225 cache.extend_from_slice(arg0.as_bytes());
226 cache.push(0);
227 let str0 = cache[str0_offset..].as_ptr().cast();
228 let mut args = [wl_argument { s: str0 }, wl_argument { u: arg1 }];
229 // SAFETY: - self.proxy has the interface INTERFACE
230 // - 0 < INTERFACE.method_count = 2
231 // - the request signature is `su`
232 unsafe {
233 self.proxy.send_request(0, &mut args);
234 }
235 })
236 }
237}
238
239impl ZwpTabletPadRingV2 {
240 /// Since when the source event is available.
241 #[allow(dead_code)]
242 pub const EVT__SOURCE__SINCE: u32 = 1;
243
244 /// Since when the angle event is available.
245 #[allow(dead_code)]
246 pub const EVT__ANGLE__SINCE: u32 = 1;
247
248 /// Since when the stop event is available.
249 #[allow(dead_code)]
250 pub const EVT__STOP__SINCE: u32 = 1;
251
252 /// Since when the frame event is available.
253 #[allow(dead_code)]
254 pub const EVT__FRAME__SINCE: u32 = 1;
255}
256
257/// An event handler for [ZwpTabletPadRingV2] proxies.
258#[allow(dead_code)]
259pub trait ZwpTabletPadRingV2EventHandler {
260 /// ring event source
261 ///
262 /// Source information for ring events.
263 ///
264 /// This event does not occur on its own. It is sent before a
265 /// wp_tablet_pad_ring.frame event and carries the source information
266 /// for all events within that frame.
267 ///
268 /// The source specifies how this event was generated. If the source is
269 /// wp_tablet_pad_ring.source.finger, a wp_tablet_pad_ring.stop event
270 /// will be sent when the user lifts the finger off the device.
271 ///
272 /// This event is optional. If the source is unknown for an interaction,
273 /// no event is sent.
274 ///
275 /// # Arguments
276 ///
277 /// - `source`: the event source
278 #[inline]
279 fn source(&self, _slf: &ZwpTabletPadRingV2Ref, source: ZwpTabletPadRingV2Source) {
280 let _ = source;
281 }
282
283 /// angle changed
284 ///
285 /// Sent whenever the angle on a ring changes.
286 ///
287 /// The angle is provided in degrees clockwise from the logical
288 /// north of the ring in the pad's current rotation.
289 ///
290 /// # Arguments
291 ///
292 /// - `degrees`: the current angle in degrees
293 #[inline]
294 fn angle(&self, _slf: &ZwpTabletPadRingV2Ref, degrees: Fixed) {
295 let _ = degrees;
296 }
297
298 /// interaction stopped
299 ///
300 /// Stop notification for ring events.
301 ///
302 /// For some wp_tablet_pad_ring.source types, a wp_tablet_pad_ring.stop
303 /// event is sent to notify a client that the interaction with the ring
304 /// has terminated. This enables the client to implement kinetic scrolling.
305 /// See the wp_tablet_pad_ring.source documentation for information on
306 /// when this event may be generated.
307 ///
308 /// Any wp_tablet_pad_ring.angle events with the same source after this
309 /// event should be considered as the start of a new interaction.
310 #[inline]
311 fn stop(&self, _slf: &ZwpTabletPadRingV2Ref) {}
312
313 /// end of a ring event sequence
314 ///
315 /// Indicates the end of a set of ring events that logically belong
316 /// together. A client is expected to accumulate the data in all events
317 /// within the frame before proceeding.
318 ///
319 /// All wp_tablet_pad_ring events before a wp_tablet_pad_ring.frame event belong
320 /// logically together. For example, on termination of a finger interaction
321 /// on a ring the compositor will send a wp_tablet_pad_ring.source event,
322 /// a wp_tablet_pad_ring.stop event and a wp_tablet_pad_ring.frame event.
323 ///
324 /// A wp_tablet_pad_ring.frame event is sent for every logical event
325 /// group, even if the group only contains a single wp_tablet_pad_ring
326 /// event. Specifically, a client may get a sequence: angle, frame,
327 /// angle, frame, etc.
328 ///
329 /// # Arguments
330 ///
331 /// - `time`: timestamp with millisecond granularity
332 #[inline]
333 fn frame(&self, _slf: &ZwpTabletPadRingV2Ref, time: u32) {
334 let _ = time;
335 }
336}
337
338impl ZwpTabletPadRingV2EventHandler for private::NoOpEventHandler {}
339
340// SAFETY: - INTERFACE is a valid wl_interface
341unsafe impl<H> EventHandler for private::EventHandler<H>
342where
343 H: ZwpTabletPadRingV2EventHandler,
344{
345 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
346
347 #[allow(unused_variables)]
348 unsafe fn handle_event(
349 &self,
350 queue: &Queue,
351 data: *mut u8,
352 slf: &UntypedBorrowedProxy,
353 opcode: u32,
354 args: *mut wl_argument,
355 ) {
356 // SAFETY: This function requires that slf has the interface INTERFACE
357 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<ZwpTabletPadRingV2Ref>(slf) };
358 match opcode {
359 0 => {
360 // SAFETY: INTERFACE requires that there are 1 arguments
361 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
362 // SAFETY: - INTERFACE requires that args[0] contains a uint
363 let arg0 = unsafe { ZwpTabletPadRingV2Source(args[0].u) };
364 self.0.source(slf, arg0);
365 }
366 1 => {
367 // SAFETY: INTERFACE requires that there are 1 arguments
368 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
369 // SAFETY: - INTERFACE requires that args[0] contains a fixed
370 let arg0 = unsafe { Fixed::from_wire(args[0].f) };
371 self.0.angle(slf, arg0);
372 }
373 2 => {
374 self.0.stop(slf);
375 }
376 3 => {
377 // SAFETY: INTERFACE requires that there are 1 arguments
378 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
379 // SAFETY: - INTERFACE requires that args[0] contains a uint
380 let arg0 = unsafe { args[0].u };
381 self.0.frame(slf, arg0);
382 }
383 _ => {
384 invalid_opcode("zwp_tablet_pad_ring_v2", opcode);
385 }
386 }
387 }
388}
389
390impl<H> CreateEventHandler<H> for private::ProxyApi
391where
392 H: ZwpTabletPadRingV2EventHandler,
393{
394 type EventHandler = private::EventHandler<H>;
395
396 #[inline]
397 fn create_event_handler(handler: H) -> Self::EventHandler {
398 private::EventHandler(handler)
399 }
400}
401
402impl ZwpTabletPadRingV2 {
403 /// Since when the source.finger enum variant is available.
404 #[allow(dead_code)]
405 pub const ENM__SOURCE_FINGER__SINCE: u32 = 1;
406}
407
408/// ring axis source
409///
410/// Describes the source types for ring events. This indicates to the
411/// client how a ring event was physically generated; a client may
412/// adjust the user interface accordingly. For example, events
413/// from a "finger" source may trigger kinetic scrolling.
414#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
415#[allow(dead_code)]
416pub struct ZwpTabletPadRingV2Source(pub u32);
417
418impl ZwpTabletPadRingV2Source {
419 /// finger
420 #[allow(dead_code)]
421 pub const FINGER: Self = Self(1);
422}
423
424impl Debug for ZwpTabletPadRingV2Source {
425 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
426 let name = match *self {
427 Self::FINGER => "FINGER",
428 _ => return Debug::fmt(&self.0, f),
429 };
430 f.write_str(name)
431 }
432}
433
434/// Functional event handlers.
435pub mod event_handlers {
436 use super::*;
437
438 /// Event handler for source events.
439 pub struct Source<F>(F);
440 impl<F> ZwpTabletPadRingV2EventHandler for Source<F>
441 where
442 F: Fn(&ZwpTabletPadRingV2Ref, ZwpTabletPadRingV2Source),
443 {
444 #[inline]
445 fn source(&self, _slf: &ZwpTabletPadRingV2Ref, source: ZwpTabletPadRingV2Source) {
446 self.0(_slf, source)
447 }
448 }
449
450 /// Event handler for angle events.
451 pub struct Angle<F>(F);
452 impl<F> ZwpTabletPadRingV2EventHandler for Angle<F>
453 where
454 F: Fn(&ZwpTabletPadRingV2Ref, Fixed),
455 {
456 #[inline]
457 fn angle(&self, _slf: &ZwpTabletPadRingV2Ref, degrees: Fixed) {
458 self.0(_slf, degrees)
459 }
460 }
461
462 /// Event handler for stop events.
463 pub struct Stop<F>(F);
464 impl<F> ZwpTabletPadRingV2EventHandler for Stop<F>
465 where
466 F: Fn(&ZwpTabletPadRingV2Ref),
467 {
468 #[inline]
469 fn stop(&self, _slf: &ZwpTabletPadRingV2Ref) {
470 self.0(_slf)
471 }
472 }
473
474 /// Event handler for frame events.
475 pub struct Frame<F>(F);
476 impl<F> ZwpTabletPadRingV2EventHandler for Frame<F>
477 where
478 F: Fn(&ZwpTabletPadRingV2Ref, u32),
479 {
480 #[inline]
481 fn frame(&self, _slf: &ZwpTabletPadRingV2Ref, time: u32) {
482 self.0(_slf, time)
483 }
484 }
485
486 impl ZwpTabletPadRingV2 {
487 /// Creates an event handler for source events.
488 ///
489 /// The event handler ignores all other events.
490 #[allow(dead_code)]
491 pub fn on_source<F>(f: F) -> Source<F>
492 where
493 F: Fn(&ZwpTabletPadRingV2Ref, ZwpTabletPadRingV2Source),
494 {
495 Source(f)
496 }
497
498 /// Creates an event handler for angle events.
499 ///
500 /// The event handler ignores all other events.
501 #[allow(dead_code)]
502 pub fn on_angle<F>(f: F) -> Angle<F>
503 where
504 F: Fn(&ZwpTabletPadRingV2Ref, Fixed),
505 {
506 Angle(f)
507 }
508
509 /// Creates an event handler for stop events.
510 ///
511 /// The event handler ignores all other events.
512 #[allow(dead_code)]
513 pub fn on_stop<F>(f: F) -> Stop<F>
514 where
515 F: Fn(&ZwpTabletPadRingV2Ref),
516 {
517 Stop(f)
518 }
519
520 /// Creates an event handler for frame events.
521 ///
522 /// The event handler ignores all other events.
523 #[allow(dead_code)]
524 pub fn on_frame<F>(f: F) -> Frame<F>
525 where
526 F: Fn(&ZwpTabletPadRingV2Ref, u32),
527 {
528 Frame(f)
529 }
530 }
531}