From 4a4a1062326292639b69a1bdd1b82d690bba785f Mon Sep 17 00:00:00 2001 From: Ben Wallis Date: Wed, 17 Jun 2020 12:40:11 +0100 Subject: [PATCH] Voxygen: Fixed weird window movement caused by moving the window with the cursor grabbed (#588) --- voxygen/src/hud/mod.rs | 6 ++++++ voxygen/src/window.rs | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 444df2a3c0..3177c9c140 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -2123,6 +2123,12 @@ impl Hud { self.force_ungrab = !state; true }, + WinEvent::Moved(_) => { + // Prevent the cursor from being grabbed while the window is being moved as this + // causes the window to move erratically + self.show.want_grab = false; + true + }, _ => false, }; diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index 36edd56d64..5e9e8b2ed8 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -162,6 +162,8 @@ pub enum Event { Close, /// The window has been resized. Resize(Vec2), + /// The window has been moved. + Moved(Vec2), /// A key has been typed that corresponds to a specific character. Char(char), /// The cursor has been panned across the screen while grabbed. @@ -552,6 +554,9 @@ impl Window { renderer.on_resize().unwrap(); events.push(Event::Resize(Vec2::new(width as u32, height as u32))); }, + glutin::WindowEvent::Moved(glutin::dpi::LogicalPosition { x, y }) => { + events.push(Event::Moved(Vec2::new(x as u32, y as u32))) + }, glutin::WindowEvent::ReceivedCharacter(c) => events.push(Event::Char(c)), glutin::WindowEvent::MouseInput { button, state, .. } => { if let (true, Some(game_inputs)) = (