mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 23:01:30 +11:00
f3ccdb7aec
Making applications track modifier keys results in unnecessary work for
consumers, it's error prone, and it turns out to have unavoidable bugs.
For example, alt-tabbing with x11 results in the alt modifier state
getting stuck.
To resolve these problems, this patch adds a Mods value to the keyboard
input event.
Based on this patch: d287fa96e3
43 lines
1.3 KiB
Rust
43 lines
1.3 KiB
Rust
extern crate winit;
|
|
|
|
use winit::{WindowEvent, ElementState};
|
|
|
|
fn main() {
|
|
let events_loop = winit::EventsLoop::new();
|
|
|
|
let window = winit::WindowBuilder::new().build(&events_loop).unwrap();
|
|
window.set_title("winit - Cursor grabbing test");
|
|
|
|
let mut grabbed = false;
|
|
|
|
events_loop.run_forever(|event| {
|
|
println!("{:?}", event);
|
|
|
|
match event {
|
|
winit::Event::WindowEvent { event, .. } => {
|
|
match event {
|
|
WindowEvent::KeyboardInput(ElementState::Pressed, _, _, _) => {
|
|
if grabbed {
|
|
grabbed = false;
|
|
window.set_cursor_state(winit::CursorState::Normal)
|
|
.ok().expect("could not ungrab mouse cursor");
|
|
} else {
|
|
grabbed = true;
|
|
window.set_cursor_state(winit::CursorState::Grab)
|
|
.ok().expect("could not grab mouse cursor");
|
|
}
|
|
},
|
|
|
|
WindowEvent::Closed => events_loop.interrupt(),
|
|
|
|
a @ WindowEvent::MouseMoved(_, _) => {
|
|
println!("{:?}", a);
|
|
},
|
|
|
|
_ => (),
|
|
}
|
|
},
|
|
}
|
|
});
|
|
}
|