mux: adjust window size after attach
Since the initial attach is async, we'd create the window at the default/initial size and then never reconcile the size of the remote tabs once they'd attached. This commit introduces an event that allows the gui window to do that. The action that it takes is to take the max width and height between its current size and the size of a newly added tab and resizes to that new size, if it changed. refs: https://github.com/wez/wezterm/issues/2133 refs: https://github.com/wez/wezterm/issues/2351
This commit is contained in:
1 parent
1212865974
commit
ef532fc7e5
5 files changed
+42
-2
No files matched your search
@@ -72,6 +72,10 @@ pub enum MuxNotification {
|
||||
name: Option<String>,
|
||||
data: Arc<Vec<u8>>,
|
||||
},
|
||||
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<Tab>, 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(())
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ impl GuiFrontEnd {
|
||||
})
|
||||
.detach();
|
||||
}
|
||||
MuxNotification::TabAddedToWindow { .. } => {}
|
||||
MuxNotification::PaneRemoved(_) => {}
|
||||
MuxNotification::WindowInvalidated(_) => {}
|
||||
MuxNotification::PaneOutput(_) => {}
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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))) => {}
|
||||
|
||||
Reference in new issue
Block a user