2022-06-10 20:43:33 +10:00
|
|
|
#![allow(clippy::single_match)]
|
|
|
|
|
2020-09-10 11:58:30 +10:00
|
|
|
use simple_logger::SimpleLogger;
|
2023-05-29 04:02:59 +10:00
|
|
|
use winit::event::{ElementState, Event, KeyEvent, WindowEvent};
|
2022-04-10 11:32:02 +10:00
|
|
|
use winit::event_loop::EventLoop;
|
2023-05-29 04:02:59 +10:00
|
|
|
use winit::keyboard::Key;
|
2019-07-30 04:16:14 +10:00
|
|
|
use winit::window::{Fullscreen, WindowBuilder};
|
2014-07-31 17:56:53 +10:00
|
|
|
|
2023-03-02 09:47:45 +11:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
use winit::platform::macos::WindowExtMacOS;
|
|
|
|
|
2014-07-31 17:56:53 +10:00
|
|
|
fn main() {
|
2020-09-10 11:58:30 +10:00
|
|
|
SimpleLogger::new().init().unwrap();
|
2019-02-06 02:30:33 +11:00
|
|
|
let event_loop = EventLoop::new();
|
2017-09-01 19:04:57 +10:00
|
|
|
|
2018-12-19 15:07:33 +11:00
|
|
|
let mut decorations = true;
|
2022-07-01 21:07:10 +10:00
|
|
|
let mut minimized = false;
|
2018-12-19 15:07:33 +11:00
|
|
|
|
2019-02-06 02:30:33 +11:00
|
|
|
let window = WindowBuilder::new()
|
2016-05-08 17:28:42 +10:00
|
|
|
.with_title("Hello world!")
|
2019-02-06 02:30:33 +11:00
|
|
|
.build(&event_loop)
|
2014-08-02 16:24:30 +10:00
|
|
|
.unwrap();
|
2014-07-31 17:56:53 +10:00
|
|
|
|
2022-07-01 21:07:10 +10:00
|
|
|
let mut monitor_index = 0;
|
|
|
|
let mut monitor = event_loop
|
|
|
|
.available_monitors()
|
|
|
|
.next()
|
|
|
|
.expect("no monitor found!");
|
|
|
|
println!("Monitor: {:?}", monitor.name());
|
|
|
|
|
|
|
|
let mut mode_index = 0;
|
|
|
|
let mut mode = monitor.video_modes().next().expect("no mode found");
|
2023-01-27 15:18:58 +11:00
|
|
|
println!("Mode: {mode}");
|
2022-07-01 21:07:10 +10:00
|
|
|
|
|
|
|
println!("Keys:");
|
|
|
|
println!("- Esc\tExit");
|
|
|
|
println!("- F\tToggle exclusive fullscreen mode");
|
|
|
|
println!("- B\tToggle borderless mode");
|
2023-03-02 09:47:45 +11:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
println!("- C\tToggle simple fullscreen mode");
|
2022-07-01 21:07:10 +10:00
|
|
|
println!("- S\tNext screen");
|
|
|
|
println!("- M\tNext mode for this screen");
|
|
|
|
println!("- D\tToggle window decorations");
|
|
|
|
println!("- X\tMaximize window");
|
|
|
|
println!("- Z\tMinimize window");
|
|
|
|
|
|
|
|
event_loop.run(move |event, elwt, control_flow| {
|
2022-04-10 11:32:02 +10:00
|
|
|
control_flow.set_wait();
|
2015-06-16 21:48:08 +10:00
|
|
|
|
|
|
|
match event {
|
2019-06-25 02:14:55 +10:00
|
|
|
Event::WindowEvent { event, .. } => match event {
|
2022-04-10 11:32:02 +10:00
|
|
|
WindowEvent::CloseRequested => control_flow.set_exit(),
|
2019-06-25 02:14:55 +10:00
|
|
|
WindowEvent::KeyboardInput {
|
2023-05-29 04:02:59 +10:00
|
|
|
event:
|
|
|
|
KeyEvent {
|
|
|
|
logical_key: key,
|
2022-07-01 21:07:10 +10:00
|
|
|
state: ElementState::Pressed,
|
2019-06-25 02:14:55 +10:00
|
|
|
..
|
|
|
|
},
|
|
|
|
..
|
2023-05-29 04:02:59 +10:00
|
|
|
} => match key {
|
|
|
|
Key::Escape => control_flow.set_exit(),
|
|
|
|
// WARNING: Consider using `key_without_modifers()` if available on your platform.
|
|
|
|
// See the `key_binding` example
|
|
|
|
Key::Character(ch) => match ch.to_lowercase().as_str() {
|
|
|
|
"f" | "b" if window.fullscreen().is_some() => {
|
|
|
|
window.set_fullscreen(None);
|
2019-06-25 02:14:55 +10:00
|
|
|
}
|
2023-05-29 04:02:59 +10:00
|
|
|
"f" => {
|
|
|
|
let fullscreen = Some(Fullscreen::Exclusive(mode.clone()));
|
|
|
|
println!("Setting mode: {fullscreen:?}");
|
|
|
|
window.set_fullscreen(fullscreen);
|
|
|
|
}
|
|
|
|
"b" => {
|
|
|
|
let fullscreen = Some(Fullscreen::Borderless(Some(monitor.clone())));
|
|
|
|
println!("Setting mode: {fullscreen:?}");
|
|
|
|
window.set_fullscreen(fullscreen);
|
|
|
|
}
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
"c" => {
|
|
|
|
window.set_simple_fullscreen(!window.simple_fullscreen());
|
|
|
|
}
|
|
|
|
"s" => {
|
|
|
|
monitor_index += 1;
|
|
|
|
if let Some(mon) = elwt.available_monitors().nth(monitor_index) {
|
|
|
|
monitor = mon;
|
|
|
|
} else {
|
|
|
|
monitor_index = 0;
|
|
|
|
monitor =
|
|
|
|
elwt.available_monitors().next().expect("no monitor found!");
|
|
|
|
}
|
|
|
|
println!("Monitor: {:?}", monitor.name());
|
2022-07-01 21:07:10 +10:00
|
|
|
|
|
|
|
mode_index = 0;
|
|
|
|
mode = monitor.video_modes().next().expect("no mode found");
|
2023-05-29 04:02:59 +10:00
|
|
|
println!("Mode: {mode}");
|
|
|
|
}
|
|
|
|
"m" => {
|
|
|
|
mode_index += 1;
|
|
|
|
if let Some(m) = monitor.video_modes().nth(mode_index) {
|
|
|
|
mode = m;
|
|
|
|
} else {
|
|
|
|
mode_index = 0;
|
|
|
|
mode = monitor.video_modes().next().expect("no mode found");
|
|
|
|
}
|
|
|
|
println!("Mode: {mode}");
|
|
|
|
}
|
|
|
|
"d" => {
|
|
|
|
decorations = !decorations;
|
|
|
|
window.set_decorations(decorations);
|
|
|
|
}
|
|
|
|
"x" => {
|
|
|
|
let is_maximized = window.is_maximized();
|
|
|
|
window.set_maximized(!is_maximized);
|
|
|
|
}
|
|
|
|
"z" => {
|
|
|
|
minimized = !minimized;
|
|
|
|
window.set_minimized(minimized);
|
2022-07-01 21:07:10 +10:00
|
|
|
}
|
2023-05-29 04:02:59 +10:00
|
|
|
_ => (),
|
|
|
|
},
|
2018-04-13 03:12:15 +10:00
|
|
|
_ => (),
|
2019-06-25 02:14:55 +10:00
|
|
|
},
|
|
|
|
_ => (),
|
2017-01-29 01:45:01 +11:00
|
|
|
},
|
2019-06-25 02:14:55 +10:00
|
|
|
_ => {}
|
2015-06-16 21:48:08 +10:00
|
|
|
}
|
2017-01-29 01:45:01 +11:00
|
|
|
});
|
2014-07-31 17:56:53 +10:00
|
|
|
}
|