Skip to content

Update scale factor and drawable size when macOS window changes screen#38269

Merged
localcc merged 3 commits intozed-industries:mainfrom
rlueder:fix-macos-monitor-disconnect-scaling
Nov 13, 2025
Merged

Update scale factor and drawable size when macOS window changes screen#38269
localcc merged 3 commits intozed-industries:mainfrom
rlueder:fix-macos-monitor-disconnect-scaling

Conversation

@rlueder
Copy link
Contributor

@rlueder rlueder commented Sep 16, 2025

Summary

Fixes UI scaling issue that occurs when starting Zed after disconnecting an external monitor on macOS. The window's scale factor and drawable size are now properly updated when the window changes screens.

Problem Description

When an external monitor is disconnected and Zed is started with only the built-in screen active, the UI scale becomes incorrect. This happens because:

  1. macOS triggers the window_did_change_screen callback when a window moves between displays (including when displays are disconnected)
  2. The existing implementation only restarted the display link but didn't update the window's scale factor or drawable size
  3. This left the window with stale scaling information from the previous display configuration

Root Cause

The window_did_change_screen callback in crates/gpui/src/platform/mac/window.rs was missing the logic to update the window's scale factor and drawable size when moving between screens. This logic was only present in the view_did_change_backing_properties callback, which isn't triggered when external monitors are disconnected.

Solution

  • Extracted common logic: Created a new update_window_scale_factor() function that encapsulates the scale factor and drawable size update logic
  • Added scale factor update to screen change: Modified window_did_change_screen to call this function after restarting the display link
  • Refactored existing code: Updated view_did_change_backing_properties to use the new shared function, reducing code duplication

The fix ensures that whenever a window changes screens (due to monitor disconnect, reconnect, or manual movement), the scale factor, drawable size, and renderer state are properly synchronized.

Testing

  • ✅ Verified that UI scaling remains correct after disconnecting external monitor
  • ✅ Confirmed that reconnecting external monitor works properly
  • ✅ Tested that manual window movement between displays updates scaling correctly
  • ✅ No regressions observed in normal window operations

To verity my fix worked I had to copy my preview workspace over my dev workspace, once I had done this I could reproduce the issue on main consistently. After switching to the branch with this fix the issue was resolved.

The fix is similar to what was done on #35686 (Windows)

Closes #37245 #38229

Release Notes:

  • Fixed: Update scale factor and drawable size when macOS window changes screen

When an external monitor is disconnected on macOS, the UI scale factor
becomes incorrect because window_did_change_screen only starts the display
link but doesn't update the scale factor or trigger resize callbacks.

This fix adds a shared update_window_scale_factor helper function that
handles scale factor updates and resize callback triggering. Both
window_did_change_screen and view_did_change_backing_properties now use
this shared function to eliminate code duplication.

The approach mirrors the Windows fix in PR zed-industries#35686 for similar DPI change issues.

Fixes zed-industries#38229
@cla-bot
Copy link

cla-bot bot commented Sep 16, 2025

We require contributors to sign our Contributor License Agreement, and we don't have @rlueder on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@rlueder
Copy link
Contributor Author

rlueder commented Sep 16, 2025

@cla-bot check

@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Sep 16, 2025
@cla-bot
Copy link

cla-bot bot commented Sep 16, 2025

The cla-bot has been summoned, and re-checked this pull request!

@maxdeviant maxdeviant changed the title fix: Update scale factor and drawable size when macOS window changes screen Update scale factor and drawable size when macOS window changes screen Sep 16, 2025
@localcc localcc enabled auto-merge (squash) November 13, 2025 16:50
@localcc localcc merged commit 46eb9e5 into zed-industries:main Nov 13, 2025
23 checks passed
@rlueder rlueder deleted the fix-macos-monitor-disconnect-scaling branch November 19, 2025 19:27
11happy pushed a commit to 11happy/zed that referenced this pull request Dec 1, 2025
zed-industries#38269)

Summary

Fixes UI scaling issue that occurs when starting Zed after disconnecting
an external monitor on macOS. The window's scale factor and drawable
size are now properly updated when the window changes screens.

Problem Description

When an external monitor is disconnected and Zed is started with only
the built-in screen active, the UI scale becomes incorrect. This happens
because:

1. macOS triggers the `window_did_change_screen` callback when a window
moves between displays (including when displays are disconnected)
2. The existing implementation only restarted the display link but
didn't update the window's scale factor or drawable size
3. This left the window with stale scaling information from the previous
display configuration

Root Cause

The `window_did_change_screen` callback in
`crates/gpui/src/platform/mac/window.rs` was missing the logic to update
the window's scale factor and drawable size when moving between screens.
This logic was only present in the `view_did_change_backing_properties
callback`, which isn't triggered when external monitors are
disconnected.

Solution

- Extracted common logic: Created a new `update_window_scale_factor()`
function that encapsulates the scale factor and drawable size update
logic
- Added scale factor update to screen change: Modified
`window_did_change_screen` to call this function after restarting the
display link
- Refactored existing code: Updated `view_did_change_backing_properties`
to use the new shared function, reducing code duplication

The fix ensures that whenever a window changes screens (due to monitor
disconnect, reconnect, or manual movement), the scale factor, drawable
size, and renderer state are properly synchronized.

Testing

- ✅ Verified that UI scaling remains correct after disconnecting
external monitor
- ✅ Confirmed that reconnecting external monitor works properly
- ✅ Tested that manual window movement between displays updates scaling
correctly
- ✅ No regressions observed in normal window operations

To verity my fix worked I had to copy my preview workspace over my dev
workspace, once I had done this I could reproduce the issue on main
consistently. After switching to the branch with this fix the issue was
resolved.

The fix is similar to what was done on
zed-industries#35686 (Windows)

Closes zed-industries#37245 zed-industries#38229

Release Notes:

- Fixed: Update scale factor and drawable size when macOS window changes
screen

---------

Co-authored-by: Kate <work@localcc.cc>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Blurry UI on built-in screen after using Zed on an external monitor

4 participants