From 458e99dbb6aae6b418d2b0061d37a89cd831efe8 Mon Sep 17 00:00:00 2001 From: Yerke Tulibergenov Date: Tue, 13 Aug 2024 01:03:56 -0700 Subject: [PATCH] WIP: add logging to help investigate incorrect terminal size on macOS --- mux/src/domain.rs | 2 ++ mux/src/lib.rs | 1 + mux/src/localpane.rs | 1 + mux/src/tab.rs | 1 + term/src/terminalstate/mod.rs | 5 +++++ window/src/connection.rs | 2 +- window/src/os/macos/connection.rs | 4 ++++ window/src/os/macos/window.rs | 17 +++++++++++++++++ 8 files changed, 32 insertions(+), 1 deletion(-) diff --git a/mux/src/domain.rs b/mux/src/domain.rs index 3cb3767d5c3..3a01aa14f4b 100644 --- a/mux/src/domain.rs +++ b/mux/src/domain.rs @@ -606,6 +606,8 @@ impl Domain for LocalDomain { let child_result = pair.slave.spawn_command(cmd); let mut writer = WriterWrapper::new(pair.master.take_writer()?); + log::warn!("LocalDomain.spawn_pane size: {size:?}"); + let mut terminal = wezterm_term::Terminal::new( size, std::sync::Arc::new(config::TermConfig::new()), diff --git a/mux/src/lib.rs b/mux/src/lib.rs index f46e5ee0896..479e2e15a9f 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -1278,6 +1278,7 @@ impl Mux { let tab = Arc::new(Tab::new(&size)); tab.assign_pane(&pane); + log::warn!("Mux.move_pane_to_new_tab size: {size:?}"); pane.resize(size)?; self.add_tab_and_active_pane(&tab)?; self.add_tab_to_window(&tab, window_id)?; diff --git a/mux/src/localpane.rs b/mux/src/localpane.rs index 09f72878061..dba8d09e835 100644 --- a/mux/src/localpane.rs +++ b/mux/src/localpane.rs @@ -411,6 +411,7 @@ impl Pane for LocalPane { } fn resize(&self, size: TerminalSize) -> Result<(), Error> { + log::warn!("LocalPane.resize size: {size:?}"); self.pty.lock().resize(PtySize { rows: size.rows.try_into()?, cols: size.cols.try_into()?, diff --git a/mux/src/tab.rs b/mux/src/tab.rs index 8eec504fb5f..844ca793473 100644 --- a/mux/src/tab.rs +++ b/mux/src/tab.rs @@ -491,6 +491,7 @@ fn apply_sizes_from_splits(tree: &Tree, size: &TerminalSize) { apply_sizes_from_splits(&*right, &data.second); } Tree::Leaf(pane) => { + log::warn!("apply_sizes_from_splits size: {size:?}"); pane.resize(*size).ok(); } } diff --git a/term/src/terminalstate/mod.rs b/term/src/terminalstate/mod.rs index ddbd8772a0d..71a4e7e5306 100644 --- a/term/src/terminalstate/mod.rs +++ b/term/src/terminalstate/mod.rs @@ -515,6 +515,8 @@ impl TerminalState { let unicode_version = config.unicode_version(); + log::warn!("TerminalState.new size: {size:?}"); + TerminalState { config, screen, @@ -876,6 +878,9 @@ impl TerminalState { self.seqno, self.enable_conpty_quirks, ); + + log::warn!("TerminalState.resize size: {size:?}"); + self.top_and_bottom_margins = 0..size.rows as i64; self.left_and_right_margins = 0..size.cols; self.pixel_height = size.pixel_height; diff --git a/window/src/connection.rs b/window/src/connection.rs index 9564d4999b8..aa919a1ceb7 100644 --- a/window/src/connection.rs +++ b/window/src/connection.rs @@ -84,7 +84,7 @@ pub trait ConnectionOps { fn resolve_geometry(&self, geometry: RequestedWindowGeometry) -> ResolvedGeometry { let bounds = match self.screens() { Ok(screens) => { - log::trace!("{screens:?}"); + log::warn!("ConnectionOps.resolve_geometry {screens:?}"); match geometry.origin { GeometryOrigin::ScreenCoordinateSystem => screens.virtual_rect, diff --git a/window/src/os/macos/connection.rs b/window/src/os/macos/connection.rs index b5a85d2e198..84232928bf8 100644 --- a/window/src/os/macos/connection.rs +++ b/window/src/os/macos/connection.rs @@ -180,6 +180,7 @@ impl ConnectionOps for Connection { for idx in 0..unsafe { screens.count() } { let screen = unsafe { screens.objectAtIndex(idx) }; let screen = nsscreen_to_screen_info(screen); + // This seems to be incorrect. Union does not adjust for scaling factor. virtual_rect = virtual_rect.union(&screen.rect); by_name.insert(screen.name.clone(), screen); } @@ -202,6 +203,8 @@ impl ConnectionOps for Connection { pub fn nsscreen_to_screen_info(screen: *mut Object) -> ScreenInfo { let frame = unsafe { NSScreen::frame(screen) }; let backing_frame = unsafe { NSScreen::convertRectToBacking_(screen, frame) }; + log::warn!("nsscreen_to_screen_info frame: width: {}, height: {}", frame.size.width, frame.size.height); + log::warn!("nsscreen_to_screen_info backing_frame: width: {}, height: {}", backing_frame.size.width, backing_frame.size.height); let rect = euclid::rect( backing_frame.origin.x as isize, backing_frame.origin.y as isize, @@ -220,6 +223,7 @@ pub fn nsscreen_to_screen_info(screen: *mut Object) -> ScreenInfo { backing_frame.origin.y ) }; + log::warn!("nsscreen_to_screen_info name: {name}"); let has_max_fps: BOOL = unsafe { msg_send!(screen, respondsToSelector: sel!(maximumFramesPerSecond)) }; diff --git a/window/src/os/macos/window.rs b/window/src/os/macos/window.rs index 7576e72b637..bad078e8920 100644 --- a/window/src/os/macos/window.rs +++ b/window/src/os/macos/window.rs @@ -453,12 +453,19 @@ impl Window { y, } = conn.resolve_geometry(geometry); + log::warn!("new_window ResolvedGeometry: width: {width}, height: {height}, x: {x:?}, y: {y:?}"); + let scale_factor = (conn.default_dpi() / crate::DEFAULT_DPI) as usize; + // let scale_factor = 2 as usize; let width = width / scale_factor; let height = height / scale_factor; let x = x.map(|x| x / scale_factor as i32); let y = y.map(|y| y / scale_factor as i32); + log::warn!("new_window conn.default_dpi: {}", conn.default_dpi()); + log::warn!("new_window scale_factor: {scale_factor}"); + log::warn!("new_window after scaling: width: {width}, height: {height}, x: {x:?}, y: {y:?}"); + let initial_pos = match (x, y) { (Some(x), Some(y)) => Some(ScreenPoint::new(x as isize, y as isize)), _ => None, @@ -615,11 +622,17 @@ impl Window { let backing_frame = NSView::convertRectToBacking(*view, frame); let width = backing_frame.size.width; let height = backing_frame.size.height; + log::warn!("new_window backing frame: width: {width}, height: {height}"); + + let dpi_for_window_screen_value = dpi_for_window_screen(*window, &config); + log::warn!("new_window dpi_for_window_screen: {dpi_for_window_screen_value:?}"); let dpi = dpi_for_window_screen(*window, &config) .unwrap_or(crate::DEFAULT_DPI * (backing_frame.size.width / frame.size.width)) as usize; + log::warn!("new_window dpi: {dpi}"); + let weak_window = window.weak(); let window_handle = Window { id: window_id, @@ -1201,6 +1214,7 @@ impl WindowInner { unsafe { NSWindow::setLevel_(*self.window, window_level_to_nswindow_level(level)); // Dispatch a resize event with the updated window state + log::warn!("WindowInner.set_window_level"); WindowView::did_resize(&mut **self.view, sel!(windowDidResize:), nil); } } @@ -2785,6 +2799,7 @@ impl WindowView { let backing_frame = unsafe { NSView::convertRectToBacking(this as *mut _, frame) }; let width = backing_frame.size.width; let height = backing_frame.size.height; + log::warn!("did_resize backing frame: width: {width}, height: {height}, x: {}, y: {}", backing_frame.origin.x, backing_frame.origin.y); if let Some(this) = Self::get_this(this) { let mut inner = this.inner.borrow_mut(); @@ -2845,6 +2860,7 @@ impl WindowView { .unwrap_or(crate::DEFAULT_DPI * (backing_frame.size.width / frame.size.width)) as usize; + log::warn!("WindowView.did_resize dpi: {dpi}"); inner.events.dispatch(WindowEvent::Resized { dimensions: Dimensions { pixel_width: width as usize, @@ -2920,6 +2936,7 @@ impl WindowView { // and a repaint. inner.screen_changed = false; drop(inner); + log::warn!("WindowView.draw_rect screen_changed"); Self::did_resize(view, sel, nil); return; }