gdk4/auto/
key_event.rs

1// This file was generated by gir (https://github.com/gtk-rs/gir)
2// from gir-files (https://github.com/gtk-rs/gir-files)
3// DO NOT EDIT
4
5use crate::{ffi, ModifierType};
6use glib::{prelude::*, translate::*};
7
8glib::wrapper! {
9    /// An event related to a key-based device.
10    #[doc(alias = "GdkKeyEvent")]
11    pub struct KeyEvent(Shared<ffi::GdkKeyEvent>);
12
13    match fn {
14        ref => |ptr| ffi::gdk_event_ref(ptr as *mut ffi::GdkEvent),
15        unref => |ptr| ffi::gdk_event_unref(ptr as *mut ffi::GdkEvent),
16    }
17}
18
19impl StaticType for KeyEvent {
20    fn static_type() -> glib::Type {
21        unsafe { from_glib(ffi::gdk_key_event_get_type()) }
22    }
23}
24
25impl KeyEvent {
26    /// Extracts the consumed modifiers from a key event.
27    ///
28    /// # Returns
29    ///
30    /// the consumed modifiers or @self
31    #[doc(alias = "gdk_key_event_get_consumed_modifiers")]
32    #[doc(alias = "get_consumed_modifiers")]
33    pub fn consumed_modifiers(&self) -> ModifierType {
34        unsafe {
35            from_glib(ffi::gdk_key_event_get_consumed_modifiers(
36                self.to_glib_none().0,
37            ))
38        }
39    }
40
41    /// Extracts the keycode from a key event.
42    ///
43    /// # Returns
44    ///
45    /// the keycode of @self
46    #[doc(alias = "gdk_key_event_get_keycode")]
47    #[doc(alias = "get_keycode")]
48    pub fn keycode(&self) -> u32 {
49        unsafe { ffi::gdk_key_event_get_keycode(self.to_glib_none().0) }
50    }
51
52    /// Extracts the layout from a key event.
53    ///
54    /// # Returns
55    ///
56    /// the layout of @self
57    #[doc(alias = "gdk_key_event_get_layout")]
58    #[doc(alias = "get_layout")]
59    pub fn layout(&self) -> u32 {
60        unsafe { ffi::gdk_key_event_get_layout(self.to_glib_none().0) }
61    }
62
63    /// Extracts the shift level from a key event.
64    ///
65    /// # Returns
66    ///
67    /// the shift level of @self
68    #[doc(alias = "gdk_key_event_get_level")]
69    #[doc(alias = "get_level")]
70    pub fn level(&self) -> u32 {
71        unsafe { ffi::gdk_key_event_get_level(self.to_glib_none().0) }
72    }
73
74    /// Extracts whether the key event is for a modifier key.
75    ///
76    /// # Returns
77    ///
78    /// [`true`] if the @self is for a modifier key
79    #[doc(alias = "gdk_key_event_is_modifier")]
80    pub fn is_modifier(&self) -> bool {
81        unsafe { from_glib(ffi::gdk_key_event_is_modifier(self.to_glib_none().0)) }
82    }
83}