added setting to hide mouse cursor when typing

macos-click-through
Jan Sosulski 3 years ago committed by Keith Simmons
parent 15f9e82af1
commit f17020b6af

@ -8,6 +8,7 @@ pub struct WindowSettings {
pub fullscreen: bool, pub fullscreen: bool,
pub iso_layout: bool, pub iso_layout: bool,
pub remember_window_size: bool, pub remember_window_size: bool,
pub hide_mouse_when_typing: bool,
} }
impl Default for WindowSettings { impl Default for WindowSettings {
@ -19,6 +20,7 @@ impl Default for WindowSettings {
refresh_rate: 60, refresh_rate: 60,
no_idle: SETTINGS.get::<CmdLineSettings>().no_idle, no_idle: SETTINGS.get::<CmdLineSettings>().no_idle,
remember_window_size: false, remember_window_size: false,
hide_mouse_when_typing: false,
} }
} }
} }

@ -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())

@ -120,7 +120,7 @@ impl GlutinWindowWrapper {
} }
pub fn handle_event(&mut self, event: Event<()>) { pub fn handle_event(&mut self, event: Event<()>) {
self.keyboard_manager.handle_event(&event); self.keyboard_manager.handle_event(&event, &self.windowed_context);
self.mouse_manager.handle_event( self.mouse_manager.handle_event(
&event, &event,
&self.keyboard_manager, &self.keyboard_manager,

@ -316,13 +316,16 @@ impl MouseManager {
Event::WindowEvent { Event::WindowEvent {
event: WindowEvent::CursorMoved { position, .. }, event: WindowEvent::CursorMoved { position, .. },
.. ..
} => self.handle_pointer_motion( } => {
self.handle_pointer_motion(
position.x as i32, position.x as i32,
position.y as i32, position.y as i32,
keyboard_manager, keyboard_manager,
renderer, renderer,
windowed_context, windowed_context,
), );
windowed_context.window().set_cursor_visible(true);
}
Event::WindowEvent { Event::WindowEvent {
event: event:
WindowEvent::MouseWheel { WindowEvent::MouseWheel {

Loading…
Cancel
Save