diff --git a/mux/src/lib.rs b/mux/src/lib.rs index 305b58299..cb23889f0 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -72,6 +72,10 @@ pub enum MuxNotification { name: Option, data: Arc>, }, + TabAddedToWindow { + tab_id: TabId, + window_id: WindowId, + }, } static SUB_ID: AtomicUsize = AtomicUsize::new(0); @@ -763,6 +767,7 @@ impl Mux { } pub fn add_tab_to_window(&self, tab: &Rc, window_id: WindowId) -> anyhow::Result<()> { + let tab_id = tab.tab_id(); { let mut window = self .get_window_mut(window_id) @@ -770,6 +775,7 @@ impl Mux { window.push(tab); } self.recompute_pane_count(); + self.notify(MuxNotification::TabAddedToWindow { tab_id, window_id }); Ok(()) } diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rs index 8fe8400e9..9cd2412ce 100644 --- a/wezterm-gui/src/frontend.rs +++ b/wezterm-gui/src/frontend.rs @@ -59,6 +59,7 @@ impl GuiFrontEnd { }) .detach(); } + MuxNotification::TabAddedToWindow { .. } => {} MuxNotification::PaneRemoved(_) => {} MuxNotification::WindowInvalidated(_) => {} MuxNotification::PaneOutput(_) => {} diff --git a/wezterm-gui/src/main.rs b/wezterm-gui/src/main.rs index 1fd0857c2..9ca8a7ede 100644 --- a/wezterm-gui/src/main.rs +++ b/wezterm-gui/src/main.rs @@ -298,7 +298,12 @@ async fn spawn_tab_in_default_domain_if_mux_is_empty( let window_id = { // Force the builder to notify the frontend early, - // so that the attach await below doesn't block it + // so that the attach await below doesn't block it. + // This has the consequence of creating the window + // at the initial size instead of populating it + // from the size specified in the remote mux. + // We use the TabAddedToWindow mux notification + // to detect and adjust the size later on. let builder = mux.new_empty_window(None); *builder }; diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index b64482f0c..32c100038 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -1002,6 +1002,32 @@ impl TermWindow { alert: Alert::ToastNotification { .. }, .. } => {} + MuxNotification::TabAddedToWindow { + window_id: _, + tab_id, + } => { + let mux = Mux::get().unwrap(); + let mut size = self.terminal_size; + if let Some(tab) = mux.get_tab(tab_id) { + // If we attached to a remote domain and loaded in + // a tab async, we need to fixup its size, either + // by resizing it or resizes ourselves. + // The strategy here is to adjust both by taking + // the maximal size in both horizontal and vertical + // dimensions and applying that. In practice that + // means that a new local client will resize larger + // to adjust to the size of an existing client. + let tab_size = tab.get_size(); + size.rows = size.rows.max(tab_size.rows); + size.cols = size.cols.max(tab_size.cols); + + if size.rows != self.terminal_size.rows + || size.cols != self.terminal_size.cols + { + self.set_window_size(size, window)?; + } + } + } MuxNotification::PaneOutput(pane_id) => { self.mux_pane_output_event(pane_id); } @@ -1187,7 +1213,8 @@ impl TermWindow { let mux = Mux::get().expect("mux is calling us"); return mux.get_window(mux_window_id).is_some(); } - MuxNotification::WindowRemoved(window_id) + MuxNotification::TabAddedToWindow { window_id, .. } + | MuxNotification::WindowRemoved(window_id) | MuxNotification::WindowInvalidated(window_id) => { if window_id != mux_window_id { return true; diff --git a/wezterm-mux-server-impl/src/dispatch.rs b/wezterm-mux-server-impl/src/dispatch.rs index 40b41afe1..55308629c 100644 --- a/wezterm-mux-server-impl/src/dispatch.rs +++ b/wezterm-mux-server-impl/src/dispatch.rs @@ -139,6 +139,7 @@ where .await?; stream.flush().await.context("flushing PDU to client")?; } + Ok(Item::Notif(MuxNotification::TabAddedToWindow { .. })) => {} Ok(Item::Notif(MuxNotification::WindowRemoved(_window_id))) => {} Ok(Item::Notif(MuxNotification::WindowCreated(_window_id))) => {} Ok(Item::Notif(MuxNotification::WindowInvalidated(_window_id))) => {}