gtk4/
keyval_trigger.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use std::fmt;
4
5use gdk::Key;
6use glib::translate::*;
7
8use crate::{ffi, prelude::*, ShortcutTrigger};
9
10glib::wrapper! {
11    /// A [`ShortcutTrigger`][crate::ShortcutTrigger] that triggers when a specific keyval and modifiers are pressed.
12    ///
13    /// ## Properties
14    ///
15    ///
16    /// #### `keyval`
17    ///  The key value for the trigger.
18    ///
19    /// Readable | Writeable | Construct Only
20    ///
21    ///
22    /// #### `modifiers`
23    ///  The key modifiers for the trigger.
24    ///
25    /// Readable | Writeable | Construct Only
26    ///
27    /// # Implements
28    ///
29    /// [`ShortcutTriggerExt`][trait@crate::prelude::ShortcutTriggerExt], [`trait@glib::ObjectExt`], [`ShortcutTriggerExtManual`][trait@crate::prelude::ShortcutTriggerExtManual]
30    pub struct KeyvalTrigger(Object<ffi::GtkKeyvalTrigger, ffi::GtkKeyvalTriggerClass>) @extends ShortcutTrigger;
31
32    match fn {
33        type_ => || ffi::gtk_keyval_trigger_get_type(),
34    }
35}
36
37impl KeyvalTrigger {
38    /// Creates a [`ShortcutTrigger`][crate::ShortcutTrigger] that will trigger whenever
39    /// the key with the given @keyval and @modifiers is pressed.
40    /// ## `keyval`
41    /// The keyval to trigger for
42    /// ## `modifiers`
43    /// the modifiers that need to be present
44    ///
45    /// # Returns
46    ///
47    /// A new [`ShortcutTrigger`][crate::ShortcutTrigger]
48    #[doc(alias = "gtk_keyval_trigger_new")]
49    pub fn new(keyval: Key, modifiers: gdk::ModifierType) -> Self {
50        assert_initialized_main_thread!();
51        unsafe {
52            ShortcutTrigger::from_glib_full(ffi::gtk_keyval_trigger_new(
53                keyval.into_glib(),
54                modifiers.into_glib(),
55            ))
56            .unsafe_cast()
57        }
58    }
59
60    /// Gets the keyval that must be pressed to succeed
61    /// triggering @self.
62    ///
63    /// # Returns
64    ///
65    /// the keyval
66    #[doc(alias = "gtk_keyval_trigger_get_keyval")]
67    #[doc(alias = "get_keyval")]
68    pub fn keyval(&self) -> Key {
69        unsafe { from_glib(ffi::gtk_keyval_trigger_get_keyval(self.to_glib_none().0)) }
70    }
71
72    /// Gets the modifiers that must be present to succeed
73    /// triggering @self.
74    ///
75    /// # Returns
76    ///
77    /// the modifiers
78    #[doc(alias = "gtk_keyval_trigger_get_modifiers")]
79    #[doc(alias = "get_modifiers")]
80    pub fn modifiers(&self) -> gdk::ModifierType {
81        unsafe { from_glib(ffi::gtk_keyval_trigger_get_modifiers(self.to_glib_none().0)) }
82    }
83}
84
85impl fmt::Display for KeyvalTrigger {
86    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
87        f.write_str("KeyvalTrigger")
88    }
89}