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::*, ::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        slf: &UntypedBorrowedProxy,
438        opcode: u32,
439        args: *mut wl_argument,
440    ) {
441        // SAFETY: This function required that slf has the interface INTERFACE
442        let slf = unsafe { proxy::low_level::from_untyped_borrowed::<WlKeyboardRef>(slf) };
443        match opcode {
444            0 => {
445                // SAFETY: INTERFACE requires that there are 3 arguments
446                let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
447                // SAFETY: - INTERFACE requires that args[0] contains a uint
448                let arg0 = unsafe { WlKeyboardKeymapFormat(args[0].u) };
449                // SAFETY: - INTERFACE requires that args[1] contains a file descriptor
450                let arg1 = unsafe { OwnedFd::from_raw_fd(args[1].h) };
451                // SAFETY: - INTERFACE requires that args[2] contains a uint
452                let arg2 = unsafe { args[2].u };
453                self.0.keymap(slf, arg0, arg1, arg2);
454            }
455            1 => {
456                // SAFETY: INTERFACE requires that there are 3 arguments
457                let args = unsafe { &*args.cast::<[wl_argument; 3]>() };
458                // SAFETY: - INTERFACE requires that args[0] contains a uint
459                let arg0 = unsafe { args[0].u };
460                // SAFETY: - INTERFACE requires that args[1] contains an object
461                let arg1 = unsafe {
462                    if let Some(p) = NonNull::new(args[1].o.cast()) {
463                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
464                    } else {
465                        None
466                    }
467                };
468                // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
469                let arg1 = arg1.as_ref().map(|arg1| unsafe {
470                    proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
471                });
472                // SAFETY: - INTERFACE requires that args[2] contains an array
473                let arg2 = unsafe {
474                    let a = &*args[2].a;
475                    std::slice::from_raw_parts(a.data.cast(), a.size)
476                };
477                self.0.enter(slf, arg0, arg1, arg2);
478            }
479            2 => {
480                // SAFETY: INTERFACE requires that there are 2 arguments
481                let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
482                // SAFETY: - INTERFACE requires that args[0] contains a uint
483                let arg0 = unsafe { args[0].u };
484                // SAFETY: - INTERFACE requires that args[1] contains an object
485                let arg1 = unsafe {
486                    if let Some(p) = NonNull::new(args[1].o.cast()) {
487                        Some(UntypedBorrowedProxy::new_immutable(queue.libwayland(), p))
488                    } else {
489                        None
490                    }
491                };
492                // SAFETY: - INTERFACE requires that the object has the interface WlSurface::WL_INTERFACE
493                let arg1 = arg1.as_ref().map(|arg1| unsafe {
494                    proxy::low_level::from_untyped_borrowed::<WlSurfaceRef>(arg1)
495                });
496                self.0.leave(slf, arg0, arg1);
497            }
498            3 => {
499                // SAFETY: INTERFACE requires that there are 4 arguments
500                let args = unsafe { &*args.cast::<[wl_argument; 4]>() };
501                // SAFETY: - INTERFACE requires that args[0] contains a uint
502                let arg0 = unsafe { args[0].u };
503                // SAFETY: - INTERFACE requires that args[1] contains a uint
504                let arg1 = unsafe { args[1].u };
505                // SAFETY: - INTERFACE requires that args[2] contains a uint
506                let arg2 = unsafe { args[2].u };
507                // SAFETY: - INTERFACE requires that args[3] contains a uint
508                let arg3 = unsafe { WlKeyboardKeyState(args[3].u) };
509                self.0.key(slf, arg0, arg1, arg2, arg3);
510            }
511            4 => {
512                // SAFETY: INTERFACE requires that there are 5 arguments
513                let args = unsafe { &*args.cast::<[wl_argument; 5]>() };
514                // SAFETY: - INTERFACE requires that args[0] contains a uint
515                let arg0 = unsafe { args[0].u };
516                // SAFETY: - INTERFACE requires that args[1] contains a uint
517                let arg1 = unsafe { args[1].u };
518                // SAFETY: - INTERFACE requires that args[2] contains a uint
519                let arg2 = unsafe { args[2].u };
520                // SAFETY: - INTERFACE requires that args[3] contains a uint
521                let arg3 = unsafe { args[3].u };
522                // SAFETY: - INTERFACE requires that args[4] contains a uint
523                let arg4 = unsafe { args[4].u };
524                self.0.modifiers(slf, arg0, arg1, arg2, arg3, arg4);
525            }
526            5 => {
527                // SAFETY: INTERFACE requires that there are 2 arguments
528                let args = unsafe { &*args.cast::<[wl_argument; 2]>() };
529                // SAFETY: - INTERFACE requires that args[0] contains an int
530                let arg0 = unsafe { args[0].i };
531                // SAFETY: - INTERFACE requires that args[1] contains an int
532                let arg1 = unsafe { args[1].i };
533                self.0.repeat_info(slf, arg0, arg1);
534            }
535            _ => {
536                invalid_opcode("wl_keyboard", opcode);
537            }
538        }
539    }
540}
541
542impl<H> CreateEventHandler<H> for private::ProxyApi
543where
544    H: WlKeyboardEventHandler,
545{
546    type EventHandler = private::EventHandler<H>;
547
548    #[inline]
549    fn create_event_handler(handler: H) -> Self::EventHandler {
550        private::EventHandler(handler)
551    }
552}
553
554impl WlKeyboard {
555    /// Since when the keymap_format.no_keymap enum variant is available.
556    #[allow(dead_code)]
557    pub const ENM__KEYMAP_FORMAT_NO_KEYMAP__SINCE: u32 = 1;
558    /// Since when the keymap_format.xkb_v1 enum variant is available.
559    #[allow(dead_code)]
560    pub const ENM__KEYMAP_FORMAT_XKB_V1__SINCE: u32 = 1;
561
562    /// Since when the key_state.released enum variant is available.
563    #[allow(dead_code)]
564    pub const ENM__KEY_STATE_RELEASED__SINCE: u32 = 1;
565    /// Since when the key_state.pressed enum variant is available.
566    #[allow(dead_code)]
567    pub const ENM__KEY_STATE_PRESSED__SINCE: u32 = 1;
568    /// Since when the key_state.repeated enum variant is available.
569    #[allow(dead_code)]
570    pub const ENM__KEY_STATE_REPEATED__SINCE: u32 = 10;
571}
572
573/// keyboard mapping format
574///
575/// This specifies the format of the keymap provided to the
576/// client with the wl_keyboard.keymap event.
577#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
578#[allow(dead_code)]
579pub struct WlKeyboardKeymapFormat(pub u32);
580
581impl WlKeyboardKeymapFormat {
582    /// no keymap; client must understand how to interpret the raw keycode
583    #[allow(dead_code)]
584    pub const NO_KEYMAP: Self = Self(0);
585
586    /// libxkbcommon compatible, null-terminated string; to determine the xkb keycode, clients must add 8 to the key event keycode
587    #[allow(dead_code)]
588    pub const XKB_V1: Self = Self(1);
589}
590
591impl Debug for WlKeyboardKeymapFormat {
592    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
593        let name = match *self {
594            Self::NO_KEYMAP => "NO_KEYMAP",
595            Self::XKB_V1 => "XKB_V1",
596            _ => return Debug::fmt(&self.0, f),
597        };
598        f.write_str(name)
599    }
600}
601
602/// physical key state
603///
604/// Describes the physical state of a key that produced the key event.
605///
606/// Since version 10, the key can be in a "repeated" pseudo-state which
607/// means the same as "pressed", but is used to signal repetition in the
608/// key event.
609///
610/// The key may only enter the repeated state after entering the pressed
611/// state and before entering the released state. This event may be
612/// generated multiple times while the key is down.
613#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
614#[allow(dead_code)]
615pub struct WlKeyboardKeyState(pub u32);
616
617impl WlKeyboardKeyState {
618    /// key is not pressed
619    #[allow(dead_code)]
620    pub const RELEASED: Self = Self(0);
621
622    /// key is pressed
623    #[allow(dead_code)]
624    pub const PRESSED: Self = Self(1);
625
626    /// key was repeated
627    #[allow(dead_code)]
628    pub const REPEATED: Self = Self(2);
629}
630
631impl Debug for WlKeyboardKeyState {
632    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
633        let name = match *self {
634            Self::RELEASED => "RELEASED",
635            Self::PRESSED => "PRESSED",
636            Self::REPEATED => "REPEATED",
637            _ => return Debug::fmt(&self.0, f),
638        };
639        f.write_str(name)
640    }
641}
642
643/// Functional event handlers.
644pub mod event_handlers {
645    use super::*;
646
647    /// Event handler for keymap events.
648    pub struct Keymap<F>(F);
649    impl<F> WlKeyboardEventHandler for Keymap<F>
650    where
651        F: Fn(&WlKeyboardRef, WlKeyboardKeymapFormat, OwnedFd, u32),
652    {
653        #[inline]
654        fn keymap(
655            &self,
656            _slf: &WlKeyboardRef,
657            format: WlKeyboardKeymapFormat,
658            fd: OwnedFd,
659            size: u32,
660        ) {
661            self.0(_slf, format, fd, size)
662        }
663    }
664
665    /// Event handler for enter events.
666    pub struct Enter<F>(F);
667    impl<F> WlKeyboardEventHandler for Enter<F>
668    where
669        F: Fn(&WlKeyboardRef, u32, Option<&WlSurfaceRef>, &[u8]),
670    {
671        #[inline]
672        fn enter(
673            &self,
674            _slf: &WlKeyboardRef,
675            serial: u32,
676            surface: Option<&WlSurfaceRef>,
677            keys: &[u8],
678        ) {
679            self.0(_slf, serial, surface, keys)
680        }
681    }
682
683    /// Event handler for leave events.
684    pub struct Leave<F>(F);
685    impl<F> WlKeyboardEventHandler for Leave<F>
686    where
687        F: Fn(&WlKeyboardRef, u32, Option<&WlSurfaceRef>),
688    {
689        #[inline]
690        fn leave(&self, _slf: &WlKeyboardRef, serial: u32, surface: Option<&WlSurfaceRef>) {
691            self.0(_slf, serial, surface)
692        }
693    }
694
695    /// Event handler for key events.
696    pub struct Key<F>(F);
697    impl<F> WlKeyboardEventHandler for Key<F>
698    where
699        F: Fn(&WlKeyboardRef, u32, u32, u32, WlKeyboardKeyState),
700    {
701        #[inline]
702        fn key(
703            &self,
704            _slf: &WlKeyboardRef,
705            serial: u32,
706            time: u32,
707            key: u32,
708            state: WlKeyboardKeyState,
709        ) {
710            self.0(_slf, serial, time, key, state)
711        }
712    }
713
714    /// Event handler for modifiers events.
715    pub struct Modifiers<F>(F);
716    impl<F> WlKeyboardEventHandler for Modifiers<F>
717    where
718        F: Fn(&WlKeyboardRef, u32, u32, u32, u32, u32),
719    {
720        #[inline]
721        fn modifiers(
722            &self,
723            _slf: &WlKeyboardRef,
724            serial: u32,
725            mods_depressed: u32,
726            mods_latched: u32,
727            mods_locked: u32,
728            group: u32,
729        ) {
730            self.0(
731                _slf,
732                serial,
733                mods_depressed,
734                mods_latched,
735                mods_locked,
736                group,
737            )
738        }
739    }
740
741    /// Event handler for repeat_info events.
742    pub struct RepeatInfo<F>(F);
743    impl<F> WlKeyboardEventHandler for RepeatInfo<F>
744    where
745        F: Fn(&WlKeyboardRef, i32, i32),
746    {
747        #[inline]
748        fn repeat_info(&self, _slf: &WlKeyboardRef, rate: i32, delay: i32) {
749            self.0(_slf, rate, delay)
750        }
751    }
752
753    impl WlKeyboard {
754        /// Creates an event handler for keymap events.
755        ///
756        /// The event handler ignores all other events.
757        #[allow(dead_code)]
758        pub fn on_keymap<F>(f: F) -> Keymap<F>
759        where
760            F: Fn(&WlKeyboardRef, WlKeyboardKeymapFormat, OwnedFd, u32),
761        {
762            Keymap(f)
763        }
764
765        /// Creates an event handler for enter events.
766        ///
767        /// The event handler ignores all other events.
768        #[allow(dead_code)]
769        pub fn on_enter<F>(f: F) -> Enter<F>
770        where
771            F: Fn(&WlKeyboardRef, u32, Option<&WlSurfaceRef>, &[u8]),
772        {
773            Enter(f)
774        }
775
776        /// Creates an event handler for leave events.
777        ///
778        /// The event handler ignores all other events.
779        #[allow(dead_code)]
780        pub fn on_leave<F>(f: F) -> Leave<F>
781        where
782            F: Fn(&WlKeyboardRef, u32, Option<&WlSurfaceRef>),
783        {
784            Leave(f)
785        }
786
787        /// Creates an event handler for key events.
788        ///
789        /// The event handler ignores all other events.
790        #[allow(dead_code)]
791        pub fn on_key<F>(f: F) -> Key<F>
792        where
793            F: Fn(&WlKeyboardRef, u32, u32, u32, WlKeyboardKeyState),
794        {
795            Key(f)
796        }
797
798        /// Creates an event handler for modifiers events.
799        ///
800        /// The event handler ignores all other events.
801        #[allow(dead_code)]
802        pub fn on_modifiers<F>(f: F) -> Modifiers<F>
803        where
804            F: Fn(&WlKeyboardRef, u32, u32, u32, u32, u32),
805        {
806            Modifiers(f)
807        }
808
809        /// Creates an event handler for repeat_info events.
810        ///
811        /// The event handler ignores all other events.
812        #[allow(dead_code)]
813        pub fn on_repeat_info<F>(f: F) -> RepeatInfo<F>
814        where
815            F: Fn(&WlKeyboardRef, i32, i32),
816        {
817            RepeatInfo(f)
818        }
819    }
820}