From 255c9d7fe567ddf695cf496c22c171e4b8e57e5a Mon Sep 17 00:00:00 2001 From: amrbashir Date: Mon, 13 Jun 2022 16:00:59 +0200 Subject: [PATCH 1/4] Fix hiding a maximized window On Windows --- CHANGELOG.md | 1 + src/platform_impl/windows/window_state.rs | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdc63ad11e..57f6f1b92b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre # Unreleased +- On Windows, Fix hiding a maximized window. - Build docs on `docs.rs` for iOS and Android as well. - **Breaking:** Removed the `WindowAttributes` struct, since all its functionality is accessible from `WindowBuilder`. - Added `WindowBuilder::transparent` getter to check if the user set `transparent` attribute. diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index 77f8dcda2f..4139cae143 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -264,7 +264,22 @@ impl WindowFlags { self = self.mask(); new = new.mask(); - let diff = self ^ new; + dbg!(self); + dbg!(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; } From f7c64b448e202e119b510731e2d8c532dde75334 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Mon, 13 Jun 2022 16:03:06 +0200 Subject: [PATCH 2/4] remove dbg! usages --- src/platform_impl/windows/window_state.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index 4139cae143..1c9d9d3791 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -264,9 +264,6 @@ impl WindowFlags { self = self.mask(); new = new.mask(); - dbg!(self); - dbg!(new); - let mut diff = self ^ new; // when hiding a maximized window, `self` contains `WindowFlags::MAXIMIZED` From 65a59357071d13cb316301d69af1dca519a1ba5a Mon Sep 17 00:00:00 2001 From: amrbashir Date: Tue, 14 Jun 2022 22:41:53 +0200 Subject: [PATCH 3/4] remove invisible masking and split the visibile check --- src/platform_impl/windows/window_state.rs | 34 +++++++---------------- 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index 1c9d9d3791..969611f0de 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -100,7 +100,6 @@ bitflags! { const EXCLUSIVE_FULLSCREEN_OR_MASK = WindowFlags::ALWAYS_ON_TOP.bits; const NO_DECORATIONS_AND_MASK = !WindowFlags::RESIZABLE.bits; - const INVISIBLE_AND_MASK = !WindowFlags::MAXIMIZED.bits; } } @@ -200,9 +199,6 @@ impl WindowFlags { if self.contains(WindowFlags::MARKER_EXCLUSIVE_FULLSCREEN) { self |= WindowFlags::EXCLUSIVE_FULLSCREEN_OR_MASK; } - if !self.contains(WindowFlags::VISIBLE) { - self &= WindowFlags::INVISIBLE_AND_MASK; - } if !self.contains(WindowFlags::DECORATIONS) { self &= WindowFlags::NO_DECORATIONS_AND_MASK; } @@ -264,34 +260,18 @@ impl WindowFlags { self = self.mask(); new = new.mask(); - 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; - } + let diff = self ^ new; if diff == WindowFlags::empty() { return; } - if diff.contains(WindowFlags::VISIBLE) { + if new.contains(WindowFlags::VISIBLE) { unsafe { - ShowWindow( - window, - match new.contains(WindowFlags::VISIBLE) { - true => SW_SHOW, - false => SW_HIDE, - }, - ); + ShowWindow(window, SW_SHOW); } } + if diff.contains(WindowFlags::ALWAYS_ON_TOP) { unsafe { SetWindowPos( @@ -335,6 +315,12 @@ impl WindowFlags { } } + if !new.contains(WindowFlags::VISIBLE) { + unsafe { + ShowWindow(window, SW_HIDE); + } + } + if diff != WindowFlags::empty() { let (style, style_ex) = new.to_window_styles(); From 8bfa98fe980f6f617163b825166ea635edc2b46e Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Sat, 25 Jun 2022 17:40:55 +0200 Subject: [PATCH 4/4] spelling --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23af77f148..9560eb7cc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ And please only add new entries to the top of this list, right below the `# Unre # Unreleased -- On Windows, Fix hiding a maximized window. +- On Windows, fix hiding a maximized window. - On X11, fix events for caps lock key not being sent - Build docs on `docs.rs` for iOS and Android as well. - **Breaking:** Removed the `WindowAttributes` struct, since all its functionality is accessible from `WindowBuilder`.