mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-24 06:11:30 +11:00
bdc01fee1a
* Implement set_fullscreen for windows * Implement get_current_monitor for windows * Implement set_maximized * Implement set_decorations for windows * Update CHANGELOG.md * Fixed minor syntax bug for stable rust version * Added support for WindowBuilder::with_maximized * Move all window sized related functions to main thread * Refactor and formatting force_window_active * Remove unused code * Update CHANGELOG.md * Refactor and change keyboard handling code * Reformatting and refactoring * Added back missing link for comment * Fixed set_maximized and set_fullscreen wrong order bug * Call ShowWindow(SW_RESTORE) when restore_saved_window * Sync system maximized status when set_fullscreen * Fixed wrong function name
80 lines
2.7 KiB
Rust
80 lines
2.7 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();
|
|
|
|
let mut is_fullscreen = true;
|
|
let mut is_maximized = false;
|
|
let mut decorations = true;
|
|
|
|
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(virtual_code),
|
|
state,
|
|
..
|
|
},
|
|
..
|
|
} => match (virtual_code, state) {
|
|
(winit::VirtualKeyCode::Escape, _) => return ControlFlow::Break,
|
|
(winit::VirtualKeyCode::F11, winit::ElementState::Pressed) => {
|
|
is_fullscreen = !is_fullscreen;
|
|
if !is_fullscreen {
|
|
window.set_fullscreen(None);
|
|
} else {
|
|
window.set_fullscreen(Some(window.get_current_monitor()));
|
|
}
|
|
}
|
|
(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);
|
|
}
|
|
_ => (),
|
|
},
|
|
_ => (),
|
|
},
|
|
_ => {}
|
|
}
|
|
|
|
ControlFlow::Continue
|
|
});
|
|
}
|