Commit 46eb9e5
Update scale factor and drawable size when macOS window changes screen (#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
#35686 (Windows)
Closes #37245 #38229
Release Notes:
- Fixed: Update scale factor and drawable size when macOS window changes
screen
---------
Co-authored-by: Kate <[email protected]>1 parent cb7bd5f commit 46eb9e5
1 file changed
+27
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1967 | 1967 | | |
1968 | 1968 | | |
1969 | 1969 | | |
| 1970 | + | |
| 1971 | + | |
| 1972 | + | |
| 1973 | + | |
| 1974 | + | |
| 1975 | + | |
| 1976 | + | |
| 1977 | + | |
| 1978 | + | |
| 1979 | + | |
| 1980 | + | |
| 1981 | + | |
| 1982 | + | |
| 1983 | + | |
| 1984 | + | |
| 1985 | + | |
| 1986 | + | |
| 1987 | + | |
| 1988 | + | |
| 1989 | + | |
| 1990 | + | |
| 1991 | + | |
| 1992 | + | |
| 1993 | + | |
1970 | 1994 | | |
1971 | 1995 | | |
1972 | 1996 | | |
1973 | 1997 | | |
| 1998 | + | |
| 1999 | + | |
1974 | 2000 | | |
1975 | 2001 | | |
1976 | 2002 | | |
| |||
2079 | 2105 | | |
2080 | 2106 | | |
2081 | 2107 | | |
2082 | | - | |
2083 | | - | |
2084 | | - | |
2085 | | - | |
2086 | | - | |
2087 | | - | |
2088 | | - | |
2089 | | - | |
2090 | | - | |
2091 | | - | |
2092 | | - | |
2093 | | - | |
2094 | | - | |
2095 | | - | |
2096 | | - | |
2097 | | - | |
2098 | | - | |
2099 | | - | |
2100 | | - | |
2101 | | - | |
2102 | | - | |
| 2108 | + | |
2103 | 2109 | | |
2104 | 2110 | | |
2105 | 2111 | | |
| |||
0 commit comments