gtk4/mnemonic_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, ShortcutTrigger};
9
10glib::wrapper! {
11 /// A [`ShortcutTrigger`][crate::ShortcutTrigger] that triggers when a specific mnemonic is pressed.
12 ///
13 /// Mnemonics require a *mnemonic modifier* (typically <kbd>Alt</kbd>) to be
14 /// pressed together with the mnemonic key.
15 ///
16 /// ## Properties
17 ///
18 ///
19 /// #### `keyval`
20 /// The key value for the trigger.
21 ///
22 /// Readable | Writeable | Construct Only
23 ///
24 /// # Implements
25 ///
26 /// [`ShortcutTriggerExt`][trait@crate::prelude::ShortcutTriggerExt], [`trait@glib::ObjectExt`], [`ShortcutTriggerExtManual`][trait@crate::prelude::ShortcutTriggerExtManual]
27 pub struct MnemonicTrigger(Object<ffi::GtkMnemonicTrigger, ffi::GtkMnemonicTriggerClass>) @extends ShortcutTrigger;
28
29 match fn {
30 type_ => || ffi::gtk_mnemonic_trigger_get_type(),
31 }
32}
33
34impl MnemonicTrigger {
35 /// Creates a [`ShortcutTrigger`][crate::ShortcutTrigger] that will trigger whenever the key with
36 /// the given @keyval is pressed and mnemonics have been activated.
37 ///
38 /// Mnemonics are activated by calling code when a key event with the right
39 /// modifiers is detected.
40 /// ## `keyval`
41 /// The keyval to trigger for
42 ///
43 /// # Returns
44 ///
45 /// A new [`ShortcutTrigger`][crate::ShortcutTrigger]
46 #[doc(alias = "gtk_mnemonic_trigger_new")]
47 pub fn new(keyval: Key) -> Self {
48 assert_initialized_main_thread!();
49 unsafe { from_glib_full(ffi::gtk_mnemonic_trigger_new(keyval.into_glib())) }
50 }
51
52 /// Gets the keyval that must be pressed to succeed triggering @self.
53 ///
54 /// # Returns
55 ///
56 /// the keyval
57 #[doc(alias = "gtk_mnemonic_trigger_get_keyval")]
58 #[doc(alias = "get_keyval")]
59 pub fn keyval(&self) -> Key {
60 unsafe { from_glib(ffi::gtk_mnemonic_trigger_get_keyval(self.to_glib_none().0)) }
61 }
62}
63
64impl fmt::Display for MnemonicTrigger {
65 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
66 f.write_str("MnemonicTrigger")
67 }
68}