gdk4/
keymap_key.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::fmt;
4
5use crate::ffi;
6use glib::translate::*;
7
8glib::wrapper! {
9    /// A [`KeymapKey`][crate::KeymapKey] is a hardware key that can be mapped to a keyval.
10    #[doc(alias = "GdkKeymapKey")]
11    pub struct KeymapKey(BoxedInline<ffi::GdkKeymapKey>);
12}
13
14impl KeymapKey {
15    #[inline]
16    pub fn new(keycode: u32, group: i32, level: i32) -> Self {
17        assert_initialized_main_thread!();
18        unsafe {
19            Self::unsafe_from(ffi::GdkKeymapKey {
20                group,
21                keycode,
22                level,
23            })
24        }
25    }
26
27    #[inline]
28    pub fn keycode(&self) -> u32 {
29        self.inner.keycode
30    }
31
32    #[inline]
33    pub fn group(&self) -> i32 {
34        self.inner.group
35    }
36
37    #[inline]
38    pub fn level(&self) -> i32 {
39        self.inner.level
40    }
41}
42
43impl fmt::Debug for KeymapKey {
44    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
45        f.debug_struct("KeymapKey")
46            .field("keycode", &self.keycode())
47            .field("group", &self.group())
48            .field("level", &self.level())
49            .finish()
50    }
51}