Skip to main content

gtk4/
shortcut_trigger.rs

1// Take a look at the license at the top of the repository in the LICENSE file.
2
3use glib::translate::*;
4
5use crate::{ShortcutTrigger, ffi, prelude::*};
6
7impl ShortcutTrigger {
8    /// Creates a shortcut trigger that will trigger for
9    /// any alias of the given key.
10    ///
11    /// See `keyval_get_aliases()` for more information
12    /// on aliases.
13    /// ## `keyval`
14    /// The keyval to trigger for
15    /// ## `modifiers`
16    /// the modifiers that need to be present
17    ///
18    /// # Returns
19    ///
20    /// a new [`ShortcutTrigger`][crate::ShortcutTrigger]
21    #[cfg(feature = "v4_24")]
22    #[cfg_attr(docsrs, doc(cfg(feature = "v4_24")))]
23    #[doc(alias = "gtk_shortcut_trigger_create_with_aliases")]
24    pub fn create_with_aliases(key: gdk::Key, modifiers: gdk::ModifierType) -> ShortcutTrigger {
25        assert_initialized_main_thread!();
26        unsafe {
27            from_glib_full(ffi::gtk_shortcut_trigger_create_with_aliases(
28                key.into_glib(),
29                modifiers.into_glib(),
30            ))
31        }
32    }
33}
34
35// rustdoc-stripper-ignore-next
36/// Trait containing manually implemented methods of
37/// [`ShortcutTrigger`](crate::ShortcutTrigger).
38pub trait ShortcutTriggerExtManual: IsA<ShortcutTrigger> {
39    #[doc(alias = "gtk_shortcut_trigger_compare")]
40    fn compare(&self, trigger2: &impl IsA<ShortcutTrigger>) -> std::cmp::Ordering {
41        unsafe {
42            from_glib(ffi::gtk_shortcut_trigger_compare(
43                ToGlibPtr::<*mut ffi::GtkShortcutTrigger>::to_glib_none(self.as_ref()).0
44                    as glib::ffi::gconstpointer,
45                ToGlibPtr::<*mut ffi::GtkShortcutTrigger>::to_glib_none(trigger2.as_ref()).0
46                    as glib::ffi::gconstpointer,
47            ))
48        }
49    }
50
51    #[doc(alias = "gtk_shortcut_trigger_equal")]
52    fn equal(&self, trigger2: &impl IsA<ShortcutTrigger>) -> bool {
53        unsafe {
54            from_glib(ffi::gtk_shortcut_trigger_equal(
55                ToGlibPtr::<*mut ffi::GtkShortcutTrigger>::to_glib_none(self.as_ref()).0
56                    as glib::ffi::gconstpointer,
57                ToGlibPtr::<*mut ffi::GtkShortcutTrigger>::to_glib_none(trigger2.as_ref()).0
58                    as glib::ffi::gconstpointer,
59            ))
60        }
61    }
62
63    #[doc(alias = "gtk_shortcut_trigger_hash")]
64    fn hash(&self) -> u32 {
65        unsafe {
66            ffi::gtk_shortcut_trigger_hash(
67                ToGlibPtr::<*mut ffi::GtkShortcutTrigger>::to_glib_none(self.as_ref()).0
68                    as glib::ffi::gconstpointer,
69            )
70        }
71    }
72}
73
74impl<O: IsA<ShortcutTrigger>> ShortcutTriggerExtManual for O {}