|
|
@ -1,3 +1,4 @@
|
|
|
|
|
|
|
|
use glutin::{PossiblyCurrent, WindowedContext};
|
|
|
|
use glutin::event::{ElementState, Event, KeyEvent, WindowEvent};
|
|
|
|
use glutin::event::{ElementState, Event, KeyEvent, WindowEvent};
|
|
|
|
use glutin::keyboard::Key;
|
|
|
|
use glutin::keyboard::Key;
|
|
|
|
|
|
|
|
|
|
|
@ -6,7 +7,7 @@ use winit::platform::modifier_supplement::KeyEventExtModifierSupplement;
|
|
|
|
use crate::bridge::{SerialCommand, UiCommand};
|
|
|
|
use crate::bridge::{SerialCommand, UiCommand};
|
|
|
|
use crate::channel_utils::LoggingTx;
|
|
|
|
use crate::channel_utils::LoggingTx;
|
|
|
|
use crate::settings::SETTINGS;
|
|
|
|
use crate::settings::SETTINGS;
|
|
|
|
use crate::window::KeyboardSettings;
|
|
|
|
use crate::window::{KeyboardSettings, WindowSettings};
|
|
|
|
|
|
|
|
|
|
|
|
pub struct KeyboardManager {
|
|
|
|
pub struct KeyboardManager {
|
|
|
|
command_sender: LoggingTx<UiCommand>,
|
|
|
|
command_sender: LoggingTx<UiCommand>,
|
|
|
@ -31,7 +32,7 @@ impl KeyboardManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub fn handle_event(&mut self, event: &Event<()>) {
|
|
|
|
pub fn handle_event(&mut self, event: &Event<()>, windowed_context: &WindowedContext<PossiblyCurrent>) {
|
|
|
|
match event {
|
|
|
|
match event {
|
|
|
|
Event::WindowEvent {
|
|
|
|
Event::WindowEvent {
|
|
|
|
event: WindowEvent::Focused(_focused),
|
|
|
|
event: WindowEvent::Focused(_focused),
|
|
|
@ -66,12 +67,16 @@ impl KeyboardManager {
|
|
|
|
Event::MainEventsCleared => {
|
|
|
|
Event::MainEventsCleared => {
|
|
|
|
// And the window wasn't just focused.
|
|
|
|
// And the window wasn't just focused.
|
|
|
|
let settings = SETTINGS.get::<KeyboardSettings>();
|
|
|
|
let settings = SETTINGS.get::<KeyboardSettings>();
|
|
|
|
|
|
|
|
let window_settings = SETTINGS.get::<WindowSettings>();
|
|
|
|
|
|
|
|
|
|
|
|
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_event in self.queued_key_events.iter() {
|
|
|
|
for key_event in self.queued_key_events.iter() {
|
|
|
|
// And a key was pressed
|
|
|
|
// And a key was pressed
|
|
|
|
if key_event.state == ElementState::Pressed {
|
|
|
|
if key_event.state == ElementState::Pressed {
|
|
|
|
|
|
|
|
if window_settings.hide_mouse_when_typing {
|
|
|
|
|
|
|
|
windowed_context.window().set_cursor_visible(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
if let Some(keybinding) = self.maybe_get_keybinding(key_event) {
|
|
|
|
if let Some(keybinding) = self.maybe_get_keybinding(key_event) {
|
|
|
|
self.command_sender
|
|
|
|
self.command_sender
|
|
|
|
.send(SerialCommand::Keyboard(keybinding).into())
|
|
|
|
.send(SerialCommand::Keyboard(keybinding).into())
|
|
|
|