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

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

Open
3 tasks done
neobyteUK opened this issue Apr 24, 2024 · 5 comments · May be fixed by #42048
Open
3 tasks done
Assignees
Labels
30-x-y bug 🪲 has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/linux platform/windows status/confirmed A maintainer reproduced the bug or agreed with the feature

Comments

@neobyteUK
Copy link

Preflight Checklist

Electron Version

30.0.1

What operating system are you using?

Windows

Operating System Version

Windows 10 Pro 22H2 19045.4291

What arch are you using?

x64

Last Known Working Electron version

27

Expected Behavior

As per documentation for .center() : "Moves window to the center of the screen.".

https://www.electronjs.org/docs/latest/api/browser-window#wincenter

Actual Behavior

When a BrowserWindow has a parent window defined, calling .center() on the child centers the window relative to the parent, not the screen.

Testcase Gist URL

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

Additional Information

This issue does not exist in 27.3.11 but DOES exist in 28.0.0 onwards.

Credit to yangannyx for creating the gist in response to my initial query regarding this on discord.

@electron-issue-triage electron-issue-triage bot added the has-repro-gist Issue can be reproduced with code at https://gist.github.com/ label Apr 24, 2024
@yangannyx
Copy link

Hello! To add to this, I'm seeing a few differences in behavior between MacOS and Windows on child windows.

  1. MacOS child windows get centered relative to the screen, while Windows child windows become centered relative to the parent screen.
  2. Dragging the parent window in MacOS will also drag the child windows to preserve their distance/position to the parent window. On Windows, dragging the parent window has no effect on the child window's position.

If it's manageable, I think this would be cool to parameterize in some way

@codebytere
Copy link
Member

Looks like this might be an upstream-instigated change, as our Windows implementation hasn't changed in ~6 years:

widget()->CenterWindow(GetSize());

@codebytere
Copy link
Member

codebytere commented Apr 24, 2024

Good news and bad news: I found the CL that caused this after a quick sprint through Chromium: https://chromium-review.googlesource.com/c/chromium/src/+/4916277, but the CL indicates the previous behavior was unintended and that the new behavior (centering relative to parent) is correct and intended in the method we call. I'll see what the potential options are, as we should ensure the end-user experience remains the same as it was and adheres to expectations from documentation.

@codebytere codebytere added platform/windows platform/linux status/confirmed A maintainer reproduced the bug or agreed with the feature 30-x-y labels Apr 24, 2024
@codebytere
Copy link
Member

@yangannyx if you could, it'd be helpful to make this:

Dragging the parent window in MacOS will also drag the child windows to preserve their distance/position to the parent window. On Windows, dragging the parent window has no effect on the child window's position.

its own issue!

@codebytere codebytere self-assigned this Apr 24, 2024
@yangannyx
Copy link

yangannyx commented Apr 24, 2024

@codebytere, I actually see there's existing electron documentation that describes the drag behavior discrepancy here. I'm leaning towards not opening an issue for this reason, since it doesn't seem like a regression

@codebytere codebytere linked a pull request May 6, 2024 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
30-x-y bug 🪲 has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/linux platform/windows status/confirmed A maintainer reproduced the bug or agreed with the feature
Projects
Status: 👍 Does Not Block Stable
Development

Successfully merging a pull request may close this issue.

3 participants