fix: win.center() sets the correct size and position on frameless windows#51732
Merged
Conversation
33de011 to
f7e3a46
Compare
Member
Author
f7e3a46 to
03d1bea
Compare
Member
Author
|
/request-review @mlaurencin |
e312d90 to
f8124af
Compare
Member
Author
|
Marked tests as passing because the macOS ARM64 failures are unrelated (#51776). |
f8124af to
55800bc
Compare
…dows on Linux and Windows
55800bc to
0629bd8
Compare
jkleinsc
approved these changes
Jun 8, 2026
|
Release Notes Persisted
|
This was referenced Jun 8, 2026
Contributor
|
I have automatically backported this PR to "41-x-y", please check out #51919 |
Contributor
|
I have automatically backported this PR to "43-x-y", please check out #51920 |
Contributor
|
I have automatically backported this PR to "42-x-y", please check out #51921 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description of Change
Fixes #51731.
Calling
win.center()caused frameless windows with insets to shrink on both Windows and Linux. Additionally, on Windows, frameless windows were not centered correctly on launch or when callingwin.center().This PR corrects both the shrinking and the positioning by introducing a shared implementation for
NativeWindowViews::Center()for Linux and Windows. It is based on the existing Linux codepath but has been updated to useSetBounds(), which properly handles insets, instead of the lower levelwidget()->SetBounds(). On Windows, it replaces the call togfx::CenterAndSizeWindow(size), which places windows too high if they have asymmetric insets.While
CenterAndSizeWindowcould be patched upstream (this is an approach I have taken for other APIs) I looked at its implementation and do not see a benefit in having a divergent path for Windows in this instance. The upstream API is not cross-platform and is not used much even on Windows, and Electron isn't getting anything for free that it doesn't already have to support to position windows correctly. It is possible that I'm missing something, but I have done my best to test this simplification thoroughly.With the new shared implementation, centering on both platforms is now accurate (at least at 100% DPI) and does not change the window's size. I was also able to get rid of an extra call to set bounds on init now that
Center()has an improved implementation.I added new tests for both initial window bounds and
win.center()for framed and frameless windows. I also verified that frameless and framed windows are centered in the exact size and position on Windows as in 41.2.0 (prior to the insets changes).(On Wayland,
win.center()is still effectively a no-op, as the compositor will not honour the move. However, the window will no longer shrink if it is called.)Backports to 41, 42, 43.
Checklist
npm testpassesRelease Notes
Notes: Fixed an issue on Linux and Windows where frameless windows would shrink when calling
win.center(). Additionally, fixed an issue where frameless windows would appear slightly off-center on Windows.