From 23722eaeb72778245288e6a4d696902be755ff33 Mon Sep 17 00:00:00 2001 From: Long0x0 <51022287+Long0x0@users.noreply.github.com> Date: Sun, 25 Aug 2024 17:00:35 +0800 Subject: [PATCH] Fix the flashing problem of the window initialization on Windows --- src/platform_impl/windows/window.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/platform_impl/windows/window.rs b/src/platform_impl/windows/window.rs index 30b779f2d2..ad09f6beea 100644 --- a/src/platform_impl/windows/window.rs +++ b/src/platform_impl/windows/window.rs @@ -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() { @@ -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,