pub struct Modifiers { /* private fields */ }Expand description
Keyboard modifier state.
Implementations§
Source§impl Modifiers
impl Modifiers
pub const NONE: Modifiers
pub const CTRL: Modifiers
pub const SHIFT: Modifiers
pub const ALT: Modifiers
pub const SUPER: Modifiers
Sourcepub const COMMAND: Modifiers
pub const COMMAND: Modifiers
The primary accelerator modifier for this platform: SUPER
(Command, ⌘) on macOS, CTRL everywhere else.
Desktop platforms disagree about which physical key carries application
accelerators, and on macOS the disagreement is not cosmetic: Control is
reserved there for the text system and for the secondary click, while ⌘
is what a user presses for Save, Copy or Find. Code that hard-codes
CTRL to mean “the accelerator” therefore listens to the wrong key on
one of the three desktop platforms.
Compare against this constant (or call Modifiers::command) and the
same code means Ctrl+A on Windows and Linux and ⌘A on macOS. This
mirrors Qt’s Qt::CTRL, which likewise resolves to ⌘ on macOS, and the
convention the native menu bar already applies when it turns a declared
chord into an NSMenuItem key equivalent.
pub fn empty() -> Self
pub fn ctrl(self) -> bool
pub fn shift(self) -> bool
pub fn alt(self) -> bool
pub fn super_key(self) -> bool
Sourcepub fn command(self) -> bool
pub fn command(self) -> bool
Whether the platform’s primary accelerator modifier
(Modifiers::COMMAND) is held: Command (⌘) on macOS, Control
everywhere else.
Use this instead of ctrl wherever the chord means “the
accelerator” — select-all, the discontiguous-selection click, jump to
the end of a list. Keep ctrl for the chords that really
are Control on every platform, macOS included: Ctrl+Tab cycles tabs
there too (⌘Tab belongs to the application switcher and never reaches
an app).
Sourcepub fn with_command_convention(self) -> Modifiers
pub fn with_command_convention(self) -> Modifiers
These modifiers with a declared CTRL reinterpreted as the platform’s
primary accelerator — see Modifiers::COMMAND and
KeyStroke::with_command_convention,
which is where this is applied.
A no-op off macOS (where COMMAND is CTRL), and a no-op for a chord
that already names SUPER explicitly: Ctrl+Super stays ⌃⌘, a genuine
two-modifier chord, rather than collapsing to one.