From aed0e3ebf82b4acef0d4b84daa1dabed1a01f4a8 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 31 Jul 2022 11:25:39 -0700 Subject: [PATCH] populate pixel dims + dpi in PaneEntry This makes those fields usable in `wezterm cli list --format json`. This doesn't change the ABI of the mux protocol, but prior to this commit, those fields were always 0. refs: #2319 --- mux/src/renderable.rs | 5 +++++ mux/src/tab.rs | 6 +++--- term/src/terminalstate/mod.rs | 11 +++++++++++ wezterm-client/src/pane/clientpane.rs | 2 ++ wezterm-gui/src/termwindow/render.rs | 2 ++ wezterm/src/main.rs | 20 ++++++++++++++++++-- 6 files changed, 41 insertions(+), 5 deletions(-) diff --git a/mux/src/renderable.rs b/mux/src/renderable.rs index 8b8f91061..948524492 100644 --- a/mux/src/renderable.rs +++ b/mux/src/renderable.rs @@ -40,6 +40,8 @@ pub struct RenderableDimensions { /// expressed as a stable index. pub scrollback_top: StableRowIndex, pub dpi: u32, + pub pixel_width: usize, + pub pixel_height: usize, } impl_lua_conversion_dynamic!(RenderableDimensions); @@ -127,6 +129,7 @@ pub fn terminal_get_lines( /// Implements Pane::get_dimensions for Terminal pub fn terminal_get_dimensions(term: &mut Terminal) -> RenderableDimensions { + let size = term.get_size(); let screen = term.screen(); RenderableDimensions { cols: screen.physical_cols, @@ -135,5 +138,7 @@ pub fn terminal_get_dimensions(term: &mut Terminal) -> RenderableDimensions { physical_top: screen.visible_row_to_stable_row(0), scrollback_top: screen.phys_to_stable_row_index(0), dpi: screen.dpi, + pixel_width: size.pixel_width, + pixel_height: size.pixel_height, } } diff --git a/mux/src/tab.rs b/mux/src/tab.rs index 0cd395e6e..b77e10ace 100644 --- a/mux/src/tab.rs +++ b/mux/src/tab.rs @@ -220,9 +220,9 @@ fn pane_tree( size: TerminalSize { cols: dims.cols, rows: dims.viewport_rows, - pixel_height: 0, - pixel_width: 0, - dpi: 0, + pixel_height: dims.pixel_height, + pixel_width: dims.pixel_width, + dpi: dims.dpi, }, working_dir: working_dir.map(Into::into), workspace: workspace.to_string(), diff --git a/term/src/terminalstate/mod.rs b/term/src/terminalstate/mod.rs index 118e309d4..4cca2789c 100644 --- a/term/src/terminalstate/mod.rs +++ b/term/src/terminalstate/mod.rs @@ -844,6 +844,17 @@ impl TerminalState { } } + pub fn get_size(&self) -> TerminalSize { + let screen = self.screen(); + TerminalSize { + dpi: self.dpi, + pixel_width: self.pixel_width, + pixel_height: self.pixel_height, + rows: screen.physical_rows, + cols: screen.physical_cols, + } + } + /// When dealing with selection, mark a range of lines as dirty pub fn make_all_lines_dirty(&mut self) { let seqno = self.seqno; diff --git a/wezterm-client/src/pane/clientpane.rs b/wezterm-client/src/pane/clientpane.rs index af8efb233..3ed66f54e 100644 --- a/wezterm-client/src/pane/clientpane.rs +++ b/wezterm-client/src/pane/clientpane.rs @@ -74,6 +74,8 @@ impl ClientPane { physical_top: 0, scrollback_top: 0, dpi: size.dpi, + pixel_width: size.pixel_width, + pixel_height: size.pixel_height, }, title, fetch_limiter, diff --git a/wezterm-gui/src/termwindow/render.rs b/wezterm-gui/src/termwindow/render.rs index 4779e5b10..3eeecf1da 100644 --- a/wezterm-gui/src/termwindow/render.rs +++ b/wezterm-gui/src/termwindow/render.rs @@ -951,6 +951,8 @@ impl super::TermWindow { scrollback_top: 0, viewport_rows: 1, dpi: self.terminal_size.dpi, + pixel_height: self.render_metrics.cell_size.height as usize, + pixel_width: self.terminal_size.pixel_width, }, config: &self.config, cursor_border_color: LinearRgba::default(), diff --git a/wezterm/src/main.rs b/wezterm/src/main.rs index 2571c3602..75495c10e 100644 --- a/wezterm/src/main.rs +++ b/wezterm/src/main.rs @@ -575,6 +575,9 @@ async fn resolve_pane_id(client: &Client, pane_id: Option) -> anyhow::Re struct CliListResultPtySize { rows: usize, cols: usize, + pixel_width: usize, + pixel_height: usize, + dpi: u32, } // This will be serialized to JSON via the 'List' command. // As such it is intended to be a stable output format, @@ -600,7 +603,14 @@ impl From for CliListResultItem { workspace, title, working_dir, - size: TerminalSize { rows, cols, .. }, + size: + TerminalSize { + rows, + cols, + pixel_width, + pixel_height, + dpi, + }, .. } = pane; @@ -609,7 +619,13 @@ impl From for CliListResultItem { tab_id, pane_id, workspace, - size: CliListResultPtySize { rows, cols }, + size: CliListResultPtySize { + rows, + cols, + pixel_width, + pixel_height, + dpi, + }, title, cwd: working_dir .as_ref()