mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-23 22:01:31 +11:00
On Windows, keep window maximized when setting size bounds (#2899)
This commit is contained in:
parent
75173118b0
commit
2b2dd6b65d
|
@ -1,6 +1,7 @@
|
||||||
#![allow(clippy::single_match)]
|
#![allow(clippy::single_match)]
|
||||||
|
|
||||||
use simple_logger::SimpleLogger;
|
use simple_logger::SimpleLogger;
|
||||||
|
use winit::dpi::PhysicalSize;
|
||||||
use winit::event::{ElementState, Event, KeyEvent, WindowEvent};
|
use winit::event::{ElementState, Event, KeyEvent, WindowEvent};
|
||||||
use winit::event_loop::EventLoop;
|
use winit::event_loop::EventLoop;
|
||||||
use winit::keyboard::Key;
|
use winit::keyboard::Key;
|
||||||
|
@ -18,6 +19,8 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
|
|
||||||
let mut decorations = true;
|
let mut decorations = true;
|
||||||
let mut minimized = false;
|
let mut minimized = false;
|
||||||
|
let mut with_min_size = false;
|
||||||
|
let mut with_max_size = false;
|
||||||
|
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.with_title("Hello world!")
|
.with_title("Hello world!")
|
||||||
|
@ -46,6 +49,8 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
println!("- D\tToggle window decorations");
|
println!("- D\tToggle window decorations");
|
||||||
println!("- X\tMaximize window");
|
println!("- X\tMaximize window");
|
||||||
println!("- Z\tMinimize window");
|
println!("- Z\tMinimize window");
|
||||||
|
println!("- I\tToggle mIn size limit");
|
||||||
|
println!("- A\tToggle mAx size limit");
|
||||||
|
|
||||||
event_loop.run(move |event, elwt, control_flow| {
|
event_loop.run(move |event, elwt, control_flow| {
|
||||||
control_flow.set_wait();
|
control_flow.set_wait();
|
||||||
|
@ -120,6 +125,32 @@ fn main() -> Result<(), impl std::error::Error> {
|
||||||
minimized = !minimized;
|
minimized = !minimized;
|
||||||
window.set_minimized(minimized);
|
window.set_minimized(minimized);
|
||||||
}
|
}
|
||||||
|
"i" => {
|
||||||
|
with_min_size = !with_min_size;
|
||||||
|
let min_size = if with_min_size {
|
||||||
|
Some(PhysicalSize::new(100, 100))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
window.set_min_inner_size(min_size);
|
||||||
|
eprintln!(
|
||||||
|
"Min: {with_min_size}: {min_size:?} => {:?}",
|
||||||
|
window.inner_size()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
"a" => {
|
||||||
|
with_max_size = !with_max_size;
|
||||||
|
let max_size = if with_max_size {
|
||||||
|
Some(PhysicalSize::new(200, 200))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
window.set_max_inner_size(max_size);
|
||||||
|
eprintln!(
|
||||||
|
"Max: {with_max_size}: {max_size:?} => {:?}",
|
||||||
|
window.inner_size()
|
||||||
|
);
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
_ => (),
|
_ => (),
|
||||||
|
|
|
@ -215,6 +215,10 @@ impl Window {
|
||||||
let scale_factor = self.scale_factor();
|
let scale_factor = self.scale_factor();
|
||||||
let physical_size = size.to_physical::<u32>(scale_factor);
|
let physical_size = size.to_physical::<u32>(scale_factor);
|
||||||
|
|
||||||
|
let window_flags = self.window_state_lock().window_flags;
|
||||||
|
window_flags.set_size(self.hwnd(), physical_size);
|
||||||
|
|
||||||
|
if physical_size != self.inner_size() {
|
||||||
let window_state = Arc::clone(&self.window_state);
|
let window_state = Arc::clone(&self.window_state);
|
||||||
let window = self.window.clone();
|
let window = self.window.clone();
|
||||||
self.thread_executor.execute_in_thread(move || {
|
self.thread_executor.execute_in_thread(move || {
|
||||||
|
@ -223,9 +227,8 @@ impl Window {
|
||||||
f.set(WindowFlags::MAXIMIZED, false)
|
f.set(WindowFlags::MAXIMIZED, false)
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let window_flags = self.window_state_lock().window_flags;
|
|
||||||
window_flags.set_size(self.hwnd(), physical_size);
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue