WIP: add logging to help investigate incorrect terminal size on macOS #5941
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.
Some logging changes to help investigate #2958. Not meant for merging, but rather just to help other folks to figure out the solution.
I have the following in my config:
When you have a setup with Retina screen (such as MBP internal screen) and non-Retina external monitor,
ConnectionOps.screens
(link) incorrectly calculatesvirtual_rect
. Specifically it doesn't adjust for scaling factor, which is 2 for Retina displays and 1 for non-Retina displays. Current algorithm completely ignores scaling factors and just naively adds backing coordinates.Here is one of the setups I have checked:
The top display is an external non-Retina monitor and the bottom one is an internal MBP Retina display. As you can see, non-Retina display (which has both frame and backing frame (width of 3440, height of 1440), and scale of 1) is bigger than the internal one (which has frame (width of 1728, height of 1117) and backing frame (width of 3456, height of 2234), and scale of 2). But
virtual_rect
is incorrectly calculated as having width of 3456 (max of 3440 and 3456) and height of 3674 (1440 + 2234).Some helpful resources I used while trying to understand macOS's behavior:
https://www.thinkandbuild.it/deal-with-multiple-screens-programming/
https://stackoverflow.com/questions/14579880/strange-nsscreen-coordinates
https://stackoverflow.com/questions/21751105/mac-os-x-convert-between-nsview-coordinates-and-global-screen-coordinates
https://developer.apple.com/documentation/appkit/nsscreen
https://developer.apple.com/documentation/appkit/nsscreen/1388389-convertrecttobacking
https://developer.apple.com/documentation/appkit/nsview/view_coordinates
Here are slightly edited logs (I removed duplicate lines with
nsscreen_to_screen_info
) when I run wezterm-gui from non-Retina external monitor. Notice that there are 3 lines withTerminalState.resize
that have different values of pixel_width, pixel_height, and dpi.Here are slightly edited logs (I removed duplicate lines with
nsscreen_to_screen_info
) when I run wezterm-gui from an internal MBP Retina display. Notice that there are 2 lines withTerminalState.resize
that have the same values of pixel_width, pixel_height, and dpi.