From 1db52fdce3fbcd563506f3b0b0f30033eb23f0b5 Mon Sep 17 00:00:00 2001 From: Imbris Date: Wed, 15 Jul 2020 00:56:50 -0400 Subject: [PATCH] Fixes for Alt key related issues --- voxygen/src/window.rs | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/voxygen/src/window.rs b/voxygen/src/window.rs index b23efed7b5..4f066dcf5a 100644 --- a/voxygen/src/window.rs +++ b/voxygen/src/window.rs @@ -475,6 +475,7 @@ pub struct Window { pub zoom_inversion: bool, pub mouse_y_inversion: bool, fullscreen: bool, + modifiers: winit::event::ModifiersState, needs_refresh_resize: bool, keypress_map: HashMap, pub remapping_keybindings: Option, @@ -578,6 +579,7 @@ impl Window { zoom_inversion: settings.gameplay.zoom_inversion, mouse_y_inversion: settings.gameplay.mouse_y_inversion, fullscreen: false, + modifiers: Default::default(), needs_refresh_resize: false, keypress_map, remapping_keybindings: None, @@ -915,7 +917,32 @@ impl Window { } self.events.push(Event::MouseButton(button, state)); }, - WindowEvent::KeyboardInput { input, .. } => { + WindowEvent::ModifiersChanged(modifiers) => self.modifiers = modifiers, + WindowEvent::KeyboardInput { + input, + is_synthetic, + .. + } => { + // Ignore synthetic tab presses so that we don't get tabs when alt-tabbing back + // into the window + if matches!( + input.virtual_keycode, + Some(winit::event::VirtualKeyCode::Tab) + ) && is_synthetic + { + return; + } + // Ignore Alt-F4 so we don't try to do anything heavy like take a screenshot + // when the window is about to close + if matches!(input, winit::event::KeyboardInput { + state: winit::event::ElementState::Pressed, + virtual_keycode: Some(winit::event::VirtualKeyCode::F4), + .. + }) && self.modifiers.alt() + { + return; + } + if let Some(key) = input.virtual_keycode { if let Some(game_inputs) = Window::map_input( KeyMouse::Key(key),