diff --git a/codec/src/lib.rs b/codec/src/lib.rs index e9cd803b1..67bba1fc4 100644 --- a/codec/src/lib.rs +++ b/codec/src/lib.rs @@ -436,6 +436,7 @@ pdu! { SplitPane: 34, KillPane: 35, SpawnV2: 36, + PaneRemoved: 37, } impl Pdu { @@ -511,6 +512,7 @@ impl Pdu { Some(*pane_id) } Pdu::SetClipboard(SetClipboard { pane_id, .. }) => Some(*pane_id), + Pdu::PaneRemoved(PaneRemoved { pane_id }) => Some(*pane_id), _ => None, } } @@ -589,6 +591,11 @@ pub struct SpawnV2 { pub size: PtySize, } +#[derive(Deserialize, Serialize, PartialEq, Debug)] +pub struct PaneRemoved { + pub pane_id: PaneId, +} + #[derive(Deserialize, Serialize, PartialEq, Debug)] pub struct KillPane { pub pane_id: PaneId, diff --git a/mux/src/lib.rs b/mux/src/lib.rs index 827933d0e..b933ff20b 100644 --- a/mux/src/lib.rs +++ b/mux/src/lib.rs @@ -36,6 +36,7 @@ use crate::activity::Activity; #[derive(Clone, Debug)] pub enum MuxNotification { PaneOutput(PaneId), + PaneRemoved(PaneId), WindowCreated(WindowId), WindowInvalidated(WindowId), Alert { @@ -383,6 +384,7 @@ impl Mux { if let Some(pane) = self.panes.borrow_mut().remove(&pane_id) { log::debug!("killing pane {}", pane_id); pane.kill(); + self.notify(MuxNotification::PaneRemoved(pane_id)); } } diff --git a/wezterm-client/src/pane/clienttab.rs b/wezterm-client/src/pane/clienttab.rs index 3b6c70daa..0b15ad973 100644 --- a/wezterm-client/src/pane/clienttab.rs +++ b/wezterm-client/src/pane/clienttab.rs @@ -113,6 +113,12 @@ impl ClientPane { log::error!("ClientPane: Ignoring SetClipboard request {:?}", clipboard); } }, + Pdu::PaneRemoved(PaneRemoved { pane_id }) => { + log::trace!("remote pane {} has been removed", pane_id); + self.renderable.borrow().inner.borrow_mut().dead = true; + let mux = mux::Mux::get().unwrap(); + mux.prune_dead_windows(); + } _ => bail!("unhandled unilateral pdu: {:?}", pdu), }; Ok(()) diff --git a/wezterm-client/src/pane/renderable.rs b/wezterm-client/src/pane/renderable.rs index 74a8987e7..0a7066b9f 100644 --- a/wezterm-client/src/pane/renderable.rs +++ b/wezterm-client/src/pane/renderable.rs @@ -347,11 +347,9 @@ impl RenderableInner { dirty.remove(stable_row); } - if !dirty.is_empty() { - Mux::get() - .unwrap() - .notify(mux::MuxNotification::PaneOutput(self.local_pane_id)); - } + Mux::get() + .unwrap() + .notify(mux::MuxNotification::PaneOutput(self.local_pane_id)); let mut to_fetch = RangeSet::new(); for r in dirty.iter() { diff --git a/wezterm-gui/src/frontend.rs b/wezterm-gui/src/frontend.rs index 2eb66ef98..48abbb8ff 100644 --- a/wezterm-gui/src/frontend.rs +++ b/wezterm-gui/src/frontend.rs @@ -38,6 +38,7 @@ impl GuiFrontEnd { }) .detach(); } + MuxNotification::PaneRemoved(_) => {} MuxNotification::WindowInvalidated(_) => {} MuxNotification::PaneOutput(_) => {} MuxNotification::Alert { diff --git a/wezterm-mux-server-impl/src/dispatch.rs b/wezterm-mux-server-impl/src/dispatch.rs index 4b423e3ca..d86bc585b 100644 --- a/wezterm-mux-server-impl/src/dispatch.rs +++ b/wezterm-mux-server-impl/src/dispatch.rs @@ -81,6 +81,12 @@ where Ok(Item::Notif(MuxNotification::PaneOutput(pane_id))) => { handler.schedule_pane_push(pane_id); } + Ok(Item::Notif(MuxNotification::PaneRemoved(pane_id))) => { + Pdu::PaneRemoved(codec::PaneRemoved { pane_id }) + .encode_async(&mut stream, 0) + .await?; + stream.flush().await.context("flushing PDU to client")?; + } Ok(Item::Notif(MuxNotification::Alert { pane_id, alert: _ })) => { // FIXME: queue notification to send to client! handler.schedule_pane_push(pane_id); diff --git a/wezterm-mux-server-impl/src/sessionhandler.rs b/wezterm-mux-server-impl/src/sessionhandler.rs index 9cd458b20..ac1433cc0 100644 --- a/wezterm-mux-server-impl/src/sessionhandler.rs +++ b/wezterm-mux-server-impl/src/sessionhandler.rs @@ -532,6 +532,7 @@ impl SessionHandler { | Pdu::GetLinesResponse { .. } | Pdu::GetCodecVersionResponse { .. } | Pdu::GetTlsCredsResponse { .. } + | Pdu::PaneRemoved { .. } | Pdu::ErrorResponse { .. } => { send_response(Err(anyhow!("expected a request, got {:?}", decoded.pdu))) }