From af52cfea6a3bc416ce9d68f8a338c1c3f422f8b3 Mon Sep 17 00:00:00 2001 From: timokoesters Date: Sat, 29 Jun 2019 03:39:47 +0200 Subject: [PATCH] Show cursor when unfocussing the window --- voxygen/src/hud/mod.rs | 15 +++++++-------- voxygen/src/window.rs | 7 ++++++- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 04f74b94fc..ef2718b885 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -713,9 +713,6 @@ impl Hud { } WinEvent::InputUpdate(GameInput::ToggleCursor, true) if !self.typing() => { self.force_ungrab = !self.force_ungrab; - if self.force_ungrab { - global_state.window.grab_cursor(false); - } true } _ if !self.show.ui => false, @@ -786,15 +783,17 @@ impl Hud { // Else the player is typing in chat WinEvent::InputUpdate(_key, _) => self.typing(), WinEvent::Char(_) => self.typing(), + WinEvent::Focused(state) => { + self.force_ungrab = !state; + true + } _ => false, }; // Handle cursor grab. - if !self.force_ungrab { - if cursor_grabbed != self.show.want_grab { - global_state.window.grab_cursor(self.show.want_grab); - } - } + global_state + .window + .grab_cursor(!self.force_ungrab && self.show.want_grab); handled } diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index dfc635f477..6e4ca05c50 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -59,6 +59,8 @@ pub enum Event { ViewDistanceChanged(u32), /// Game settings have changed. SettingsChanged, + /// The window is (un)focused + Focused(bool), } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)] @@ -225,7 +227,10 @@ impl Window { }, _ => {} }, - glutin::WindowEvent::Focused(new_focus) => *focused = new_focus, + glutin::WindowEvent::Focused(state) => { + *focused = state; + events.push(Event::Focused(state)); + } _ => {} }, glutin::Event::DeviceEvent { event, .. } => match event {