From d1c941a8ee6ee98f002c2ac994cd52d339e7d2b3 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Mon, 13 Jun 2022 16:04:59 +0200 Subject: [PATCH] remove `WindowFlags::MAXIMIZED` from diff if we are hiding --- src/platform_impl/windows/window_state.rs | 28 +++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index 32f04dd83a..1e967b7265 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -239,7 +239,19 @@ impl WindowFlags { self = self.mask(); new = new.mask(); - let diff = self ^ new; + let mut diff = self ^ new; + + // when hiding a maximized window, `self` contains `WindowFlags::MAXIMIZED` + // but `new` won't have it as it is removed in `new.mask()` call by applying `WindowFlags::INVISIBLE_AND_MASK` + // so `diff` will contain `WindowFlags::MAXIMIZED` and that will cause the window to unmaximize, but + // since we are trying to hide the window, we need to apply `WindowFlags::INVISIBLE_AND_MASK` on `diff` too. + if diff.contains(WindowFlags::MAXIMIZED) + && diff.contains(WindowFlags::VISIBLE) + && !new.contains(WindowFlags::VISIBLE) + { + diff &= WindowFlags::INVISIBLE_AND_MASK; + } + if diff == WindowFlags::empty() { return; } @@ -274,12 +286,14 @@ impl WindowFlags { } if diff.contains(WindowFlags::MAXIMIZED) || new.contains(WindowFlags::MAXIMIZED) { - unsafe { - if new.contains(WindowFlags::MAXIMIZED) { - ShowWindow(window, SW_MAXIMIZE); - } else if new.contains(WindowFlags::VISIBLE) { - ShowWindow(window, SW_RESTORE); - } + unsafe { + ShowWindow( + window, + match new.contains(WindowFlags::MAXIMIZED) { + true => SW_MAXIMIZE, + false => SW_RESTORE, + }, + ); } }