To reduce compile-times and avoid some overhead to binary size, this will modify some of our generic functions to use non-generic inner functions where possible. The inner functions are marked carefully with `#[inline(never)]` to prevent being inlined by LLVM at their callsites While looking for generic functions to optimize, I have also taken the opportunity to annotate public non-generic getters and setters with `#[inline]` to ensure that LLVM will inline them across crate boundaries. By default, only generic functions are automatically inlined, and only when enabling fat LTO are constant functions reliably inlined across crate boundaries.
63 lines
1.6 KiB
Rust
63 lines
1.6 KiB
Rust
// Copyright 2023 System76 <info@system76.com>
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
//! Subscribe to common application keyboard shortcuts.
|
|
|
|
use iced::{Event, Subscription, event, keyboard};
|
|
use iced_core::keyboard::key::Named;
|
|
use iced_futures::event::listen_raw;
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
|
pub enum Action {
|
|
Escape,
|
|
FocusNext,
|
|
FocusPrevious,
|
|
Fullscreen,
|
|
Search,
|
|
}
|
|
|
|
#[cold]
|
|
pub fn subscription() -> Subscription<Action> {
|
|
listen_raw(|event, status, _| {
|
|
if event::Status::Ignored != status {
|
|
return None;
|
|
}
|
|
|
|
match event {
|
|
Event::Keyboard(keyboard::Event::KeyPressed {
|
|
key: keyboard::Key::Named(key),
|
|
modifiers,
|
|
..
|
|
}) => match key {
|
|
Named::Tab if !modifiers.control() => {
|
|
return Some(if modifiers.shift() {
|
|
Action::FocusPrevious
|
|
} else {
|
|
Action::FocusNext
|
|
});
|
|
}
|
|
|
|
Named::Escape => {
|
|
return Some(Action::Escape);
|
|
}
|
|
|
|
Named::F11 => {
|
|
return Some(Action::Fullscreen);
|
|
}
|
|
|
|
_ => (),
|
|
},
|
|
Event::Keyboard(keyboard::Event::KeyPressed {
|
|
key: keyboard::Key::Character(c),
|
|
modifiers,
|
|
..
|
|
}) if c == "f" && modifiers.control() => {
|
|
return Some(Action::Search);
|
|
}
|
|
|
|
_ => (),
|
|
}
|
|
|
|
None
|
|
})
|
|
}
|