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: BrowserWindow.center() should center relative to screen #42048

Merged
merged 2 commits into from
May 8, 2024

Conversation

codebytere
Copy link
Member

Description of Change

Closes #41956.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/4916277

The above CL changed window.center() behavior on Windows/Linux (which use Widget) such that the window is now centered relative to the parent window and not the full screen as is the expected behavior and the behavior on macOS. Chromium perceived this a bug, but it's important we maintain our end-user behavior consistency here as it's been this way for the lifetime of the method.

Tested with https://gist.github.com/yangannyx/277e71dc348b289cde39e94b4b59d683

cc @yangannyx

Checklist

Release Notes

Notes: Fixed an issue where calling window.center() on Windows and Linux incorrectly centered the window.

@codebytere codebytere added semver/patch backwards-compatible bug fixes target/30-x-y PR should also be added to the "30-x-y" branch. target/31-x-y PR should also be added to the "31-x-y" branch. labels May 6, 2024
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label May 6, 2024
@codebytere codebytere force-pushed the fix-center-relative-to-screen branch from 35dc19f to e22f152 Compare May 6, 2024 12:16
@VerteDinde
Copy link
Member

I think the Windows tests may be legitimately failing on sizing BrowserWindow.center() centers the window, unfortunately

@codebytere
Copy link
Member Author

@VerteDinde yeah - i think this might be the reason we didn't have tests already :( it passes on each platform locally, but acts really weird in CI. Might need to just forego the test i think

@nornagon
Copy link
Member

nornagon commented May 6, 2024

Not gonna block this but I feel kinda mixed about this. I sort of agree with Chromium that it could be considered a bug that the parent was ignored, and it does kinda make sense for it to work that way. It's unclear to me what the use case is for wanting to center a child window in the screen as opposed to the parent. And it's nice to just back directly onto the Widget API.

On the other hand, it is a real behavior change that we didn't intend, and the code to revert the behavior isn't that long. If you decide to go ahead with merging this, perhaps put a comment here that explains why we're not using the Widget API?

@codebytere
Copy link
Member Author

@nornagon done!

@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label May 7, 2024
@nornagon nornagon merged commit 731bc7a into main May 8, 2024
16 checks passed
@nornagon nornagon deleted the fix-center-relative-to-screen branch May 8, 2024 22:42
Copy link

release-clerk bot commented May 8, 2024

Release Notes Persisted

Fixed an issue where calling window.center() on Windows and Linux incorrectly centered the window.

@trop
Copy link
Contributor

trop bot commented May 8, 2024

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

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

trop bot commented May 8, 2024

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

@trop trop bot added in-flight/31-x-y merged/30-x-y PR was merged to the "30-x-y" branch. merged/31-x-y PR was merged to the "31-x-y" branch. and removed target/31-x-y PR should also be added to the "31-x-y" branch. in-flight/30-x-y labels May 8, 2024
@trop trop bot removed the in-flight/31-x-y label May 9, 2024
Mrnikifabio pushed a commit to Mrnikifabio/electron that referenced this pull request May 14, 2024
@codebytere codebytere mentioned this pull request May 15, 2024
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged/30-x-y PR was merged to the "30-x-y" branch. merged/31-x-y PR was merged to the "31-x-y" branch. semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Calling .center() on BrowserWindow with parent now centers relative to parent instead of screen
3 participants