2016-03-26 18:07:52 +01:00
|
|
|
extern crate winit;
|
2014-07-31 09:56:53 +02:00
|
|
|
|
2015-10-24 21:32:46 -04:00
|
|
|
use std::io::{self, Write};
|
2017-09-07 09:33:46 +01:00
|
|
|
use winit::{ControlFlow, Event, WindowEvent};
|
2014-07-31 09:56:53 +02:00
|
|
|
|
|
|
|
fn main() {
|
2017-09-01 11:04:57 +02:00
|
|
|
let mut events_loop = winit::EventsLoop::new();
|
|
|
|
|
2014-07-31 09:56:53 +02:00
|
|
|
// enumerating monitors
|
|
|
|
let monitor = {
|
2017-09-01 11:04:57 +02:00
|
|
|
for (num, monitor) in events_loop.get_available_monitors().enumerate() {
|
2015-01-09 23:06:14 +01:00
|
|
|
println!("Monitor #{}: {:?}", num, monitor.get_name());
|
2014-07-31 09:56:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
print!("Please write the number of the monitor to use: ");
|
2015-10-24 21:32:46 -04:00
|
|
|
io::stdout().flush().unwrap();
|
2015-04-24 09:25:39 +02: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 11:04:57 +02:00
|
|
|
let monitor = events_loop.get_available_monitors().nth(num).expect("Please enter a valid ID");
|
2014-07-31 09:56:53 +02:00
|
|
|
|
2015-01-09 23:06:14 +01:00
|
|
|
println!("Using {:?}", monitor.get_name());
|
2014-07-31 09:56:53 +02:00
|
|
|
|
|
|
|
monitor
|
|
|
|
};
|
|
|
|
|
2018-04-13 01:12:15 +08:00
|
|
|
let window = winit::WindowBuilder::new()
|
2016-05-08 09:28:42 +02:00
|
|
|
.with_title("Hello world!")
|
2017-09-07 09:33:46 +01:00
|
|
|
.with_fullscreen(Some(monitor))
|
2017-01-28 15:45:01 +01:00
|
|
|
.build(&events_loop)
|
2014-08-02 08:24:30 +02:00
|
|
|
.unwrap();
|
2014-07-31 09:56:53 +02:00
|
|
|
|
2018-04-13 01:12:15 +08:00
|
|
|
let mut is_fullscreen = true;
|
|
|
|
let mut is_maximized = false;
|
|
|
|
let mut decorations = true;
|
|
|
|
|
2017-01-28 15:45:01 +01:00
|
|
|
events_loop.run_forever(|event| {
|
2015-06-16 13:48:08 +02:00
|
|
|
println!("{:?}", event);
|
|
|
|
|
|
|
|
match event {
|
2018-04-13 01:12:15 +08:00
|
|
|
Event::WindowEvent { event, .. } => match event {
|
2018-04-24 16:20:40 -04:00
|
|
|
WindowEvent::CloseRequested => return ControlFlow::Break,
|
2018-04-13 01:12:15 +08:00
|
|
|
WindowEvent::KeyboardInput {
|
|
|
|
input:
|
|
|
|
winit::KeyboardInput {
|
|
|
|
virtual_keycode: Some(virtual_code),
|
|
|
|
state,
|
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
|
|
|
} => match (virtual_code, state) {
|
|
|
|
(winit::VirtualKeyCode::Escape, _) => return ControlFlow::Break,
|
2018-04-18 02:07:54 +08:00
|
|
|
(winit::VirtualKeyCode::F, winit::ElementState::Pressed) => {
|
2018-04-13 01:12:15 +08:00
|
|
|
is_fullscreen = !is_fullscreen;
|
|
|
|
if !is_fullscreen {
|
|
|
|
window.set_fullscreen(None);
|
|
|
|
} else {
|
|
|
|
window.set_fullscreen(Some(window.get_current_monitor()));
|
2018-04-24 16:20:40 -04:00
|
|
|
}
|
2018-04-13 01:12:15 +08:00
|
|
|
}
|
|
|
|
(winit::VirtualKeyCode::M, winit::ElementState::Pressed) => {
|
|
|
|
is_maximized = !is_maximized;
|
|
|
|
window.set_maximized(is_maximized);
|
|
|
|
}
|
|
|
|
(winit::VirtualKeyCode::D, winit::ElementState::Pressed) => {
|
|
|
|
decorations = !decorations;
|
|
|
|
window.set_decorations(decorations);
|
|
|
|
}
|
|
|
|
_ => (),
|
|
|
|
},
|
|
|
|
_ => (),
|
2017-01-28 15:45:01 +01:00
|
|
|
},
|
2017-04-22 13:52:35 -07:00
|
|
|
_ => {}
|
2015-06-16 13:48:08 +02:00
|
|
|
}
|
2017-06-08 00:12:41 +10:00
|
|
|
|
|
|
|
ControlFlow::Continue
|
2017-01-28 15:45:01 +01:00
|
|
|
});
|
2014-07-31 09:56:53 +02:00
|
|
|
}
|