Skip to content

Commit

Permalink
remove WindowFlags::MAXIMIZED from diff if we are hiding
Browse files Browse the repository at this point in the history
  • Loading branch information
amrbashir authored Jun 13, 2022
1 parent 095e757 commit d1c941a
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/platform_impl/windows/window_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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,
},
);
}
}

Expand Down

0 comments on commit d1c941a

Please sign in to comment.