Window is resized after Mac sleeps when connected to external monitor
What Operating System(s) are you seeing this problem on?
macOS
Which Wayland compositor or X11 Window manager(s) are you using?
No response
WezTerm version
20231201-121352-6d58e519
Did you try the latest nightly build to see if the issue is better (or worse!) than your current version?
Yes, and I updated the version box above to show the version of the nightly that I tried
Describe the bug
When my M1 MBP is connected to my 4K external display and is in clamshell mode, if it goes to sleep and is awakened, wezterm windows get smaller (mostly the height but the width also changes a little). I've only been able to reproduce this when my macOS Display settings are scaled. When selecting 3840 x 2160 as the resolution, the wezterm window is not resized after the Mac sleeps and wakes.
To Reproduce
-
Attach MacBook to external monitor in clamshell
-
In macOS System Settings > Displays, change the resolution to a scaled resolution (my monitor is 4K but selecting 3840 x 2160 makes application/text way too small so I prefer 2560 x 1440):
-
Maximize wezterm window (but not in macOS full screen mode):
-
Put Mac to sleep
-
Wake Mac
-
The Wezterm window is now much smaller in height (the width changed a little as well):
Configuration
The issue also occurs with no config (wezterm -n)
Expected Behavior
The wezterm windows should remain the same size after waking the Mac.
Logs
After executing WEZTERM_LOG=wezterm_gui::termwindow=trace,wezterm_gui::termwindow::render=info,info wezterm start --always-new-process, I put my MBP to sleep/locked the screen. These are the logs once the MBP was awakened/unlocked:
16:02:27.217 DEBUG wezterm_gui::termwindow > Resized { dimensions: Dimensions { pixel_width: 645, pixel_height: 408, dpi: 72 }, window_state: (empty), live_resizing: true }
16:02:27.219 TRACE wezterm_gui::termwindow::resize > resize event, live=true current cells: RowsAndCols { rows: 24, cols: 80 }, current dims: Dimensions { pixel_width: 1366, pixel_height: 816, dpi: 144 }, new dims: Dimensions { pixel_width: 645, pixel_height: 408, dpi: 72 } window_state:(empty)
16:02:27.219 TRACE wezterm_gui::termwindow::resize > dpi_changed=true, font_scale_changed=false scale_changed=true simple_dpi_change=true
16:02:27.222 TRACE wezterm_gui::termwindow::resize > scaling_changed, follow with applying dimensions. scale_changed_cells=Some(RowsAndCols { rows: 24, cols: 80 })
16:02:27.222 TRACE wezterm_gui::termwindow::resize > apply_dimensions Dimensions { pixel_width: 645, pixel_height: 408, dpi: 72 } scale_changed_cells Some(RowsAndCols { rows: 24, cols: 80 }). window_state (empty)
16:02:27.230 TRACE wezterm_gui::termwindow::resize > apply_dimensions computed size TerminalSize { rows: 24, cols: 80, pixel_width: 640, pixel_height: 408, dpi: 72 }, dims Dimensions { pixel_width: 645, pixel_height: 408, dpi: 72 }
16:02:27.232 TRACE wezterm_gui::termwindow::resize > scale changed so resize from Dimensions { pixel_width: 1366, pixel_height: 816, dpi: 144 } to Dimensions { pixel_width: 645, pixel_height: 408, dpi: 72 } RowsAndCols { rows: 24, cols: 80 } (event called with Dimensions { pixel_width: 645, pixel_height: 408, dpi: 72 })
16:02:27.233 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:27.236 DEBUG wezterm_gui::termwindow > Resized { dimensions: Dimensions { pixel_width: 645, pixel_height: 408, dpi: 72 }, window_state: (empty), live_resizing: false }
16:02:27.236 TRACE wezterm_gui::termwindow::resize > resize event, live=false current cells: RowsAndCols { rows: 24, cols: 80 }, current dims: Dimensions { pixel_width: 645, pixel_height: 408, dpi: 72 }, new dims: Dimensions { pixel_width: 645, pixel_height: 408, dpi: 72 } window_state:(empty)
16:02:27.244 TRACE wezterm_gui::termwindow::resize > dimensions didn't change NOP!
16:02:27.397 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:27.397 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:27.398 DEBUG wezterm_gui::termwindow > NeedRepaint
16:02:27.581 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:28.233 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:28.233 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:28.234 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:32.441 DEBUG wezterm_gui::termwindow > Resized { dimensions: Dimensions { pixel_width: 1366, pixel_height: 816, dpi: 144 }, window_state: (empty), live_resizing: true }
16:02:32.441 TRACE wezterm_gui::termwindow::resize > resize event, live=true current cells: RowsAndCols { rows: 24, cols: 80 }, current dims: Dimensions { pixel_width: 645, pixel_height: 408, dpi: 72 }, new dims: Dimensions { pixel_width: 1366, pixel_height: 816, dpi: 144 } window_state:(empty)
16:02:32.441 TRACE wezterm_gui::termwindow::resize > dpi_changed=true, font_scale_changed=false scale_changed=true simple_dpi_change=true
16:02:32.462 TRACE wezterm_gui::termwindow::resize > scaling_changed, follow with applying dimensions. scale_changed_cells=Some(RowsAndCols { rows: 24, cols: 80 })
16:02:32.462 TRACE wezterm_gui::termwindow::resize > apply_dimensions Dimensions { pixel_width: 1366, pixel_height: 816, dpi: 144 } scale_changed_cells Some(RowsAndCols { rows: 24, cols: 80 }). window_state (empty)
16:02:32.558 TRACE wezterm_gui::termwindow::resize > apply_dimensions computed size TerminalSize { rows: 24, cols: 80, pixel_width: 1360, pixel_height: 816, dpi: 144 }, dims Dimensions { pixel_width: 1365, pixel_height: 816, dpi: 144 }
16:02:32.560 TRACE wezterm_gui::termwindow::resize > scale changed so resize from Dimensions { pixel_width: 645, pixel_height: 408, dpi: 72 } to Dimensions { pixel_width: 1365, pixel_height: 816, dpi: 144 } RowsAndCols { rows: 24, cols: 80 } (event called with Dimensions { pixel_width: 1366, pixel_height: 816, dpi: 144 })
16:02:32.561 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:32.563 DEBUG wezterm_gui::termwindow > Resized { dimensions: Dimensions { pixel_width: 1366, pixel_height: 816, dpi: 144 }, window_state: (empty), live_resizing: false }
16:02:32.563 TRACE wezterm_gui::termwindow::resize > resize event, live=false current cells: RowsAndCols { rows: 24, cols: 80 }, current dims: Dimensions { pixel_width: 1365, pixel_height: 816, dpi: 144 }, new dims: Dimensions { pixel_width: 1366, pixel_height: 816, dpi: 144 } window_state:(empty)
16:02:32.563 TRACE wezterm_gui::termwindow::resize > dpi_changed=false, font_scale_changed=false scale_changed=false simple_dpi_change=false
16:02:32.585 TRACE wezterm_gui::termwindow::resize > scaling_changed, follow with applying dimensions. scale_changed_cells=None
16:02:32.585 TRACE wezterm_gui::termwindow::resize > apply_dimensions Dimensions { pixel_width: 1366, pixel_height: 816, dpi: 144 } scale_changed_cells None. window_state (empty)
16:02:32.585 TRACE wezterm_gui::termwindow::resize > apply_dimensions computed size TerminalSize { rows: 24, cols: 80, pixel_width: 1360, pixel_height: 816, dpi: 144 }, dims Dimensions { pixel_width: 1366, pixel_height: 816, dpi: 144 }
16:02:32.630 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:32.631 DEBUG wezterm_gui::termwindow > NeedRepaint
16:02:32.644 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:32.645 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:32.646 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:32.646 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:32.646 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:32.646 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:33.565 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:33.566 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
16:02:33.568 DEBUG wezterm_gui::termwindow > Notification(Any { .. })
Debug Overlay:
Debug Overlay
wezterm version: 20231201-121352-6d58e519 aarch64-apple-darwin
Window Environment: macOS 13.6.1 (22G313)
OpenGL: Apple M1 Pro 4.1 Metal - 83.1
Enter lua statements or expressions and hit Enter.
Press ESC or CTRL-D to exit
> wezterm.gui.screens()
{
"active": {
"effective_dpi": 144,
"height": 2880,
"max_fps": 60,
"name": "DELL U2720Q",
"scale": 2,
"width": 5120,
"x": 0,
"y": 0,
},
"by_name": {
"DELL U2720Q": {
"effective_dpi": 144,
"height": 2880,
"max_fps": 60,
"name": "DELL U2720Q",
"scale": 2,
"width": 5120,
"x": 0,
"y": 0,
},
},
"main": {
"effective_dpi": 144,
"height": 2880,
"max_fps": 60,
"name": "DELL U2720Q",
"scale": 2,
"width": 5120,
"x": 0,
"y": 0,
},
"origin_x": 0,
"origin_y": 0,
"virtual_height": 2880,
"virtual_width": 5120,
}
Anything else?
I looked at many other issues that were possibly similar but this problem seemed to be different. Here are those issues:
- https://github.com/wez/wezterm/issues/3965
- https://github.com/wez/wezterm/issues/3396
- https://github.com/wez/wezterm/issues/2958
- https://github.com/wez/wezterm/issues/3965
I also tried to reproduce the issue with other applications including other terminals but all of them kept their window size after sleep/wake.
I have the same issue with an M1 MBP and an external monitor; when coming back from sleep, the window height of Wezterm is shrunk every time.
• I have the external monitor set as the main display at a resolution of 3440 x 1440, and the MBP display mirrors the external display.
• Note: I also have the same issue with Alacritty; aside from that, I haven't seen this with any other applications.
I've been experiencing this same issue. My window after waking from sleep looks just like the screenshots of the issue poster. I recently switched from Alacritty to WezTerm hoping the issue was just with Alacritty, but the issue is exactly the same. I've spent some time troubleshooting and have determined that this issue isn't present in iTerm. It also exists whether my window manager app Rectangle.app is running or not. Please let me know if there's more info I can provide.
Alternatively I'm wondering if there could be a workaround to add an event for when the machine wakes from sleep.
Environment:
- 2021 16 inch MacBook Pro with M1 Pro in clamshell mode
- 2016 LG UltraFine monitor (WezTerm is full sized on this monitor)
- 2022 LG DualUp monitor
- zsh, tmux,neovim
I'm having the same issue, and to reproduce it I have the external display set as extended, and use both the MacBook display and the external one simultaneously. Then I lock my Mac (Cmd+Ctrl+Q), then press Esc to turn off the screen, after this, I wait until my external display shows that the input was lost and turned off. Once this happens you can login back and the issue will happen.
I tested the kitty terminal and this issue doesn't happen. Could it be some mac config in the app or a code that recognizes this kind of behaviour?
To keep this issue alive, I'll add simply: I'm having this issue as well.
Same here
Had to switch to kitty because of this.
Also albeit out of scope but font rendering is really hard to get right in wezterm. More nobs to turn comparing to Kitty but much harder to get it right. Kitty is bearable with the default settings.
I can confirm. Alacritty has this same issue.
Same issue, M1 Max Studio with external monitor
Same issue, mbp and external monitor
This issue hasn't been too noticeable or an issue really since I've started using AeroSpace. I've been testing out Ghostty lately and I haven't noticed this issue yet with that terminal emulator. I like WezTerm a lot but this issue is making me consider sticking with Ghostty although I like WezTerm overall better.
@kronning6 If it isn't an issue when using Aerospace, why switch? I also use Aerospace, and I'm glad not to wrestle with this issue therefore. However, I've also been testing Ghostty, but have you opened a new tab in Ghostty? Aerospace (or MacOS) treats it as a new window even though it isn't which makes the one window take up less of the screen. It is an odd behavior, but they point out the issue is with MacOS. Wezterm handles this for you, which I actually think is a nice reason to use Wezterm over Ghostty for Aerospace users, for now... among other good reasons.
@theherk Yes that is a pretty annoying issue. I use tmux, so I don't happen to run into the issue as I don't use tabs. I did notice that when I set this setting: macos-titlebar-style = hidden, opening a new tab now just opens a new window for me.
I agree my reason for sticking with Ghostty for now isn't that great since Aerospace removes the need to readjust the window size manually, I have just grown a bit tied seeing the window size readjust so I'm going to enjoy that for a little bit here haha.
Same here, M2 Max Studio with external monitor
@theherk Yes that is a pretty annoying issue. I use tmux, so I don't happen to run into the issue as I don't use tabs. I did notice that when I set this setting:
macos-titlebar-style = hidden, opening a new tab now just opens a new window for me.I agree my reason for sticking with Ghostty for now isn't that great since Aerospace removes the need to readjust the window size manually, I have just grown a bit tied seeing the window size readjust so I'm going to enjoy that for a little bit here haha.
I've now switched to Kitty and now to Ghostty because of this as well. I'm using the following settings to disable window decorations in Ghostty (which indeed incapacitates tabs, but I don't use them anyway since I also use tmux).
window-decoration = false
macos-titlebar-style = native
window-save-state = always
Perhaps an unpopular opinion, but tabs are a bit pointless in terminals imho. I'm a huge fan of suckless terminal (aka st), which does not have tabs and even a scroll buffer and I never felt constrained. If there was a port that can be compiled for MAC I'd use that instead for sure.
I'm on M3 MacBook Pro with 2 external monitors btw.
+1 probably the only thing that is bugging me about otherwise perfect wezterm
but I found smth that could fix it for the time being - setting initial rows and cols and binding some combination to reset window's size (cmd + r in this case):
local wezterm = require("wezterm")
local config = wezterm.config_builder()
config.initial_rows = 60
config.initial_cols = 240
local act = wezterm.action
config.keys = {
{
key = "r",
mods = "CMD",
action = act.ResetFontAndWindowSize,
},
}
note that it resets font to initial value as well