Skip to content

Commit

Permalink
egui-winit: Fix shift key getting stuck with shift:both_capslock X11 …
Browse files Browse the repository at this point in the history
…option set (#849)

Listen for modifiers using ModifiersChanged
  • Loading branch information
5225225 authored Nov 1, 2021
1 parent 09b8269 commit 461f380
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
2 changes: 2 additions & 0 deletions egui-winit/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
34 changes: 12 additions & 22 deletions egui-winit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 461f380

Please sign in to comment.