mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
e2c84725de
* Format everything and add rustfmt to travis * Remove extern crate winit from examples and add force_multiline_blocks * Format the code properly * Fix inconsistent period in PULL_REQUEST_TEMPLATE.md * Only run rustfmt on nightly * Travis fixings
43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
use winit::{
|
|
event::{ElementState, Event, KeyboardInput, WindowEvent},
|
|
event_loop::{ControlFlow, EventLoop},
|
|
window::WindowBuilder,
|
|
};
|
|
|
|
fn main() {
|
|
let event_loop = EventLoop::new();
|
|
|
|
let window = WindowBuilder::new()
|
|
.with_title("Super Cursor Grab'n'Hide Simulator 9000")
|
|
.build(&event_loop)
|
|
.unwrap();
|
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
*control_flow = ControlFlow::Wait;
|
|
if let Event::WindowEvent { event, .. } = event {
|
|
match event {
|
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
WindowEvent::KeyboardInput {
|
|
input:
|
|
KeyboardInput {
|
|
state: ElementState::Released,
|
|
virtual_keycode: Some(key),
|
|
modifiers,
|
|
..
|
|
},
|
|
..
|
|
} => {
|
|
use winit::event::VirtualKeyCode::*;
|
|
match key {
|
|
Escape => *control_flow = ControlFlow::Exit,
|
|
G => window.set_cursor_grab(!modifiers.shift).unwrap(),
|
|
H => window.set_cursor_visible(modifiers.shift),
|
|
_ => (),
|
|
}
|
|
},
|
|
_ => (),
|
|
}
|
|
}
|
|
});
|
|
}
|