From dedfc4513b60fa1cd2cf04da94f81b992b304b83 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 11 Oct 2020 10:02:37 -0700 Subject: [PATCH] wayland: clear modifiers when keyboard focus changes refs: #222 --- window/src/os/wayland/window.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/window/src/os/wayland/window.rs b/window/src/os/wayland/window.rs index 9c94a1ae4..65513ef98 100644 --- a/window/src/os/wayland/window.rs +++ b/window/src/os/wayland/window.rs @@ -313,8 +313,19 @@ impl WaylandWindowInner { .key_event(&key_event, &Window::Wayland(WaylandWindow(self.window_id))); } KeyboardEvent::Modifiers { modifiers } => self.modifiers = modifiers, - KeyboardEvent::Enter { .. } => self.callbacks.focus_change(true), - KeyboardEvent::Leave { .. } => self.callbacks.focus_change(false), + // Clear the modifiers when we change focus, otherwise weird + // things can happen. For instance, if we lost focus because + // CTRL+SHIFT+N was pressed to spawn a new window, we'd be + // left stuck with CTRL+SHIFT held down and the window would + // be left in a broken state. + KeyboardEvent::Enter { .. } => { + self.modifiers = Modifiers::NONE; + self.callbacks.focus_change(true) + } + KeyboardEvent::Leave { .. } => { + self.modifiers = Modifiers::NONE; + self.callbacks.focus_change(false) + } } }