Skip to content

Commit

Permalink
Fix the flashing problem of the window initialization on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Long0x0 committed Aug 25, 2024
1 parent c8d3b8f commit 23722ea
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/platform_impl/windows/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1233,10 +1233,6 @@ impl<'a, T: 'static> InitData<'a, T> {
win.set_content_protected(true);
}

// Set visible before setting the size to ensure the
// attribute is correctly applied.
win.set_visible(attributes.visible);

win.set_enabled_buttons(attributes.enabled_buttons);

if attributes.fullscreen.0.is_some() {
Expand All @@ -1262,6 +1258,18 @@ impl<'a, T: 'static> InitData<'a, T> {
}
}

// Setting visible before setting the size causes black/white flickering;
// showing the decorated window directly results in an unpleasant white
// background. So here's a hack: set visible on the undecorated window,
// then apply the decorations again. The window will remain transparent
// until it gets repainted. Changes to flag `SWP_FRAMECHANGED` trigger
// `WM_NCCALCSIZE` event.
win.set_decorations(false);
win.set_undecorated_shadow(false);
win.set_visible(attributes.visible);
win.set_decorations(attributes.decorations);
win.set_undecorated_shadow(self.pl_attribs.decoration_shadow);

// let margins = MARGINS {
// cxLeftWidth: 1,
// cxRightWidth: 1,
Expand Down

0 comments on commit 23722ea

Please sign in to comment.