Skip to content

Commit

Permalink
On Windows, set fullscreen/maximized creating window
Browse files Browse the repository at this point in the history
  • Loading branch information
kazatsuyu authored Jan 19, 2024
1 parent b0c59c8 commit 572d7ee
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,28 +1284,17 @@ impl<'a> InitData<'a> {

win.set_enabled_buttons(attributes.enabled_buttons);

if attributes.fullscreen.is_some() {
win.set_fullscreen(attributes.fullscreen.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,
Expand Down Expand Up @@ -1396,6 +1385,8 @@ unsafe fn init(
let parent = fallback_parent();

let menu = attributes.platform_specific.menu;
let fullscreen = attributes.fullscreen.clone();
let maximized = attributes.maximized;
let mut initdata = InitData {
event_loop,
attributes,
Expand Down Expand Up @@ -1432,7 +1423,18 @@ unsafe fn init(

// 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.is_some() {
win.set_fullscreen(fullscreen.map(Into::into));
unsafe { force_window_active(win.window) };
} else if maximized {
win.set_maximized(true);
}

Ok(win)
}

unsafe fn register_window_class(class_name: &[u16]) {
Expand Down

0 comments on commit 572d7ee

Please sign in to comment.