Skip to content

Commit

Permalink
WIP: add logging to help investigate incorrect terminal size on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
yerke committed Aug 13, 2024
1 parent 0ac1e94 commit 458e99d
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions mux/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
1 change: 1 addition & 0 deletions mux/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
1 change: 1 addition & 0 deletions mux/src/localpane.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?,
Expand Down
1 change: 1 addition & 0 deletions mux/src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Expand Down
5 changes: 5 additions & 0 deletions term/src/terminalstate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,8 @@ impl TerminalState {

let unicode_version = config.unicode_version();

log::warn!("TerminalState.new size: {size:?}");

TerminalState {
config,
screen,
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion window/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions window/src/os/macos/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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,
Expand All @@ -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)) };
Expand Down
17 changes: 17 additions & 0 deletions window/src/os/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 458e99d

Please sign in to comment.