freya_core/events/modifiers.rs
1use keyboard_types::Modifiers;
2
3/// Extension trait for [`Modifiers`] adding OS-aware helpers.
4pub trait ModifiersExt {
5 /// Returns the platform's command modifier.
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() -> Modifiers;
11
12 /// Returns the platform's word navigation modifier.
13 ///
14 /// Maps to [`Modifiers::ALT`] (Option) on macOS and to [`Modifiers::CONTROL`]
15 /// on every other platform. Used for word-wise cursor movement and deletion.
16 fn ctrl_or_alt() -> Modifiers;
17}
18
19impl ModifiersExt for Modifiers {
20 fn ctrl_or_meta() -> Modifiers {
21 if cfg!(target_os = "macos") {
22 Modifiers::META
23 } else {
24 Modifiers::CONTROL
25 }
26 }
27
28 fn ctrl_or_alt() -> Modifiers {
29 if cfg!(target_os = "macos") {
30 Modifiers::ALT
31 } else {
32 Modifiers::CONTROL
33 }
34 }
35}