From cd9ad33a088b3ab5dbcf3ff1681ebce323c5c61d Mon Sep 17 00:00:00 2001 From: "Ngo Iok Ui (Wu Yu Wei)" Date: Wed, 15 Jun 2022 14:53:59 +0800 Subject: [PATCH] Fix window can't be hidden when maximized (#384) * Fix window can't be hidden when maximized * remove `WindowFlags::MAXIMIZED` from diff if we are hiding * Update src/platform_impl/windows/window_state.rs Co-authored-by: Lucas Fernandes Nogueira * Revert "Update src/platform_impl/windows/window_state.rs" This reverts commit a5083fd1998dc05f164079c39cd09f2e2023e8a1. Co-authored-by: amrbashir Co-authored-by: Lucas Fernandes Nogueira --- .changes/flag.md | 5 +++++ src/platform_impl/windows/window_state.rs | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .changes/flag.md diff --git a/.changes/flag.md b/.changes/flag.md new file mode 100644 index 000000000..5e2d0823b --- /dev/null +++ b/.changes/flag.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +Fix window can't be hidden when maximized. \ No newline at end of file diff --git a/src/platform_impl/windows/window_state.rs b/src/platform_impl/windows/window_state.rs index 8111a24b9..bb7fb8588 100644 --- a/src/platform_impl/windows/window_state.rs +++ b/src/platform_impl/windows/window_state.rs @@ -244,7 +244,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; }