mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 14:51:30 +11:00
22bc119cd7
This expands input events to represent sub-pixel mouse positions, devices responsible for generating events, and raw device-oriented events. The X11 back end is refactored to make full use of the new expressiveness. Other backends have had new functionality minimally stubbed out, save for the macos backend which already supports sub-pixel mouse positions.
44 lines
1.4 KiB
Rust
44 lines
1.4 KiB
Rust
extern crate winit;
|
|
|
|
use winit::{WindowEvent, ElementState, KeyboardInput};
|
|
|
|
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 { input: KeyboardInput { state: 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);
|
|
},
|
|
|
|
_ => (),
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
});
|
|
}
|