diff --git a/Cargo.lock b/Cargo.lock index b8eb9bd5a..756e09997 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4823,6 +4823,7 @@ dependencies = [ "umask", "wezterm-gui-subcommands", "wezterm-mux-server-impl", + "wezterm-term", "winapi", ] diff --git a/codec/src/lib.rs b/codec/src/lib.rs index 36cf02820..1870140e4 100644 --- a/codec/src/lib.rs +++ b/codec/src/lib.rs @@ -17,7 +17,7 @@ use mux::pane::PaneId; use mux::renderable::{RenderableDimensions, StableCursorPosition}; use mux::tab::{PaneNode, SerdeUrl, SplitRequest, TabId}; use mux::window::WindowId; -use portable_pty::{CommandBuilder, PtySize}; +use portable_pty::CommandBuilder; use rangeset::*; use serde::{Deserialize, Serialize}; use smol::io::AsyncWriteExt; @@ -32,7 +32,7 @@ use termwiz::image::{ImageData, TextureCoordinate}; use termwiz::surface::{Line, SequenceNo}; use thiserror::Error; use wezterm_term::color::ColorPalette; -use wezterm_term::{Alert, ClipboardSelection, StableRowIndex}; +use wezterm_term::{Alert, ClipboardSelection, StableRowIndex, TerminalSize}; #[derive(Error, Debug)] #[error("Corrupt Response")] @@ -416,7 +416,7 @@ macro_rules! pdu { /// The overall version of the codec. /// This must be bumped when backwards incompatible changes /// are made to the types and protocol. -pub const CODEC_VERSION: usize = 24; +pub const CODEC_VERSION: usize = 25; // Defines the Pdu enum. // Each struct has an explicit identifying number. @@ -623,7 +623,7 @@ pub struct SpawnV2 { pub window_id: Option, pub command: Option, pub command_dir: Option, - pub size: PtySize, + pub size: TerminalSize, pub workspace: String, } @@ -642,7 +642,7 @@ pub struct SpawnResponse { pub tab_id: TabId, pub pane_id: PaneId, pub window_id: WindowId, - pub size: PtySize, + pub size: TerminalSize, } #[derive(Deserialize, Serialize, PartialEq, Debug)] @@ -757,7 +757,7 @@ pub struct GetClientListResponse { pub struct Resize { pub containing_tab_id: TabId, pub pane_id: PaneId, - pub size: PtySize, + pub size: TerminalSize, } #[derive(Deserialize, Serialize, PartialEq, Debug)] diff --git a/config/src/config.rs b/config/src/config.rs index 9ded00829..5f4e7750e 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -27,7 +27,7 @@ use crate::{ use anyhow::Context; use luahelper::impl_lua_conversion_dynamic; use mlua::FromLua; -use portable_pty::{CommandBuilder, PtySize}; +use portable_pty::CommandBuilder; use std::collections::HashMap; use std::ffi::OsStr; use std::io::Read; @@ -39,6 +39,7 @@ use termwiz::surface::CursorShape; use wezterm_bidi::ParagraphDirectionHint; use wezterm_dynamic::{FromDynamic, ToDynamic}; use wezterm_input_types::{Modifiers, WindowDecorations}; +use wezterm_term::TerminalSize; #[derive(Debug, Clone, FromDynamic, ToDynamic)] pub struct Config { @@ -1054,10 +1055,10 @@ impl Config { } } - pub fn initial_size(&self) -> PtySize { - PtySize { - rows: self.initial_rows, - cols: self.initial_cols, + pub fn initial_size(&self, dpi: u32) -> TerminalSize { + TerminalSize { + rows: self.initial_rows as usize, + cols: self.initial_cols as usize, // Guess at a plausible default set of pixel dimensions. // This is based on "typical" 10 point font at "normal" // pixel density. @@ -1067,8 +1068,9 @@ impl Config { // the GUI has had a chance to update the pixel dimensions // when running under X11. // This is a bit gross. - pixel_width: 8 * self.initial_cols, - pixel_height: 16 * self.initial_rows, + pixel_width: 8 * self.initial_cols as usize, + pixel_height: 16 * self.initial_rows as usize, + dpi, } } diff --git a/mux/src/connui.rs b/mux/src/connui.rs index 9f2d3bf85..f5b52cf16 100644 --- a/mux/src/connui.rs +++ b/mux/src/connui.rs @@ -1,7 +1,6 @@ use crate::termwiztermtab; use anyhow::{anyhow, bail, Context as _}; use crossbeam::channel::{unbounded, Receiver, Sender}; -use portable_pty::PtySize; use promise::spawn::block_on; use promise::Promise; use std::sync::Mutex; @@ -11,6 +10,7 @@ use termwiz::lineedit::*; use termwiz::surface::{Change, Position}; use termwiz::terminal::*; use unicode_segmentation::UnicodeSegmentation; +use wezterm_term::TerminalSize; #[derive(Default)] struct PasswordPromptHost { @@ -237,7 +237,7 @@ impl HeadlessImpl { #[derive(Default, Clone, Copy, Debug)] pub struct ConnectionUIParams { - pub size: PtySize, + pub size: TerminalSize, pub disable_close_delay: bool, pub window_id: Option, } diff --git a/mux/src/domain.rs b/mux/src/domain.rs index 1ff2e3979..d9012ef5b 100644 --- a/mux/src/domain.rs +++ b/mux/src/domain.rs @@ -14,9 +14,10 @@ use anyhow::{bail, Error}; use async_trait::async_trait; use config::{configuration, WslDomain}; use downcast_rs::{impl_downcast, Downcast}; -use portable_pty::{native_pty_system, CommandBuilder, PtySize, PtySystem}; +use portable_pty::{native_pty_system, CommandBuilder, PtySystem}; use std::ffi::OsString; use std::rc::Rc; +use wezterm_term::TerminalSize; static DOMAIN_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::AtomicUsize::new(0); pub type DomainId = usize; @@ -45,7 +46,7 @@ pub trait Domain: Downcast { /// Spawn a new command within this domain async fn spawn( &self, - size: PtySize, + size: TerminalSize, command: Option, command_dir: Option, window: WindowId, @@ -124,7 +125,7 @@ pub trait Domain: Downcast { async fn spawn_pane( &self, - size: PtySize, + size: TerminalSize, command: Option, command_dir: Option, ) -> anyhow::Result>; @@ -303,12 +304,14 @@ impl LocalDomain { impl Domain for LocalDomain { async fn spawn_pane( &self, - size: PtySize, + size: TerminalSize, command: Option, command_dir: Option, ) -> anyhow::Result> { let mut cmd = self.build_command(command, command_dir)?; - let pair = self.pty_system.openpty(size)?; + let pair = self + .pty_system + .openpty(crate::terminal_size_to_pty_size(size)?)?; let pane_id = alloc_pane_id(); cmd.env("WEZTERM_PANE", pane_id.to_string()); @@ -330,7 +333,7 @@ impl Domain for LocalDomain { let writer = pair.master.try_clone_writer()?; let mut terminal = wezterm_term::Terminal::new( - crate::pty_size_to_terminal_size(size), + size, std::sync::Arc::new(config::TermConfig::new()), "WezTerm", config::wezterm_version(), diff --git a/mux/src/lib.rs b/mux/src/lib.rs index 1e433eda0..305b58299 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -15,6 +15,7 @@ use percent_encoding::percent_decode_str; use portable_pty::{CommandBuilder, ExitStatus, PtySize}; use std::cell::{Ref, RefCell, RefMut}; use std::collections::HashMap; +use std::convert::TryInto; use std::io::{Read, Write}; use std::rc::Rc; use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering}; @@ -24,7 +25,7 @@ use std::time::Instant; use termwiz::escape::csi::{DecPrivateMode, DecPrivateModeCode, Device, Mode}; use termwiz::escape::{Action, CSI}; use thiserror::*; -use wezterm_term::{Clipboard, ClipboardSelection, DownloadHandler}; +use wezterm_term::{Clipboard, ClipboardSelection, DownloadHandler, TerminalSize}; #[cfg(windows)] use winapi::um::winsock2::{SOL_SOCKET, SO_RCVBUF, SO_SNDBUF}; @@ -944,7 +945,7 @@ impl Mux { request: SplitRequest, source: SplitSource, domain: config::keyassignment::SpawnTabDomain, - ) -> anyhow::Result<(Rc, PtySize)> { + ) -> anyhow::Result<(Rc, TerminalSize)> { let (_pane_domain_id, window_id, tab_id) = self .resolve_pane_id(pane_id) .ok_or_else(|| anyhow!("pane_id {} invalid", pane_id))?; @@ -982,11 +983,12 @@ impl Mux { let dims = pane.get_dimensions(); - let size = PtySize { - cols: dims.cols as u16, - rows: dims.viewport_rows as u16, + let size = TerminalSize { + cols: dims.cols, + rows: dims.viewport_rows, pixel_height: 0, // FIXME: split pane pixel dimensions pixel_width: 0, + dpi: dims.dpi, }; Ok((pane, size)) @@ -1045,7 +1047,7 @@ impl Mux { domain: SpawnTabDomain, command: Option, command_dir: Option, - size: PtySize, + size: TerminalSize, current_pane_id: Option, workspace_for_new_window: String, ) -> anyhow::Result<(Rc, Rc, WindowId)> { @@ -1154,13 +1156,13 @@ pub enum SessionTerminated { WindowClosed, } -pub(crate) fn pty_size_to_terminal_size(size: portable_pty::PtySize) -> wezterm_term::TerminalSize { - wezterm_term::TerminalSize { - physical_rows: size.rows as usize, - physical_cols: size.cols as usize, - pixel_width: size.pixel_width as usize, - pixel_height: size.pixel_height as usize, - } +pub(crate) fn terminal_size_to_pty_size(size: TerminalSize) -> anyhow::Result { + Ok(PtySize { + rows: size.rows.try_into()?, + cols: size.cols.try_into()?, + pixel_height: size.pixel_height.try_into()?, + pixel_width: size.pixel_width.try_into()?, + }) } struct MuxClipboard { diff --git a/mux/src/localpane.rs b/mux/src/localpane.rs index edb59d7b2..5a3515972 100644 --- a/mux/src/localpane.rs +++ b/mux/src/localpane.rs @@ -13,6 +13,7 @@ use rangeset::RangeSet; use smol::channel::{bounded, Receiver, TryRecvError}; use std::cell::{RefCell, RefMut}; use std::collections::{HashMap, HashSet}; +use std::convert::TryInto; use std::io::Result as IoResult; use std::ops::Range; use std::sync::Arc; @@ -24,7 +25,7 @@ use url::Url; use wezterm_term::color::ColorPalette; use wezterm_term::{ Alert, AlertHandler, CellAttributes, Clipboard, DownloadHandler, KeyCode, KeyModifiers, - MouseEvent, SemanticZone, StableRowIndex, Terminal, TerminalConfiguration, + MouseEvent, SemanticZone, StableRowIndex, Terminal, TerminalConfiguration, TerminalSize, }; #[derive(Debug)] @@ -275,14 +276,14 @@ impl Pane for LocalPane { self.terminal.borrow_mut().key_up(key, mods) } - fn resize(&self, size: PtySize) -> Result<(), Error> { - self.pty.borrow_mut().resize(size)?; - self.terminal.borrow_mut().resize( - size.rows as usize, - size.cols as usize, - size.pixel_width as usize, - size.pixel_height as usize, - ); + fn resize(&self, size: TerminalSize) -> Result<(), Error> { + self.pty.borrow_mut().resize(PtySize { + rows: size.rows.try_into()?, + cols: size.cols.try_into()?, + pixel_width: size.pixel_width.try_into()?, + pixel_height: size.pixel_height.try_into()?, + })?; + self.terminal.borrow_mut().resize(size); Ok(()) } diff --git a/mux/src/pane.rs b/mux/src/pane.rs index 92ef3957d..c36517cc6 100644 --- a/mux/src/pane.rs +++ b/mux/src/pane.rs @@ -4,7 +4,6 @@ use crate::Mux; use async_trait::async_trait; use config::keyassignment::{KeyAssignment, ScrollbackEraseMode}; use downcast_rs::{impl_downcast, Downcast}; -use portable_pty::PtySize; use rangeset::RangeSet; use serde::{Deserialize, Serialize}; use std::cell::RefMut; @@ -18,7 +17,7 @@ use url::Url; use wezterm_term::color::ColorPalette; use wezterm_term::{ Clipboard, DownloadHandler, KeyCode, KeyModifiers, MouseEvent, SemanticZone, StableRowIndex, - TerminalConfiguration, + TerminalConfiguration, TerminalSize, }; static PANE_ID: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::AtomicUsize::new(0); @@ -353,7 +352,7 @@ pub trait Pane: Downcast { fn send_paste(&self, text: &str) -> anyhow::Result<()>; fn reader(&self) -> anyhow::Result>>; fn writer(&self) -> RefMut; - fn resize(&self, size: PtySize) -> anyhow::Result<()>; + fn resize(&self, size: TerminalSize) -> anyhow::Result<()>; /// Called as a hint that the pane is being resized as part of /// a zoom-to-fill-all-the-tab-space operation. fn set_zoomed(&self, _zoomed: bool) {} @@ -504,7 +503,7 @@ mod test { fn writer(&self) -> RefMut { unimplemented!() } - fn resize(&self, _: PtySize) -> anyhow::Result<()> { + fn resize(&self, _: TerminalSize) -> anyhow::Result<()> { unimplemented!() } diff --git a/mux/src/renderable.rs b/mux/src/renderable.rs index fa1941a41..d36db3eb7 100644 --- a/mux/src/renderable.rs +++ b/mux/src/renderable.rs @@ -38,6 +38,7 @@ pub struct RenderableDimensions { /// The top of the scrollback (the earliest row we remember) /// expressed as a stable index. pub scrollback_top: StableRowIndex, + pub dpi: u32, } impl_lua_conversion_dynamic!(RenderableDimensions); @@ -95,5 +96,6 @@ pub fn terminal_get_dimensions(term: &mut Terminal) -> RenderableDimensions { scrollback_rows: screen.scrollback_rows(), physical_top: screen.visible_row_to_stable_row(0), scrollback_top: screen.phys_to_stable_row_index(0), + dpi: screen.dpi, } } diff --git a/mux/src/ssh.rs b/mux/src/ssh.rs index a7aebf3f0..39de5b2b3 100644 --- a/mux/src/ssh.rs +++ b/mux/src/ssh.rs @@ -24,6 +24,7 @@ use termwiz::render::terminfo::TerminfoRenderer; use termwiz::surface::Change; use termwiz::terminal::{ScreenSize, Terminal, TerminalWaker}; use wezterm_ssh::{ConfigMap, Session, SessionEvent, SshChildProcess, SshPty}; +use wezterm_term::TerminalSize; #[derive(Default)] struct PasswordPromptHost { @@ -268,12 +269,12 @@ fn connect_ssh_session( stdout_tx: Sender, child_tx: Sender, pty_tx: Sender, - size: Arc>, + size: Arc>, command_line: Option, env: HashMap, ) -> anyhow::Result<()> { struct StdoutShim<'a> { - size: Arc>, + size: Arc>, stdout: &'a mut BufWriter, } @@ -297,7 +298,7 @@ fn connect_ssh_session( struct TerminalShim<'a> { stdout: &'a mut StdoutShim<'a>, stdin: &'a mut FileDescriptor, - size: Arc>, + size: Arc>, renderer: TerminfoRenderer, parser: InputParser, input_queue: VecDeque, @@ -488,7 +489,7 @@ fn connect_ssh_session( // set up the real pty for the pane match smol::block_on(session.request_pty( &config::configuration().term, - *size.lock().unwrap(), + crate::terminal_size_to_pty_size(*size.lock().unwrap())?, command_line.as_ref().map(|s| s.as_str()), Some(env), )) { @@ -538,7 +539,7 @@ fn connect_ssh_session( impl Domain for RemoteSshDomain { async fn spawn_pane( &self, - size: PtySize, + size: TerminalSize, command: Option, command_dir: Option, ) -> anyhow::Result> { @@ -556,7 +557,7 @@ impl Domain for RemoteSshDomain { let (concrete_pty, concrete_child) = session .request_pty( &config::configuration().term, - size, + crate::terminal_size_to_pty_size(size)?, command_line.as_ref().map(|s| s.as_str()), Some(env), ) @@ -649,7 +650,7 @@ impl Domain for RemoteSshDomain { // session without duplicating a lot of logic over here. let terminal = wezterm_term::Terminal::new( - crate::pty_size_to_terminal_size(size), + size, std::sync::Arc::new(config::TermConfig::new()), "WezTerm", config::wezterm_version(), @@ -868,7 +869,7 @@ enum WrappedSshPtyInner { Connecting { reader: Option, connected: Receiver, - size: Arc>, + size: Arc>, }, Connected { reader: Option, @@ -914,7 +915,7 @@ impl WrappedSshPtyInner { .. } => { if let Ok(pty) = connected.try_recv() { - let res = pty.resize(*size.lock().unwrap()); + let res = pty.resize(crate::terminal_size_to_pty_size(*size.lock().unwrap())?); *self = Self::Connected { pty, reader: reader.take(), @@ -934,7 +935,13 @@ impl portable_pty::MasterPty for WrappedSshPty { let mut inner = self.inner.borrow_mut(); match &mut *inner { WrappedSshPtyInner::Connecting { ref mut size, .. } => { - *size.lock().unwrap() = new_size; + { + let mut size = size.lock().unwrap(); + size.cols = new_size.cols as usize; + size.rows = new_size.rows as usize; + size.pixel_height = new_size.pixel_height as usize; + size.pixel_width = new_size.pixel_width as usize; + } inner.check_connected() } WrappedSshPtyInner::Connected { pty, .. } => pty.resize(new_size), @@ -945,7 +952,7 @@ impl portable_pty::MasterPty for WrappedSshPty { let mut inner = self.inner.borrow_mut(); match &*inner { WrappedSshPtyInner::Connecting { size, .. } => { - let size = *size.lock().unwrap(); + let size = crate::terminal_size_to_pty_size(*size.lock().unwrap())?; inner.check_connected()?; Ok(size) } diff --git a/mux/src/tab.rs b/mux/src/tab.rs index d96cbdb41..49e5af07e 100644 --- a/mux/src/tab.rs +++ b/mux/src/tab.rs @@ -4,13 +4,13 @@ use crate::{Mux, WindowId}; use bintree::PathBranch; use config::configuration; use config::keyassignment::PaneDirection; -use portable_pty::PtySize; use rangeset::range_intersection; use serde::{Deserialize, Serialize}; use std::cell::{RefCell, RefMut}; use std::convert::TryInto; use std::rc::Rc; use url::Url; +use wezterm_term::TerminalSize; pub type Tree = bintree::Tree, SplitDirectionAndSize>; pub type Cursor = bintree::Cursor, SplitDirectionAndSize>; @@ -22,7 +22,7 @@ pub type TabId = usize; pub struct Tab { id: TabId, pane: RefCell>, - size: RefCell, + size: RefCell, active: RefCell, zoomed: RefCell>>, } @@ -75,8 +75,8 @@ pub enum SplitDirection { #[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)] pub struct SplitDirectionAndSize { pub direction: SplitDirection, - pub first: PtySize, - pub second: PtySize, + pub first: TerminalSize, + pub second: TerminalSize, } #[derive(Debug, Clone, Copy, Eq, PartialEq, Serialize, Deserialize)] @@ -129,7 +129,7 @@ impl SplitDirectionAndSize { } } - pub fn width(&self) -> u16 { + pub fn width(&self) -> usize { if self.direction == SplitDirection::Horizontal { self.first.cols + self.second.cols + 1 } else { @@ -137,7 +137,7 @@ impl SplitDirectionAndSize { } } - pub fn height(&self) -> u16 { + pub fn height(&self) -> usize { if self.direction == SplitDirection::Vertical { self.first.rows + self.second.rows + 1 } else { @@ -145,18 +145,19 @@ impl SplitDirectionAndSize { } } - pub fn size(&self) -> PtySize { + pub fn size(&self) -> TerminalSize { let cell_width = self.first.pixel_width / self.first.cols; let cell_height = self.first.pixel_height / self.first.rows; let rows = self.height(); let cols = self.width(); - PtySize { + TerminalSize { rows, cols, pixel_height: cell_height * rows, pixel_width: cell_width * cols, + dpi: self.first.dpi, } } } @@ -215,11 +216,12 @@ fn pane_tree( title: pane.get_title(), is_active_pane: is_pane(pane, &active), is_zoomed_pane: is_pane(pane, &zoomed), - size: PtySize { - cols: dims.cols as u16, - rows: dims.viewport_rows as u16, + size: TerminalSize { + cols: dims.cols, + rows: dims.viewport_rows, pixel_height: 0, pixel_width: 0, + dpi: 0, }, working_dir: working_dir.map(Into::into), workspace: workspace.to_string(), @@ -280,7 +282,7 @@ fn compute_min_size(tree: &mut Tree) -> (usize, usize) { } } -fn adjust_x_size(tree: &mut Tree, mut x_adjust: isize, cell_dimensions: &PtySize) { +fn adjust_x_size(tree: &mut Tree, mut x_adjust: isize, cell_dimensions: &TerminalSize) { let (min_x, _) = compute_min_size(tree); while x_adjust != 0 { match tree { @@ -290,63 +292,67 @@ fn adjust_x_size(tree: &mut Tree, mut x_adjust: isize, cell_dimensions: &PtySize left, right, data: Some(data), - } => match data.direction { - SplitDirection::Vertical => { - let new_cols = (data.first.cols as isize) - .saturating_add(x_adjust) - .max(min_x as isize); - x_adjust = new_cols.saturating_sub(data.first.cols as isize); + } => { + data.first.dpi = cell_dimensions.dpi; + data.second.dpi = cell_dimensions.dpi; + match data.direction { + SplitDirection::Vertical => { + let new_cols = (data.first.cols as isize) + .saturating_add(x_adjust) + .max(min_x as isize); + x_adjust = new_cols.saturating_sub(data.first.cols as isize); - if x_adjust != 0 { - adjust_x_size(&mut *left, x_adjust, cell_dimensions); - data.first.cols = new_cols.try_into().unwrap(); + if x_adjust != 0 { + adjust_x_size(&mut *left, x_adjust, cell_dimensions); + data.first.cols = new_cols.try_into().unwrap(); + data.first.pixel_width = + data.first.cols.saturating_mul(cell_dimensions.pixel_width); + + adjust_x_size(&mut *right, x_adjust, cell_dimensions); + data.second.cols = data.first.cols; + data.second.pixel_width = data.first.pixel_width; + } + return; + } + SplitDirection::Horizontal if x_adjust > 0 => { + adjust_x_size(&mut *left, 1, cell_dimensions); + data.first.cols += 1; data.first.pixel_width = data.first.cols.saturating_mul(cell_dimensions.pixel_width); - - adjust_x_size(&mut *right, x_adjust, cell_dimensions); - data.second.cols = data.first.cols; - data.second.pixel_width = data.first.pixel_width; - } - return; - } - SplitDirection::Horizontal if x_adjust > 0 => { - adjust_x_size(&mut *left, 1, cell_dimensions); - data.first.cols += 1; - data.first.pixel_width = - data.first.cols.saturating_mul(cell_dimensions.pixel_width); - x_adjust -= 1; - - if x_adjust > 0 { - adjust_x_size(&mut *right, 1, cell_dimensions); - data.second.cols += 1; - data.second.pixel_width = - data.second.cols.saturating_mul(cell_dimensions.pixel_width); x_adjust -= 1; + + if x_adjust > 0 { + adjust_x_size(&mut *right, 1, cell_dimensions); + data.second.cols += 1; + data.second.pixel_width = + data.second.cols.saturating_mul(cell_dimensions.pixel_width); + x_adjust -= 1; + } + } + SplitDirection::Horizontal => { + // x_adjust is negative + if data.first.cols > 1 { + adjust_x_size(&mut *left, -1, cell_dimensions); + data.first.cols -= 1; + data.first.pixel_width = + data.first.cols.saturating_mul(cell_dimensions.pixel_width); + x_adjust += 1; + } + if x_adjust < 0 && data.second.cols > 1 { + adjust_x_size(&mut *right, -1, cell_dimensions); + data.second.cols -= 1; + data.second.pixel_width = + data.second.cols.saturating_mul(cell_dimensions.pixel_width); + x_adjust += 1; + } } } - SplitDirection::Horizontal => { - // x_adjust is negative - if data.first.cols > 1 { - adjust_x_size(&mut *left, -1, cell_dimensions); - data.first.cols -= 1; - data.first.pixel_width = - data.first.cols.saturating_mul(cell_dimensions.pixel_width); - x_adjust += 1; - } - if x_adjust < 0 && data.second.cols > 1 { - adjust_x_size(&mut *right, -1, cell_dimensions); - data.second.cols -= 1; - data.second.pixel_width = - data.second.cols.saturating_mul(cell_dimensions.pixel_width); - x_adjust += 1; - } - } - }, + } } } } -fn adjust_y_size(tree: &mut Tree, mut y_adjust: isize, cell_dimensions: &PtySize) { +fn adjust_y_size(tree: &mut Tree, mut y_adjust: isize, cell_dimensions: &TerminalSize) { let (_, min_y) = compute_min_size(tree); while y_adjust != 0 { match tree { @@ -356,66 +362,70 @@ fn adjust_y_size(tree: &mut Tree, mut y_adjust: isize, cell_dimensions: &PtySize left, right, data: Some(data), - } => match data.direction { - SplitDirection::Horizontal => { - let new_rows = (data.first.rows as isize) - .saturating_add(y_adjust) - .max(min_y as isize); - y_adjust = new_rows.saturating_sub(data.first.rows as isize); + } => { + data.first.dpi = cell_dimensions.dpi; + data.second.dpi = cell_dimensions.dpi; + match data.direction { + SplitDirection::Horizontal => { + let new_rows = (data.first.rows as isize) + .saturating_add(y_adjust) + .max(min_y as isize); + y_adjust = new_rows.saturating_sub(data.first.rows as isize); - if y_adjust != 0 { - adjust_y_size(&mut *left, y_adjust, cell_dimensions); - data.first.rows = new_rows.try_into().unwrap(); + if y_adjust != 0 { + adjust_y_size(&mut *left, y_adjust, cell_dimensions); + data.first.rows = new_rows.try_into().unwrap(); + data.first.pixel_height = + data.first.rows.saturating_mul(cell_dimensions.pixel_height); + + adjust_y_size(&mut *right, y_adjust, cell_dimensions); + data.second.rows = data.first.rows; + data.second.pixel_height = data.first.pixel_height; + } + return; + } + SplitDirection::Vertical if y_adjust > 0 => { + adjust_y_size(&mut *left, 1, cell_dimensions); + data.first.rows += 1; data.first.pixel_height = data.first.rows.saturating_mul(cell_dimensions.pixel_height); - - adjust_y_size(&mut *right, y_adjust, cell_dimensions); - data.second.rows = data.first.rows; - data.second.pixel_height = data.first.pixel_height; - } - return; - } - SplitDirection::Vertical if y_adjust > 0 => { - adjust_y_size(&mut *left, 1, cell_dimensions); - data.first.rows += 1; - data.first.pixel_height = - data.first.rows.saturating_mul(cell_dimensions.pixel_height); - y_adjust -= 1; - if y_adjust > 0 { - adjust_y_size(&mut *right, 1, cell_dimensions); - data.second.rows += 1; - data.second.pixel_height = data - .second - .rows - .saturating_mul(cell_dimensions.pixel_height); y_adjust -= 1; + if y_adjust > 0 { + adjust_y_size(&mut *right, 1, cell_dimensions); + data.second.rows += 1; + data.second.pixel_height = data + .second + .rows + .saturating_mul(cell_dimensions.pixel_height); + y_adjust -= 1; + } + } + SplitDirection::Vertical => { + // y_adjust is negative + if data.first.rows > 1 { + adjust_y_size(&mut *left, -1, cell_dimensions); + data.first.rows -= 1; + data.first.pixel_height = + data.first.rows.saturating_mul(cell_dimensions.pixel_height); + y_adjust += 1; + } + if y_adjust < 0 && data.second.rows > 1 { + adjust_y_size(&mut *right, -1, cell_dimensions); + data.second.rows -= 1; + data.second.pixel_height = data + .second + .rows + .saturating_mul(cell_dimensions.pixel_height); + y_adjust += 1; + } } } - SplitDirection::Vertical => { - // y_adjust is negative - if data.first.rows > 1 { - adjust_y_size(&mut *left, -1, cell_dimensions); - data.first.rows -= 1; - data.first.pixel_height = - data.first.rows.saturating_mul(cell_dimensions.pixel_height); - y_adjust += 1; - } - if y_adjust < 0 && data.second.rows > 1 { - adjust_y_size(&mut *right, -1, cell_dimensions); - data.second.rows -= 1; - data.second.pixel_height = data - .second - .rows - .saturating_mul(cell_dimensions.pixel_height); - y_adjust += 1; - } - } - }, + } } } } -fn apply_sizes_from_splits(tree: &Tree, size: &PtySize) { +fn apply_sizes_from_splits(tree: &Tree, size: &TerminalSize) { match tree { Tree::Empty => return, Tree::Node { data: None, .. } => return, @@ -433,17 +443,18 @@ fn apply_sizes_from_splits(tree: &Tree, size: &PtySize) { } } -fn cell_dimensions(size: &PtySize) -> PtySize { - PtySize { +fn cell_dimensions(size: &TerminalSize) -> TerminalSize { + TerminalSize { rows: 1, cols: 1, pixel_width: size.pixel_width / size.cols, pixel_height: size.pixel_height / size.rows, + dpi: size.dpi, } } impl Tab { - pub fn new(size: &PtySize) -> Self { + pub fn new(size: &TerminalSize) -> Self { Self { id: TAB_ID.fetch_add(1, ::std::sync::atomic::Ordering::Relaxed), pane: RefCell::new(Some(Tree::new())), @@ -464,7 +475,7 @@ impl Tab { /// PaneEntry, or to create a new Pane from that entry. /// make_pane is expected to add the pane to the mux if it creates /// a new pane, otherwise the pane won't poll/update in the GUI. - pub fn sync_with_pane_tree(&self, size: PtySize, root: PaneNode, mut make_pane: F) + pub fn sync_with_pane_tree(&self, size: TerminalSize, root: PaneNode, mut make_pane: F) where F: FnMut(PaneEntry) -> Rc, { @@ -829,7 +840,7 @@ impl Tab { self.id } - pub fn get_size(&self) -> PtySize { + pub fn get_size(&self) -> TerminalSize { *self.size.borrow() } @@ -839,7 +850,7 @@ impl Tab { /// this algorithm biases towards adjusting the left/top nodes /// first. For large resizes this tends to proportionally adjust /// the relative sizes of the elements in a split. - pub fn resize(&self, size: PtySize) { + pub fn resize(&self, size: TerminalSize) { if size.rows == 0 || size.cols == 0 { // Ignore "impossible" resize requests return; @@ -857,13 +868,14 @@ impl Tab { let current_size = *self.size.borrow(); // Constrain the new size to the minimum possible dimensions - let cols = size.cols.max(min_x as u16); - let rows = size.rows.max(min_y as u16); - let size = PtySize { + let cols = size.cols.max(min_x); + let rows = size.rows.max(min_y); + let size = TerminalSize { rows, cols, pixel_width: cols * dims.pixel_width, pixel_height: rows * dims.pixel_height, + dpi: dims.dpi, }; if size != current_size { @@ -890,7 +902,7 @@ impl Tab { self.set_zoomed(was_zoomed); } - fn apply_pane_size(&self, pane_size: PtySize, cursor: &mut Cursor) { + fn apply_pane_size(&self, pane_size: TerminalSize, cursor: &mut Cursor) { let cell_width = pane_size.pixel_width / pane_size.cols; let cell_height = pane_size.pixel_height / pane_size.rows; if let Ok(Some(node)) = cursor.node_mut() { @@ -935,16 +947,17 @@ impl Tab { return; } - fn compute_size(node: &mut Tree) -> Option { + fn compute_size(node: &mut Tree) -> Option { match node { Tree::Empty => None, Tree::Leaf(pane) => { let dims = pane.get_dimensions(); - let size = PtySize { - cols: dims.cols as u16, - rows: dims.viewport_rows as u16, + let size = TerminalSize { + cols: dims.cols, + rows: dims.viewport_rows, pixel_height: 0, pixel_width: 0, + dpi: dims.dpi, }; Some(size) } @@ -1023,7 +1036,7 @@ impl Tab { .saturating_add(delta) .max(1) .min((width as isize).saturating_sub(2)); - node.first.cols = cols as u16; + node.first.cols = cols as usize; node.first.pixel_width = node.first.cols.saturating_mul(cell_dimensions.pixel_width); @@ -1039,7 +1052,7 @@ impl Tab { .saturating_add(delta) .max(1) .min((height as isize).saturating_sub(2)); - node.first.rows = rows as u16; + node.first.rows = rows as usize; node.first.pixel_height = node.first.rows.saturating_mul(cell_dimensions.pixel_height); @@ -1351,11 +1364,12 @@ impl Tab { // Now we need to increase the size of the current node // and propagate the revised size to its children. - let size = PtySize { + let size = TerminalSize { rows: parent.height(), cols: parent.width(), pixel_width: cell_dims.pixel_width * parent.width(), pixel_height: cell_dims.pixel_height * parent.height(), + dpi: cell_dims.dpi, }; if let Some(unsplit) = cursor.leaf_mut() { @@ -1482,7 +1496,7 @@ impl Tab { } } - fn cell_dimensions(&self) -> PtySize { + fn cell_dimensions(&self) -> TerminalSize { cell_dimensions(&*self.size.borrow()) } @@ -1582,17 +1596,19 @@ impl Tab { return Some(SplitDirectionAndSize { direction: request.direction, - first: PtySize { + first: TerminalSize { rows: height1 as _, cols: width1 as _, - pixel_height: cell_dims.pixel_height * height1 as u16, - pixel_width: cell_dims.pixel_width * width1 as u16, + pixel_height: cell_dims.pixel_height * height1, + pixel_width: cell_dims.pixel_width * width1, + dpi: cell_dims.dpi, }, - second: PtySize { + second: TerminalSize { rows: height2 as _, cols: width2 as _, - pixel_height: cell_dims.pixel_height * height2 as u16, - pixel_width: cell_dims.pixel_width * width2 as u16, + pixel_height: cell_dims.pixel_height * height2, + pixel_width: cell_dims.pixel_width * width2, + dpi: cell_dims.dpi, }, }); } @@ -1614,17 +1630,19 @@ impl Tab { SplitDirectionAndSize { direction: request.direction, - first: PtySize { + first: TerminalSize { rows: height1 as _, cols: width1 as _, - pixel_height: cell_dims.pixel_height * height1 as u16, - pixel_width: cell_dims.pixel_width * width1 as u16, + pixel_height: cell_dims.pixel_height * height1, + pixel_width: cell_dims.pixel_width * width1, + dpi: cell_dims.dpi, }, - second: PtySize { + second: TerminalSize { rows: height2 as _, cols: width2 as _, - pixel_height: cell_dims.pixel_height * height2 as u16, - pixel_width: cell_dims.pixel_width * width2 as u16, + pixel_height: cell_dims.pixel_height * height2, + pixel_width: cell_dims.pixel_width * width2, + dpi: cell_dims.dpi, }, } }) @@ -1656,8 +1674,8 @@ impl Tab { || split_info.first.cols == 0 || split_info.second.rows == 0 || split_info.second.cols == 0 - || split_info.top_of_second() as u16 + split_info.second.rows > tab_size.rows - || split_info.left_of_second() as u16 + split_info.second.cols > tab_size.cols + || split_info.top_of_second() + split_info.second.rows > tab_size.rows + || split_info.left_of_second() + split_info.second.cols > tab_size.cols { log::error!( "No splace for split!!! {:#?} height={} width={} top_of_second={} left_of_second={} tab_size={:?}", @@ -1795,7 +1813,7 @@ impl PaneNode { } } - pub fn root_size(&self) -> Option { + pub fn root_size(&self) -> Option { match self { PaneNode::Empty => None, PaneNode::Split { node, .. } => Some(node.size()), @@ -1823,7 +1841,7 @@ pub struct PaneEntry { pub tab_id: TabId, pub pane_id: PaneId, pub title: String, - pub size: PtySize, + pub size: TerminalSize, pub working_dir: Option, pub is_active_pane: bool, pub is_zoomed_pane: bool, @@ -1875,11 +1893,11 @@ mod test { struct FakePane { id: PaneId, - size: RefCell, + size: RefCell, } impl FakePane { - fn new(id: PaneId, size: PtySize) -> Rc { + fn new(id: PaneId, size: TerminalSize) -> Rc { Rc::new(Self { id, size: RefCell::new(size), @@ -1928,7 +1946,7 @@ mod test { fn writer(&self) -> RefMut { unimplemented!() } - fn resize(&self, size: PtySize) -> anyhow::Result<()> { + fn resize(&self, size: TerminalSize) -> anyhow::Result<()> { *self.size.borrow_mut() = size; Ok(()) } @@ -1964,11 +1982,12 @@ mod test { #[test] fn tab_splitting() { - let size = PtySize { + let size = TerminalSize { rows: 24, cols: 80, pixel_width: 800, pixel_height: 600, + dpi: 96, }; let tab = Tab::new(&size); @@ -2006,17 +2025,19 @@ mod test { horz_size, SplitDirectionAndSize { direction: SplitDirection::Horizontal, - second: PtySize { + second: TerminalSize { rows: 24, cols: 40, pixel_width: 400, - pixel_height: 600 + pixel_height: 600, + dpi: 96, }, - first: PtySize { + first: TerminalSize { rows: 24, cols: 39, pixel_width: 390, - pixel_height: 600 + pixel_height: 600, + dpi: 96, }, } ); @@ -2034,17 +2055,19 @@ mod test { vert_size, SplitDirectionAndSize { direction: SplitDirection::Vertical, - second: PtySize { + second: TerminalSize { rows: 12, cols: 80, pixel_width: 800, - pixel_height: 300 + pixel_height: 300, + dpi: 96, }, - first: PtySize { + first: TerminalSize { rows: 11, cols: 80, pixel_width: 800, - pixel_height: 275 + pixel_height: 275, + dpi: 96, } } ); diff --git a/mux/src/termwiztermtab.rs b/mux/src/termwiztermtab.rs index b23e134c7..60d22c966 100644 --- a/mux/src/termwiztermtab.rs +++ b/mux/src/termwiztermtab.rs @@ -29,7 +29,7 @@ use termwiz::terminal::{ScreenSize, TerminalWaker}; use termwiz::Context; use url::Url; use wezterm_term::color::ColorPalette; -use wezterm_term::{KeyCode, KeyModifiers, MouseEvent, StableRowIndex}; +use wezterm_term::{KeyCode, KeyModifiers, MouseEvent, StableRowIndex, TerminalSize}; struct TermWizTerminalDomain { domain_id: DomainId, @@ -46,7 +46,7 @@ impl TermWizTerminalDomain { impl Domain for TermWizTerminalDomain { async fn spawn_pane( &self, - _size: PtySize, + _size: TerminalSize, _command: Option, _command_dir: Option, ) -> anyhow::Result> { @@ -90,14 +90,14 @@ pub struct TermWizTerminalPane { impl TermWizTerminalPane { fn new( domain_id: DomainId, - size: PtySize, + size: TerminalSize, input_tx: Sender, render_rx: FileDescriptor, ) -> Self { let pane_id = alloc_pane_id(); let terminal = RefCell::new(wezterm_term::Terminal::new( - crate::pty_size_to_terminal_size(size), + size, std::sync::Arc::new(config::TermConfig::new()), "WezTerm", config::wezterm_version(), @@ -167,18 +167,13 @@ impl Pane for TermWizTerminalPane { self.writer.borrow_mut() } - fn resize(&self, size: PtySize) -> anyhow::Result<()> { + fn resize(&self, size: TerminalSize) -> anyhow::Result<()> { self.input_tx.send(InputEvent::Resized { rows: size.rows as usize, cols: size.cols as usize, })?; - self.terminal.borrow_mut().resize( - size.rows as usize, - size.cols as usize, - size.pixel_width as usize, - size.pixel_height as usize, - ); + self.terminal.borrow_mut().resize(size); Ok(()) } @@ -404,7 +399,7 @@ impl termwiz::terminal::Terminal for TermWizTerminal { } } -pub fn allocate(size: PtySize) -> (TermWizTerminal, Rc) { +pub fn allocate(size: TerminalSize) -> (TermWizTerminal, Rc) { let render_pipe = Pipe::new().expect("Pipe creation not to fail"); let (input_tx, input_rx) = channel(); @@ -448,7 +443,7 @@ pub async fn run< T: Send + 'static, F: Send + 'static + FnOnce(TermWizTerminal) -> anyhow::Result, >( - size: PtySize, + size: TerminalSize, window_id: Option, f: F, ) -> anyhow::Result { @@ -477,7 +472,7 @@ pub async fn run< async fn register_tab( input_tx: Sender, render_rx: FileDescriptor, - size: PtySize, + size: TerminalSize, window_id: Option, ) -> anyhow::Result<(PaneId, WindowId)> { let mux = Mux::get().unwrap(); diff --git a/mux/src/tmux.rs b/mux/src/tmux.rs index 2480f8a1e..01d457833 100644 --- a/mux/src/tmux.rs +++ b/mux/src/tmux.rs @@ -5,13 +5,14 @@ use crate::tmux_commands::{ListAllPanes, TmuxCommand}; use crate::{Mux, MuxWindowBuilder}; use async_trait::async_trait; use filedescriptor::FileDescriptor; -use portable_pty::{CommandBuilder, PtySize}; +use portable_pty::CommandBuilder; use std::cell::RefCell; use std::collections::{HashMap, HashSet, VecDeque}; use std::io::Write; use std::rc::Rc; use std::sync::{Arc, Condvar, Mutex}; use termwiz::tmux_cc::*; +use wezterm_term::TerminalSize; #[derive(PartialEq, Eq, Debug, Copy, Clone)] enum State { @@ -206,7 +207,7 @@ impl TmuxDomain { impl Domain for TmuxDomain { async fn spawn_pane( &self, - _size: PtySize, + _size: TerminalSize, _command: Option, _command_dir: Option, ) -> anyhow::Result> { diff --git a/mux/src/tmux_commands.rs b/mux/src/tmux_commands.rs index aa625b632..eaa2684ca 100644 --- a/mux/src/tmux_commands.rs +++ b/mux/src/tmux_commands.rs @@ -13,6 +13,7 @@ use std::io::Write as _; use std::rc::Rc; use std::sync::{Arc, Condvar, Mutex}; use termwiz::tmux_cc::*; +use wezterm_term::TerminalSize; pub(crate) trait TmuxCommand: Send + Debug { fn get_command(&self) -> String; @@ -129,11 +130,12 @@ impl TmuxDomainState { }; let writer = pane_pty.try_clone_writer()?; let mux = Mux::get().expect("should be called at main thread"); - let size = PtySize { - rows: pane.pane_height as u16, - cols: pane.pane_width as u16, + let size = TerminalSize { + rows: pane.pane_height as usize, + cols: pane.pane_width as usize, pixel_width: 0, pixel_height: 0, + dpi: 0, }; let child = TmuxChild { @@ -141,7 +143,7 @@ impl TmuxDomainState { }; let terminal = wezterm_term::Terminal::new( - crate::pty_size_to_terminal_size(size), + size, std::sync::Arc::new(config::TermConfig::new()), "WezTerm", config::wezterm_version(), @@ -269,7 +271,7 @@ impl TmuxCommand for ListAllPanes { #[derive(Debug)] pub(crate) struct Resize { - pub size: portable_pty::PtySize, + pub size: PtySize, } impl TmuxCommand for Resize { diff --git a/term/src/screen.rs b/term/src/screen.rs index 3feab973d..4369a7530 100644 --- a/term/src/screen.rs +++ b/term/src/screen.rs @@ -38,6 +38,7 @@ pub struct Screen { pub physical_rows: usize, /// Physical, visible width of the screen pub physical_cols: usize, + pub dpi: u32, } fn scrollback_size(config: &Arc, allow_scrollback: bool) -> usize { @@ -53,15 +54,14 @@ impl Screen { /// The Cells in the viewable portion of the screen are set to the /// default cell attributes. pub fn new( - physical_rows: usize, - physical_cols: usize, + size: TerminalSize, config: &Arc, allow_scrollback: bool, seqno: SequenceNo, bidi_mode: BidiMode, ) -> Screen { - let physical_rows = physical_rows.max(1); - let physical_cols = physical_cols.max(1); + let physical_rows = size.rows.max(1); + let physical_cols = size.cols.max(1); let mut lines = VecDeque::with_capacity(physical_rows + scrollback_size(config, allow_scrollback)); @@ -78,6 +78,7 @@ impl Screen { physical_rows, physical_cols, stable_row_index_offset: 0, + dpi: size.dpi, } } @@ -162,18 +163,25 @@ impl Screen { /// Resize the physical, viewable portion of the screen pub fn resize( &mut self, - physical_rows: usize, - physical_cols: usize, + size: TerminalSize, cursor: CursorPosition, seqno: SequenceNo, is_conpty: bool, ) -> CursorPosition { - let physical_rows = physical_rows.max(1); - let physical_cols = physical_cols.max(1); - if physical_rows == self.physical_rows && physical_cols == self.physical_cols { + let physical_rows = size.rows.max(1); + let physical_cols = size.cols.max(1); + + if physical_rows == self.physical_rows + && physical_cols == self.physical_cols + && size.dpi == self.dpi + { return cursor; } - log::debug!("resize screen to {}x{}", physical_cols, physical_rows); + log::debug!( + "resize screen to {physical_cols}x{physical_rows} dpi={}", + size.dpi + ); + self.dpi = size.dpi; // pre-prune blank lines that range from the cursor position to the end of the display; // this avoids growing the scrollback size when rapidly switching between normal and diff --git a/term/src/terminal.rs b/term/src/terminal.rs index ac07d4c80..06d147262 100644 --- a/term/src/terminal.rs +++ b/term/src/terminal.rs @@ -91,11 +91,25 @@ impl DerefMut for Terminal { } #[derive(Clone, Copy, PartialEq, Eq, Debug)] +#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))] pub struct TerminalSize { - pub physical_rows: usize, - pub physical_cols: usize, + pub rows: usize, + pub cols: usize, pub pixel_width: usize, pub pixel_height: usize, + pub dpi: u32, +} + +impl Default for TerminalSize { + fn default() -> Self { + Self { + rows: 24, + cols: 80, + pixel_width: 0, + pixel_height: 0, + dpi: 0, + } + } } impl Terminal { diff --git a/term/src/terminalstate/mod.rs b/term/src/terminalstate/mod.rs index e986d3d38..4b9e8ea14 100644 --- a/term/src/terminalstate/mod.rs +++ b/term/src/terminalstate/mod.rs @@ -169,21 +169,13 @@ impl DerefMut for ScreenOrAlt { impl ScreenOrAlt { pub fn new( - physical_rows: usize, - physical_cols: usize, + size: TerminalSize, config: &Arc, seqno: SequenceNo, bidi_mode: BidiMode, ) -> Self { - let screen = Screen::new(physical_rows, physical_cols, config, true, seqno, bidi_mode); - let alt_screen = Screen::new( - physical_rows, - physical_cols, - config, - false, - seqno, - bidi_mode, - ); + let screen = Screen::new(size, config, true, seqno, bidi_mode); + let alt_screen = Screen::new(size, config, false, seqno, bidi_mode); Self { screen, @@ -196,19 +188,14 @@ impl ScreenOrAlt { pub fn resize( &mut self, - physical_rows: usize, - physical_cols: usize, + size: TerminalSize, cursor_main: CursorPosition, cursor_alt: CursorPosition, seqno: SequenceNo, is_conpty: bool, ) -> (CursorPosition, CursorPosition) { - let cursor_main = - self.screen - .resize(physical_rows, physical_cols, cursor_main, seqno, is_conpty); - let cursor_alt = - self.alt_screen - .resize(physical_rows, physical_cols, cursor_alt, seqno, is_conpty); + let cursor_main = self.screen.resize(size, cursor_main, seqno, is_conpty); + let cursor_alt = self.alt_screen.resize(size, cursor_alt, seqno, is_conpty); (cursor_main, cursor_alt) } @@ -344,6 +331,7 @@ pub struct TerminalState { pixel_width: usize, pixel_height: usize, + dpi: u32, clipboard: Option>, device_control_handler: Option>, @@ -487,13 +475,7 @@ impl TerminalState { ) -> TerminalState { let writer = Box::new(ThreadedWriter::new(writer)); let seqno = 1; - let screen = ScreenOrAlt::new( - size.physical_rows, - size.physical_cols, - &config, - seqno, - config.bidi_mode(), - ); + let screen = ScreenOrAlt::new(size, &config, seqno, config.bidi_mode()); let color_map = default_color_map(); @@ -504,8 +486,8 @@ impl TerminalState { screen, pen: CellAttributes::default(), cursor: CursorPosition::default(), - top_and_bottom_margins: 0..size.physical_rows as VisibleRowIndex, - left_and_right_margins: 0..size.physical_cols, + top_and_bottom_margins: 0..size.rows as VisibleRowIndex, + left_and_right_margins: 0..size.cols, left_and_right_margin_mode: false, wrap_next: false, clear_semantic_attribute_on_newline: false, @@ -537,12 +519,13 @@ impl TerminalState { shift_out: false, newline_mode: false, current_mouse_buttons: vec![], - tabs: TabStop::new(size.physical_cols, 8), + tabs: TabStop::new(size.cols, 8), title: "wezterm".to_string(), icon_title: None, palette: None, pixel_height: size.pixel_height, pixel_width: size.pixel_width, + dpi: size.dpi, clipboard: None, device_control_handler: None, alert_handler: None, @@ -795,13 +778,7 @@ impl TerminalState { /// specified dimensions. /// We need to resize both the primary and alt screens, adjusting /// the cursor positions of both accordingly. - pub fn resize( - &mut self, - physical_rows: usize, - physical_cols: usize, - pixel_width: usize, - pixel_height: usize, - ) { + pub fn resize(&mut self, size: TerminalSize) { let (cursor_main, cursor_alt) = if self.screen.alt_screen_is_active { ( self.screen @@ -823,18 +800,18 @@ impl TerminalState { }; let (adjusted_cursor_main, adjusted_cursor_alt) = self.screen.resize( - physical_rows, - physical_cols, + size, cursor_main, cursor_alt, self.seqno, self.enable_conpty_quirks, ); - self.top_and_bottom_margins = 0..physical_rows as i64; - self.left_and_right_margins = 0..physical_cols; - self.pixel_height = pixel_height; - self.pixel_width = pixel_width; - self.tabs.resize(physical_cols); + self.top_and_bottom_margins = 0..size.rows as i64; + self.left_and_right_margins = 0..size.cols; + self.pixel_height = size.pixel_height; + self.pixel_width = size.pixel_width; + self.dpi = size.dpi; + self.tabs.resize(size.cols); if self.screen.alt_screen_is_active { self.set_cursor_pos( diff --git a/term/src/test/c1.rs b/term/src/test/c1.rs index 19f2c5cee..2e9e608bf 100644 --- a/term/src/test/c1.rs +++ b/term/src/test/c1.rs @@ -39,7 +39,13 @@ fn test_hts() { term.assert_cursor_pos(8, 1, None, None); // Check that tabs are expanded if we resize - term.resize(4, 80, 4 * 16, 80 * 8); + term.resize(TerminalSize { + rows: 4, + cols: 80, + pixel_width: 4 * 16, + pixel_height: 80 * 8, + dpi: 0, + }); term.cup(0, 1); term.print("\t"); term.assert_cursor_pos(3, 1, None, None); diff --git a/term/src/test/mod.rs b/term/src/test/mod.rs index dd173ef8b..3c6ff8cad 100644 --- a/term/src/test/mod.rs +++ b/term/src/test/mod.rs @@ -66,10 +66,11 @@ impl TestTerm { let mut term = Terminal::new( TerminalSize { - physical_rows: height, - physical_cols: width, + rows: height, + cols: width, pixel_width: width * 8, pixel_height: height * 16, + dpi: 0, }, Arc::new(TestTermConfig { scrollback }), "WezTerm", @@ -868,14 +869,26 @@ fn test_resize_wrap() { "111 ", "2222", "aa ", "333 ", " ", " ", " ", " ", ], ); - term.resize(LINES, 5, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 5, + pixel_width: 0, + pixel_height: 0, + dpi: 0, + }); assert_visible_contents( &term, file!(), line!(), &["111 ", "2222a", "a", "333 ", " ", " ", " ", " "], ); - term.resize(LINES, 6, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 6, + pixel_width: 0, + pixel_height: 0, + dpi: 0, + }); assert_visible_contents( &term, file!(), @@ -884,7 +897,13 @@ fn test_resize_wrap() { "111 ", "2222aa", "333 ", " ", " ", " ", " ", " ", ], ); - term.resize(LINES, 7, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 7, + pixel_width: 0, + pixel_height: 0, + dpi: 0, + }); assert_visible_contents( &term, file!(), @@ -893,7 +912,11 @@ fn test_resize_wrap() { "111 ", "2222aa", "333 ", " ", " ", " ", " ", " ", ], ); - term.resize(LINES, 8, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 8, + ..Default::default() + }); assert_visible_contents( &term, file!(), @@ -904,7 +927,11 @@ fn test_resize_wrap() { ); // Resize smaller again - term.resize(LINES, 7, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 7, + ..Default::default() + }); assert_visible_contents( &term, file!(), @@ -913,7 +940,11 @@ fn test_resize_wrap() { "111 ", "2222aa", "333 ", " ", " ", " ", " ", " ", ], ); - term.resize(LINES, 6, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 6, + ..Default::default() + }); assert_visible_contents( &term, file!(), @@ -922,7 +953,11 @@ fn test_resize_wrap() { "111 ", "2222aa", "333 ", " ", " ", " ", " ", " ", ], ); - term.resize(LINES, 5, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 5, + ..Default::default() + }); assert_visible_contents( &term, file!(), @@ -931,7 +966,11 @@ fn test_resize_wrap() { "111 ", "2222a", "a", "333 ", " ", " ", " ", " ", ], ); - term.resize(LINES, 4, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 4, + ..Default::default() + }); assert_visible_contents( &term, file!(), @@ -948,7 +987,11 @@ fn test_resize_wrap_issue_971() { let mut term = TestTerm::new(LINES, 4, 0); term.print("====\r\nSS\r\n"); assert_visible_contents(&term, file!(), line!(), &["====", "SS ", " ", " "]); - term.resize(LINES, 6, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 6, + ..Default::default() + }); assert_visible_contents(&term, file!(), line!(), &["====", "SS ", " ", " "]); } @@ -958,7 +1001,11 @@ fn test_resize_wrap_sgc_issue_978() { let mut term = TestTerm::new(LINES, 4, 0); term.print("\u{1b}(0qqqq\u{1b}(B\r\nSS\r\n"); assert_visible_contents(&term, file!(), line!(), &["────", "SS ", " ", " "]); - term.resize(LINES, 6, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 6, + ..Default::default() + }); assert_visible_contents(&term, file!(), line!(), &["────", "SS ", " ", " "]); } @@ -968,7 +1015,11 @@ fn test_resize_wrap_dectcm_issue_978() { let mut term = TestTerm::new(LINES, 4, 0); term.print("\u{1b}[?25l====\u{1b}[?25h\r\nSS\r\n"); assert_visible_contents(&term, file!(), line!(), &["====", "SS ", " ", " "]); - term.resize(LINES, 6, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 6, + ..Default::default() + }); assert_visible_contents(&term, file!(), line!(), &["====", "SS ", " ", " "]); } @@ -978,7 +1029,11 @@ fn test_resize_wrap_escape_code_issue_978() { let mut term = TestTerm::new(LINES, 4, 0); term.print("====\u{1b}[0m\r\nSS\r\n"); assert_visible_contents(&term, file!(), line!(), &["====", "SS ", " ", " "]); - term.resize(LINES, 6, 0, 0); + term.resize(TerminalSize { + rows: LINES, + cols: 6, + ..Default::default() + }); assert_visible_contents(&term, file!(), line!(), &["====", "SS ", " ", " "]); } diff --git a/wezterm-client/src/domain.rs b/wezterm-client/src/domain.rs index 685f9e4ee..8945d8a28 100644 --- a/wezterm-client/src/domain.rs +++ b/wezterm-client/src/domain.rs @@ -11,12 +11,13 @@ use mux::pane::{Pane, PaneId}; use mux::tab::{SplitRequest, Tab, TabId}; use mux::window::WindowId; use mux::{Mux, MuxNotification}; -use portable_pty::{CommandBuilder, PtySize}; +use portable_pty::CommandBuilder; use promise::spawn::spawn_into_new_thread; use std::cell::RefCell; use std::collections::HashMap; use std::rc::Rc; use std::sync::{Arc, Mutex}; +use wezterm_term::TerminalSize; pub struct ClientInner { pub client: Client, @@ -482,7 +483,7 @@ impl Domain for ClientDomain { async fn spawn_pane( &self, - _size: PtySize, + _size: TerminalSize, _command: Option, _command_dir: Option, ) -> anyhow::Result> { @@ -491,7 +492,7 @@ impl Domain for ClientDomain { async fn spawn( &self, - size: PtySize, + size: TerminalSize, command: Option, command_dir: Option, window: WindowId, diff --git a/wezterm-client/src/pane/clientpane.rs b/wezterm-client/src/pane/clientpane.rs index bb5eceea8..d1677eb5d 100644 --- a/wezterm-client/src/pane/clientpane.rs +++ b/wezterm-client/src/pane/clientpane.rs @@ -10,7 +10,6 @@ use mux::pane::{alloc_pane_id, CloseReason, Pane, PaneId, Pattern, SearchResult} use mux::renderable::{RenderableDimensions, StableCursorPosition}; use mux::tab::TabId; use mux::{Mux, MuxNotification}; -use portable_pty::PtySize; use rangeset::RangeSet; use ratelim::RateLimiter; use std::cell::{RefCell, RefMut}; @@ -22,7 +21,9 @@ use termwiz::input::KeyEvent; use termwiz::surface::SequenceNo; use url::Url; use wezterm_term::color::ColorPalette; -use wezterm_term::{Alert, Clipboard, KeyCode, KeyModifiers, Line, MouseEvent, StableRowIndex}; +use wezterm_term::{ + Alert, Clipboard, KeyCode, KeyModifiers, Line, MouseEvent, StableRowIndex, TerminalSize, +}; pub struct ClientPane { client: Arc, @@ -44,7 +45,7 @@ impl ClientPane { client: &Arc, remote_tab_id: TabId, remote_pane_id: PaneId, - size: PtySize, + size: TerminalSize, title: &str, ) -> Self { let local_pane_id = alloc_pane_id(); @@ -72,6 +73,7 @@ impl ClientPane { scrollback_rows: size.rows as _, physical_top: 0, scrollback_top: 0, + dpi: size.dpi, }, title, fetch_limiter, @@ -278,7 +280,7 @@ impl Pane for ClientPane { inner.update_last_send(); } - fn resize(&self, size: PtySize) -> anyhow::Result<()> { + fn resize(&self, size: TerminalSize) -> anyhow::Result<()> { let render = self.renderable.borrow(); let mut inner = render.inner.borrow_mut(); diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index aff90208a..060a7ae39 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -178,12 +178,13 @@ fn run_serial(config: config::ConfigHandle, opts: &SerialCommand) -> anyhow::Res let mux = setup_mux(domain.clone(), &config, Some("local"), None)?; let gui = crate::frontend::try_new()?; + let dpi = config.dpi.unwrap_or_else(|| ::window::default_dpi()) as u32; { let window_id = mux.new_empty_window(None); block_on(domain.attach(Some(*window_id)))?; // FIXME: blocking // FIXME: blocking - let _tab = block_on(domain.spawn(config.initial_size(), None, None, *window_id))?; + let _tab = block_on(domain.spawn(config.initial_size(dpi), None, None, *window_id))?; } maybe_show_configuration_error_window(); @@ -301,8 +302,9 @@ async fn spawn_tab_in_default_domain_if_mux_is_empty( true }); + let dpi = config.dpi.unwrap_or_else(|| ::window::default_dpi()) as u32; let _tab = domain - .spawn(config.initial_size(), cmd, None, *window_id) + .spawn(config.initial_size(dpi), cmd, None, *window_id) .await?; Ok(()) } @@ -462,7 +464,7 @@ impl Publish { window_id: None, command, command_dir: None, - size: config.initial_size(), + size: config.initial_size(0), workspace: workspace.unwrap_or( config .default_workspace diff --git a/wezterm-gui/src/overlay/copy.rs b/wezterm-gui/src/overlay/copy.rs index 87b42d834..364e6186a 100644 --- a/wezterm-gui/src/overlay/copy.rs +++ b/wezterm-gui/src/overlay/copy.rs @@ -7,7 +7,6 @@ use mux::domain::DomainId; use mux::pane::{Pane, PaneId, Pattern, SearchResult}; use mux::renderable::*; use mux::tab::TabId; -use portable_pty::PtySize; use rangeset::RangeSet; use std::cell::{RefCell, RefMut}; use std::collections::HashMap; @@ -22,6 +21,7 @@ use url::Url; use wezterm_term::color::ColorPalette; use wezterm_term::{ unicode_column_width, Clipboard, KeyCode, KeyModifiers, Line, MouseEvent, StableRowIndex, + TerminalSize, }; use window::{KeyCode as WKeyCode, Modifiers, WindowOps}; @@ -741,7 +741,7 @@ impl Pane for CopyOverlay { self.delegate.writer() } - fn resize(&self, size: PtySize) -> anyhow::Result<()> { + fn resize(&self, size: TerminalSize) -> anyhow::Result<()> { self.delegate.resize(size) } diff --git a/wezterm-gui/src/overlay/mod.rs b/wezterm-gui/src/overlay/mod.rs index f658cb7d1..303f5a62f 100644 --- a/wezterm-gui/src/overlay/mod.rs +++ b/wezterm-gui/src/overlay/mod.rs @@ -2,9 +2,9 @@ use crate::termwindow::TermWindow; use mux::pane::{Pane, PaneId}; use mux::tab::{Tab, TabId}; use mux::termwiztermtab::{allocate, TermWizTerminal}; -use portable_pty::PtySize; use std::pin::Pin; use std::rc::Rc; +use wezterm_term::TerminalSize; pub mod confirm_close_pane; pub mod copy; @@ -63,12 +63,12 @@ where { let pane_id = pane.pane_id(); let dims = pane.get_dimensions(); - let size = PtySize { - cols: dims.cols as u16, - rows: dims.viewport_rows as u16, - pixel_width: term_window.render_metrics.cell_size.width as u16 * dims.cols as u16, - pixel_height: term_window.render_metrics.cell_size.height as u16 - * dims.viewport_rows as u16, + let size = TerminalSize { + cols: dims.cols, + rows: dims.viewport_rows, + pixel_width: term_window.render_metrics.cell_size.width as usize * dims.cols, + pixel_height: term_window.render_metrics.cell_size.height as usize * dims.viewport_rows, + dpi: dims.dpi, }; let (tw_term, tw_tab) = allocate(size); diff --git a/wezterm-gui/src/overlay/quickselect.rs b/wezterm-gui/src/overlay/quickselect.rs index 49be27da6..a939f0976 100644 --- a/wezterm-gui/src/overlay/quickselect.rs +++ b/wezterm-gui/src/overlay/quickselect.rs @@ -5,7 +5,6 @@ use config::ConfigHandle; use mux::domain::DomainId; use mux::pane::{Pane, PaneId, Pattern, SearchResult}; use mux::renderable::*; -use portable_pty::PtySize; use rangeset::RangeSet; use std::cell::{RefCell, RefMut}; use std::collections::HashMap; @@ -17,7 +16,9 @@ use termwiz::color::AnsiColor; use termwiz::surface::{SequenceNo, SEQ_ZERO}; use url::Url; use wezterm_term::color::ColorPalette; -use wezterm_term::{Clipboard, KeyCode, KeyModifiers, Line, MouseEvent, StableRowIndex}; +use wezterm_term::{ + Clipboard, KeyCode, KeyModifiers, Line, MouseEvent, StableRowIndex, TerminalSize, +}; use window::WindowOps; const PATTERNS: [&str; 14] = [ @@ -288,7 +289,7 @@ impl Pane for QuickSelectOverlay { self.delegate.writer() } - fn resize(&self, size: PtySize) -> anyhow::Result<()> { + fn resize(&self, size: TerminalSize) -> anyhow::Result<()> { self.delegate.resize(size) } diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 60c5e4ff3..71f15f00f 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -42,7 +42,6 @@ use mux::tab::{ }; use mux::window::WindowId as MuxWindowId; use mux::{Mux, MuxNotification}; -use portable_pty::PtySize; use smol::channel::Sender; use smol::Timer; use std::cell::{RefCell, RefMut}; @@ -58,7 +57,7 @@ use wezterm_font::FontConfiguration; use wezterm_gui_subcommands::GuiPosition; use wezterm_term::color::ColorPalette; use wezterm_term::input::LastMouseClick; -use wezterm_term::{Alert, StableRowIndex, TerminalConfiguration}; +use wezterm_term::{Alert, StableRowIndex, TerminalConfiguration, TerminalSize}; pub mod background; pub mod box_model; @@ -335,7 +334,7 @@ pub struct TermWindow { pub dimensions: Dimensions, pub window_state: WindowState, /// Terminal dimensions - terminal_size: PtySize, + terminal_size: TerminalSize, pub mux_window_id: MuxWindowId, pub mux_window_id_for_subscriptions: Arc>, pub render_metrics: RenderMetrics, @@ -549,11 +548,12 @@ impl TermWindow { 0 }; - let terminal_size = PtySize { - rows: physical_rows as u16, - cols: physical_cols as u16, - pixel_width: (render_metrics.cell_size.width as usize * physical_cols) as u16, - pixel_height: (render_metrics.cell_size.height as usize * physical_rows) as u16, + let terminal_size = TerminalSize { + rows: physical_rows, + cols: physical_cols, + pixel_width: (render_metrics.cell_size.width as usize * physical_cols), + pixel_height: (render_metrics.cell_size.height as usize * physical_rows), + dpi: dpi as u32, }; if terminal_size != size { @@ -578,19 +578,19 @@ impl TermWindow { pixel_max: terminal_size.pixel_width as f32, pixel_cell: render_metrics.cell_size.width as f32, }; - let padding_left = config.window_padding.left.evaluate_as_pixels(h_context) as u16; - let padding_right = resize::effective_right_padding(&config, h_context); + let padding_left = config.window_padding.left.evaluate_as_pixels(h_context) as usize; + let padding_right = resize::effective_right_padding(&config, h_context) as usize; let v_context = DimensionContext { dpi: dpi as f32, pixel_max: terminal_size.pixel_height as f32, pixel_cell: render_metrics.cell_size.height as f32, }; - let padding_top = config.window_padding.top.evaluate_as_pixels(v_context) as u16; - let padding_bottom = config.window_padding.bottom.evaluate_as_pixels(v_context) as u16; + let padding_top = config.window_padding.top.evaluate_as_pixels(v_context) as usize; + let padding_bottom = config.window_padding.bottom.evaluate_as_pixels(v_context) as usize; let dimensions = Dimensions { pixel_width: (terminal_size.pixel_width + padding_left + padding_right) as usize, - pixel_height: ((terminal_size.rows * render_metrics.cell_size.height as u16) + pixel_height: ((terminal_size.rows * render_metrics.cell_size.height as usize) + padding_top + padding_bottom) as usize + tab_bar_height, @@ -2367,6 +2367,7 @@ impl TermWindow { AttachDomain(domain) => { let window = self.mux_window_id; let domain = domain.to_string(); + let dpi = self.dimensions.dpi as u32; promise::spawn::spawn(async move { let mux = Mux::get().unwrap(); @@ -2383,7 +2384,7 @@ impl TermWindow { if !have_panes_in_domain { let config = config::configuration(); let _tab = domain - .spawn(config.initial_size(), None, None, window) + .spawn(config.initial_size(dpi), None, None, window) .await?; } diff --git a/wezterm-gui/src/termwindow/render.rs b/wezterm-gui/src/termwindow/render.rs index b49a4f74d..4bd2a39ba 100644 --- a/wezterm-gui/src/termwindow/render.rs +++ b/wezterm-gui/src/termwindow/render.rs @@ -945,6 +945,7 @@ impl super::TermWindow { scrollback_rows: 0, scrollback_top: 0, viewport_rows: 1, + dpi: self.terminal_size.dpi, }, config: &self.config, cursor_border_color: LinearRgba::default(), diff --git a/wezterm-gui/src/termwindow/resize.rs b/wezterm-gui/src/termwindow/resize.rs index 40e15b643..81841598c 100644 --- a/wezterm-gui/src/termwindow/resize.rs +++ b/wezterm-gui/src/termwindow/resize.rs @@ -2,9 +2,9 @@ use crate::utilsprites::RenderMetrics; use ::window::{Dimensions, Window, WindowOps, WindowState}; use config::{ConfigHandle, DimensionContext}; use mux::Mux; -use portable_pty::PtySize; use std::rc::Rc; use wezterm_font::FontConfiguration; +use wezterm_term::TerminalSize; #[derive(Debug, Clone, Copy)] pub struct RowsAndCols { @@ -158,11 +158,12 @@ impl super::TermWindow { let (size, dims) = if let Some(cell_dims) = scale_changed_cells { // Scaling preserves existing terminal dimensions, yielding a new // overall set of window dimensions - let size = PtySize { - rows: cell_dims.rows as u16, - cols: cell_dims.cols as u16, - pixel_height: cell_dims.rows as u16 * self.render_metrics.cell_size.height as u16, - pixel_width: cell_dims.cols as u16 * self.render_metrics.cell_size.width as u16, + let size = TerminalSize { + rows: cell_dims.rows, + cols: cell_dims.cols, + pixel_height: cell_dims.rows * self.render_metrics.cell_size.height as usize, + pixel_width: cell_dims.cols * self.render_metrics.cell_size.width as usize, + dpi: dimensions.dpi as u32, }; let rows = size.rows; @@ -178,16 +179,17 @@ impl super::TermWindow { pixel_max: size.pixel_height as f32, pixel_cell: self.render_metrics.cell_size.height as f32, }; - let padding_left = config.window_padding.left.evaluate_as_pixels(h_context) as u16; - let padding_top = config.window_padding.top.evaluate_as_pixels(v_context) as u16; - let padding_bottom = config.window_padding.bottom.evaluate_as_pixels(v_context) as u16; + let padding_left = config.window_padding.left.evaluate_as_pixels(h_context) as usize; + let padding_top = config.window_padding.top.evaluate_as_pixels(v_context) as usize; + let padding_bottom = + config.window_padding.bottom.evaluate_as_pixels(v_context) as usize; let padding_right = effective_right_padding(&config, h_context); - let pixel_height = (rows * self.render_metrics.cell_size.height as u16) + let pixel_height = (rows * self.render_metrics.cell_size.height as usize) + (padding_top + padding_bottom) - + tab_bar_height as u16; + + tab_bar_height as usize; - let pixel_width = (cols * self.render_metrics.cell_size.width as u16) + let pixel_width = (cols * self.render_metrics.cell_size.width as usize) + (padding_left + padding_right); let dims = Dimensions { @@ -210,9 +212,10 @@ impl super::TermWindow { pixel_max: self.terminal_size.pixel_height as f32, pixel_cell: self.render_metrics.cell_size.height as f32, }; - let padding_left = config.window_padding.left.evaluate_as_pixels(h_context) as u16; - let padding_top = config.window_padding.top.evaluate_as_pixels(v_context) as u16; - let padding_bottom = config.window_padding.bottom.evaluate_as_pixels(v_context) as u16; + let padding_left = config.window_padding.left.evaluate_as_pixels(h_context) as usize; + let padding_top = config.window_padding.top.evaluate_as_pixels(v_context) as usize; + let padding_bottom = + config.window_padding.bottom.evaluate_as_pixels(v_context) as usize; let padding_right = effective_right_padding(&config, h_context); let avail_width = dimensions.pixel_width.saturating_sub( @@ -230,15 +233,16 @@ impl super::TermWindow { let rows = avail_height / self.render_metrics.cell_size.height as usize; let cols = avail_width / self.render_metrics.cell_size.width as usize; - let size = PtySize { - rows: rows as u16, - cols: cols as u16, + let size = TerminalSize { + rows, + cols, // Take care to use the exact pixel dimensions of the cells, rather // than the available space, so that apps that are sensitive to // the pixels-per-cell have consistent values at a given font size. // https://github.com/wez/wezterm/issues/535 - pixel_height: rows as u16 * self.render_metrics.cell_size.height as u16, - pixel_width: cols as u16 * self.render_metrics.cell_size.width as u16, + pixel_height: rows * self.render_metrics.cell_size.height as usize, + pixel_width: cols * self.render_metrics.cell_size.width as usize, + dpi: dimensions.dpi as u32, }; (size, *dimensions) @@ -388,7 +392,7 @@ impl super::TermWindow { self.adjust_font_scale(1.0, window); } - pub fn set_window_size(&mut self, size: PtySize, window: &Window) -> anyhow::Result<()> { + pub fn set_window_size(&mut self, size: TerminalSize, window: &Window) -> anyhow::Result<()> { let config = &self.config; let fontconfig = Rc::new(FontConfiguration::new( Some(config.clone()), @@ -396,11 +400,12 @@ impl super::TermWindow { )?); let render_metrics = RenderMetrics::new(&fontconfig)?; - let terminal_size = PtySize { - rows: size.rows as u16, - cols: size.cols as u16, - pixel_width: (render_metrics.cell_size.width as u16 * size.cols), - pixel_height: (render_metrics.cell_size.height as u16 * size.rows), + let terminal_size = TerminalSize { + rows: size.rows, + cols: size.cols, + pixel_width: (render_metrics.cell_size.width as usize * size.cols), + pixel_height: (render_metrics.cell_size.height as usize * size.rows), + dpi: size.dpi, }; let show_tab_bar = config.enable_tab_bar && !config.hide_tab_bar_if_only_one_tab; @@ -420,15 +425,15 @@ impl super::TermWindow { pixel_max: self.dimensions.pixel_height as f32, pixel_cell: render_metrics.cell_size.height as f32, }; - let padding_left = config.window_padding.left.evaluate_as_pixels(h_context) as u16; - let padding_top = config.window_padding.top.evaluate_as_pixels(v_context) as u16; - let padding_bottom = config.window_padding.bottom.evaluate_as_pixels(v_context) as u16; + let padding_left = config.window_padding.left.evaluate_as_pixels(h_context) as usize; + let padding_top = config.window_padding.top.evaluate_as_pixels(v_context) as usize; + let padding_bottom = config.window_padding.bottom.evaluate_as_pixels(v_context) as usize; let dimensions = Dimensions { - pixel_width: ((terminal_size.cols * render_metrics.cell_size.width as u16) + pixel_width: ((terminal_size.cols as usize * render_metrics.cell_size.width as usize) + padding_left - + effective_right_padding(&config, h_context)) as usize, - pixel_height: ((terminal_size.rows * render_metrics.cell_size.height as u16) + + effective_right_padding(&config, h_context)), + pixel_height: ((terminal_size.rows as usize * render_metrics.cell_size.height as usize) + padding_top + padding_bottom) as usize + tab_bar_height, @@ -448,11 +453,11 @@ impl super::TermWindow { } pub fn reset_font_and_window_size(&mut self, window: &Window) -> anyhow::Result<()> { - let size = self.config.initial_size(); + let size = self.config.initial_size(self.dimensions.dpi as u32); self.set_window_size(size, window) } - pub fn effective_right_padding(&self, config: &ConfigHandle) -> u16 { + pub fn effective_right_padding(&self, config: &ConfigHandle) -> usize { effective_right_padding( config, DimensionContext { @@ -468,10 +473,10 @@ impl super::TermWindow { /// This is needed because the default is 0, but if the user has /// enabled the scroll bar then they will expect it to have a reasonable /// size unless they've specified differently. -pub fn effective_right_padding(config: &ConfigHandle, context: DimensionContext) -> u16 { +pub fn effective_right_padding(config: &ConfigHandle, context: DimensionContext) -> usize { if config.enable_scroll_bar && config.window_padding.right.is_zero() { - context.pixel_cell as u16 + context.pixel_cell as usize } else { - config.window_padding.right.evaluate_as_pixels(context) as u16 + config.window_padding.right.evaluate_as_pixels(context) as usize } } diff --git a/wezterm-gui/src/termwindow/spawn.rs b/wezterm-gui/src/termwindow/spawn.rs index e662f2969..e1f715992 100644 --- a/wezterm-gui/src/termwindow/spawn.rs +++ b/wezterm-gui/src/termwindow/spawn.rs @@ -6,8 +6,9 @@ use mux::activity::Activity; use mux::domain::SplitSource; use mux::tab::SplitRequest; use mux::Mux; -use portable_pty::{CommandBuilder, PtySize}; +use portable_pty::CommandBuilder; use std::sync::Arc; +use wezterm_term::TerminalSize; #[derive(Copy, Debug, Clone, Eq, PartialEq)] pub enum SpawnWhere { @@ -19,7 +20,7 @@ pub enum SpawnWhere { impl super::TermWindow { pub fn spawn_command(&self, spawn: &SpawnCommand, spawn_where: SpawnWhere) { let size = if spawn_where == SpawnWhere::NewWindow { - self.config.initial_size() + self.config.initial_size(self.dimensions.dpi as u32) } else { self.terminal_size }; @@ -31,7 +32,7 @@ impl super::TermWindow { fn spawn_command_impl( spawn: &SpawnCommand, spawn_where: SpawnWhere, - size: PtySize, + size: TerminalSize, src_window_id: MuxWindowId, term_config: Arc, ) { @@ -51,7 +52,7 @@ impl super::TermWindow { pub async fn spawn_command_internal( spawn: SpawnCommand, spawn_where: SpawnWhere, - size: PtySize, + size: TerminalSize, src_window_id: MuxWindowId, term_config: Arc, ) -> anyhow::Result<()> { diff --git a/wezterm-gui/src/update.rs b/wezterm-gui/src/update.rs index b2f1dac71..6e8325583 100644 --- a/wezterm-gui/src/update.rs +++ b/wezterm-gui/src/update.rs @@ -4,7 +4,6 @@ use config::{configuration, wezterm_version}; use http_req::request::{HttpVersion, Request}; use http_req::uri::Uri; use mux::connui::{ConnectionUI, ConnectionUIParams}; -use portable_pty::PtySize; use regex::Regex; use serde::*; use std::collections::HashMap; @@ -18,6 +17,7 @@ use termwiz::escape::csi::{Cursor, Sgr}; use termwiz::escape::osc::{ITermDimension, ITermFileData, ITermProprietary}; use termwiz::escape::{OneBased, OperatingSystemCommand, CSI}; use termwiz::surface::{Change, CursorVisibility}; +use wezterm_term::TerminalSize; use wezterm_toast_notification::*; #[derive(Debug, Serialize, Deserialize, Clone)] @@ -155,11 +155,12 @@ fn show_update_available(release: Release) { } let mut updater = UPDATER_WINDOW.lock().unwrap(); - let size = PtySize { + let size = TerminalSize { cols: 80, rows: 35, pixel_width: 0, pixel_height: 0, + dpi: 0, }; let ui = ConnectionUI::with_params(ConnectionUIParams { size, diff --git a/wezterm-mux-server/Cargo.toml b/wezterm-mux-server/Cargo.toml index f2568326a..04d685019 100644 --- a/wezterm-mux-server/Cargo.toml +++ b/wezterm-mux-server/Cargo.toml @@ -22,6 +22,7 @@ promise = { path = "../promise" } umask = { path = "../umask" } wezterm-mux-server-impl = { path = "../wezterm-mux-server-impl" } wezterm-gui-subcommands = { path = "../wezterm-gui-subcommands" } +wezterm-term = { path = "../term" } [target."cfg(windows)".dependencies] winapi = { version = "0.3", features = [ "winuser" ]} diff --git a/wezterm-mux-server/src/main.rs b/wezterm-mux-server/src/main.rs index dcefb0c27..48bf61913 100644 --- a/wezterm-mux-server/src/main.rs +++ b/wezterm-mux-server/src/main.rs @@ -209,7 +209,7 @@ async fn async_run(cmd: Option) -> anyhow::Result<()> { let config = config::configuration(); let _tab = mux .default_domain() - .spawn(config.initial_size(), cmd, None, *window_id) + .spawn(config.initial_size(0), cmd, None, *window_id) .await?; Ok(()) } diff --git a/wezterm/src/main.rs b/wezterm/src/main.rs index 4528b6080..163537506 100644 --- a/wezterm/src/main.rs +++ b/wezterm/src/main.rs @@ -18,6 +18,7 @@ use tabout::{tabulate_output, Alignment, Column}; use umask::UmaskSaver; use wezterm_client::client::{unix_connect_with_retry, Client}; use wezterm_gui_subcommands::*; +use wezterm_term::TerminalSize; mod asciicast; @@ -563,8 +564,8 @@ async fn resolve_pane_id(client: &Client, pane_id: Option) -> anyhow::Re #[derive(serde::Serialize)] struct CliListResultPtySize { - rows: u16, - cols: u16, + rows: usize, + cols: usize, } // This will be serialized to JSON via the 'List' command. // As such it is intended to be a stable output format, @@ -590,7 +591,7 @@ impl From for CliListResultItem { workspace, title, working_dir, - size: portable_pty::PtySize { rows, cols, .. }, + size: TerminalSize { rows, cols, .. }, .. } = pane; @@ -1000,6 +1001,8 @@ async fn run_cli_async(config: config::ConfigHandle, cli: CliCommand) -> anyhow: let workspace = workspace.unwrap_or_else(|| mux::DEFAULT_WORKSPACE.to_string()); + let size = config.initial_size(0); + let spawned = client .spawn_v2(codec::SpawnV2 { domain: domain_name.map_or(SpawnTabDomain::DefaultDomain, |name| { @@ -1013,7 +1016,7 @@ async fn run_cli_async(config: config::ConfigHandle, cli: CliCommand) -> anyhow: Some(builder) }, command_dir: canon_cwd(cwd)?, - size: config::configuration().initial_size(), + size, workspace, }) .await?;