Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getNormalBounds() for transparent windows on Windows #38218

Merged
merged 1 commit into from May 17, 2023

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented May 9, 2023

Description of Change

Closes #38180.

Fixes an issue where getNormalBounds() returns incorrect bounds when a BrowserWindow is transparent and maximized. The underlying logic in widget doesn't account well for the transparent case - this is something we already account for in other areas.

Checklist

Release Notes

Notes: Fixed an issue where getNormalBounds() returns incorrect bounds for transparent maximized windows on Windows.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/23-x-y PR should also be added to the "23-x-y" branch. target/24-x-y PR should also be added to the "24-x-y" branch. target/25-x-y PR should also be added to the "25-x-y" branch. labels May 9, 2023
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label May 9, 2023
@tomasmi
Copy link

tomasmi commented May 9, 2023

I will have to point out that the fix is not going to work also if the window is minimized.
if (transparent() && (IsMaximized() || IsMinimized())) { return last_normal_bounds_dip_; }
We have our own fork of it and we were returning last normal bounds dip because
There was an issue with restore on Windows, that sometimes causes the Window to receive the wrong size

@codebytere
Copy link
Member Author

codebytere commented May 9, 2023

@tomasmi interesting 🤔 i checked briefly with the window minimized and the result for getNormalBounds() after minimizing a transparent window showed for me on Windows 11 as correct:

console.log(mainWindow.getNormalBounds())
// { x: 560, y: 280, width: 800, height: 600 }

mainWindow.maximize()
console.log(mainWindow.getNormalBounds())
// { x: 560, y: 280, width: 800, height: 600 }

mainWindow.minimize()
console.log(mainWindow.getNormalBounds())
// { x: 560, y: 280, width: 800, height: 600 }

@dsanders11
Copy link
Member

@codebytere, I think that's actually the inadvertent result of another bug with transparent windows, which is if you maximize a window, then minimize it, isMaximized returns true (https://gist.github.com/dsanders11/5bbe6026933faf96d7bcd5861bd51464), and so the code path in this PR gets taken when it otherwise wouldn't.

This PR doesn't cover the case of a fullscreen window, which suffers from the same bug as maximized.

Off the top of my head, I think some refactoring around restore_bounds_ could make this simpler. If it was made an absl::optional and cleared on unmaximize/unfullscreen, then the code change in this PR could be simplified to check if restore_bounds_ is set, and if so return that. Otherwise returning restore_bounds_ for the minimized state might return a stale value from a previous maximize.

@codebytere
Copy link
Member Author

Once this is rebased on #38234 it should work as expected

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label May 10, 2023
deepak1556
deepak1556 previously approved these changes May 11, 2023
@deepak1556 deepak1556 dismissed their stale review May 11, 2023 11:53

Dismissing to rebase on top of #38234

@codebytere codebytere changed the title fix: getNormalBounds() for transparent windows on Win fix: getNormalBounds() for transparent windows on Windows May 17, 2023
@codebytere codebytere merged commit 32d8f84 into main May 17, 2023
17 checks passed
@codebytere codebytere deleted the fix-normal-bounds-win branch May 17, 2023 11:11
@release-clerk
Copy link

release-clerk bot commented May 17, 2023

Release Notes Persisted

Fixed an issue where getNormalBounds() returns incorrect bounds for transparent maximized windows on Windows.

@trop
Copy link
Contributor

trop bot commented May 17, 2023

I have automatically backported this PR to "23-x-y", please check out #38347

@trop trop bot added in-flight/23-x-y and removed target/23-x-y PR should also be added to the "23-x-y" branch. labels May 17, 2023
@trop
Copy link
Contributor

trop bot commented May 17, 2023

I have automatically backported this PR to "25-x-y", please check out #38348

@trop
Copy link
Contributor

trop bot commented May 17, 2023

I have automatically backported this PR to "24-x-y", please check out #38349

@trop trop bot added in-flight/25-x-y in-flight/24-x-y merged/25-x-y PR was merged to the "25-x-y" branch. merged/23-x-y PR was merged to the "23-x-y" branch. merged/24-x-y PR was merged to the "24-x-y" branch and removed target/25-x-y PR should also be added to the "25-x-y" branch. target/24-x-y PR should also be added to the "24-x-y" branch. in-flight/25-x-y in-flight/23-x-y labels May 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged/23-x-y PR was merged to the "23-x-y" branch. merged/24-x-y PR was merged to the "24-x-y" branch merged/25-x-y PR was merged to the "25-x-y" branch. semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: getNormalBounds() returns actual window bounds for transparent maximized windows
4 participants