get_registry/common/protocols/wayland/wl_keyboard.rs
1//! keyboard input device
2//!
3//! The wl_keyboard interface represents one or more keyboards
4//! associated with a seat.
5//!
6//! Each wl_keyboard has the following logical state:
7//!
8//! - an active surface (possibly null),
9//! - the keys currently logically down,
10//! - the active modifiers,
11//! - the active group.
12//!
13//! By default, the active surface is null, the keys currently logically down
14//! are empty, the active modifiers and the active group are 0.
15
16use super::super::all_types::*;
17use ::wl_client::builder::prelude::*;
18
19static INTERFACE: wl_interface = wl_interface {
20 name: c"wl_keyboard".as_ptr(),
21 version: 10,
22 method_count: 1,
23 methods: {
24 static MESSAGES: [wl_message; 1] = [wl_message {
25 name: c"release".as_ptr(),
26 signature: c"".as_ptr(),
27 types: {
28 static TYPES: [Option<&'static wl_interface>; 0] = [];
29 TYPES.as_ptr().cast()
30 },
31 }];
32 MESSAGES.as_ptr()
33 },
34 event_count: 6,
35 events: {
36 static MESSAGES: [wl_message; 6] = [
37 wl_message {
38 name: c"keymap".as_ptr(),
39 signature: c"uhu".as_ptr(),
40 types: {
41 static TYPES: [Option<&'static wl_interface>; 3] = [None, None, None];
42 TYPES.as_ptr().cast()
43 },
44 },
45 wl_message {
46 name: c"enter".as_ptr(),
47 signature: c"uoa".as_ptr(),
48 types: {
49 static TYPES: [Option<&'static wl_interface>; 3] =
50 [None, Some(WlSurface::WL_INTERFACE), None];
51 TYPES.as_ptr().cast()
52 },
53 },
54 wl_message {
55 name: c"leave".as_ptr(),
56 signature: c"uo".as_ptr(),
57 types: {
58 static TYPES: [Option<&'static wl_interface>; 2] =
59 [None, Some(WlSurface::WL_INTERFACE)];
60 TYPES.as_ptr().cast()
61 },
62 },
63 wl_message {
64 name: c"key".as_ptr(),
65 signature: c"uuuu".as_ptr(),
66 types: {
67 static TYPES: [Option<&'static wl_interface>; 4] = [None, None, None, None];
68 TYPES.as_ptr().cast()
69 },
70 },
71 wl_message {
72 name: c"modifiers".as_ptr(),
73 signature: c"uuuuu".as_ptr(),
74 types: {
75 static TYPES: [Option<&'static wl_interface>; 5] =
76 [None, None, None, None, None];
77 TYPES.as_ptr().cast()
78 },
79 },
80 wl_message {
81 name: c"repeat_info".as_ptr(),
82 signature: c"ii".as_ptr(),
83 types: {
84 static TYPES: [Option<&'static wl_interface>; 2] = [None, None];
85 TYPES.as_ptr().cast()
86 },
87 },
88 ];
89 MESSAGES.as_ptr()
90 },
91};
92
93/// An owned wl_keyboard proxy.
94///
95/// See the documentation of [the module][self] for the interface description.
96#[derive(Clone, Eq, PartialEq)]
97#[repr(transparent)]
98pub struct WlKeyboard {
99 /// This proxy has the interface INTERFACE.
100 proxy: UntypedOwnedProxy,
101}
102
103/// A borrowed wl_keyboard proxy.
104///
105/// See the documentation of [the module][self] for the interface description.
106#[derive(Eq, PartialEq)]
107#[repr(transparent)]
108pub struct WlKeyboardRef {
109 /// This proxy has the interface INTERFACE.
110 proxy: UntypedBorrowedProxy,
111}
112
113// SAFETY: WlKeyboard is a transparent wrapper around UntypedOwnedProxy
114unsafe impl UntypedOwnedProxyWrapper for WlKeyboard {}
115
116// SAFETY: - INTERFACE is a valid wl_interface
117// - The only invariant is that self.proxy has a compatible interface
118unsafe impl OwnedProxy for WlKeyboard {
119 const INTERFACE: &'static str = "wl_keyboard";
120 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
121 const NO_OP_EVENT_HANDLER: Self::NoOpEventHandler =
122 private::EventHandler(private::NoOpEventHandler);
123 const MAX_VERSION: u32 = 10;
124
125 type Borrowed = WlKeyboardRef;
126 type Api = private::ProxyApi;
127 type NoOpEventHandler = private::EventHandler<private::NoOpEventHandler>;
128}
129
130// SAFETY: WlKeyboardRef is a transparent wrapper around UntypedBorrowedProxy
131unsafe impl UntypedBorrowedProxyWrapper for WlKeyboardRef {}
132
133// SAFETY: - The only invariant is that self.proxy has a compatible interface
134unsafe impl BorrowedProxy for WlKeyboardRef {
135 type Owned = WlKeyboard;
136}
137
138impl Deref for WlKeyboard {
139 type Target = WlKeyboardRef;
140
141 fn deref(&self) -> &Self::Target {
142 proxy::low_level::deref(self)
143 }
144}
145
146mod private {
147 pub struct ProxyApi;
148
149 #[allow(dead_code)]
150 pub struct EventHandler<H>(pub(super) H);
151
152 #[allow(dead_code)]
153 pub struct NoOpEventHandler;
154}
155
156impl Debug for WlKeyboard {
157 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
158 write!(f, "wl_keyboard#{}", self.proxy.id())
159 }
160}
161
162impl Debug for WlKeyboardRef {
163 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
164 write!(f, "wl_keyboard#{}", self.proxy.id())
165 }
166}
167
168impl PartialEq<WlKeyboardRef> for WlKeyboard {
169 fn eq(&self, other: &WlKeyboardRef) -> bool {
170 self.proxy == other.proxy
171 }
172}
173
174impl PartialEq<WlKeyboard> for WlKeyboardRef {
175 fn eq(&self, other: &WlKeyboard) -> bool {
176 self.proxy == other.proxy
177 }
178}
179
180#[allow(dead_code)]
181impl WlKeyboard {
182 /// Since when the release request is available.
183 #[allow(dead_code)]
184 pub const REQ__RELEASE__SINCE: u32 = 3;
185}
186
187#[allow(dead_code)]
188impl WlKeyboard {
189 /// release the keyboard object
190 #[inline]
191 pub fn release(&self) {
192 let mut args = [];
193 // SAFETY: - self.proxy has the interface INTERFACE
194 // - 0 < INTERFACE.method_count = 1
195 // - the request signature is ``
196 unsafe {
197 self.proxy.send_destructor(0, &mut args);
198 }
199 }
200}
201
202impl WlKeyboard {
203 /// Since when the keymap event is available.
204 #[allow(dead_code)]
205 pub const EVT__KEYMAP__SINCE: u32 = 1;
206
207 /// Since when the enter event is available.
208 #[allow(dead_code)]
209 pub const EVT__ENTER__SINCE: u32 = 1;
210
211 /// Since when the leave event is available.
212 #[allow(dead_code)]
213 pub const EVT__LEAVE__SINCE: u32 = 1;
214
215 /// Since when the key event is available.
216 #[allow(dead_code)]
217 pub const EVT__KEY__SINCE: u32 = 1;
218
219 /// Since when the modifiers event is available.
220 #[allow(dead_code)]
221 pub const EVT__MODIFIERS__SINCE: u32 = 1;
222
223 /// Since when the repeat_info event is available.
224 #[allow(dead_code)]
225 pub const EVT__REPEAT_INFO__SINCE: u32 = 4;
226}
227
228/// An event handler for [WlKeyboard] proxies.
229#[allow(dead_code)]
230pub trait WlKeyboardEventHandler {
231 /// keyboard mapping
232 ///
233 /// This event provides a file descriptor to the client which can be
234 /// memory-mapped in read-only mode to provide a keyboard mapping
235 /// description.
236 ///
237 /// From version 7 onwards, the fd must be mapped with MAP_PRIVATE by
238 /// the recipient, as MAP_SHARED may fail.
239 ///
240 /// # Arguments
241 ///
242 /// - `format`: keymap format
243 /// - `fd`: keymap file descriptor
244 /// - `size`: keymap size, in bytes
245 #[inline]
246 fn keymap(&self, _slf: &WlKeyboardRef, format: WlKeyboardKeymapFormat, fd: OwnedFd, size: u32) {
247 let _ = format;
248 let _ = fd;
249 let _ = size;
250 }
251
252 /// enter event
253 ///
254 /// Notification that this seat's keyboard focus is on a certain
255 /// surface.
256 ///
257 /// The compositor must send the wl_keyboard.modifiers event after this
258 /// event.
259 ///
260 /// In the wl_keyboard logical state, this event sets the active surface to
261 /// the surface argument and the keys currently logically down to the keys
262 /// in the keys argument. The compositor must not send this event if the
263 /// wl_keyboard already had an active surface immediately before this event.
264 ///
265 /// Clients should not use the list of pressed keys to emulate key-press
266 /// events. The order of keys in the list is unspecified.
267 ///
268 /// # Arguments
269 ///
270 /// - `serial`: serial number of the enter event
271 /// - `surface`: surface gaining keyboard focus
272 /// - `keys`: the keys currently logically down
273 ///
274 /// All borrowed proxies passed to this function are guaranteed to be
275 /// immutable and non-null.
276 #[inline]
277 fn enter(
278 &self,
279 _slf: &WlKeyboardRef,
280 serial: u32,
281 surface: Option<&WlSurfaceRef>,
282 keys: &[u8],
283 ) {
284 let _ = serial;
285 let _ = surface;
286 let _ = keys;
287 }
288
289 /// leave event
290 ///
291 /// Notification that this seat's keyboard focus is no longer on
292 /// a certain surface.
293 ///
294 /// The leave notification is sent before the enter notification
295 /// for the new focus.
296 ///
297 /// In the wl_keyboard logical state, this event resets all values to their
298 /// defaults. The compositor must not send this event if the active surface
299 /// of the wl_keyboard was not equal to the surface argument immediately
300 /// before this event.
301 ///
302 /// # Arguments
303 ///
304 /// - `serial`: serial number of the leave event
305 /// - `surface`: surface that lost keyboard focus
306 ///
307 /// All borrowed proxies passed to this function are guaranteed to be
308 /// immutable and non-null.
309 #[inline]
310 fn leave(&self, _slf: &WlKeyboardRef, serial: u32, surface: Option<&WlSurfaceRef>) {
311 let _ = serial;
312 let _ = surface;
313 }
314
315 /// key event
316 ///
317 /// A key was pressed or released.
318 /// The time argument is a timestamp with millisecond
319 /// granularity, with an undefined base.
320 ///
321 /// The key is a platform-specific key code that can be interpreted
322 /// by feeding it to the keyboard mapping (see the keymap event).
323 ///
324 /// If this event produces a change in modifiers, then the resulting
325 /// wl_keyboard.modifiers event must be sent after this event.
326 ///
327 /// In the wl_keyboard logical state, this event adds the key to the keys
328 /// currently logically down (if the state argument is pressed) or removes
329 /// the key from the keys currently logically down (if the state argument is
330 /// released). The compositor must not send this event if the wl_keyboard
331 /// did not have an active surface immediately before this event. The
332 /// compositor must not send this event if state is pressed (resp. released)
333 /// and the key was already logically down (resp. was not logically down)
334 /// immediately before this event.
335 ///
336 /// Since version 10, compositors may send key events with the "repeated"
337 /// key state when a wl_keyboard.repeat_info event with a rate argument of
338 /// 0 has been received. This allows the compositor to take over the
339 /// responsibility of key repetition.
340 ///
341 /// # Arguments
342 ///
343 /// - `serial`: serial number of the key event
344 /// - `time`: timestamp with millisecond granularity
345 /// - `key`: key that produced the event
346 /// - `state`: physical state of the key
347 #[inline]
348 fn key(
349 &self,
350 _slf: &WlKeyboardRef,
351 serial: u32,
352 time: u32,
353 key: u32,
354 state: WlKeyboardKeyState,
355 ) {
356 let _ = serial;
357 let _ = time;
358 let _ = key;
359 let _ = state;
360 }
361
362 /// modifier and group state
363 ///
364 /// Notifies clients that the modifier and/or group state has
365 /// changed, and it should update its local state.
366 ///
367 /// The compositor may send this event without a surface of the client
368 /// having keyboard focus, for example to tie modifier information to
369 /// pointer focus instead. If a modifier event with pressed modifiers is sent
370 /// without a prior enter event, the client can assume the modifier state is
371 /// valid until it receives the next wl_keyboard.modifiers event. In order to
372 /// reset the modifier state again, the compositor can send a
373 /// wl_keyboard.modifiers event with no pressed modifiers.
374 ///
375 /// In the wl_keyboard logical state, this event updates the modifiers and
376 /// group.
377 ///
378 /// # Arguments
379 ///
380 /// - `serial`: serial number of the modifiers event
381 /// - `mods_depressed`: depressed modifiers
382 /// - `mods_latched`: latched modifiers
383 /// - `mods_locked`: locked modifiers
384 /// - `group`: keyboard layout
385 #[inline]
386 fn modifiers(
387 &self,
388 _slf: &WlKeyboardRef,
389 serial: u32,
390 mods_depressed: u32,
391 mods_latched: u32,
392 mods_locked: u32,
393 group: u32,
394 ) {
395 let _ = serial;
396 let _ = mods_depressed;
397 let _ = mods_latched;
398 let _ = mods_locked;
399 let _ = group;
400 }
401
402 /// repeat rate and delay
403 ///
404 /// Informs the client about the keyboard's repeat rate and delay.
405 ///
406 /// This event is sent as soon as the wl_keyboard object has been created,
407 /// and is guaranteed to be received by the client before any key press
408 /// event.
409 ///
410 /// Negative values for either rate or delay are illegal. A rate of zero
411 /// will disable any repeating (regardless of the value of delay).
412 ///
413 /// This event can be sent later on as well with a new value if necessary,
414 /// so clients should continue listening for the event past the creation
415 /// of wl_keyboard.
416 ///
417 /// # Arguments
418 ///
419 /// - `rate`: the rate of repeating keys in characters per second
420 /// - `delay`: delay in milliseconds since key down until repeating starts
421 #[inline]
422 fn repeat_info(&self, _slf: &WlKeyboardRef, rate: i32, delay: i32) {
423 let _ = rate;
424 let _ = delay;
425 }
426}
427
428impl WlKeyboardEventHandler for private::NoOpEventHandler {}
429
430// SAFETY: - INTERFACE is a valid wl_interface
431unsafe impl<H> EventHandler for private::EventHandler<H>
432where
433 H: WlKeyboardEventHandler,
434{
435 const WL_INTERFACE: &'static wl_interface = &INTERFACE;
436
437 #[allow(unused_variables)]
438 unsafe fn handle_event(
439 &self,
440 queue: &Queue,
441 data: *mut u8,
442 slf: &UntypedBorrowedProxy,
443 opcode: u32,
444 args: *mut wl_argument,
445 ) {
446 // SAFETY: This function requires that slf has the interface INTERFACE
447 let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlKeyboardRef>(slf) };
448 match opcode {
449 0 => {
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 { WlKeyboardKeymapFormat(args[0].u) };
454 // SAFETY: - INTERFACE requires that args[1] contains a file descriptor
455 let arg1 = unsafe { OwnedFd::from_raw_fd(args[1].h) };
456 // SAFETY: - INTERFACE requires that args[2] contains a uint
457 let arg2 = unsafe { args[2].u };
458 self.0.keymap(slf, arg0, arg1, arg2);
459 }
460 1 => {
461 // SAFETY: INTERFACE requires that there are 3 arguments
462 let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
463 // SAFETY: - INTERFACE requires that args[0] contains a uint
464 let arg0 = unsafe { args[0].u };
465 // SAFETY: - INTERFACE requires that args[1] contains an object
466 let arg1 = unsafe {
467 if let Some(p) = NonNull::new(args[1].o.cast()) {
468 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
469 } else {
470 None
471 }
472 };
473 // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
474 let arg1 = arg1.as_ref().map(|arg1| unsafe {
475 proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
476 });
477 // SAFETY: - INTERFACE requires that args[2] contains an array
478 let arg2 = unsafe {
479 let a = &*args[2].a;
480 std::slice::from_raw_parts(a.data.cast(), a.size)
481 };
482 self.0.enter(slf, arg0, arg1, arg2);
483 }
484 2 => {
485 // SAFETY: INTERFACE requires that there are 2 arguments
486 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
487 // SAFETY: - INTERFACE requires that args[0] contains a uint
488 let arg0 = unsafe { args[0].u };
489 // SAFETY: - INTERFACE requires that args[1] contains an object
490 let arg1 = unsafe {
491 if let Some(p) = NonNull::new(args[1].o.cast()) {
492 Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
493 } else {
494 None
495 }
496 };
497 // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
498 let arg1 = arg1.as_ref().map(|arg1| unsafe {
499 proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
500 });
501 self.0.leave(slf, arg0, arg1);
502 }
503 3 => {
504 // SAFETY: INTERFACE requires that there are 4 arguments
505 let args = unsafe { &*args.cast::<[wl_argument; 4]>() };
506 // SAFETY: - INTERFACE requires that args[0] contains a uint
507 let arg0 = unsafe { args[0].u };
508 // SAFETY: - INTERFACE requires that args[1] contains a uint
509 let arg1 = unsafe { args[1].u };
510 // SAFETY: - INTERFACE requires that args[2] contains a uint
511 let arg2 = unsafe { args[2].u };
512 // SAFETY: - INTERFACE requires that args[3] contains a uint
513 let arg3 = unsafe { WlKeyboardKeyState(args[3].u) };
514 self.0.key(slf, arg0, arg1, arg2, arg3);
515 }
516 4 => {
517 // SAFETY: INTERFACE requires that there are 5 arguments
518 let args = unsafe { &*args.cast::<[wl_argument; 5]>() };
519 // SAFETY: - INTERFACE requires that args[0] contains a uint
520 let arg0 = unsafe { args[0].u };
521 // SAFETY: - INTERFACE requires that args[1] contains a uint
522 let arg1 = unsafe { args[1].u };
523 // SAFETY: - INTERFACE requires that args[2] contains a uint
524 let arg2 = unsafe { args[2].u };
525 // SAFETY: - INTERFACE requires that args[3] contains a uint
526 let arg3 = unsafe { args[3].u };
527 // SAFETY: - INTERFACE requires that args[4] contains a uint
528 let arg4 = unsafe { args[4].u };
529 self.0.modifiers(slf, arg0, arg1, arg2, arg3, arg4);
530 }
531 5 => {
532 // SAFETY: INTERFACE requires that there are 2 arguments
533 let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
534 // SAFETY: - INTERFACE requires that args[0] contains an int
535 let arg0 = unsafe { args[0].i };
536 // SAFETY: - INTERFACE requires that args[1] contains an int
537 let arg1 = unsafe { args[1].i };
538 self.0.repeat_info(slf, arg0, arg1);
539 }
540 _ => {
541 invalid_opcode("wl_keyboard", opcode);
542 }
543 }
544 }
545}
546
547impl<H> CreateEventHandler<H> for private::ProxyApi
548where
549 H: WlKeyboardEventHandler,
550{
551 type EventHandler = private::EventHandler<H>;
552
553 #[inline]
554 fn create_event_handler(handler: H) -> Self::EventHandler {
555 private::EventHandler(handler)
556 }
557}
558
559impl WlKeyboard {
560 /// Since when the keymap_format.no_keymap enum variant is available.
561 #[allow(dead_code)]
562 pub const ENM__KEYMAP_FORMAT_NO_KEYMAP__SINCE: u32 = 1;
563 /// Since when the keymap_format.xkb_v1 enum variant is available.
564 #[allow(dead_code)]
565 pub const ENM__KEYMAP_FORMAT_XKB_V1__SINCE: u32 = 1;
566
567 /// Since when the key_state.released enum variant is available.
568 #[allow(dead_code)]
569 pub const ENM__KEY_STATE_RELEASED__SINCE: u32 = 1;
570 /// Since when the key_state.pressed enum variant is available.
571 #[allow(dead_code)]
572 pub const ENM__KEY_STATE_PRESSED__SINCE: u32 = 1;
573 /// Since when the key_state.repeated enum variant is available.
574 #[allow(dead_code)]
575 pub const ENM__KEY_STATE_REPEATED__SINCE: u32 = 10;
576}
577
578/// keyboard mapping format
579///
580/// This specifies the format of the keymap provided to the
581/// client with the wl_keyboard.keymap event.
582#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
583#[allow(dead_code)]
584pub struct WlKeyboardKeymapFormat(pub u32);
585
586impl WlKeyboardKeymapFormat {
587 /// no keymap; client must understand how to interpret the raw keycode
588 #[allow(dead_code)]
589 pub const NO_KEYMAP: Self = Self(0);
590
591 /// libxkbcommon compatible, null-terminated string; to determine the xkb keycode, clients must add 8 to the key event keycode
592 #[allow(dead_code)]
593 pub const XKB_V1: Self = Self(1);
594}
595
596impl Debug for WlKeyboardKeymapFormat {
597 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
598 let name = match *self {
599 Self::NO_KEYMAP => "NO_KEYMAP",
600 Self::XKB_V1 => "XKB_V1",
601 _ => return Debug::fmt(&self.0, f),
602 };
603 f.write_str(name)
604 }
605}
606
607/// physical key state
608///
609/// Describes the physical state of a key that produced the key event.
610///
611/// Since version 10, the key can be in a "repeated" pseudo-state which
612/// means the same as "pressed", but is used to signal repetition in the
613/// key event.
614///
615/// The key may only enter the repeated state after entering the pressed
616/// state and before entering the released state. This event may be
617/// generated multiple times while the key is down.
618#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
619#[allow(dead_code)]
620pub struct WlKeyboardKeyState(pub u32);
621
622impl WlKeyboardKeyState {
623 /// key is not pressed
624 #[allow(dead_code)]
625 pub const RELEASED: Self = Self(0);
626
627 /// key is pressed
628 #[allow(dead_code)]
629 pub const PRESSED: Self = Self(1);
630
631 /// key was repeated
632 #[allow(dead_code)]
633 pub const REPEATED: Self = Self(2);
634}
635
636impl Debug for WlKeyboardKeyState {
637 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
638 let name = match *self {
639 Self::RELEASED => "RELEASED",
640 Self::PRESSED => "PRESSED",
641 Self::REPEATED => "REPEATED",
642 _ => return Debug::fmt(&self.0, f),
643 };
644 f.write_str(name)
645 }
646}
647
648/// Functional event handlers.
649pub mod event_handlers {
650 use super::*;
651
652 /// Event handler for keymap events.
653 pub struct Keymap<F>(F);
654 impl<F> WlKeyboardEventHandler for Keymap<F>
655 where
656 F: Fn(&WlKeyboardRef, WlKeyboardKeymapFormat, OwnedFd, u32),
657 {
658 #[inline]
659 fn keymap(
660 &self,
661 _slf: &WlKeyboardRef,
662 format: WlKeyboardKeymapFormat,
663 fd: OwnedFd,
664 size: u32,
665 ) {
666 self.0(_slf, format, fd, size)
667 }
668 }
669
670 /// Event handler for enter events.
671 pub struct Enter<F>(F);
672 impl<F> WlKeyboardEventHandler for Enter<F>
673 where
674 F: Fn(&WlKeyboardRef, u32, Option<&WlSurfaceRef>, &[u8]),
675 {
676 #[inline]
677 fn enter(
678 &self,
679 _slf: &WlKeyboardRef,
680 serial: u32,
681 surface: Option<&WlSurfaceRef>,
682 keys: &[u8],
683 ) {
684 self.0(_slf, serial, surface, keys)
685 }
686 }
687
688 /// Event handler for leave events.
689 pub struct Leave<F>(F);
690 impl<F> WlKeyboardEventHandler for Leave<F>
691 where
692 F: Fn(&WlKeyboardRef, u32, Option<&WlSurfaceRef>),
693 {
694 #[inline]
695 fn leave(&self, _slf: &WlKeyboardRef, serial: u32, surface: Option<&WlSurfaceRef>) {
696 self.0(_slf, serial, surface)
697 }
698 }
699
700 /// Event handler for key events.
701 pub struct Key<F>(F);
702 impl<F> WlKeyboardEventHandler for Key<F>
703 where
704 F: Fn(&WlKeyboardRef, u32, u32, u32, WlKeyboardKeyState),
705 {
706 #[inline]
707 fn key(
708 &self,
709 _slf: &WlKeyboardRef,
710 serial: u32,
711 time: u32,
712 key: u32,
713 state: WlKeyboardKeyState,
714 ) {
715 self.0(_slf, serial, time, key, state)
716 }
717 }
718
719 /// Event handler for modifiers events.
720 pub struct Modifiers<F>(F);
721 impl<F> WlKeyboardEventHandler for Modifiers<F>
722 where
723 F: Fn(&WlKeyboardRef, u32, u32, u32, u32, u32),
724 {
725 #[inline]
726 fn modifiers(
727 &self,
728 _slf: &WlKeyboardRef,
729 serial: u32,
730 mods_depressed: u32,
731 mods_latched: u32,
732 mods_locked: u32,
733 group: u32,
734 ) {
735 self.0(
736 _slf,
737 serial,
738 mods_depressed,
739 mods_latched,
740 mods_locked,
741 group,
742 )
743 }
744 }
745
746 /// Event handler for repeat_info events.
747 pub struct RepeatInfo<F>(F);
748 impl<F> WlKeyboardEventHandler for RepeatInfo<F>
749 where
750 F: Fn(&WlKeyboardRef, i32, i32),
751 {
752 #[inline]
753 fn repeat_info(&self, _slf: &WlKeyboardRef, rate: i32, delay: i32) {
754 self.0(_slf, rate, delay)
755 }
756 }
757
758 impl WlKeyboard {
759 /// Creates an event handler for keymap events.
760 ///
761 /// The event handler ignores all other events.
762 #[allow(dead_code)]
763 pub fn on_keymap<F>(f: F) -> Keymap<F>
764 where
765 F: Fn(&WlKeyboardRef, WlKeyboardKeymapFormat, OwnedFd, u32),
766 {
767 Keymap(f)
768 }
769
770 /// Creates an event handler for enter events.
771 ///
772 /// The event handler ignores all other events.
773 #[allow(dead_code)]
774 pub fn on_enter<F>(f: F) -> Enter<F>
775 where
776 F: Fn(&WlKeyboardRef, u32, Option<&WlSurfaceRef>, &[u8]),
777 {
778 Enter(f)
779 }
780
781 /// Creates an event handler for leave events.
782 ///
783 /// The event handler ignores all other events.
784 #[allow(dead_code)]
785 pub fn on_leave<F>(f: F) -> Leave<F>
786 where
787 F: Fn(&WlKeyboardRef, u32, Option<&WlSurfaceRef>),
788 {
789 Leave(f)
790 }
791
792 /// Creates an event handler for key events.
793 ///
794 /// The event handler ignores all other events.
795 #[allow(dead_code)]
796 pub fn on_key<F>(f: F) -> Key<F>
797 where
798 F: Fn(&WlKeyboardRef, u32, u32, u32, WlKeyboardKeyState),
799 {
800 Key(f)
801 }
802
803 /// Creates an event handler for modifiers events.
804 ///
805 /// The event handler ignores all other events.
806 #[allow(dead_code)]
807 pub fn on_modifiers<F>(f: F) -> Modifiers<F>
808 where
809 F: Fn(&WlKeyboardRef, u32, u32, u32, u32, u32),
810 {
811 Modifiers(f)
812 }
813
814 /// Creates an event handler for repeat_info events.
815 ///
816 /// The event handler ignores all other events.
817 #[allow(dead_code)]
818 pub fn on_repeat_info<F>(f: F) -> RepeatInfo<F>
819 where
820 F: Fn(&WlKeyboardRef, i32, i32),
821 {
822 RepeatInfo(f)
823 }
824 }
825}