From 461f380a24141dd138ddee7bb4f4369867ed88ba Mon Sep 17 00:00:00 2001 From: 5225225 <5225225@mailbox.org> Date: Mon, 1 Nov 2021 20:34:06 +0000 Subject: [PATCH] egui-winit: Fix shift key getting stuck with shift:both_capslock X11 option set (#849) Listen for modifiers using ModifiersChanged --- egui-winit/CHANGELOG.md | 2 ++ egui-winit/src/lib.rs | 34 ++++++++++++---------------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/egui-winit/CHANGELOG.md b/egui-winit/CHANGELOG.md index 0cf9da319ae..f710b6bbba9 100644 --- a/egui-winit/CHANGELOG.md +++ b/egui-winit/CHANGELOG.md @@ -5,6 +5,8 @@ All notable changes to the `egui-winit` integration will be noted in this file. ## Unreleased +### Fixed 🐛 +* Fix shift key getting stuck enabled with the X11 option `shift:both_capslock` enabled ([#849](https://github.com/emilk/egui/pull/849)). ## 0.15.0 - 2021-10-24 First stand-alone release. Previously part of `egui_glium`. diff --git a/egui-winit/src/lib.rs b/egui-winit/src/lib.rs index a56e277aa25..3e51fe303d1 100644 --- a/egui-winit/src/lib.rs +++ b/egui-winit/src/lib.rs @@ -289,6 +289,18 @@ impl State { }); false } + WindowEvent::ModifiersChanged(state) => { + self.egui_input.modifiers.alt = state.alt(); + self.egui_input.modifiers.ctrl = state.ctrl(); + self.egui_input.modifiers.shift = state.shift(); + self.egui_input.modifiers.mac_cmd = cfg!(target_os = "macos") && state.logo(); + self.egui_input.modifiers.command = if cfg!(target_os = "macos") { + state.logo() + } else { + state.ctrl() + }; + false + } _ => { // dbg!(event); false @@ -457,30 +469,8 @@ impl State { fn on_keyboard_input(&mut self, input: &winit::event::KeyboardInput) { if let Some(keycode) = input.virtual_keycode { - use winit::event::VirtualKeyCode; - let pressed = input.state == winit::event::ElementState::Pressed; - // We could also use `WindowEvent::ModifiersChanged` instead, I guess. - if matches!(keycode, VirtualKeyCode::LAlt | VirtualKeyCode::RAlt) { - self.egui_input.modifiers.alt = pressed; - } - if matches!(keycode, VirtualKeyCode::LControl | VirtualKeyCode::RControl) { - self.egui_input.modifiers.ctrl = pressed; - if !cfg!(target_os = "macos") { - self.egui_input.modifiers.command = pressed; - } - } - if matches!(keycode, VirtualKeyCode::LShift | VirtualKeyCode::RShift) { - self.egui_input.modifiers.shift = pressed; - } - if cfg!(target_os = "macos") - && matches!(keycode, VirtualKeyCode::LWin | VirtualKeyCode::RWin) - { - self.egui_input.modifiers.mac_cmd = pressed; - self.egui_input.modifiers.command = pressed; - } - if pressed { // VirtualKeyCode::Paste etc in winit are broken/untrustworthy, // so we detect these things manually: