winit-sonoma-fix/examples/multiwindow.rs

55 lines
1.9 KiB
Rust
Raw Normal View History

2016-03-27 04:07:52 +11:00
extern crate winit;
fn main() {
let mut events_loop = winit::EventsLoop::new();
2017-01-29 01:45:01 +11:00
let window1 = winit::Window::new(&events_loop).unwrap();
let window2 = winit::Window::new(&events_loop).unwrap();
let window3 = winit::Window::new(&events_loop).unwrap();
2017-07-28 21:28:55 +10:00
let window4 = winit::Window::new(&events_loop).unwrap();
2017-07-28 21:28:55 +10:00
let window4_id = window4.id();
let mut window4_opt = Some(window4);
let mut num_windows = 4;
println!("Press any key on any window to drop the 4th window explicitly. (Testing impl Drop for Window)");
2014-12-24 03:12:29 +11:00
if cfg!(target_os = "linux") {
println!("Running this example under wayland may not display a window at all.\n\
This is normal and because this example does not actually draw anything in the window,\
thus the compositor does not display it.");
}
2017-01-29 01:45:01 +11:00
events_loop.run_forever(|event| {
2015-06-16 21:48:08 +10:00
match event {
2017-01-29 01:45:01 +11:00
winit::Event::WindowEvent { event: winit::WindowEvent::Closed, window_id } => {
if window_id == window1.id() {
println!("Window 1 has been closed")
} else if window_id == window2.id() {
println!("Window 2 has been closed")
} else if window_id == window3.id() {
println!("Window 3 has been closed");
2017-07-28 21:28:55 +10:00
} else if window_id == window4_id {
println!("Window 4 has been closed");
2017-01-29 01:45:01 +11:00
} else {
unreachable!()
}
num_windows -= 1;
if num_windows == 0 {
return winit::ControlFlow::Break;
2017-01-29 01:45:01 +11:00
}
},
2017-07-28 21:28:55 +10:00
winit::Event::WindowEvent { event: winit::WindowEvent::KeyboardInput{..}, .. } => {
println!("Dropping window 4 explicitly");
window4_opt = None;
},
2017-01-29 01:45:01 +11:00
_ => (),
2015-06-16 21:48:08 +10:00
}
winit::ControlFlow::Continue
2017-01-29 01:45:01 +11:00
})
}