Skip to main content

freya_core/events/
modifiers.rs

1use keyboard_types::Modifiers;
2
3/// Extension trait for [`Modifiers`] adding OS-aware helpers.
4pub trait ModifiersExt {
5    /// Returns `true` if the platform's command modifier is pressed.
6    ///
7    /// Maps to [`Modifiers::META`] (Command) on macOS and to [`Modifiers::CONTROL`]
8    /// on every other platform. Useful to express shortcuts like copy, paste or
9    /// select-all once and have them work natively on every OS.
10    fn ctrl_or_meta(&self) -> bool;
11}
12
13impl ModifiersExt for Modifiers {
14    fn ctrl_or_meta(&self) -> bool {
15        if cfg!(target_os = "macos") {
16            self.meta()
17        } else {
18            self.ctrl()
19        }
20    }
21}