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