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::keyboard::Key;
use glutin::{PossiblyCurrent, WindowedContext};
use winit::platform::modifier_supplement::KeyEventExtModifierSupplement;
use crate::bridge::{SerialCommand, UiCommand};
use crate::channel_utils::LoggingTx;
use crate::settings::SETTINGS;
use crate::window::{KeyboardSettings, WindowSettings};
use crate::window::KeyboardSettings;
pub struct KeyboardManager {
command_sender: LoggingTx<UiCommand>,
@ -32,11 +31,7 @@ impl KeyboardManager {
}
}
pub fn handle_event(
&mut self,
event: &Event<()>,
windowed_context: &WindowedContext<PossiblyCurrent>,
) {
pub fn handle_event(&mut self, event: &Event<()>) {
match event {
Event::WindowEvent {
event: WindowEvent::Focused(_focused),
@ -71,16 +66,12 @@ impl KeyboardManager {
Event::MainEventsCleared => {
// And the window wasn't just focused.
let settings = SETTINGS.get::<KeyboardSettings>();
let window_settings = SETTINGS.get::<WindowSettings>();
if !self.should_ignore_input(&settings) {
// If we have a keyboard event this frame
for key_event in self.queued_key_events.iter() {
// And a key was 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) {
self.command_sender
.send(SerialCommand::Keyboard(keybinding).into())

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

@ -12,6 +12,8 @@ use super::keyboard_manager::KeyboardManager;
use crate::bridge::{SerialCommand, UiCommand};
use crate::channel_utils::LoggingTx;
use crate::renderer::{Renderer, WindowDrawDetails};
use crate::settings::SETTINGS;
use crate::window::WindowSettings;
fn clamp_position(
position: PhysicalPosition<f32>,
@ -62,6 +64,8 @@ pub struct MouseManager {
scroll_position: PhysicalPosition<f32>,
window_details_under_mouse: Option<WindowDrawDetails>,
mouse_hidden: bool,
pub enabled: bool,
}
@ -76,6 +80,7 @@ impl MouseManager {
drag_position: PhysicalPosition::new(0, 0),
scroll_position: PhysicalPosition::new(0.0, 0.0),
window_details_under_mouse: None,
mouse_hidden: false,
enabled: true,
}
}
@ -324,7 +329,10 @@ impl MouseManager {
renderer,
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:
@ -354,6 +362,21 @@ impl MouseManager {
state == &ElementState::Pressed,
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