Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add logging to help investigate incorrect terminal size on macOS #5941

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

yerke
Copy link
Contributor

@yerke yerke commented Aug 13, 2024

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:

config.initial_rows = 24
config.initial_cols = 80

When you have a setup with Retina screen (such as MBP internal screen) and non-Retina external monitor, ConnectionOps.screens (link) incorrectly calculates virtual_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:
Screenshot 2024-08-13 at 00 44 10

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 with TerminalState.resize that have different values of pixel_width, pixel_height, and dpi.

01:21:07.824  WARN   window::os::macos::connection > nsscreen_to_screen_info frame: width: 3440, height: 1440
01:21:07.825  WARN   window::os::macos::connection > nsscreen_to_screen_info backing_frame: width: 3440, height: 1440
01:21:07.829  WARN   window::os::macos::connection > nsscreen_to_screen_info name: DELL U3419W
01:21:07.829  WARN   window::os::macos::connection > nsscreen_to_screen_info frame: width: 1728, height: 1117
01:21:07.829  WARN   window::os::macos::connection > nsscreen_to_screen_info backing_frame: width: 3456, height: 2234
01:21:07.829  WARN   window::os::macos::connection > nsscreen_to_screen_info name: Built-in Retina Display
01:21:07.842  WARN   mux::domain                   > LocalDomain.spawn_pane size: TerminalSize { rows: 24, cols: 80, pixel_width: 880, pixel_height: 624, dpi: 72 }
01:21:07.843  WARN   wezterm_term::terminalstate   > TerminalState.new size: TerminalSize { rows: 24, cols: 80, pixel_width: 880, pixel_height: 624, dpi: 72 }
01:21:07.864  WARN   window::connection            > ConnectionOps.resolve_geometry Screens { main: ScreenInfo { name: "DELL U3419W", rect: Rect(3440x1440 at (0, 0)), scale: 1.0, max_fps: Some(60), effective_dpi: Some(72.0) }, active: ScreenInfo { name: "DELL U3419W", rect: Rect(3440x1440 at (0, 0)), scale: 1.0, max_fps: Some(60), effective_dpi: Some(72.0) }, by_name: {"DELL U3419W": ScreenInfo { name: "DELL U3419W", rect: Rect(3440x1440 at (0, 0)), scale: 1.0, max_fps: Some(60), effective_dpi: Some(72.0) }, "Built-in Retina Display": ScreenInfo { name: "Built-in Retina Display", rect: Rect(3456x2234 at (0, -2234)), scale: 2.0, max_fps: Some(120), effective_dpi: Some(144.0) }}, virtual_rect: Rect(3456x3674 at (0, -2234)) }
01:21:07.865  WARN   window::os::macos::window     > new_window ResolvedGeometry: width: 902, height: 675, x: None, y: None
01:21:07.867  WARN   window::os::macos::window     > new_window conn.default_dpi: 72
01:21:07.867  WARN   window::os::macos::window     > new_window scale_factor: 1
01:21:07.867  WARN   window::os::macos::window     > new_window after scaling: width: 902, height: 675, x: None, y: None
01:21:07.883  WARN   window::os::macos::window     > new_window backing frame: width: 902, height: 675
01:21:07.884  WARN   window::os::macos::window     > new_window dpi_for_window_screen: None
01:21:07.884  WARN   window::os::macos::window     > new_window dpi: 72
01:21:07.938  WARN   window::os::macos::window     > did_resize backing frame: width: 1804, height: 1350, x: 0, y: -1350
01:21:07.938  WARN   window::os::macos::window     > WindowView.did_resize dpi: 144
01:21:07.942  WARN   mux::tab                      > apply_sizes_from_splits size: TerminalSize { rows: 24, cols: 80, pixel_width: 1840, pixel_height: 1224, dpi: 144 }
01:21:07.942  WARN   mux::localpane                > LocalPane.resize size: TerminalSize { rows: 24, cols: 80, pixel_width: 1840, pixel_height: 1224, dpi: 144 }
01:21:07.943  WARN   wezterm_term::terminalstate   > TerminalState.resize size: TerminalSize { rows: 24, cols: 80, pixel_width: 1840, pixel_height: 1224, dpi: 144 }
01:21:07.947  WARN   window::os::macos::window     > did_resize backing frame: width: 1804, height: 1350, x: 0, y: -1350
01:21:07.947  WARN   window::os::macos::window     > WindowView.did_resize dpi: 144
01:21:07.947  WARN   mux::tab                      > apply_sizes_from_splits size: TerminalSize { rows: 24, cols: 76, pixel_width: 1748, pixel_height: 1224, dpi: 144 }
01:21:07.947  WARN   mux::localpane                > LocalPane.resize size: TerminalSize { rows: 24, cols: 76, pixel_width: 1748, pixel_height: 1224, dpi: 144 }
01:21:07.947  WARN   wezterm_term::terminalstate   > TerminalState.resize size: TerminalSize { rows: 24, cols: 76, pixel_width: 1748, pixel_height: 1224, dpi: 144 }
01:21:07.965  WARN   window::os::macos::window     > did_resize backing frame: width: 1886, height: 1324, x: 0, y: -1324
01:21:07.965  WARN   window::os::macos::window     > WindowView.did_resize dpi: 72
01:21:07.969  WARN   mux::tab                      > apply_sizes_from_splits size: TerminalSize { rows: 48, cols: 169, pixel_width: 1859, pixel_height: 1248, dpi: 72 }
01:21:07.969  WARN   mux::localpane                > LocalPane.resize size: TerminalSize { rows: 48, cols: 169, pixel_width: 1859, pixel_height: 1248, dpi: 72 }
01:21:07.969  WARN   wezterm_term::terminalstate   > TerminalState.resize size: TerminalSize { rows: 48, cols: 169, pixel_width: 1859, pixel_height: 1248, dpi: 72 }

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 with TerminalState.resize that have the same values of pixel_width, pixel_height, and dpi.

01:24:49.402  WARN   window::os::macos::connection > nsscreen_to_screen_info frame: width: 3440, height: 1440
01:24:49.402  WARN   window::os::macos::connection > nsscreen_to_screen_info backing_frame: width: 3440, height: 1440
01:24:49.403  WARN   window::os::macos::connection > nsscreen_to_screen_info name: DELL U3419W
01:24:49.403  WARN   window::os::macos::connection > nsscreen_to_screen_info frame: width: 1728, height: 1117
01:24:49.403  WARN   window::os::macos::connection > nsscreen_to_screen_info backing_frame: width: 3456, height: 2234
01:24:49.403  WARN   window::os::macos::connection > nsscreen_to_screen_info name: Built-in Retina Display
01:24:49.416  WARN   mux::domain                   > LocalDomain.spawn_pane size: TerminalSize { rows: 24, cols: 80, pixel_width: 1840, pixel_height: 1224, dpi: 144 }
01:24:49.416  WARN   wezterm_term::terminalstate   > TerminalState.new size: TerminalSize { rows: 24, cols: 80, pixel_width: 1840, pixel_height: 1224, dpi: 144 }
01:24:49.440  WARN   window::connection            > ConnectionOps.resolve_geometry Screens { main: ScreenInfo { name: "DELL U3419W", rect: Rect(3440x1440 at (0, 0)), scale: 1.0, max_fps: Some(60), effective_dpi: Some(72.0) }, active: ScreenInfo { name: "Built-in Retina Display", rect: Rect(3456x2234 at (0, -2234)), scale: 2.0, max_fps: Some(120), effective_dpi: Some(144.0) }, by_name: {"Built-in Retina Display": ScreenInfo { name: "Built-in Retina Display", rect: Rect(3456x2234 at (0, -2234)), scale: 2.0, max_fps: Some(120), effective_dpi: Some(144.0) }, "DELL U3419W": ScreenInfo { name: "DELL U3419W", rect: Rect(3440x1440 at (0, 0)), scale: 1.0, max_fps: Some(60), effective_dpi: Some(72.0) }}, virtual_rect: Rect(3456x3674 at (0, -2234)) }
01:24:49.441  WARN   window::os::macos::window     > new_window ResolvedGeometry: width: 1886, height: 1324, x: None, y: None
01:24:49.445  WARN   window::os::macos::window     > new_window conn.default_dpi: 144
01:24:49.445  WARN   window::os::macos::window     > new_window scale_factor: 2
01:24:49.445  WARN   window::os::macos::window     > new_window after scaling: width: 943, height: 662, x: None, y: None
01:24:49.456  WARN   window::os::macos::window     > new_window backing frame: width: 1886, height: 1324
01:24:49.456  WARN   window::os::macos::window     > new_window dpi_for_window_screen: None
01:24:49.456  WARN   window::os::macos::window     > new_window dpi: 144
01:24:49.499  WARN   window::os::macos::window     > did_resize backing frame: width: 1886, height: 1324, x: 0, y: -1324
01:24:49.500  WARN   window::os::macos::window     > WindowView.did_resize dpi: 144
01:24:49.501  WARN   mux::tab                      > apply_sizes_from_splits size: TerminalSize { rows: 24, cols: 80, pixel_width: 1840, pixel_height: 1224, dpi: 144 }
01:24:49.501  WARN   mux::localpane                > LocalPane.resize size: TerminalSize { rows: 24, cols: 80, pixel_width: 1840, pixel_height: 1224, dpi: 144 }
01:24:49.501  WARN   wezterm_term::terminalstate   > TerminalState.resize size: TerminalSize { rows: 24, cols: 80, pixel_width: 1840, pixel_height: 1224, dpi: 144 }
01:24:49.505  WARN   window::os::macos::window     > did_resize backing frame: width: 1886, height: 1324, x: 0, y: -1324
01:24:49.505  WARN   window::os::macos::window     > WindowView.did_resize dpi: 144
01:24:49.505  WARN   mux::tab                      > apply_sizes_from_splits size: TerminalSize { rows: 24, cols: 80, pixel_width: 1840, pixel_height: 1224, dpi: 144 }
01:24:49.505  WARN   mux::localpane                > LocalPane.resize size: TerminalSize { rows: 24, cols: 80, pixel_width: 1840, pixel_height: 1224, dpi: 144 }
01:24:49.506  WARN   wezterm_term::terminalstate   > TerminalState.resize size: TerminalSize { rows: 24, cols: 80, pixel_width: 1840, pixel_height: 1224, dpi: 144 }

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.

1 participant