On Windows, set fullscreen/maximized creating window

This commit is contained in:
白山風露
2024-01-20 02:43:08 +09:00
committed by Kirill Chibisov
parent 0270516067
commit 45b5f3b031

View File

@@ -1210,28 +1210,17 @@ impl<'a, T: 'static> InitData<'a, T> {
win.set_enabled_buttons(attributes.enabled_buttons);
if attributes.fullscreen.0.is_some() {
win.set_fullscreen(attributes.fullscreen.0.map(Into::into));
unsafe { force_window_active(win.window) };
} else {
let size = attributes
.inner_size
.unwrap_or_else(|| PhysicalSize::new(800, 600).into());
let max_size = attributes
.max_inner_size
.unwrap_or_else(|| PhysicalSize::new(f64::MAX, f64::MAX).into());
let min_size = attributes
.min_inner_size
.unwrap_or_else(|| PhysicalSize::new(0, 0).into());
let clamped_size = Size::clamp(size, min_size, max_size, win.scale_factor());
win.request_inner_size(clamped_size);
if attributes.maximized {
// Need to set MAXIMIZED after setting `inner_size` as
// `Window::request_inner_size` changes MAXIMIZED to false.
win.set_maximized(true);
}
}
let size = attributes
.inner_size
.unwrap_or_else(|| PhysicalSize::new(800, 600).into());
let max_size = attributes
.max_inner_size
.unwrap_or_else(|| PhysicalSize::new(f64::MAX, f64::MAX).into());
let min_size = attributes
.min_inner_size
.unwrap_or_else(|| PhysicalSize::new(0, 0).into());
let clamped_size = Size::clamp(size, min_size, max_size, win.scale_factor());
win.request_inner_size(clamped_size);
// let margins = MARGINS {
// cxLeftWidth: 1,
@@ -1312,6 +1301,9 @@ where
#[cfg(not(feature = "rwh_06"))]
let parent = fallback_parent();
let fullscreen = attributes.fullscreen.clone();
let maximized = attributes.maximized;
let mut initdata = InitData {
event_loop,
attributes,
@@ -1349,7 +1341,18 @@ where
// If the handle is non-null, then window creation must have succeeded, which means
// that we *must* have populated the `InitData.window` field.
Ok(initdata.window.unwrap())
let win = initdata.window.unwrap();
// Need to set FULLSCREEN or MAXIMIZED after CreateWindowEx
// This is because if the size is changed in WM_CREATE, the restored size will be stored in that size.
if fullscreen.0.is_some() {
win.set_fullscreen(fullscreen.0.map(Into::into));
unsafe { force_window_active(win.window) };
} else if maximized {
win.set_maximized(true);
}
Ok(win)
}
unsafe fn register_window_class<T: 'static>(class_name: &[u16]) {