1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::translate::*;
use std::fmt;

glib::wrapper! {
    /// A [`KeymapKey`][crate::KeymapKey] is a hardware key that can be mapped to a keyval.
    #[doc(alias = "GdkKeymapKey")]
    pub struct KeymapKey(BoxedInline<ffi::GdkKeymapKey>);
}

impl KeymapKey {
    #[inline]
    pub fn new(keycode: u32, group: i32, level: i32) -> Self {
        assert_initialized_main_thread!();
        unsafe {
            Self::unsafe_from(ffi::GdkKeymapKey {
                group,
                keycode,
                level,
            })
        }
    }

    #[inline]
    pub fn keycode(&self) -> u32 {
        self.inner.keycode
    }

    #[inline]
    pub fn group(&self) -> i32 {
        self.inner.group
    }

    #[inline]
    pub fn level(&self) -> i32 {
        self.inner.level
    }
}

impl fmt::Debug for KeymapKey {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        f.debug_struct("KeymapKey")
            .field("keycode", &self.keycode())
            .field("group", &self.group())
            .field("level", &self.level())
            .finish()
    }
}