mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 06:41:31 +11:00
d9bda3e985
* Move DeviceEvent handling to the message target window. Previously, device events seem to have only been sent to one particular window, and when that window was closed Winit would stop receiving device events. This also allows users to create windowless event loops that process device events - an intriguing idea, to say the least. * Emit LWin and RWin VirtualKeyCodes on Windows * Implement ModifiersChanged on Windows * Make ModifiersChanged a tuple variant instead of a struct variant * Add changelog entries * Format * Update changelog entry * Fix AltGr handling * Reformat * Publicly expose ModifiersChanged and deprecate misc. modifiers fields
54 lines
2 KiB
Rust
54 lines
2 KiB
Rust
use winit::{
|
|
event::{DeviceEvent, ElementState, Event, KeyboardInput, ModifiersState, 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();
|
|
|
|
let mut modifiers = ModifiersState::default();
|
|
|
|
event_loop.run(move |event, _, control_flow| {
|
|
*control_flow = ControlFlow::Wait;
|
|
match event {
|
|
Event::WindowEvent { event, .. } => match event {
|
|
WindowEvent::CloseRequested => *control_flow = ControlFlow::Exit,
|
|
WindowEvent::KeyboardInput {
|
|
input:
|
|
KeyboardInput {
|
|
state: ElementState::Released,
|
|
virtual_keycode: Some(key),
|
|
..
|
|
},
|
|
..
|
|
} => {
|
|
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()),
|
|
_ => (),
|
|
}
|
|
}
|
|
_ => (),
|
|
},
|
|
Event::DeviceEvent { event, .. } => match event {
|
|
DeviceEvent::MouseMotion { delta } => println!("mouse moved: {:?}", delta),
|
|
DeviceEvent::Button { button, state } => match state {
|
|
ElementState::Pressed => println!("mouse button {} pressed", button),
|
|
ElementState::Released => println!("mouse button {} released", button),
|
|
},
|
|
DeviceEvent::ModifiersChanged(m) => modifiers = m,
|
|
_ => (),
|
|
},
|
|
_ => (),
|
|
}
|
|
});
|
|
}
|