mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
10419ff441
Fixes #1402.
56 lines
1.6 KiB
Rust
56 lines
1.6 KiB
Rust
#![allow(clippy::single_match)]
|
|
|
|
use std::collections::HashMap;
|
|
|
|
use simple_logger::SimpleLogger;
|
|
use winit::{
|
|
event::{ElementState, Event, KeyboardInput, WindowEvent},
|
|
event_loop::EventLoop,
|
|
window::Window,
|
|
};
|
|
|
|
fn main() {
|
|
SimpleLogger::new().init().unwrap();
|
|
let event_loop = EventLoop::new();
|
|
|
|
let mut windows = HashMap::new();
|
|
for _ in 0..3 {
|
|
let window = Window::new(&event_loop).unwrap();
|
|
windows.insert(window.id(), window);
|
|
}
|
|
|
|
event_loop.run(move |event, event_loop, control_flow| {
|
|
control_flow.set_wait();
|
|
|
|
match event {
|
|
Event::WindowEvent { event, window_id } => {
|
|
match event {
|
|
WindowEvent::CloseRequested => {
|
|
println!("Window {:?} has received the signal to close", window_id);
|
|
|
|
// This drops the window, causing it to close.
|
|
windows.remove(&window_id);
|
|
|
|
if windows.is_empty() {
|
|
control_flow.set_exit();
|
|
}
|
|
}
|
|
WindowEvent::KeyboardInput {
|
|
input:
|
|
KeyboardInput {
|
|
state: ElementState::Pressed,
|
|
..
|
|
},
|
|
..
|
|
} => {
|
|
let window = Window::new(event_loop).unwrap();
|
|
windows.insert(window.id(), window);
|
|
}
|
|
_ => (),
|
|
}
|
|
}
|
|
_ => (),
|
|
}
|
|
})
|
|
}
|