winit-sonoma-fix/examples/fullscreen.rs
Victor Berger 61d25be3e0
wayland: upgrade wayland-window (#339)
* wayland: upgrade wayland-window

This new version of wayland window considerably simplifies the
window handling for winit, meaning much of the previous juggling
is no longer needed, and the windows will appear even if nothing is
drawn.

* wayland: cleanup unused stuff
2017-11-03 17:35:29 +01:00

53 lines
1.5 KiB
Rust

extern crate winit;
use std::io::{self, Write};
use winit::{ControlFlow, Event, WindowEvent};
fn main() {
let mut events_loop = winit::EventsLoop::new();
// enumerating monitors
let monitor = {
for (num, monitor) in events_loop.get_available_monitors().enumerate() {
println!("Monitor #{}: {:?}", num, monitor.get_name());
}
print!("Please write the number of the monitor to use: ");
io::stdout().flush().unwrap();
let mut num = String::new();
io::stdin().read_line(&mut num).unwrap();
let num = num.trim().parse().ok().expect("Please enter a number");
let monitor = events_loop.get_available_monitors().nth(num).expect("Please enter a valid ID");
println!("Using {:?}", monitor.get_name());
monitor
};
let _window = winit::WindowBuilder::new()
.with_title("Hello world!")
.with_fullscreen(Some(monitor))
.build(&events_loop)
.unwrap();
events_loop.run_forever(|event| {
println!("{:?}", event);
match event {
Event::WindowEvent { event, .. } => {
match event {
WindowEvent::Closed => return ControlFlow::Break,
WindowEvent::KeyboardInput {
input: winit::KeyboardInput { virtual_keycode: Some(winit::VirtualKeyCode::Escape), .. }, ..
} => return ControlFlow::Break,
_ => ()
}
},
_ => {}
}
ControlFlow::Continue
});
}