get_registry/common/protocols/tablet_v2/zwp_tablet_pad_strip_v2.rs
1//! pad strip
2//!
3//! A linear interaction area, such as the strips found in Wacom Cintiq
4//! models.
5//!
6//! Events on a strip are logically grouped by the wl_tablet_pad_strip.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_strip_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"position".as_ptr(),
50 signature: c"u".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_strip_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 ZwpTabletPadStripV2 {
83 /// This proxy has the interface INTERFACE.
84 proxy: UntypedOwnedProxy,
85}
86
87/// A borrowed zwp_tablet_pad_strip_v2 proxy.
88///
89/// See the documentation of [the module][self] for the interface description.
90#[derive(Eq, PartialEq)]
91#[repr(transparent)]
92pub struct ZwpTabletPadStripV2Ref {
93 /// This proxy has the interface INTERFACE.
94 proxy: UntypedBorrowedProxy,
95}
96
97// SAFETY: ZwpTabletPadStripV2 is a transparent wrapper around UntypedOwnedProxy
98unsafe impl UntypedOwnedProxyWrapper for ZwpTabletPadStripV2 {}
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 ZwpTabletPadStripV2 {
103 const INTERFACE: &'static str = "zwp_tablet_pad_strip_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 = ZwpTabletPadStripV2Ref;
110 type Api = private::ProxyApi;
111 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
112}
113
114// SAFETY: ZwpTabletPadStripV2Ref is a transparent wrapper around UntypedBorrowedProxy
115unsafe impl UntypedBorrowedProxyWrapper for ZwpTabletPadStripV2Ref {}
116
117// SAFETY: - The only invariant is that self.proxy has a compatible interface
118unsafe impl BorrowedProxy for ZwpTabletPadStripV2Ref {
119 type Owned = ZwpTabletPadStripV2;
120}
121
122impl Deref for ZwpTabletPadStripV2 {
123 type Target = ZwpTabletPadStripV2Ref;
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 ZwpTabletPadStripV2 {
141 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
142 write!(f, "zwp_tablet_pad_strip_v2#{}", self.proxy.id())
143 }
144}
145
146impl Debug for ZwpTabletPadStripV2Ref {
147 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
148 write!(f, "zwp_tablet_pad_strip_v2#{}", self.proxy.id())
149 }
150}
151
152impl PartialEq<ZwpTabletPadStripV2Ref> for ZwpTabletPadStripV2 {
153 fn eq(&self, other: &ZwpTabletPadStripV2Ref) -> bool {
154 self.proxy == other.proxy
155 }
156}
157
158impl PartialEq<ZwpTabletPadStripV2> for ZwpTabletPadStripV2Ref {
159 fn eq(&self, other: &ZwpTabletPadStripV2) -> bool {
160 self.proxy == other.proxy
161 }
162}
163
164#[allow(dead_code)]
165impl ZwpTabletPadStripV2 {
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 ZwpTabletPadStripV2 {
177 /// destroy the strip object
178 ///
179 /// This destroys the client's resource for this strip 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 ZwpTabletPadStripV2Ref {
194 /// set compositor feedback
195 ///
196 /// Requests the compositor to use the provided feedback string
197 /// associated with this strip. 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 strip 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 strip, and 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 /// strip. Requests providing other serials than the most recent one will be
214 /// ignored.
215 ///
216 /// # Arguments
217 ///
218 /// - `description`: strip 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 ZwpTabletPadStripV2 {
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 position event is available.
245 #[allow(dead_code)]
246 pub const EVT__POSITION__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 [ZwpTabletPadStripV2] proxies.
258#[allow(dead_code)]
259pub trait ZwpTabletPadStripV2EventHandler {
260 /// strip event source
261 ///
262 /// Source information for strip events.
263 ///
264 /// This event does not occur on its own. It is sent before a
265 /// wp_tablet_pad_strip.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_strip.source.finger, a wp_tablet_pad_strip.stop event
270 /// will be sent when the user lifts their 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: &ZwpTabletPadStripV2Ref, source: ZwpTabletPadStripV2Source) {
280 let _ = source;
281 }
282
283 /// position changed
284 ///
285 /// Sent whenever the position on a strip changes.
286 ///
287 /// The position is normalized to a range of [0, 65535], the 0-value
288 /// represents the top-most and/or left-most position of the strip in
289 /// the pad's current rotation.
290 ///
291 /// # Arguments
292 ///
293 /// - `position`: the current position
294 #[inline]
295 fn position(&self, _slf: &ZwpTabletPadStripV2Ref, position: u32) {
296 let _ = position;
297 }
298
299 /// interaction stopped
300 ///
301 /// Stop notification for strip events.
302 ///
303 /// For some wp_tablet_pad_strip.source types, a wp_tablet_pad_strip.stop
304 /// event is sent to notify a client that the interaction with the strip
305 /// has terminated. This enables the client to implement kinetic
306 /// scrolling. See the wp_tablet_pad_strip.source documentation for
307 /// information on when this event may be generated.
308 ///
309 /// Any wp_tablet_pad_strip.position events with the same source after this
310 /// event should be considered as the start of a new interaction.
311 #[inline]
312 fn stop(&self, _slf: &ZwpTabletPadStripV2Ref) {}
313
314 /// end of a strip event sequence
315 ///
316 /// Indicates the end of a set of events that represent one logical
317 /// hardware strip event. A client is expected to accumulate the data
318 /// in all events within the frame before proceeding.
319 ///
320 /// All wp_tablet_pad_strip events before a wp_tablet_pad_strip.frame event belong
321 /// logically together. For example, on termination of a finger interaction
322 /// on a strip the compositor will send a wp_tablet_pad_strip.source event,
323 /// a wp_tablet_pad_strip.stop event and a wp_tablet_pad_strip.frame
324 /// event.
325 ///
326 /// A wp_tablet_pad_strip.frame event is sent for every logical event
327 /// group, even if the group only contains a single wp_tablet_pad_strip
328 /// event. Specifically, a client may get a sequence: position, frame,
329 /// position, frame, etc.
330 ///
331 /// # Arguments
332 ///
333 /// - `time`: timestamp with millisecond granularity
334 #[inline]
335 fn frame(&self, _slf: &ZwpTabletPadStripV2Ref, time: u32) {
336 let _ = time;
337 }
338}
339
340impl ZwpTabletPadStripV2EventHandler for private::NoOpEventHandler {}
341
342// SAFETY: - INTERFACE is a valid wl_interface
343unsafe impl<H> EventHandler for private::EventHandler<H>
344where
345 H: ZwpTabletPadStripV2EventHandler,
346{
347 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
348
349 #[allow(unused_variables)]
350 unsafe fn handle_event(
351 &self,
352 queue: &Queue,
353 data: *mut u8,
354 slf: &UntypedBorrowedProxy,
355 opcode: u32,
356 args: *mut wl_argument,
357 ) {
358 // SAFETY: This function requires that slf has the interface INTERFACE
359 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<ZwpTabletPadStripV2Ref>(slf) };
360 match opcode {
361 0 => {
362 // SAFETY: INTERFACE requires that there are 1 arguments
363 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
364 // SAFETY: - INTERFACE requires that args[0] contains a uint
365 let arg0 = unsafe { ZwpTabletPadStripV2Source(args[0].u) };
366 self.0.source(slf, arg0);
367 }
368 1 => {
369 // SAFETY: INTERFACE requires that there are 1 arguments
370 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
371 // SAFETY: - INTERFACE requires that args[0] contains a uint
372 let arg0 = unsafe { args[0].u };
373 self.0.position(slf, arg0);
374 }
375 2 => {
376 self.0.stop(slf);
377 }
378 3 => {
379 // SAFETY: INTERFACE requires that there are 1 arguments
380 let args = unsafe { &*args.cast::<[wl_argument; 1]>() };
381 // SAFETY: - INTERFACE requires that args[0] contains a uint
382 let arg0 = unsafe { args[0].u };
383 self.0.frame(slf, arg0);
384 }
385 _ => {
386 invalid_opcode("zwp_tablet_pad_strip_v2", opcode);
387 }
388 }
389 }
390}
391
392impl<H> CreateEventHandler<H> for private::ProxyApi
393where
394 H: ZwpTabletPadStripV2EventHandler,
395{
396 type EventHandler = private::EventHandler<H>;
397
398 #[inline]
399 fn create_event_handler(handler: H) -> Self::EventHandler {
400 private::EventHandler(handler)
401 }
402}
403
404impl ZwpTabletPadStripV2 {
405 /// Since when the source.finger enum variant is available.
406 #[allow(dead_code)]
407 pub const ENM__SOURCE_FINGER__SINCE: u32 = 1;
408}
409
410/// strip axis source
411///
412/// Describes the source types for strip events. This indicates to the
413/// client how a strip event was physically generated; a client may
414/// adjust the user interface accordingly. For example, events
415/// from a "finger" source may trigger kinetic scrolling.
416#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
417#[allow(dead_code)]
418pub struct ZwpTabletPadStripV2Source(pub u32);
419
420impl ZwpTabletPadStripV2Source {
421 /// finger
422 #[allow(dead_code)]
423 pub const FINGER: Self = Self(1);
424}
425
426impl Debug for ZwpTabletPadStripV2Source {
427 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
428 let name = match *self {
429 Self::FINGER => "FINGER",
430 _ => return Debug::fmt(&self.0, f),
431 };
432 f.write_str(name)
433 }
434}
435
436/// Functional event handlers.
437pub mod event_handlers {
438 use super::*;
439
440 /// Event handler for source events.
441 pub struct Source<F>(F);
442 impl<F> ZwpTabletPadStripV2EventHandler for Source<F>
443 where
444 F: Fn(&ZwpTabletPadStripV2Ref, ZwpTabletPadStripV2Source),
445 {
446 #[inline]
447 fn source(&self, _slf: &ZwpTabletPadStripV2Ref, source: ZwpTabletPadStripV2Source) {
448 self.0(_slf, source)
449 }
450 }
451
452 /// Event handler for position events.
453 pub struct Position<F>(F);
454 impl<F> ZwpTabletPadStripV2EventHandler for Position<F>
455 where
456 F: Fn(&ZwpTabletPadStripV2Ref, u32),
457 {
458 #[inline]
459 fn position(&self, _slf: &ZwpTabletPadStripV2Ref, position: u32) {
460 self.0(_slf, position)
461 }
462 }
463
464 /// Event handler for stop events.
465 pub struct Stop<F>(F);
466 impl<F> ZwpTabletPadStripV2EventHandler for Stop<F>
467 where
468 F: Fn(&ZwpTabletPadStripV2Ref),
469 {
470 #[inline]
471 fn stop(&self, _slf: &ZwpTabletPadStripV2Ref) {
472 self.0(_slf)
473 }
474 }
475
476 /// Event handler for frame events.
477 pub struct Frame<F>(F);
478 impl<F> ZwpTabletPadStripV2EventHandler for Frame<F>
479 where
480 F: Fn(&ZwpTabletPadStripV2Ref, u32),
481 {
482 #[inline]
483 fn frame(&self, _slf: &ZwpTabletPadStripV2Ref, time: u32) {
484 self.0(_slf, time)
485 }
486 }
487
488 impl ZwpTabletPadStripV2 {
489 /// Creates an event handler for source events.
490 ///
491 /// The event handler ignores all other events.
492 #[allow(dead_code)]
493 pub fn on_source<F>(f: F) -> Source<F>
494 where
495 F: Fn(&ZwpTabletPadStripV2Ref, ZwpTabletPadStripV2Source),
496 {
497 Source(f)
498 }
499
500 /// Creates an event handler for position events.
501 ///
502 /// The event handler ignores all other events.
503 #[allow(dead_code)]
504 pub fn on_position<F>(f: F) -> Position<F>
505 where
506 F: Fn(&ZwpTabletPadStripV2Ref, u32),
507 {
508 Position(f)
509 }
510
511 /// Creates an event handler for stop events.
512 ///
513 /// The event handler ignores all other events.
514 #[allow(dead_code)]
515 pub fn on_stop<F>(f: F) -> Stop<F>
516 where
517 F: Fn(&ZwpTabletPadStripV2Ref),
518 {
519 Stop(f)
520 }
521
522 /// Creates an event handler for frame events.
523 ///
524 /// The event handler ignores all other events.
525 #[allow(dead_code)]
526 pub fn on_frame<F>(f: F) -> Frame<F>
527 where
528 F: Fn(&ZwpTabletPadStripV2Ref, u32),
529 {
530 Frame(f)
531 }
532 }
533}