diff --git a/codec/src/lib.rs b/codec/src/lib.rs index f8d2f1362ea0..c0f753f5501a 100644 --- a/codec/src/lib.rs +++ b/codec/src/lib.rs @@ -492,6 +492,7 @@ pdu! { GetPaneDirection: 60, GetPaneDirectionResponse: 61, AdjustPaneSize: 62, + TogglePaneZoomState: 63, } impl Pdu { @@ -852,6 +853,11 @@ pub struct SetPaneZoomed { pub zoomed: bool, } +#[derive(Deserialize, Serialize, PartialEq, Debug)] +pub struct TogglePaneZoomState { + pub pane_id: PaneId, +} + #[derive(Deserialize, Serialize, PartialEq, Debug)] pub struct GetPaneDirection { pub pane_id: PaneId, diff --git a/wezterm-client/src/client.rs b/wezterm-client/src/client.rs index 8a7145574f3d..83aca60c0f85 100644 --- a/wezterm-client/src/client.rs +++ b/wezterm-client/src/client.rs @@ -1328,4 +1328,5 @@ impl Client { GetPaneDirectionResponse ); rpc!(adjust_pane_size, AdjustPaneSize, UnitResponse); + rpc!(toggle_pane_zoom_state, TogglePaneZoomState, UnitResponse); } diff --git a/wezterm-mux-server-impl/src/sessionhandler.rs b/wezterm-mux-server-impl/src/sessionhandler.rs index 31df12dad8c2..4413a7700e8e 100644 --- a/wezterm-mux-server-impl/src/sessionhandler.rs +++ b/wezterm-mux-server-impl/src/sessionhandler.rs @@ -945,6 +945,26 @@ impl SessionHandler { .detach(); } + Pdu::TogglePaneZoomState(TogglePaneZoomState { pane_id }) => { + spawn_into_main_thread(async move { + catch( + move || { + let mux = Mux::get(); + let (_domain_id, _window_id, tab_id) = mux + .resolve_pane_id(pane_id) + .ok_or_else(|| anyhow!("no such pane {}", pane_id))?; + let tab = mux + .get_tab(tab_id) + .ok_or_else(|| anyhow!("no such tab {}", tab_id))?; + tab.toggle_zoom(); + Ok(Pdu::UnitResponse(UnitResponse {})) + }, + send_response, + ) + }) + .detach(); + } + Pdu::Invalid { .. } => send_response(Err(anyhow!("invalid PDU {:?}", decoded.pdu))), Pdu::Pong { .. } | Pdu::ListPanesResponse { .. } @@ -1021,7 +1041,7 @@ async fn split_pane(split: SplitPane, client_id: Option>) -> anyho Ok::(Pdu::SpawnResponse(SpawnResponse { pane_id: pane.pane_id(), - tab_id: tab_id, + tab_id, window_id, size, })) diff --git a/wezterm/src/cli/mod.rs b/wezterm/src/cli/mod.rs index 0dbd5bd09cfa..7c324c511084 100644 --- a/wezterm/src/cli/mod.rs +++ b/wezterm/src/cli/mod.rs @@ -22,6 +22,7 @@ mod set_window_title; mod spawn_command; mod split_pane; mod tls_creds; +mod toggle_pane_zoom_state; #[derive(Debug, Parser, Clone, Copy)] enum CliOutputFormatKind { @@ -159,6 +160,10 @@ Outputs the pane-id for the newly created pane on success" /// Rename a workspace #[command(name = "rename-workspace", rename_all = "kebab")] RenameWorkspace(rename_workspace::RenameWorkspace), + + /// Toggle the zoom state of the current pane + #[command(name = "toggle-pane-zoom-state", rename_all = "kebab")] + TogglePaneZoomState(toggle_pane_zoom_state::TogglePaneZoomState), } async fn run_cli_async(opts: &crate::Opt, cli: CliCommand) -> anyhow::Result<()> { @@ -194,6 +199,7 @@ async fn run_cli_async(opts: &crate::Opt, cli: CliCommand) -> anyhow::Result<()> CliSubCommand::SetTabTitle(cmd) => cmd.run(client).await, CliSubCommand::SetWindowTitle(cmd) => cmd.run(client).await, CliSubCommand::RenameWorkspace(cmd) => cmd.run(client).await, + CliSubCommand::TogglePaneZoomState(cmd) => cmd.run(client).await, } } diff --git a/wezterm/src/cli/toggle_pane_zoom_state.rs b/wezterm/src/cli/toggle_pane_zoom_state.rs new file mode 100644 index 000000000000..9320ec552c5e --- /dev/null +++ b/wezterm/src/cli/toggle_pane_zoom_state.rs @@ -0,0 +1,18 @@ +use crate::cli::resolve_pane_id; +use clap::Parser; +use mux::pane::PaneId; +use wezterm_client::client::Client; + +#[derive(Debug, Parser, Clone)] +pub struct TogglePaneZoomState {} + +impl TogglePaneZoomState { + pub async fn run(&self, client: Client) -> anyhow::Result<()> { + let none: Option = None; + let pane_id = resolve_pane_id(&client, none).await?; + client + .toggle_pane_zoom_state(codec::TogglePaneZoomState { pane_id }) + .await?; + Ok(()) + } +}