Implement set_maximized, get_current_monitor, set_fullscreen and set_decorations for windows (#457)
* 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
This commit is contained in:
parent
457c0b7208
commit
bdc01fee1a
7 changed files with 536 additions and 100 deletions
|
|
@ -25,24 +25,51 @@ fn main() {
|
|||
monitor
|
||||
};
|
||||
|
||||
let _window = winit::WindowBuilder::new()
|
||||
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(winit::VirtualKeyCode::Escape), .. }, ..
|
||||
} => return ControlFlow::Break,
|
||||
_ => ()
|
||||
}
|
||||
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);
|
||||
}
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
},
|
||||
_ => {}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue