2016-03-27 04:07:52 +11:00
|
|
|
extern crate winit;
|
2014-07-31 17:56:53 +10:00
|
|
|
|
2015-10-25 12:32:46 +11:00
|
|
|
use std::io::{self, Write};
|
2017-09-07 18:33:46 +10:00
|
|
|
use winit::{ControlFlow, Event, WindowEvent};
|
2014-07-31 17:56:53 +10:00
|
|
|
|
|
|
|
fn main() {
|
2017-09-01 19:04:57 +10:00
|
|
|
let mut events_loop = winit::EventsLoop::new();
|
|
|
|
|
2014-07-31 17:56:53 +10:00
|
|
|
// enumerating monitors
|
|
|
|
let monitor = {
|
2017-09-01 19:04:57 +10:00
|
|
|
for (num, monitor) in events_loop.get_available_monitors().enumerate() {
|
2015-01-10 09:06:14 +11:00
|
|
|
println!("Monitor #{}: {:?}", num, monitor.get_name());
|
2014-07-31 17:56:53 +10:00
|
|
|
}
|
|
|
|
|
|
|
|
print!("Please write the number of the monitor to use: ");
|
2015-10-25 12:32:46 +11:00
|
|
|
io::stdout().flush().unwrap();
|
2015-04-24 17:25:39 +10:00
|
|
|
|
|
|
|
let mut num = String::new();
|
|
|
|
io::stdin().read_line(&mut num).unwrap();
|
|
|
|
let num = num.trim().parse().ok().expect("Please enter a number");
|
2017-09-01 19:04:57 +10:00
|
|
|
let monitor = events_loop.get_available_monitors().nth(num).expect("Please enter a valid ID");
|
2014-07-31 17:56:53 +10:00
|
|
|
|
2015-01-10 09:06:14 +11:00
|
|
|
println!("Using {:?}", monitor.get_name());
|
2014-07-31 17:56:53 +10:00
|
|
|
|
|
|
|
monitor
|
|
|
|
};
|
|
|
|
|
2017-01-29 01:45:01 +11:00
|
|
|
let _window = winit::WindowBuilder::new()
|
2016-05-08 17:28:42 +10:00
|
|
|
.with_title("Hello world!")
|
2017-09-07 18:33:46 +10:00
|
|
|
.with_fullscreen(Some(monitor))
|
2017-01-29 01:45:01 +11:00
|
|
|
.build(&events_loop)
|
2014-08-02 16:24:30 +10:00
|
|
|
.unwrap();
|
2014-07-31 17:56:53 +10:00
|
|
|
|
2017-07-20 02:53:49 +10: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
|
|
|
println!("{:?}", event);
|
|
|
|
|
|
|
|
match event {
|
2017-06-08 00:12:41 +10:00
|
|
|
Event::WindowEvent { event, .. } => {
|
2017-01-29 01:45:01 +11:00
|
|
|
match event {
|
2017-06-20 21:25:53 +10:00
|
|
|
WindowEvent::Closed => return ControlFlow::Break,
|
2017-06-08 00:12:41 +10:00
|
|
|
WindowEvent::KeyboardInput {
|
2017-04-23 06:52:35 +10:00
|
|
|
input: winit::KeyboardInput { virtual_keycode: Some(winit::VirtualKeyCode::Escape), .. }, ..
|
2017-06-20 21:25:53 +10:00
|
|
|
} => return ControlFlow::Break,
|
2017-01-29 01:45:01 +11:00
|
|
|
_ => ()
|
|
|
|
}
|
|
|
|
},
|
2017-04-23 06:52:35 +10:00
|
|
|
_ => {}
|
2015-06-16 21:48:08 +10:00
|
|
|
}
|
2017-06-08 00:12:41 +10:00
|
|
|
|
|
|
|
ControlFlow::Continue
|
2017-01-29 01:45:01 +11:00
|
|
|
});
|
2014-07-31 17:56:53 +10:00
|
|
|
}
|