|
|
@ -1,5 +1,6 @@
|
|
|
|
use glutin::event::{ElementState, Event, KeyEvent, WindowEvent};
|
|
|
|
use glutin::event::{ElementState, Event, KeyEvent, WindowEvent};
|
|
|
|
use glutin::keyboard::Key;
|
|
|
|
use glutin::keyboard::Key;
|
|
|
|
|
|
|
|
use glutin::keyboard::Key::Dead;
|
|
|
|
|
|
|
|
|
|
|
|
use glutin::platform::modifier_supplement::KeyEventExtModifierSupplement;
|
|
|
|
use glutin::platform::modifier_supplement::KeyEventExtModifierSupplement;
|
|
|
|
|
|
|
|
|
|
|
@ -16,6 +17,7 @@ pub struct KeyboardManager {
|
|
|
|
shift: bool,
|
|
|
|
shift: bool,
|
|
|
|
ctrl: bool,
|
|
|
|
ctrl: bool,
|
|
|
|
alt: bool,
|
|
|
|
alt: bool,
|
|
|
|
|
|
|
|
pre_is_dead: Option<char>,
|
|
|
|
logo: bool,
|
|
|
|
logo: bool,
|
|
|
|
ignore_input_this_frame: bool,
|
|
|
|
ignore_input_this_frame: bool,
|
|
|
|
queued_input_events: Vec<InputEvent>,
|
|
|
|
queued_input_events: Vec<InputEvent>,
|
|
|
@ -27,6 +29,7 @@ impl KeyboardManager {
|
|
|
|
shift: false,
|
|
|
|
shift: false,
|
|
|
|
ctrl: false,
|
|
|
|
ctrl: false,
|
|
|
|
alt: false,
|
|
|
|
alt: false,
|
|
|
|
|
|
|
|
pre_is_dead: None,
|
|
|
|
logo: false,
|
|
|
|
logo: false,
|
|
|
|
ignore_input_this_frame: false,
|
|
|
|
ignore_input_this_frame: false,
|
|
|
|
queued_input_events: Vec::new(),
|
|
|
|
queued_input_events: Vec::new(),
|
|
|
@ -79,23 +82,34 @@ 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
|
|
|
|
|
|
|
|
let mut pre_is_dead = self.pre_is_dead;
|
|
|
|
for input_event in self.queued_input_events.iter() {
|
|
|
|
for input_event in self.queued_input_events.iter() {
|
|
|
|
match input_event {
|
|
|
|
match input_event {
|
|
|
|
InputEvent::KeyEvent(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, &mut pre_is_dead)
|
|
|
|
|
|
|
|
{
|
|
|
|
EVENT_AGGREGATOR
|
|
|
|
EVENT_AGGREGATOR
|
|
|
|
.send(UiCommand::Serial(SerialCommand::Keyboard(keybinding)));
|
|
|
|
.send(UiCommand::Serial(SerialCommand::Keyboard(keybinding)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if key_event.state == ElementState::Released {
|
|
|
|
|
|
|
|
// dead key detect here
|
|
|
|
|
|
|
|
if let Dead(dead_key) = key_event.logical_key {
|
|
|
|
|
|
|
|
pre_is_dead = dead_key; //should wait for the next input text_with_all_modifiers, and ignore the next ime.
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
InputEvent::ImeInput(raw_input) => {
|
|
|
|
InputEvent::ImeInput(raw_input) => {
|
|
|
|
EVENT_AGGREGATOR
|
|
|
|
if pre_is_dead.is_none() {
|
|
|
|
.send(UiCommand::Serial(SerialCommand::Keyboard(raw_input.to_string())));
|
|
|
|
EVENT_AGGREGATOR
|
|
|
|
|
|
|
|
.send(UiCommand::Serial(SerialCommand::Keyboard(raw_input.to_string())));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.pre_is_dead = pre_is_dead;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
@ -111,14 +125,29 @@ impl KeyboardManager {
|
|
|
|
self.ignore_input_this_frame || (self.logo && !settings.use_logo)
|
|
|
|
self.ignore_input_this_frame || (self.logo && !settings.use_logo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn maybe_get_keybinding(&self, key_event: &KeyEvent) -> Option<String> {
|
|
|
|
fn maybe_get_keybinding(
|
|
|
|
|
|
|
|
&self,
|
|
|
|
|
|
|
|
key_event: &KeyEvent,
|
|
|
|
|
|
|
|
pre_is_dead: &mut Option<char>,
|
|
|
|
|
|
|
|
) -> Option<String> {
|
|
|
|
// Determine if this key event represents a key which won't ever
|
|
|
|
// Determine if this key event represents a key which won't ever
|
|
|
|
// present text.
|
|
|
|
// present text.
|
|
|
|
|
|
|
|
|
|
|
|
if let Some(key_text) = is_control_key(key_event.logical_key) {
|
|
|
|
if let Some(key_text) = is_control_key(key_event.logical_key) {
|
|
|
|
Some(self.format_keybinding_string(true, true, key_text))
|
|
|
|
if pre_is_dead.is_some() {
|
|
|
|
|
|
|
|
//recover dead key to normal character
|
|
|
|
|
|
|
|
let real_char = String::from(pre_is_dead.unwrap());
|
|
|
|
|
|
|
|
*pre_is_dead = None;
|
|
|
|
|
|
|
|
Some(real_char + &self.format_keybinding_string(true, true, key_text))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Some(self.format_keybinding_string(true, true, key_text))
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let key_text = key_event.text;
|
|
|
|
let key_text = if pre_is_dead.is_none() {
|
|
|
|
|
|
|
|
key_event.text
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
key_event.text_with_all_modifiers()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
*pre_is_dead = None;
|
|
|
|
if let Some(ori_key_text) = key_text {
|
|
|
|
if let Some(ori_key_text) = key_text {
|
|
|
|
let mut key_text = ori_key_text;
|
|
|
|
let mut key_text = ori_key_text;
|
|
|
|
if self.alt {
|
|
|
|
if self.alt {
|
|
|
|