egui-winit: Fix shift key getting stuck with shift:both_capslock X11 option set (#849)
Listen for modifiers using ModifiersChanged
This commit is contained in:
parent
09b8269326
commit
461f380a24
2 changed files with 14 additions and 22 deletions
|
@ -5,6 +5,8 @@ All notable changes to the `egui-winit` integration will be noted in this file.
|
||||||
|
|
||||||
## Unreleased
|
## 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
|
## 0.15.0 - 2021-10-24
|
||||||
First stand-alone release. Previously part of `egui_glium`.
|
First stand-alone release. Previously part of `egui_glium`.
|
||||||
|
|
|
@ -289,6 +289,18 @@ impl State {
|
||||||
});
|
});
|
||||||
false
|
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);
|
// dbg!(event);
|
||||||
false
|
false
|
||||||
|
@ -457,30 +469,8 @@ impl State {
|
||||||
|
|
||||||
fn on_keyboard_input(&mut self, input: &winit::event::KeyboardInput) {
|
fn on_keyboard_input(&mut self, input: &winit::event::KeyboardInput) {
|
||||||
if let Some(keycode) = input.virtual_keycode {
|
if let Some(keycode) = input.virtual_keycode {
|
||||||
use winit::event::VirtualKeyCode;
|
|
||||||
|
|
||||||
let pressed = input.state == winit::event::ElementState::Pressed;
|
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 {
|
if pressed {
|
||||||
// VirtualKeyCode::Paste etc in winit are broken/untrustworthy,
|
// VirtualKeyCode::Paste etc in winit are broken/untrustworthy,
|
||||||
// so we detect these things manually:
|
// so we detect these things manually:
|
||||||
|
|
Loading…
Reference in a new issue