mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-26 07:11:31 +11:00
cfd087d9a5
* Explicit mouse-related DeviceEvents This makes the API more intuitive for common use-cases and allows us to better propagate platform knowledge of motion semantics. * Improve event naming consistency * Clarify axis event forwards-compatibility * Rename WindowEvent::MouseMoved/Entered/Left to CursorMoved/... This emphasizes the difference between motion of the host GUI cursor, as used for clicking on things, and raw mouse(-like) input data, as used for first-person controls. * Add support for windows and OSX, fix merging * Fix warnings and errors on Linux * Remove unnecessary breaking changes * Add MouseWheel events to windows and OSX * Fix bad push call. * Fix docs, naming, and x11 events * Remove mutability warning * Add changelog entry
46 lines
1.4 KiB
Rust
46 lines
1.4 KiB
Rust
extern crate winit;
|
|
|
|
use winit::{ControlFlow, WindowEvent, ElementState, KeyboardInput};
|
|
|
|
fn main() {
|
|
let mut 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 => return ControlFlow::Break,
|
|
|
|
a @ WindowEvent::CursorMoved { .. } => {
|
|
println!("{:?}", a);
|
|
},
|
|
|
|
_ => (),
|
|
}
|
|
}
|
|
_ => {}
|
|
}
|
|
|
|
ControlFlow::Continue
|
|
});
|
|
}
|