|
|
@ -8,9 +8,9 @@ use crate::event_aggregator::EVENT_AGGREGATOR;
|
|
|
|
use crate::settings::SETTINGS;
|
|
|
|
use crate::settings::SETTINGS;
|
|
|
|
use crate::window::KeyboardSettings;
|
|
|
|
use crate::window::KeyboardSettings;
|
|
|
|
|
|
|
|
|
|
|
|
enum KeyOrIme {
|
|
|
|
enum InputEvent {
|
|
|
|
Key(KeyEvent),
|
|
|
|
KeyEvent(KeyEvent),
|
|
|
|
Ime(String),
|
|
|
|
ImeInput(String),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub struct KeyboardManager {
|
|
|
|
pub struct KeyboardManager {
|
|
|
|
shift: bool,
|
|
|
|
shift: bool,
|
|
|
@ -18,7 +18,7 @@ pub struct KeyboardManager {
|
|
|
|
alt: bool,
|
|
|
|
alt: bool,
|
|
|
|
logo: bool,
|
|
|
|
logo: bool,
|
|
|
|
ignore_input_this_frame: bool,
|
|
|
|
ignore_input_this_frame: bool,
|
|
|
|
queued_key_or_ime_events: Vec<KeyOrIme>,
|
|
|
|
queued_input_events: Vec<InputEvent>,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl KeyboardManager {
|
|
|
|
impl KeyboardManager {
|
|
|
@ -29,7 +29,7 @@ impl KeyboardManager {
|
|
|
|
alt: false,
|
|
|
|
alt: false,
|
|
|
|
logo: false,
|
|
|
|
logo: false,
|
|
|
|
ignore_input_this_frame: false,
|
|
|
|
ignore_input_this_frame: false,
|
|
|
|
queued_key_or_ime_events: Vec::new(),
|
|
|
|
queued_input_events: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -52,15 +52,15 @@ impl KeyboardManager {
|
|
|
|
} => {
|
|
|
|
} => {
|
|
|
|
// Store the event so that we can ignore it properly if the window was just
|
|
|
|
// Store the event so that we can ignore it properly if the window was just
|
|
|
|
// focused.
|
|
|
|
// focused.
|
|
|
|
self.queued_key_or_ime_events
|
|
|
|
self.queued_input_events
|
|
|
|
.push(KeyOrIme::Key(key_event.clone()));
|
|
|
|
.push(InputEvent::KeyEvent(key_event.clone()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Event::WindowEvent {
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::ReceivedImeText(string),
|
|
|
|
event: WindowEvent::ReceivedImeText(string),
|
|
|
|
..
|
|
|
|
..
|
|
|
|
} => {
|
|
|
|
} => {
|
|
|
|
self.queued_key_or_ime_events
|
|
|
|
self.queued_input_events
|
|
|
|
.push(KeyOrIme::Ime(string.to_string()));
|
|
|
|
.push(InputEvent::ImeInput(string.to_string()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Event::WindowEvent {
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::ModifiersChanged(modifiers),
|
|
|
|
event: WindowEvent::ModifiersChanged(modifiers),
|
|
|
@ -79,9 +79,9 @@ impl KeyboardManager {
|
|
|
|
|
|
|
|
|
|
|
|
if !self.should_ignore_input(&settings) {
|
|
|
|
if !self.should_ignore_input(&settings) {
|
|
|
|
// If we have a keyboard event this frame
|
|
|
|
// If we have a keyboard event this frame
|
|
|
|
for key_or_ime_event in self.queued_key_or_ime_events.iter() {
|
|
|
|
for key_or_ime_event in self.queued_input_events.iter() {
|
|
|
|
match key_or_ime_event {
|
|
|
|
match key_or_ime_event {
|
|
|
|
KeyOrIme::Key(key_event) => {
|
|
|
|
InputEvent::KeyEvent(key_event) => {
|
|
|
|
// And a key was pressed
|
|
|
|
// And a key was pressed
|
|
|
|
if key_event.state == ElementState::Pressed {
|
|
|
|
if key_event.state == ElementState::Pressed {
|
|
|
|
if let Some(keybinding) = self.maybe_get_keybinding(key_event) {
|
|
|
|
if let Some(keybinding) = self.maybe_get_keybinding(key_event) {
|
|
|
@ -90,7 +90,7 @@ impl KeyboardManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
KeyOrIme::Ime(raw_input) => {
|
|
|
|
InputEvent::ImeInput(raw_input) => {
|
|
|
|
EVENT_AGGREGATOR
|
|
|
|
EVENT_AGGREGATOR
|
|
|
|
.send(UiCommand::Serial(SerialCommand::Keyboard(raw_input.to_string())));
|
|
|
|
.send(UiCommand::Serial(SerialCommand::Keyboard(raw_input.to_string())));
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -101,7 +101,7 @@ impl KeyboardManager {
|
|
|
|
// Regardless of whether this was a valid keyboard input or not, rest ignoring and
|
|
|
|
// Regardless of whether this was a valid keyboard input or not, rest ignoring and
|
|
|
|
// whatever event was queued.
|
|
|
|
// whatever event was queued.
|
|
|
|
self.ignore_input_this_frame = false;
|
|
|
|
self.ignore_input_this_frame = false;
|
|
|
|
self.queued_key_or_ime_events.clear();
|
|
|
|
self.queued_input_events.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
_ => {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|