Unify keyboard subscriptions into listen

This commit is contained in:
Héctor Ramón Jiménez 2025-12-02 18:35:50 +01:00
parent 0df5765e2f
commit 7e5b6f6802
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
9 changed files with 77 additions and 96 deletions

View file

@ -65,14 +65,14 @@ impl Stopwatch {
}
};
fn handle_hotkey(
key: keyboard::Key,
_physical_key: keyboard::key::Physical,
_modifiers: keyboard::Modifiers,
) -> Option<Message> {
fn handle_hotkey(event: keyboard::Event) -> Option<Message> {
use keyboard::key;
match key.as_ref() {
let keyboard::Event::KeyPressed { modified_key, .. } = event else {
return None;
};
match modified_key.as_ref() {
keyboard::Key::Named(key::Named::Space) => {
Some(Message::Toggle)
}
@ -81,7 +81,10 @@ impl Stopwatch {
}
}
Subscription::batch(vec![tick, keyboard::on_key_press(handle_hotkey)])
Subscription::batch(vec![
tick,
keyboard::listen().filter_map(handle_hotkey),
])
}
fn view(&self) -> Element<'_, Message> {