add physical_key to key subscriptions
This commit is contained in:
parent
3fc85b900d
commit
86083d8ec8
8 changed files with 29 additions and 17 deletions
|
|
@ -381,14 +381,15 @@ where
|
|||
program.subscription(&self.state).map(Event::Program);
|
||||
debug::subscriptions_tracked(subscription.units());
|
||||
|
||||
let hotkeys =
|
||||
futures::keyboard::on_key_press(|key, _modifiers| match key {
|
||||
let hotkeys = futures::keyboard::on_key_press(
|
||||
|key, _physical_key, _modifiers| match key {
|
||||
keyboard::Key::Named(keyboard::key::Named::F12) => {
|
||||
Some(Message::ToggleComet)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
.map(Event::Message);
|
||||
},
|
||||
)
|
||||
.map(Event::Message);
|
||||
|
||||
let commands = debug::commands().map(Event::Command);
|
||||
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ impl Layout {
|
|||
fn subscription(&self) -> Subscription<Message> {
|
||||
use keyboard::key;
|
||||
|
||||
keyboard::on_key_release(|key, _modifiers| match key {
|
||||
keyboard::on_key_release(|key, _physical_key, _modifiers| match key {
|
||||
keyboard::Key::Named(key::Named::ArrowLeft) => {
|
||||
Some(Message::Previous)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -117,12 +117,12 @@ impl Example {
|
|||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
keyboard::on_key_press(|key_code, modifiers| {
|
||||
keyboard::on_key_press(|key, _physical_key, modifiers| {
|
||||
if !modifiers.command() {
|
||||
return None;
|
||||
}
|
||||
|
||||
handle_hotkey(key_code)
|
||||
handle_hotkey(key)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ impl Example {
|
|||
fn subscription(&self) -> Subscription<Message> {
|
||||
use keyboard::key;
|
||||
|
||||
keyboard::on_key_press(|key, _modifiers| {
|
||||
keyboard::on_key_press(|key, _physical_key, _modifiers| {
|
||||
if let keyboard::Key::Named(key::Named::F5) = key {
|
||||
Some(Message::Screenshot)
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -67,6 +67,7 @@ impl Stopwatch {
|
|||
|
||||
fn handle_hotkey(
|
||||
key: keyboard::Key,
|
||||
_physical_key: keyboard::key::Physical,
|
||||
_modifiers: keyboard::Modifiers,
|
||||
) -> Option<Message> {
|
||||
use keyboard::key;
|
||||
|
|
|
|||
|
|
@ -190,7 +190,7 @@ impl Styling {
|
|||
}
|
||||
|
||||
fn subscription(&self) -> Subscription<Message> {
|
||||
keyboard::on_key_press(|key, _modifiers| match key {
|
||||
keyboard::on_key_press(|key, _physical_key, _modifiers| match key {
|
||||
keyboard::Key::Named(
|
||||
keyboard::key::Named::ArrowUp | keyboard::key::Named::ArrowLeft,
|
||||
) => Some(Message::PreviousTheme),
|
||||
|
|
|
|||
|
|
@ -254,7 +254,7 @@ impl Todos {
|
|||
fn subscription(&self) -> Subscription<Message> {
|
||||
use keyboard::key;
|
||||
|
||||
keyboard::on_key_press(|key, modifiers| {
|
||||
keyboard::on_key_press(|key, _physical_key, modifiers| {
|
||||
let keyboard::Key::Named(key) = key else {
|
||||
return None;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
use crate::MaybeSend;
|
||||
use crate::core;
|
||||
use crate::core::event;
|
||||
use crate::core::keyboard::{Event, Key, Modifiers};
|
||||
use crate::core::keyboard::{Event, Key, Modifiers, key};
|
||||
use crate::subscription::{self, Subscription};
|
||||
|
||||
/// Listens to keyboard key presses and calls the given function
|
||||
|
|
@ -11,7 +11,7 @@ use crate::subscription::{self, Subscription};
|
|||
/// If the function returns `None`, the key press will be simply
|
||||
/// ignored.
|
||||
pub fn on_key_press<Message>(
|
||||
f: fn(Key, Modifiers) -> Option<Message>,
|
||||
f: fn(Key, key::Physical, Modifiers) -> Option<Message>,
|
||||
) -> Subscription<Message>
|
||||
where
|
||||
Message: MaybeSend + 'static,
|
||||
|
|
@ -22,10 +22,15 @@ where
|
|||
subscription::filter_map((OnKeyPress, f), move |event| match event {
|
||||
subscription::Event::Interaction {
|
||||
event:
|
||||
core::Event::Keyboard(Event::KeyPressed { key, modifiers, .. }),
|
||||
core::Event::Keyboard(Event::KeyPressed {
|
||||
key,
|
||||
physical_key,
|
||||
modifiers,
|
||||
..
|
||||
}),
|
||||
status: event::Status::Ignored,
|
||||
..
|
||||
} => f(key, modifiers),
|
||||
} => f(key, physical_key, modifiers),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
|
@ -36,7 +41,7 @@ where
|
|||
/// If the function returns `None`, the key release will be simply
|
||||
/// ignored.
|
||||
pub fn on_key_release<Message>(
|
||||
f: fn(Key, Modifiers) -> Option<Message>,
|
||||
f: fn(Key, key::Physical, Modifiers) -> Option<Message>,
|
||||
) -> Subscription<Message>
|
||||
where
|
||||
Message: MaybeSend + 'static,
|
||||
|
|
@ -47,10 +52,15 @@ where
|
|||
subscription::filter_map((OnKeyRelease, f), move |event| match event {
|
||||
subscription::Event::Interaction {
|
||||
event:
|
||||
core::Event::Keyboard(Event::KeyReleased { key, modifiers, .. }),
|
||||
core::Event::Keyboard(Event::KeyReleased {
|
||||
key,
|
||||
physical_key,
|
||||
modifiers,
|
||||
..
|
||||
}),
|
||||
status: event::Status::Ignored,
|
||||
..
|
||||
} => f(key, modifiers),
|
||||
} => f(key, physical_key, modifiers),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue