Skip to content

fix: use win.getBounds() instead of getPosition()/getSize() to prevent window drift on Linux#315493

Open
harshagarwalnyu wants to merge 4 commits into
microsoft:mainfrom
harshagarwalnyu:fix-window-drift-linux
Open

fix: use win.getBounds() instead of getPosition()/getSize() to prevent window drift on Linux#315493
harshagarwalnyu wants to merge 4 commits into
microsoft:mainfrom
harshagarwalnyu:fix-window-drift-linux

Conversation

@harshagarwalnyu
Copy link
Copy Markdown

Fixes #117180

On Linux (specifically GNOME/X11), win.getPosition() can sometimes return the coordinates of the content area instead of the window frame when native titlebars are enabled. When these coordinates are saved and later used to restore the window position (e.g., in the constructor or via setBounds), the window manager adds the titlebar height again, causing the window to drift downwards with each restart.

Using win.getBounds() is more robust as it is designed to return the full window geometry including decorations, ensuring that the saved coordinates correctly represent the window frame.

Copilot AI review requested due to automatic review settings May 9, 2026 20:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses Linux window-position “drift” when native titlebars are enabled by ensuring we persist/compute window geometry using Electron’s full window bounds (frame-inclusive) rather than composing coordinates from getPosition() + getSize().

Changes:

  • Update CodeWindow.getBounds() to delegate directly to BrowserWindow.getBounds().

@harshagarwalnyu
Copy link
Copy Markdown
Author

Verified this fix on GNOME/X11 (Ubuntu 22.04). Using win.getBounds() correctly accounts for the window decorations (titlebars), preventing the coordinate drift that occurs when manually composing from getPosition() and getSize(). This ensures the window restored position remains consistent across restarts.

@harshagarwalnyu harshagarwalnyu force-pushed the fix-window-drift-linux branch from 1c4c89f to 470fe80 Compare May 9, 2026 22:01
@harshagarwalnyu
Copy link
Copy Markdown
Author

@mjbvz Hi! Could you approve the CI workflows to run on this PR? Happy to address any feedback once the checks are in. Thanks!

@harshagarwalnyu harshagarwalnyu force-pushed the fix-window-drift-linux branch from 470fe80 to 78e01bd Compare May 9, 2026 22:27
…ndow drift on Linux

On Linux (GNOME/X11) with native titlebars, getPosition() can return
content-area coordinates instead of frame coordinates. When saved and
restored, the window manager re-adds the titlebar height causing drift.

Replace two call sites with getBounds() which always returns the full
frame-inclusive geometry:
- CodeWindow.getBounds() in windowImpl.ts
- maximize event handler in BaseWindow

Fixes microsoft#117180
@harshagarwalnyu harshagarwalnyu force-pushed the fix-window-drift-linux branch from 78e01bd to 9cf6e52 Compare May 10, 2026 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The initial position of the VSCode is shifted down when the native titlebar is on

3 participants