move mouse hiding to just be in the mouse manager

macos-click-through
Keith Simmons 3 years ago
parent 81f52db78b
commit 46e7bec50d

@ -1,13 +1,12 @@
use glutin::event::{ElementState, Event, KeyEvent, WindowEvent}; use glutin::event::{ElementState, Event, KeyEvent, WindowEvent};
use glutin::keyboard::Key; use glutin::keyboard::Key;
use glutin::{PossiblyCurrent, WindowedContext};
use winit::platform::modifier_supplement::KeyEventExtModifierSupplement; 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, WindowSettings}; use crate::window::KeyboardSettings;
pub struct KeyboardManager { pub struct KeyboardManager {
command_sender: LoggingTx<UiCommand>, command_sender: LoggingTx<UiCommand>,
@ -32,11 +31,7 @@ impl KeyboardManager {
} }
} }
pub fn handle_event( pub fn handle_event(&mut self, event: &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),
@ -71,16 +66,12 @@ 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,8 +120,7 @@ impl GlutinWindowWrapper {
} }
pub fn handle_event(&mut self, event: Event<()>) { pub fn handle_event(&mut self, event: Event<()>) {
self.keyboard_manager self.keyboard_manager.handle_event(&event);
.handle_event(&event, &self.windowed_context);
self.mouse_manager.handle_event( self.mouse_manager.handle_event(
&event, &event,
&self.keyboard_manager, &self.keyboard_manager,

@ -12,6 +12,8 @@ use super::keyboard_manager::KeyboardManager;
use crate::bridge::{SerialCommand, UiCommand}; use crate::bridge::{SerialCommand, UiCommand};
use crate::channel_utils::LoggingTx; use crate::channel_utils::LoggingTx;
use crate::renderer::{Renderer, WindowDrawDetails}; use crate::renderer::{Renderer, WindowDrawDetails};
use crate::settings::SETTINGS;
use crate::window::WindowSettings;
fn clamp_position( fn clamp_position(
position: PhysicalPosition<f32>, position: PhysicalPosition<f32>,
@ -62,6 +64,8 @@ pub struct MouseManager {
scroll_position: PhysicalPosition<f32>, scroll_position: PhysicalPosition<f32>,
window_details_under_mouse: Option<WindowDrawDetails>, window_details_under_mouse: Option<WindowDrawDetails>,
mouse_hidden: bool,
pub enabled: bool, pub enabled: bool,
} }
@ -76,6 +80,7 @@ impl MouseManager {
drag_position: PhysicalPosition::new(0, 0), drag_position: PhysicalPosition::new(0, 0),
scroll_position: PhysicalPosition::new(0.0, 0.0), scroll_position: PhysicalPosition::new(0.0, 0.0),
window_details_under_mouse: None, window_details_under_mouse: None,
mouse_hidden: false,
enabled: true, enabled: true,
} }
} }
@ -324,7 +329,10 @@ impl MouseManager {
renderer, renderer,
windowed_context, windowed_context,
); );
windowed_context.window().set_cursor_visible(true); if self.mouse_hidden {
windowed_context.window().set_cursor_visible(true);
self.mouse_hidden = false;
}
} }
Event::WindowEvent { Event::WindowEvent {
event: event:
@ -354,6 +362,21 @@ impl MouseManager {
state == &ElementState::Pressed, state == &ElementState::Pressed,
keyboard_manager, keyboard_manager,
), ),
Event::WindowEvent {
event:
WindowEvent::KeyboardInput {
event: key_event, ..
},
..
} => {
if key_event.state == ElementState::Pressed {
let window_settings = SETTINGS.get::<WindowSettings>();
if window_settings.hide_mouse_when_typing && !self.mouse_hidden {
windowed_context.window().set_cursor_visible(false);
self.mouse_hidden = true;
}
}
}
_ => {} _ => {}
} }
} }

Loading…
Cancel
Save