diff options
| author | Aram Drevekenin <aram@poor.dev> | 2026-07-27 18:24:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-27 18:24:37 +0200 |
| commit | ea07e2d5b6bbc9ea6f9c765b0838b3e91156a58d (patch) | |
| tree | 4a8fac8a9b27f2a8b32b3af61a3b5419b9937c81 /zellij-utils/src | |
| parent | Switch from the unmaintained daemonize crate to a maintained fork (#4512) (diff) | |
| download | sl0ppij-ea07e2d5b6bbc9ea6f9c765b0838b3e91156a58d.tar.gz sl0ppij-ea07e2d5b6bbc9ea6f9c765b0838b3e91156a58d.tar.xz sl0ppij-ea07e2d5b6bbc9ea6f9c765b0838b3e91156a58d.zip | |
Nested session handling (#5417)
* fix: theme query and updated pixel dimensions
* add no-ui-fullscreen key/action/capability
* protocol core
* integration test harness
* fix integration tests
* fix flaky tests
* nested ui (dimming) and directional focus initial implementation
* integration tests for nested ui dimming and directional focus
* initial full screen nesteed implementation
* fix: keep hidden floating panes hidden across nested no-ui fullscreen
* fix integration tests
* no ui fullscreen integration tests
* hardening behavior/tests
* fix(nested): re-derive descend/dim on host tab switch and new-tab so clicking dimmed chrome ascends
* initial modal implementation
* initial ui improvements
* fix integration tests
* improve nested selection ui
* nested session modal refactoring and tests
* improve integration test speed somewhat
* some ui adjustments
* simplify full/auto nested session handling
* hints in compact-bar
* guest stdin leak fix
* allow floating panes to be fullscreen
* make nested session handling configurable
* protocol reannounce
* refactor: naming confusion
* improve ux somewhat
* rustfmt
* merge fixes
* improve integration test rate limiting (fix ci)
* add pr
Diffstat (limited to 'zellij-utils/src')
36 files changed, 1414 insertions, 14 deletions
diff --git a/zellij-utils/src/cli.rs b/zellij-utils/src/cli.rs index e09755e0..6d7f0bc2 100644 --- a/zellij-utils/src/cli.rs +++ b/zellij-utils/src/cli.rs @@ -900,6 +900,18 @@ pub enum CliAction { #[clap(short, long, value_parser)] pane_id: Option<String>, }, + #[clap( + about = "Toggle between fullscreen over the entire display (including the UI bars) and normal layout" + )] + ToggleNoUiFullscreen { + #[clap( + short, + long, + value_parser, + help = "Target a specific pane by ID (eg. terminal_1, plugin_2, or 3)" + )] + pane_id: Option<String>, + }, /// Toggle frames around panes in the UI TogglePaneFrames, SetPaneFrameStyle { diff --git a/zellij-utils/src/client_server_contract/client_to_server.proto b/zellij-utils/src/client_server_contract/client_to_server.proto index bc7c0c06..d3b59483 100644 --- a/zellij-utils/src/client_server_contract/client_to_server.proto +++ b/zellij-utils/src/client_server_contract/client_to_server.proto @@ -26,6 +26,7 @@ message ClientToServerMsg { ForwardedReplyFromHostMsg forwarded_reply_from_host = 19; HostTerminalThemeChangedMsg host_terminal_theme_changed = 20; SoftKeyboardVisibilityChangedMsg soft_keyboard_visibility_changed = 21; + NestedSessionFrameFromHostMsg nested_session_frame_from_host = 22; } } @@ -137,3 +138,7 @@ enum HostTerminalThemeIndication { message SoftKeyboardVisibilityChangedMsg { bool visible = 1; } + +message NestedSessionFrameFromHostMsg { + bytes payload_bytes = 1; +} diff --git a/zellij-utils/src/client_server_contract/common_types.proto b/zellij-utils/src/client_server_contract/common_types.proto index a6debf92..1f1da83f 100644 --- a/zellij-utils/src/client_server_contract/common_types.proto +++ b/zellij-utils/src/client_server_contract/common_types.proto @@ -280,6 +280,11 @@ message Action { ToggleMobileModeAction toggle_mobile_mode = 140; FocusLastPaneAction focus_last_pane = 141; SetPaneFrameStyleAction set_pane_frame_style = 142; + ToggleFocusNoUiFullscreenAction toggle_focus_no_ui_fullscreen = 143; + ToggleNoUiFullscreenByPaneIdAction toggle_no_ui_fullscreen_by_pane_id = 144; + FocusHostSessionAction focus_host_session = 145; + ToggleHostFullscreenAction toggle_host_fullscreen = 146; + FocusGuestSessionAction focus_guest_session = 147; } } @@ -290,6 +295,9 @@ message QuitAction {} message FocusNextPaneAction {} message FocusPreviousPaneAction {} message FocusLastPaneAction {} +message FocusHostSessionAction {} +message FocusGuestSessionAction {} +message ToggleHostFullscreenAction {} message SwitchFocusAction {} message MovePaneBackwardsAction {} message ClearScreenAction {} @@ -307,6 +315,7 @@ message PageScrollDownAction {} message HalfPageScrollUpAction {} message HalfPageScrollDownAction {} message ToggleFocusFullscreenAction {} +message ToggleFocusNoUiFullscreenAction {} message TogglePaneFramesAction {} message SetPaneFrameStyleAction { string style = 1; @@ -1181,7 +1190,6 @@ message Options { optional bool show_startup_tips = 31; optional bool show_release_notes = 32; optional bool advanced_mouse_actions = 33; - optional bool mouse_scroll_resize = 53; optional string web_server_ip = 34; optional uint32 web_server_port = 35; optional string web_server_cert = 36; @@ -1201,6 +1209,8 @@ message Options { optional uint32 mobile_threshold_rows = 50; optional string pane_frame_style = 51; optional bool stacked_pane_list = 52; + optional NestedSessionHandling nested_session_handling = 53; + optional bool mouse_scroll_resize = 54; } enum OnForceClose { @@ -1235,6 +1245,14 @@ enum MobileLayout { MOBILE_LAYOUT_NEVER = 3; } +enum NestedSessionHandling { + NESTED_SESSION_HANDLING_UNSPECIFIED = 0; + NESTED_SESSION_HANDLING_ASK = 1; + NESTED_SESSION_HANDLING_FULLSCREEN = 2; + NESTED_SESSION_HANDLING_DESCEND = 3; + NESTED_SESSION_HANDLING_NEVER = 4; +} + // Pane-targeting action messages message ScrollUpByPaneIdAction { PaneId pane_id = 1; } message ScrollDownByPaneIdAction { PaneId pane_id = 1; } @@ -1253,6 +1271,7 @@ message EditScrollbackByPaneIdAction { bool ansi = 2; } message ToggleFullscreenByPaneIdAction { PaneId pane_id = 1; } +message ToggleNoUiFullscreenByPaneIdAction { PaneId pane_id = 1; } message TogglePaneEmbedOrFloatingByPaneIdAction { PaneId pane_id = 1; } message CloseFocusByPaneIdAction { PaneId pane_id = 1; } message RenamePaneByPaneIdAction { PaneId pane_id = 1; bytes name = 2; } diff --git a/zellij-utils/src/client_server_contract/server_to_client.proto b/zellij-utils/src/client_server_contract/server_to_client.proto index a8c4779d..0c7e9aec 100644 --- a/zellij-utils/src/client_server_contract/server_to_client.proto +++ b/zellij-utils/src/client_server_contract/server_to_client.proto @@ -22,6 +22,7 @@ message ServerToClientMsg { SubscribedPaneClosedMsg subscribed_pane_closed = 15; ForwardQueryToHostMsg forward_query_to_host = 16; SetSoftKeyboardMsg set_soft_keyboard = 17; + EmitNestedSessionFrameMsg emit_nested_session_frame = 18; } } @@ -99,3 +100,7 @@ message ForwardQueryToHostMsg { message SetSoftKeyboardMsg { bool on = 1; } + +message EmitNestedSessionFrameMsg { + bytes payload_bytes = 1; +} diff --git a/zellij-utils/src/data.rs b/zellij-utils/src/data.rs index 758e2ab3..62f95a06 100644 --- a/zellij-utils/src/data.rs +++ b/zellij-utils/src/data.rs @@ -254,6 +254,7 @@ impl FromStr for BareKey { "end" => Ok(BareKey::End), "backspace" => Ok(BareKey::Backspace), "delete" => Ok(BareKey::Delete), + "del" => Ok(BareKey::Delete), "insert" => Ok(BareKey::Insert), "f1" => Ok(BareKey::F(1)), "f2" => Ok(BareKey::F(2)), @@ -1751,6 +1752,12 @@ pub struct ModeInfo { pub web_server_port: Option<u16>, pub web_server_capability: Option<bool>, pub pane_frame_style: Option<PaneFrameStyle>, + pub session_dimmed: Option<bool>, + pub session_ancestry: Vec<String>, + pub host_fullscreen: Option<bool>, + pub nested_ascend_keys: Vec<KeyWithModifier>, + pub session_ascended: Option<bool>, + pub nested_descend_keys: Vec<KeyWithModifier>, } impl ModeInfo { @@ -3416,6 +3423,7 @@ pub enum PluginCommand { PageScrollUp, PageScrollDown, ToggleFocusFullscreen, + ToggleFocusNoUiFullscreen, TogglePaneFrames, SetPaneFrameStyle(PaneFrameStyle), TogglePaneEmbedOrEject, @@ -3645,6 +3653,7 @@ pub enum PluginCommand { }, SetShadowFocus(PaneId), ExitMobileMode, + FocusHostSession, } // Response type for plugin API methods that open a pane in a new tab diff --git a/zellij-utils/src/errors.rs b/zellij-utils/src/errors.rs index 8ffe0907..ae2cc239 100644 --- a/zellij-utils/src/errors.rs +++ b/zellij-utils/src/errors.rs @@ -281,6 +281,7 @@ pub enum ScreenContext { CloseFocusedPane, ToggleActiveSyncTab, ToggleActiveTerminalFullscreen, + ToggleActiveTerminalNoUiFullscreen, TogglePaneFrames, SetPaneFrameStyle, SetSelectable, @@ -314,6 +315,10 @@ pub enum ScreenContext { TerminalForegroundColor, TerminalColorRegisters, ForwardHostQuery, + NestedSessionMessageFromPane, + NestedGuestPingTick, + NestedSessionMessageFromHost, + GuestModalChoice, ForwardedReplyFromHost, ResumePaneAfterForward, HostTerminalThemeChanged, @@ -453,6 +458,7 @@ pub enum ScreenContext { ClearScreenWithPaneId, EditScrollbackWithPaneId, ToggleFullscreenWithPaneId, + ToggleNoUiFullscreenWithPaneId, TogglePaneEmbedOrFloatingWithPaneId, CloseFocusWithPaneId, RenamePaneWithPaneId, @@ -475,6 +481,9 @@ pub enum ScreenContext { ReevaluateMobileMode, SetSoftKeyboard, SetShadowFocus, + FocusHostSession, + FocusGuestSession, + ToggleHostFullscreen, } /// Stack call representations corresponding to the different types of [`PtyInstruction`]s. @@ -586,6 +595,7 @@ pub enum ClientContext { RenamedSession, ConfigFileUpdated, ForwardQueryToHost, + EmitNestedSessionFrame, } /// Stack call representations corresponding to the different types of [`ServerInstruction`]s. @@ -622,6 +632,8 @@ pub enum ServerContext { SendWebClientsForbidden, ClearMouseHelpText, ForwardQueryToHost, + KeyPassthroughChanged, + EmitNestedSessionFrameToClient, } #[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)] @@ -653,6 +665,8 @@ pub enum BackgroundJobContext { FlashTabBell, StopFlashTabBell, MobileGateTimeout, + StartNestedGuestPing, + StopNestedGuestPing, Exit, } diff --git a/zellij-utils/src/input/actions.rs b/zellij-utils/src/input/actions.rs index c0e953b6..95409609 100644 --- a/zellij-utils/src/input/actions.rs +++ b/zellij-utils/src/input/actions.rs @@ -216,6 +216,7 @@ pub enum Action { HalfPageScrollDown, /// Toggle between fullscreen focus pane and normal layout. ToggleFocusFullscreen, + ToggleFocusNoUiFullscreen, /// Toggle frames around panes in the UI TogglePaneFrames, SetPaneFrameStyle(PaneFrameStyle), @@ -508,6 +509,9 @@ pub enum Action { BreakPane, BreakPaneRight, BreakPaneLeft, + FocusHostSession, + FocusGuestSession, + ToggleHostFullscreen, RenameSession { name: String, }, @@ -623,6 +627,9 @@ pub enum Action { ToggleFocusFullscreenByPaneId { pane_id: PaneId, }, + ToggleFocusNoUiFullscreenByPaneId { + pane_id: PaneId, + }, TogglePaneEmbedOrFloatingByPaneId { pane_id: PaneId, }, @@ -1018,6 +1025,16 @@ impl Action { }, None => Ok(vec![Action::ToggleFocusFullscreen]), }, + CliAction::ToggleNoUiFullscreen { pane_id } => match pane_id { + Some(pane_id_str) => { + let pane_id = PaneId::from_str(&pane_id_str) + .map_err(|_| format!( + "Malformed pane id: {pane_id_str}, expecting either a bare integer (eg. 1), a terminal pane id (eg. terminal_1) or a plugin pane id (eg. plugin_1)" + ))?; + Ok(vec![Action::ToggleFocusNoUiFullscreenByPaneId { pane_id }]) + }, + None => Ok(vec![Action::ToggleFocusNoUiFullscreen]), + }, CliAction::TogglePaneFrames => Ok(vec![Action::TogglePaneFrames]), CliAction::SetPaneFrameStyle { style } => Ok(vec![Action::SetPaneFrameStyle(style)]), CliAction::ToggleActiveSyncTab { tab_id } => match tab_id { @@ -2883,6 +2900,33 @@ mod tests { assert!(matches!(actions[0], Action::ToggleFocusFullscreen)); } + #[test] + fn test_toggle_no_ui_fullscreen_with_pane_id() { + let cli_action = CliAction::ToggleNoUiFullscreen { + pane_id: Some("terminal_16".to_string()), + }; + let result = Action::actions_from_cli(cli_action, Box::new(|| PathBuf::from("/tmp")), None); + assert!(result.is_ok()); + let actions = result.unwrap(); + assert_eq!(actions.len(), 1); + match &actions[0] { + Action::ToggleFocusNoUiFullscreenByPaneId { pane_id } => { + assert!(matches!(pane_id, PaneId::Terminal(16))); + }, + _ => panic!("Expected ToggleFocusNoUiFullscreenByPaneId action"), + } + } + + #[test] + fn test_toggle_no_ui_fullscreen_without_pane_id() { + let cli_action = CliAction::ToggleNoUiFullscreen { pane_id: None }; + let result = Action::actions_from_cli(cli_action, Box::new(|| PathBuf::from("/tmp")), None); + assert!(result.is_ok()); + let actions = result.unwrap(); + assert_eq!(actions.len(), 1); + assert!(matches!(actions[0], Action::ToggleFocusNoUiFullscreen)); + } + // 15. TogglePaneEmbedOrFloating #[test] fn test_toggle_pane_embed_or_floating_with_pane_id() { diff --git a/zellij-utils/src/input/keybinds.rs b/zellij-utils/src/input/keybinds.rs index c3943182..2cbdeee7 100644 --- a/zellij-utils/src/input/keybinds.rs +++ b/zellij-utils/src/input/keybinds.rs @@ -116,6 +116,60 @@ impl Keybinds { } } +const MAX_SHORTCUT_SEARCH_DEPTH: usize = 4; + +pub fn shortcut_for_action( + keybinds: &KeybindsVec, + base_mode: InputMode, + is_target_action: impl Fn(&Action) -> bool, +) -> Option<Vec<KeyWithModifier>> { + let mode_binds = |mode: InputMode| -> Vec<(KeyWithModifier, Vec<Action>)> { + let mut binds = keybinds + .iter() + .find(|(bind_mode, _)| *bind_mode == mode) + .map(|(_, binds)| binds.clone()) + .unwrap_or_default(); + binds.sort_by(|(a, _), (b, _)| a.cmp(b)); + binds + }; + let mut visited: Vec<InputMode> = vec![base_mode]; + let mut queue: Vec<(InputMode, Vec<KeyWithModifier>)> = vec![(base_mode, vec![])]; + for _ in 0..MAX_SHORTCUT_SEARCH_DEPTH { + let mut next_queue: Vec<(InputMode, Vec<KeyWithModifier>)> = vec![]; + for (mode, path) in &queue { + for (key, actions) in mode_binds(*mode) { + if actions.iter().any(&is_target_action) { + let mut shortcut = path.clone(); + shortcut.push(key); + return Some(shortcut); + } + } + } + for (mode, path) in &queue { + for (key, actions) in mode_binds(*mode) { + for action in &actions { + if let Action::SwitchToMode { + input_mode: next_mode, + } = action + { + if !visited.contains(next_mode) { + visited.push(*next_mode); + let mut next_path = path.clone(); + next_path.push(key.clone()); + next_queue.push((*next_mode, next_path)); + } + } + } + } + } + if next_queue.is_empty() { + return None; + } + queue = next_queue; + } + None +} + // we need to do this because [10] in standard STDIN, [10] is both Enter (without a carriage // return) and ctrl-j - so here, if ctrl-j is bound we return its bound action, and otherwise we // just write the raw bytes to the terminal and let whichever program is there decide what they are diff --git a/zellij-utils/src/input/mod.rs b/zellij-utils/src/input/mod.rs index 0934287e..3ca7508f 100644 --- a/zellij-utils/src/input/mod.rs +++ b/zellij-utils/src/input/mod.rs @@ -55,6 +55,12 @@ mod not_wasm { web_server_port: None, web_server_capability: None, pane_frame_style: None, + session_dimmed: None, + session_ancestry: vec![], + host_fullscreen: None, + nested_ascend_keys: vec![], + session_ascended: None, + nested_descend_keys: vec![], } } diff --git a/zellij-utils/src/input/options.rs b/zellij-utils/src/input/options.rs index da5f0248..194ab24c 100644 --- a/zellij-utils/src/input/options.rs +++ b/zellij-utils/src/input/options.rs @@ -75,6 +75,37 @@ impl MobileLayoutConfiguration { } } +#[derive(Copy, Clone, Debug, PartialEq, Eq, Deserialize, Serialize, ArgEnum)] +pub enum NestedSessionHandling { + #[serde(alias = "ask")] + Ask, + #[serde(alias = "fullscreen")] + Fullscreen, + #[serde(alias = "descend")] + Descend, + #[serde(alias = "never")] + Never, +} + +impl Default for NestedSessionHandling { + fn default() -> Self { + Self::Ask + } +} + +impl FromStr for NestedSessionHandling { + type Err = String; + fn from_str(s: &str) -> Result<Self, Self::Err> { + match s { + "Ask" | "ask" => Ok(Self::Ask), + "Fullscreen" | "fullscreen" => Ok(Self::Fullscreen), + "Descend" | "descend" => Ok(Self::Descend), + "Never" | "never" => Ok(Self::Never), + _ => Err(format!("No such nested_session_handling: {}", s)), + } + } +} + impl Default for OnForceClose { fn default() -> Self { Self::Detach @@ -415,6 +446,12 @@ pub struct Options { #[clap(long, value_parser)] #[serde(default)] pub mobile_threshold_rows: Option<u16>, + + /// How to handle a nested Zellij session detected inside a pane + /// (ask, fullscreen, descend, never) + #[clap(long, arg_enum, hide_possible_values = true, value_parser)] + #[serde(default)] + pub nested_session_handling: Option<NestedSessionHandling>, } #[derive(ArgEnum, Deserialize, Serialize, Debug, Clone, Copy, PartialEq)] @@ -527,6 +564,9 @@ impl Options { let mobile_layout = other.mobile_layout.or(self.mobile_layout); let mobile_threshold_cols = other.mobile_threshold_cols.or(self.mobile_threshold_cols); let mobile_threshold_rows = other.mobile_threshold_rows.or(self.mobile_threshold_rows); + let nested_session_handling = other + .nested_session_handling + .or(self.nested_session_handling); Options { simplified_ui, @@ -582,6 +622,7 @@ impl Options { mobile_layout, mobile_threshold_cols, mobile_threshold_rows, + nested_session_handling, } } @@ -674,6 +715,9 @@ impl Options { let mobile_layout = other.mobile_layout.or(self.mobile_layout); let mobile_threshold_cols = other.mobile_threshold_cols.or(self.mobile_threshold_cols); let mobile_threshold_rows = other.mobile_threshold_rows.or(self.mobile_threshold_rows); + let nested_session_handling = other + .nested_session_handling + .or(self.nested_session_handling); Options { simplified_ui, @@ -729,6 +773,7 @@ impl Options { mobile_layout, mobile_threshold_cols, mobile_threshold_rows, + nested_session_handling, } } diff --git a/zellij-utils/src/ipc.rs b/zellij-utils/src/ipc.rs index d5edbbb4..2e36cc96 100644 --- a/zellij-utils/src/ipc.rs +++ b/zellij-utils/src/ipc.rs @@ -176,6 +176,9 @@ pub enum ClientToServerMsg { SoftKeyboardVisibilityChanged { visible: bool, }, + NestedSessionFrameFromHost { + payload_bytes: Vec<u8>, + }, } // Types of messages sent from the server to the client @@ -227,6 +230,9 @@ pub enum ServerToClientMsg { token: u32, query_bytes: Vec<u8>, }, + EmitNestedSessionFrame { + payload_bytes: Vec<u8>, + }, } #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] diff --git a/zellij-utils/src/ipc/protobuf_conversion.rs b/zellij-utils/src/ipc/protobuf_conversion.rs index c129b6f7..6c0adc2b 100644 --- a/zellij-utils/src/ipc/protobuf_conversion.rs +++ b/zellij-utils/src/ipc/protobuf_conversion.rs @@ -5,19 +5,19 @@ use crate::{ client_to_server_msg, server_to_client_msg, ActionMsg, AttachClientMsg, AttachWatcherClientMsg, BackgroundColorMsg, CliPipeOutputMsg, ClientExitedMsg, ClientToServerMsg as ProtoClientToServerMsg, ColorRegistersMsg, ConfigFileUpdatedMsg, - ConnStatusMsg, ConnectedMsg, DesktopNotificationResponseMsg, DetachSessionMsg, ExitMsg, - ExitReason as ProtoExitReason, FailedToStartWebServerMsg, FirstClientConnectedMsg, - ForegroundColorMsg, ForwardQueryToHostMsg, ForwardedReplyFromHostMsg, - HostTerminalThemeChangedMsg, + ConnStatusMsg, ConnectedMsg, DesktopNotificationResponseMsg, DetachSessionMsg, + EmitNestedSessionFrameMsg, ExitMsg, ExitReason as ProtoExitReason, + FailedToStartWebServerMsg, FirstClientConnectedMsg, ForegroundColorMsg, + ForwardQueryToHostMsg, ForwardedReplyFromHostMsg, HostTerminalThemeChangedMsg, HostTerminalThemeIndication as ProtoHostTerminalThemeIndication, InputMode as ProtoInputMode, KeyMsg, KillSessionMsg, LayoutMetadata as ProtoLayoutMetadata, - LogErrorMsg, LogMsg, PaneMetadata as ProtoPaneMetadata, PaneRenderUpdateMsg, - QueryTerminalSizeMsg, RenamedSessionMsg, RenderMsg, ResizeCause as ProtoResizeCause, - ServerToClientMsg as ProtoServerToClientMsg, SetSoftKeyboardMsg, - SoftKeyboardVisibilityChangedMsg, StartWebServerMsg, SubscribeToPaneRendersMsg, - SubscribedPaneClosedMsg, SwitchSessionMsg, TabMetadata as ProtoTabMetadata, - TerminalPixelDimensionsMsg, TerminalResizeMsg, UnblockCliPipeInputMsg, - UnblockInputThreadMsg, WebServerStartedMsg, + LogErrorMsg, LogMsg, NestedSessionFrameFromHostMsg, PaneMetadata as ProtoPaneMetadata, + PaneRenderUpdateMsg, QueryTerminalSizeMsg, RenamedSessionMsg, RenderMsg, + ResizeCause as ProtoResizeCause, ServerToClientMsg as ProtoServerToClientMsg, + SetSoftKeyboardMsg, SoftKeyboardVisibilityChangedMsg, StartWebServerMsg, + SubscribeToPaneRendersMsg, SubscribedPaneClosedMsg, SwitchSessionMsg, + TabMetadata as ProtoTabMetadata, TerminalPixelDimensionsMsg, TerminalResizeMsg, + UnblockCliPipeInputMsg, UnblockInputThreadMsg, WebServerStartedMsg, }, data::{HostTerminalThemeMode, InputMode, PaneId}, errors::prelude::*, @@ -156,6 +156,11 @@ impl From<ClientToServerMsg> for ProtoClientToServerMsg { SoftKeyboardVisibilityChangedMsg { visible }, ) }, + ClientToServerMsg::NestedSessionFrameFromHost { payload_bytes } => { + client_to_server_msg::Message::NestedSessionFrameFromHost( + NestedSessionFrameFromHostMsg { payload_bytes }, + ) + }, }; ProtoClientToServerMsg { @@ -306,6 +311,11 @@ impl TryFrom<ProtoClientToServerMsg> for ClientToServerMsg { visible: msg.visible, }) }, + Some(client_to_server_msg::Message::NestedSessionFrameFromHost(msg)) => { + Ok(ClientToServerMsg::NestedSessionFrameFromHost { + payload_bytes: msg.payload_bytes, + }) + }, None => Err(anyhow!("Empty ClientToServerMsg message")), } } @@ -394,6 +404,11 @@ impl From<ServerToClientMsg> for ProtoServerToClientMsg { ServerToClientMsg::SetSoftKeyboard { on } => { server_to_client_msg::Message::SetSoftKeyboard(SetSoftKeyboardMsg { on }) }, + ServerToClientMsg::EmitNestedSessionFrame { payload_bytes } => { + server_to_client_msg::Message::EmitNestedSessionFrame(EmitNestedSessionFrameMsg { + payload_bytes, + }) + }, }; ProtoServerToClientMsg { @@ -509,6 +524,11 @@ impl TryFrom<ProtoServerToClientMsg> for ServerToClientMsg { Some(server_to_client_msg::Message::SetSoftKeyboard(msg)) => { Ok(ServerToClientMsg::SetSoftKeyboard { on: msg.on }) }, + Some(server_to_client_msg::Message::EmitNestedSessionFrame(msg)) => { + Ok(ServerToClientMsg::EmitNestedSessionFrame { + payload_bytes: msg.payload_bytes, + }) + }, None => Err(anyhow!("Empty ServerToClientMsg message")), } } @@ -775,6 +795,18 @@ impl From<crate::input::options::Options> crate::input::options::PaneFrameStyle::Titles => "titles".to_owned(), crate::input::options::PaneFrameStyle::None => "none".to_owned(), }), + nested_session_handling: options.nested_session_handling.map(|n| { + use crate::client_server_contract::client_server_contract::NestedSessionHandling as ProtoNestedSessionHandling; + use crate::input::options::NestedSessionHandling; + match n { + NestedSessionHandling::Ask => ProtoNestedSessionHandling::Ask as i32, + NestedSessionHandling::Fullscreen => { + ProtoNestedSessionHandling::Fullscreen as i32 + }, + NestedSessionHandling::Descend => ProtoNestedSessionHandling::Descend as i32, + NestedSessionHandling::Never => ProtoNestedSessionHandling::Never as i32, + } + }), } } } @@ -788,7 +820,8 @@ impl TryFrom<crate::client_server_contract::client_server_contract::Options> ) -> Result<Self> { use crate::client_server_contract::client_server_contract::{ Clipboard as ProtoClipboard, MobileLayout as ProtoMobileLayout, - OnForceClose as ProtoOnForceClose, WebSharing as ProtoWebSharing, + NestedSessionHandling as ProtoNestedSessionHandling, OnForceClose as ProtoOnForceClose, + WebSharing as ProtoWebSharing, }; Ok(Self { @@ -897,6 +930,24 @@ impl TryFrom<crate::client_server_contract::client_server_contract::Options> .transpose()?, mobile_threshold_cols: options.mobile_threshold_cols.map(|v| v as u16), mobile_threshold_rows: options.mobile_threshold_rows.map(|v| v as u16), + nested_session_handling: options + .nested_session_handling + .map(|n| match ProtoNestedSessionHandling::from_i32(n) { + Some(ProtoNestedSessionHandling::Ask) => { + Ok(crate::input::options::NestedSessionHandling::Ask) + }, + Some(ProtoNestedSessionHandling::Fullscreen) => { + Ok(crate::input::options::NestedSessionHandling::Fullscreen) + }, + Some(ProtoNestedSessionHandling::Descend) => { + Ok(crate::input::options::NestedSessionHandling::Descend) + }, + Some(ProtoNestedSessionHandling::Never) => { + Ok(crate::input::options::NestedSessionHandling::Never) + }, + _ => Err(anyhow!("Invalid NestedSessionHandling value: {}", n)), + }) + .transpose()?, }) } } @@ -932,6 +983,8 @@ impl From<crate::input::actions::Action> EditFileAction, EditScrollbackAction, EditScrollbackByPaneIdAction, + FocusGuestSessionAction, + FocusHostSessionAction, FocusLastPaneAction, FocusNextPaneAction, FocusPaneByPaneIdAction, @@ -1031,9 +1084,12 @@ impl From<crate::input::actions::Action> ToggleFloatingPanesAction, ToggleFloatingPanesByTabIdAction, ToggleFocusFullscreenAction, + ToggleFocusNoUiFullscreenAction, ToggleFullscreenByPaneIdAction, ToggleGroupMarkingAction, + ToggleHostFullscreenAction, ToggleMouseModeAction, + ToggleNoUiFullscreenByPaneIdAction, TogglePaneBorderlessAction, TogglePaneEmbedOrFloatingAction, TogglePaneEmbedOrFloatingByPaneIdAction, @@ -1112,6 +1168,15 @@ impl From<crate::input::actions::Action> crate::input::actions::Action::FocusLastPane => { ActionType::FocusLastPane(FocusLastPaneAction {}) }, + crate::input::actions::Action::FocusHostSession => { + ActionType::FocusHostSession(FocusHostSessionAction {}) + }, + crate::input::actions::Action::FocusGuestSession => { + ActionType::FocusGuestSession(FocusGuestSessionAction {}) + }, + crate::input::actions::Action::ToggleHostFullscreen => { + ActionType::ToggleHostFullscreen(ToggleHostFullscreenAction {}) + }, crate::input::actions::Action::SwitchFocus => { ActionType::SwitchFocus(SwitchFocusAction {}) }, @@ -1192,6 +1257,9 @@ impl From<crate::input::actions::Action> crate::input::actions::Action::ToggleFocusFullscreen => { ActionType::ToggleFocusFullscreen(ToggleFocusFullscreenAction {}) }, + crate::input::actions::Action::ToggleFocusNoUiFullscreen => { + ActionType::ToggleFocusNoUiFullscreen(ToggleFocusNoUiFullscreenAction {}) + }, crate::input::actions::Action::TogglePaneFrames => { ActionType::TogglePaneFrames(TogglePaneFramesAction {}) }, @@ -1877,6 +1945,11 @@ impl From<crate::input::actions::Action> pane_id: Some(pane_id.into()), }) }, + crate::input::actions::Action::ToggleFocusNoUiFullscreenByPaneId { pane_id } => { + ActionType::ToggleNoUiFullscreenByPaneId(ToggleNoUiFullscreenByPaneIdAction { + pane_id: Some(pane_id.into()), + }) + }, crate::input::actions::Action::TogglePaneEmbedOrFloatingByPaneId { pane_id } => { ActionType::TogglePaneEmbedOrFloatingByPaneId( TogglePaneEmbedOrFloatingByPaneIdAction { @@ -2086,6 +2159,9 @@ impl TryFrom<crate::client_server_contract::client_server_contract::Action> ActionType::ToggleFocusFullscreen(_) => { Ok(crate::input::actions::Action::ToggleFocusFullscreen) }, + ActionType::ToggleFocusNoUiFullscreen(_) => { + Ok(crate::input::actions::Action::ToggleFocusNoUiFullscreen) + }, ActionType::TogglePaneFrames(_) => Ok(crate::input::actions::Action::TogglePaneFrames), ActionType::SetPaneFrameStyle(set_pane_frame_style_action) => { let style = crate::input::options::PaneFrameStyle::from_str( @@ -2552,6 +2628,13 @@ impl TryFrom<crate::client_server_contract::client_server_contract::Action> ActionType::BreakPane(_) => Ok(crate::input::actions::Action::BreakPane), ActionType::BreakPaneRight(_) => Ok(crate::input::actions::Action::BreakPaneRight), ActionType::BreakPaneLeft(_) => Ok(crate::input::actions::Action::BreakPaneLeft), + ActionType::FocusHostSession(_) => Ok(crate::input::actions::Action::FocusHostSession), + ActionType::FocusGuestSession(_) => { + Ok(crate::input::actions::Action::FocusGuestSession) + }, + ActionType::ToggleHostFullscreen(_) => { + Ok(crate::input::actions::Action::ToggleHostFullscreen) + }, ActionType::RenameSession(rename_session_action) => { Ok(crate::input::actions::Action::RenameSession { name: rename_session_action.name, @@ -2810,6 +2893,14 @@ impl TryFrom<crate::client_server_contract::client_server_contract::Action> .try_into()?, }, ), + ActionType::ToggleNoUiFullscreenByPaneId(a) => Ok( + crate::input::actions::Action::ToggleFocusNoUiFullscreenByPaneId { + pane_id: a + .pane_id + .ok_or_else(|| anyhow!("ToggleNoUiFullscreenByPaneId missing pane_id"))? + .try_into()?, + }, + ), ActionType::TogglePaneEmbedOrFloatingByPaneId(a) => Ok( crate::input::actions::Action::TogglePaneEmbedOrFloatingByPaneId { pane_id: a diff --git a/zellij-utils/src/ipc/tests/roundtrip_tests.rs b/zellij-utils/src/ipc/tests/roundtrip_tests.rs index 37214782..f8e6dc91 100644 --- a/zellij-utils/src/ipc/tests/roundtrip_tests.rs +++ b/zellij-utils/src/ipc/tests/roundtrip_tests.rs @@ -14,7 +14,8 @@ use crate::input::layout::{ }; use crate::input::mouse::{MouseEvent, MouseEventType}; use crate::input::options::{ - Clipboard, MobileLayoutConfiguration, OnForceClose, Options, PaneFrameStyle, + Clipboard, MobileLayoutConfiguration, NestedSessionHandling, OnForceClose, Options, + PaneFrameStyle, }; use crate::ipc::{ ClientToServerMsg, ColorRegister, ExitReason, PaneReference, PixelDimensions, ResizeCause, @@ -487,6 +488,7 @@ fn test_client_messages() { mobile_layout: Some(MobileLayoutConfiguration::Always), mobile_threshold_cols: Some(72), mobile_threshold_rows: Some(40), + nested_session_handling: Some(NestedSessionHandling::Fullscreen), }), layout: None, terminal_window_size: Size { rows: 80, cols: 42 }, @@ -678,6 +680,46 @@ fn test_client_messages() { }, is_web_client: true, }); + test_client_roundtrip!(ClientToServerMsg::FirstClientConnected { + cli_assets: CliAssets { + configuration_options: Some(Options { + nested_session_handling: Some(NestedSessionHandling::Ask), + ..Default::default() + }), + ..Default::default() + }, + is_web_client: true, + }); + test_client_roundtrip!(ClientToServerMsg::FirstClientConnected { + cli_assets: CliAssets { + configuration_options: Some(Options { + nested_session_handling: Some(NestedSessionHandling::Fullscreen), + ..Default::default() + }), + ..Default::default() + }, + is_web_client: true, + }); + test_client_roundtrip!(ClientToServerMsg::FirstClientConnected { + cli_assets: CliAssets { + configuration_options: Some(Options { + nested_session_handling: Some(NestedSessionHandling::Descend), + ..Default::default() + }), + ..Default::default() + }, + is_web_client: true, + }); + test_client_roundtrip!(ClientToServerMsg::FirstClientConnected { + cli_assets: CliAssets { + configuration_options: Some(Options { + nested_session_handling: Some(NestedSessionHandling::Never), + ..Default::default() + }), + ..Default::default() + }, + is_web_client: true, + }); test_client_roundtrip!(ClientToServerMsg::AttachClient { cli_assets: CliAssets::default(), tab_position_to_focus: None, @@ -708,6 +750,18 @@ fn test_client_messages() { }), is_web_client: true, }); + test_client_roundtrip!(ClientToServerMsg::AttachClient { + cli_assets: CliAssets { + configuration_options: Some(Options { + nested_session_handling: Some(NestedSessionHandling::Descend), + ..Default::default() + }), + ..Default::default() + }, + tab_position_to_focus: None, + pane_to_focus: None, + is_web_client: false, + }); // TODO: Action test_client_roundtrip!(ClientToServerMsg::Action { action: Action::Quit, @@ -1014,6 +1068,12 @@ fn test_client_messages() { is_cli_client: true, }); test_client_roundtrip!(ClientToServerMsg::Action { + action: Action::ToggleFocusNoUiFullscreen, + terminal_id: Some(1), + client_id: Some(100), + is_cli_client: true, + }); + test_client_roundtrip!(ClientToServerMsg::Action { action: Action::TogglePaneFrames, terminal_id: Some(1), client_id: Some(100), @@ -3506,6 +3566,14 @@ fn test_client_messages() { is_cli_client: true, }); test_client_roundtrip!(ClientToServerMsg::Action { + action: Action::ToggleFocusNoUiFullscreenByPaneId { + pane_id: PaneId::Terminal(1), + }, + terminal_id: Some(1), + client_id: Some(100), + is_cli_client: true, + }); + test_client_roundtrip!(ClientToServerMsg::Action { action: Action::TogglePaneEmbedOrFloatingByPaneId { pane_id: PaneId::Terminal(1), }, @@ -3640,6 +3708,12 @@ fn test_client_messages() { test_client_roundtrip!(ClientToServerMsg::HostTerminalThemeChanged { mode: HostTerminalThemeMode::Light, }); + test_client_roundtrip!(ClientToServerMsg::NestedSessionFrameFromHost { + payload_bytes: vec![], + }); + test_client_roundtrip!(ClientToServerMsg::NestedSessionFrameFromHost { + payload_bytes: (0u8..=255u8).collect(), + }); } fn test_server_messages() { @@ -3787,6 +3861,12 @@ fn test_server_messages() { token: u32::MAX, query_bytes: (0u8..=255u8).collect(), }); + test_server_roundtrip!(ServerToClientMsg::EmitNestedSessionFrame { + payload_bytes: vec![], + }); + test_server_roundtrip!(ServerToClientMsg::EmitNestedSessionFrame { + payload_bytes: (0u8..=255u8).collect(), + }); } #[test] diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index b16e7f12..4e7b3735 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -49,6 +49,9 @@ macro_rules! parse_kdl_action_arguments { "FocusNextPane" => Ok(Action::FocusNextPane), "FocusPreviousPane" => Ok(Action::FocusPreviousPane), "FocusLastPane" => Ok(Action::FocusLastPane), + "FocusHostSession" => Ok(Action::FocusHostSession), + "FocusGuestSession" => Ok(Action::FocusGuestSession), + "ToggleHostFullscreen" => Ok(Action::ToggleHostFullscreen), "SwitchFocus" => Ok(Action::SwitchFocus), "EditScrollback" => Ok(Action::EditScrollback { ansi: false }), "ScrollUp" => Ok(Action::ScrollUp), @@ -60,6 +63,7 @@ macro_rules! parse_kdl_action_arguments { "HalfPageScrollUp" => Ok(Action::HalfPageScrollUp), "HalfPageScrollDown" => Ok(Action::HalfPageScrollDown), "ToggleFocusFullscreen" => Ok(Action::ToggleFocusFullscreen), + "ToggleFocusNoUiFullscreen" => Ok(Action::ToggleFocusNoUiFullscreen), "TogglePaneFrames" => Ok(Action::TogglePaneFrames), "ToggleActiveSyncTab" => Ok(Action::ToggleActiveSyncTab), "TogglePaneEmbedOrFloating" => Ok(Action::TogglePaneEmbedOrFloating), @@ -744,6 +748,7 @@ impl Action { Action::HalfPageScrollUp => Some(KdlNode::new("HalfPageScrollUp")), Action::HalfPageScrollDown => Some(KdlNode::new("HalfPageScrollDown")), Action::ToggleFocusFullscreen => Some(KdlNode::new("ToggleFocusFullscreen")), + Action::ToggleFocusNoUiFullscreen => Some(KdlNode::new("ToggleFocusNoUiFullscreen")), Action::TogglePaneFrames => Some(KdlNode::new("TogglePaneFrames")), Action::SetPaneFrameStyle(style) => { let mut node = KdlNode::new("SetPaneFrameStyle"); @@ -1350,6 +1355,9 @@ impl Action { Action::SetDarkTheme => Some(KdlNode::new("SetDarkTheme")), Action::SetLightTheme => Some(KdlNode::new("SetLightTheme")), Action::ToggleTheme => Some(KdlNode::new("ToggleTheme")), + Action::FocusHostSession => Some(KdlNode::new("FocusHostSession")), + Action::FocusGuestSession => Some(KdlNode::new("FocusGuestSession")), + Action::ToggleHostFullscreen => Some(KdlNode::new("ToggleHostFullscreen")), _ => None, } } @@ -1541,6 +1549,15 @@ impl TryFrom<(&KdlNode, &Options)> for Action { "FocusLastPane" => { parse_kdl_action_arguments!(action_name, action_arguments, kdl_action) }, + "FocusHostSession" => { + parse_kdl_action_arguments!(action_name, action_arguments, kdl_action) + }, + "FocusGuestSession" => { + parse_kdl_action_arguments!(action_name, action_arguments, kdl_action) + }, + "ToggleHostFullscreen" => { + parse_kdl_action_arguments!(action_name, action_arguments, kdl_action) + }, "SwitchFocus" => parse_kdl_action_arguments!(action_name, action_arguments, kdl_action), "EditScrollback" => { let ansi = crate::kdl_get_bool_property_or_child_value!(kdl_action, "ansi") @@ -1570,6 +1587,9 @@ impl TryFrom<(&KdlNode, &Options)> for Action { "ToggleFocusFullscreen" => { parse_kdl_action_arguments!(action_name, action_arguments, kdl_action) }, + "ToggleFocusNoUiFullscreen" => { + parse_kdl_action_arguments!(action_name, action_arguments, kdl_action) + }, "TogglePaneFrames" => { parse_kdl_action_arguments!(action_name, action_arguments, kdl_action) }, @@ -2926,6 +2946,19 @@ impl Options { }, None => None, }; + let nested_session_handling = match kdl_property_first_arg_as_string_or_error!( + kdl_options, + "nested_session_handling" + ) { + Some((value, entry)) => { + use crate::input::options::NestedSessionHandling; + match value.parse::<NestedSessionHandling>() { + Ok(v) => Some(v), + Err(e) => return Err(kdl_parsing_error!(e, entry)), + } + }, + None => None, + }; Ok(Options { simplified_ui, @@ -2981,6 +3014,7 @@ impl Options { mobile_layout, mobile_threshold_cols, mobile_threshold_rows, + nested_session_handling, }) } pub fn from_string(stringified_keybindings: &String) -> Result<Self, ConfigError> { @@ -4505,6 +4539,44 @@ impl Options { None } } + fn nested_session_handling_to_kdl(&self, add_comments: bool) -> Option<KdlNode> { + use crate::input::options::NestedSessionHandling; + let comment_text = format!( + "{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}", + " ", + "// How to handle a nested Zellij session detected inside a pane.", + "// Options:", + "// - \"ask\" (Default — prompt with a modal)", + "// - \"fullscreen\" (always zoom into the nested session)", + "// - \"descend\" (always control the nested session on focus)", + "// - \"never\" (never prompt or descend; do it manually)", + "// ", + ); + let create_node = |value: NestedSessionHandling| -> KdlNode { + let mut node = KdlNode::new("nested_session_handling"); + let s = match value { + NestedSessionHandling::Ask => "ask", + NestedSessionHandling::Fullscreen => "fullscreen", + NestedSessionHandling::Descend => "descend", + NestedSessionHandling::Never => "never", + }; + node.push(KdlValue::String(s.to_string())); + node + }; + if let Some(value) = self.nested_session_handling { + let mut node = create_node(value); + if add_comments { + node.set_leading(format!("{}\n", comment_text)); + } + Some(node) + } else if add_comments { + let mut node = create_node(NestedSessionHandling::Ask); + node.set_leading(format!("{}\n// ", comment_text)); + Some(node) + } else { + None + } + } fn client_async_worker_tasks_to_kdl(&self, add_comments: bool) -> Option<KdlNode> { let comment_text = r#" // Number of async worker tasks to spawn per active client. @@ -4701,6 +4773,9 @@ impl Options { if let Some(mobile_threshold_rows) = self.mobile_threshold_rows_to_kdl(add_comments) { nodes.push(mobile_threshold_rows); } + if let Some(nested_session_handling) = self.nested_session_handling_to_kdl(add_comments) { + nodes.push(nested_session_handling); + } nodes } } @@ -7586,6 +7661,38 @@ fn mobile_layout_kdl_round_trip_for_every_variant() { } #[test] +fn nested_session_handling_kdl_round_trip_for_every_variant() { + use crate::input::options::NestedSessionHandling; + let cases = [ + ("ask", NestedSessionHandling::Ask), + ("fullscreen", NestedSessionHandling::Fullscreen), + ("descend", NestedSessionHandling::Descend), + ("never", NestedSessionHandling::Never), + ]; + for (value, expected) in cases { + let fake_config = format!( + r##" + nested_session_handling "{value}" + "## + ); + let document: KdlDocument = fake_config.parse().unwrap(); + let parsed = Options::from_kdl(&document).unwrap(); + assert_eq!( + parsed.nested_session_handling, + Some(expected), + "case: {value}" + ); + + let mut serialized = Options::to_kdl(&parsed, false); + let mut fake_document = KdlDocument::new(); + fake_document.nodes_mut().append(&mut serialized); + let reparsed = + Options::from_kdl(&fake_document.to_string().parse::<KdlDocument>().unwrap()).unwrap(); + assert_eq!(parsed, reparsed, "round-trip mismatch for {value}"); + } +} + +#[test] fn config_options_to_string_with_some_options() { let fake_config = r##" default_layout "compact" diff --git a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string.snap b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string.snap index 1ab39935..2d7dec36 100644 --- a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string.snap +++ b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string.snap @@ -15,6 +15,7 @@ keybinds clear-defaults=true { bind "d" { NewPane "down"; SwitchToMode "normal"; } bind "e" { TogglePaneEmbedOrFloating; SwitchToMode "normal"; } bind "f" { ToggleFocusFullscreen; SwitchToMode "normal"; } + bind "Shift f" { ToggleFocusNoUiFullscreen; SwitchToMode "normal"; } bind "h" { MoveFocus "left"; } bind "i" { TogglePanePinned; SwitchToMode "normal"; } bind "j" { MoveFocus "down"; } @@ -100,6 +101,8 @@ keybinds clear-defaults=true { bind "w" { SearchToggleOption "Wrap"; } } session { + bind "[" { FocusGuestSession; SwitchToMode "normal"; } + bind "]" { FocusHostSession; SwitchToMode "normal"; } bind "a" { LaunchOrFocusPlugin "zellij:about" { floating true @@ -114,6 +117,7 @@ keybinds clear-defaults=true { } SwitchToMode "normal" } + bind "f" { ToggleHostFullscreen; SwitchToMode "normal"; } bind "l" { LaunchOrFocusPlugin "zellij:layout-manager" { floating true diff --git a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap index bf816932..bbbb1248 100644 --- a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap +++ b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__bare_config_from_default_assets_to_string_with_comments.snap @@ -15,6 +15,7 @@ keybinds clear-defaults=true { bind "d" { NewPane "down"; SwitchToMode "normal"; } bind "e" { TogglePaneEmbedOrFloating; SwitchToMode "normal"; } bind "f" { ToggleFocusFullscreen; SwitchToMode "normal"; } + bind "Shift f" { ToggleFocusNoUiFullscreen; SwitchToMode "normal"; } bind "h" { MoveFocus "left"; } bind "i" { TogglePanePinned; SwitchToMode "normal"; } bind "j" { MoveFocus "down"; } @@ -100,6 +101,8 @@ keybinds clear-defaults=true { bind "w" { SearchToggleOption "Wrap"; } } session { + bind "[" { FocusGuestSession; SwitchToMode "normal"; } + bind "]" { FocusHostSession; SwitchToMode "normal"; } bind "a" { LaunchOrFocusPlugin "zellij:about" { floating true @@ -114,6 +117,7 @@ keybinds clear-defaults=true { } SwitchToMode "normal" } + bind "f" { ToggleHostFullscreen; SwitchToMode "normal"; } bind "l" { LaunchOrFocusPlugin "zellij:layout-manager" { floating true @@ -615,3 +619,12 @@ web_client { // Row breakpoint for mobile_layout (web/always). 0 = always match. // Default: 30 // mobile_threshold_rows 30 + +// How to handle a nested Zellij session detected inside a pane. +// Options: +// - "ask" (Default — prompt with a modal) +// - "fullscreen" (always zoom into the nested session) +// - "descend" (always control the nested session on focus) +// - "never" (never prompt or descend; do it manually) +// +// nested_session_handling "ask" diff --git a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__config_options_to_string_with_comments.snap b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__config_options_to_string_with_comments.snap index 8dcbaadd..fe42491f 100644 --- a/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__config_options_to_string_with_comments.snap +++ b/zellij-utils/src/kdl/snapshots/zellij_utils__kdl__config_options_to_string_with_comments.snap @@ -333,3 +333,12 @@ mobile_threshold_cols 72 // Row breakpoint for mobile_layout (web/always). 0 = always match. // Default: 30 mobile_threshold_rows 0 + +// How to handle a nested Zellij session detected inside a pane. +// Options: +// - "ask" (Default — prompt with a modal) +// - "fullscreen" (always zoom into the nested session) +// - "descend" (always control the nested session on focus) +// - "never" (never prompt or descend; do it manually) +// +// nested_session_handling "ask" diff --git a/zellij-utils/src/lib.rs b/zellij-utils/src/lib.rs index ba02ce96..e7a2d797 100644 --- a/zellij-utils/src/lib.rs +++ b/zellij-utils/src/lib.rs @@ -11,6 +11,7 @@ mod home_unix; mod home_windows; pub mod input; pub mod kdl; +pub mod nested_session_contract; pub mod pane_size; pub mod plugin_api; pub mod position; @@ -29,6 +30,8 @@ pub mod downloader; // Requires tokio pub mod ipc; // Requires interprocess #[cfg(not(target_family = "wasm"))] pub mod logging; // Requires log4rs +#[cfg(not(target_family = "wasm"))] +pub mod nested_session; #[cfg(all(not(target_family = "wasm"), feature = "web_server_capability"))] pub mod remote_session_tokens; #[cfg(not(target_family = "wasm"))] diff --git a/zellij-utils/src/nested_session.rs b/zellij-utils/src/nested_session.rs new file mode 100644 index 00000000..4144defc --- /dev/null +++ b/zellij-utils/src/nested_session.rs @@ -0,0 +1,470 @@ +use crate::data::{Direction, KeyWithModifier}; +use crate::nested_session_contract::nested_session_contract as proto; +use prost::Message; +use std::str::FromStr; + +pub const NESTED_DCS_PARAM: u16 = 26661; +pub const NESTED_FRAME_HEADER: &[u8] = b"\x1bP26661n"; +pub const NESTED_FRAME_TERMINATOR: &[u8] = b"\x1b\\"; + +pub const REANNOUNCE_SILENCE_MS: u64 = 3000; +pub const REANNOUNCE_CHECK_INTERVAL_MS: u64 = 1000; + +pub fn reannounce_silence_ms() -> u64 { + std::env::var("ZELLIJ_NESTED_REANNOUNCE_SILENCE_MS") + .ok() + .and_then(|value| value.parse().ok()) + .unwrap_or(REANNOUNCE_SILENCE_MS) +} + +pub fn reannounce_check_interval_ms() -> u64 { + std::env::var("ZELLIJ_NESTED_REANNOUNCE_CHECK_INTERVAL_MS") + .ok() + .and_then(|value| value.parse().ok()) + .unwrap_or(REANNOUNCE_CHECK_INTERVAL_MS) +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum NestedSessionCapability { + NestedControl, +} + +#[derive(Debug, Clone, PartialEq)] +pub enum NestedSessionMessage { + Announce { + session_name: String, + capabilities: Vec<NestedSessionCapability>, + }, + FocusHost { + direction: Option<Direction>, + }, + ToggleHostFullscreen { + fullscreen: bool, + }, + Pong, + Bye, + AnnounceAck { + ancestry: Vec<String>, + capabilities: Vec<NestedSessionCapability>, + descend_keys: Vec<KeyWithModifier>, + }, + FocusGained { + from_direction: Option<Direction>, + }, + FocusLost, + FullscreenState { + fullscreen: bool, + }, + AncestryUpdate { + ancestry: Vec<String>, + }, + Ping, + ShortcutUpdate { + ascend_keys: Vec<KeyWithModifier>, + descend_keys: Vec<KeyWithModifier>, + }, +} + +fn keys_to_proto(keys: &[KeyWithModifier]) -> Vec<String> { + keys.iter().map(|key| key.to_kdl()).collect() +} + +fn keys_from_proto(keys: &[String]) -> Vec<KeyWithModifier> { + let parsed: Vec<KeyWithModifier> = keys + .iter() + .filter_map(|key| KeyWithModifier::from_str(key).ok()) + .collect(); + if parsed.len() == keys.len() { + parsed + } else { + vec![] + } +} + +fn capabilities_to_proto(capabilities: &[NestedSessionCapability]) -> Vec<i32> { + capabilities + .iter() + .map(|capability| match capability { + NestedSessionCapability::NestedControl => proto::NestedCapability::NestedControl as i32, + }) + .collect() +} + +fn capabilities_from_proto(capabilities: &[i32]) -> Vec<NestedSessionCapability> { + capabilities + .iter() + .filter_map( + |capability| match proto::NestedCapability::from_i32(*capability) { + Some(proto::NestedCapability::NestedControl) => { + Some(NestedSessionCapability::NestedControl) + }, + _ => None, + }, + ) + .collect() +} + +fn direction_to_proto(direction: Option<Direction>) -> i32 { + match direction { + Some(Direction::Left) => proto::NestedDirection::Left as i32, + Some(Direction::Right) => proto::NestedDirection::Right as i32, + Some(Direction::Up) => proto::NestedDirection::Up as i32, + Some(Direction::Down) => proto::NestedDirection::Down as i32, + None => proto::NestedDirection::Unspecified as i32, + } +} + +fn direction_from_proto(direction: i32) -> Option<Direction> { + match proto::NestedDirection::from_i32(direction) { + Some(proto::NestedDirection::Left) => Some(Direction::Left), + Some(proto::NestedDirection::Right) => Some(Direction::Right), + Some(proto::NestedDirection::Up) => Some(Direction::Up), + Some(proto::NestedDirection::Down) => Some(Direction::Down), + _ => None, + } +} + +impl From<NestedSessionMessage> for proto::NestedSessionMessage { + fn from(message: NestedSessionMessage) -> Self { + use proto::nested_session_message::Payload; + let payload = match message { + NestedSessionMessage::Announce { + session_name, + capabilities, + } => Payload::Announce(proto::Announce { + session_name, + capabilities: capabilities_to_proto(&capabilities), + }), + NestedSessionMessage::FocusHost { direction } => Payload::FocusHost(proto::FocusHost { + direction: direction_to_proto(direction), + }), + NestedSessionMessage::ToggleHostFullscreen { fullscreen } => { + Payload::HostFullscreen(proto::ToggleHostFullscreen { fullscreen }) + }, + NestedSessionMessage::Pong => Payload::Pong(proto::Pong {}), + NestedSessionMessage::Bye => Payload::Bye(proto::Bye {}), + NestedSessionMessage::AnnounceAck { + ancestry, + capabilities, + descend_keys, + } => Payload::AnnounceAck(proto::AnnounceAck { + ancestry, + capabilities: capabilities_to_proto(&capabilities), + descend_keys: keys_to_proto(&descend_keys), + }), + NestedSessionMessage::FocusGained { from_direction } => { + Payload::FocusGained(proto::FocusGained { + from_direction: direction_to_proto(from_direction), + }) + }, + NestedSessionMessage::FocusLost => Payload::FocusLost(proto::FocusLost {}), + NestedSessionMessage::FullscreenState { fullscreen } => { + Payload::FullscreenState(proto::FullscreenState { fullscreen }) + }, + NestedSessionMessage::AncestryUpdate { ancestry } => { + Payload::AncestryUpdate(proto::AncestryUpdate { ancestry }) + }, + NestedSessionMessage::Ping => Payload::Ping(proto::Ping {}), + NestedSessionMessage::ShortcutUpdate { + ascend_keys, + descend_keys, + } => Payload::ShortcutUpdate(proto::ShortcutUpdate { + ascend_keys: keys_to_proto(&ascend_keys), + descend_keys: keys_to_proto(&descend_keys), + }), + }; + proto::NestedSessionMessage { + payload: Some(payload), + } + } +} + +impl TryFrom<proto::NestedSessionMessage> for NestedSessionMessage { + type Error = (); + fn try_from(message: proto::NestedSessionMessage) -> Result<Self, Self::Error> { + use proto::nested_session_message::Payload; + match message.payload { + Some(Payload::Announce(announce)) => Ok(NestedSessionMessage::Announce { + session_name: announce.session_name, + capabilities: capabilities_from_proto(&announce.capabilities), + }), + Some(Payload::FocusHost(focus_host)) => Ok(NestedSessionMessage::FocusHost { + direction: direction_from_proto(focus_host.direction), + }), + Some(Payload::HostFullscreen(host_fullscreen)) => { + Ok(NestedSessionMessage::ToggleHostFullscreen { + fullscreen: host_fullscreen.fullscreen, + }) + }, + Some(Payload::Pong(_)) => Ok(NestedSessionMessage::Pong), + Some(Payload::Bye(_)) => Ok(NestedSessionMessage::Bye), + Some(Payload::AnnounceAck(announce_ack)) => Ok(NestedSessionMessage::AnnounceAck { + ancestry: announce_ack.ancestry, + capabilities: capabilities_from_proto(&announce_ack.capabilities), + descend_keys: keys_from_proto(&announce_ack.descend_keys), + }), + Some(Payload::FocusGained(focus_gained)) => Ok(NestedSessionMessage::FocusGained { + from_direction: direction_from_proto(focus_gained.from_direction), + }), + Some(Payload::FocusLost(_)) => Ok(NestedSessionMessage::FocusLost), + Some(Payload::FullscreenState(fullscreen_state)) => { + Ok(NestedSessionMessage::FullscreenState { + fullscreen: fullscreen_state.fullscreen, + }) + }, + Some(Payload::AncestryUpdate(ancestry_update)) => { + Ok(NestedSessionMessage::AncestryUpdate { + ancestry: ancestry_update.ancestry, + }) + }, + Some(Payload::Ping(_)) => Ok(NestedSessionMessage::Ping), + Some(Payload::ShortcutUpdate(shortcut_update)) => { + Ok(NestedSessionMessage::ShortcutUpdate { + ascend_keys: keys_from_proto(&shortcut_update.ascend_keys), + descend_keys: keys_from_proto(&shortcut_update.descend_keys), + }) + }, + None => Err(()), + } + } +} + +pub fn encode_payload(message: &NestedSessionMessage) -> Vec<u8> { + let proto_message: proto::NestedSessionMessage = message.clone().into(); + proto_message.encode_to_vec() +} + +pub fn decode_payload(payload_bytes: &[u8]) -> Option<NestedSessionMessage> { + let proto_message = proto::NestedSessionMessage::decode(payload_bytes).ok()?; + NestedSessionMessage::try_from(proto_message).ok() +} + +pub fn encode_frame(message: &NestedSessionMessage) -> Vec<u8> { + encode_frame_from_payload(&encode_payload(message)) +} + +pub fn encode_frame_from_payload(payload_bytes: &[u8]) -> Vec<u8> { + let encoded = base64::encode(payload_bytes); + let mut frame = Vec::with_capacity( + NESTED_FRAME_HEADER.len() + encoded.len() + NESTED_FRAME_TERMINATOR.len(), + ); + frame.extend_from_slice(NESTED_FRAME_HEADER); + frame.extend_from_slice(encoded.as_bytes()); + frame.extend_from_slice(NESTED_FRAME_TERMINATOR); + frame +} + +pub fn decode_base64(encoded: &[u8]) -> Option<Vec<u8>> { + base64::decode(encoded).ok() +} + +const MAX_PARTIAL_FRAME_BYTES: usize = 1024 * 1024; + +enum FrameScanStatus { + Complete(usize), + NeedMore, + Diverged, +} + +fn frame_scan_status(buf: &[u8]) -> FrameScanStatus { + if buf.len() < NESTED_FRAME_HEADER.len() { + return if NESTED_FRAME_HEADER.starts_with(buf) { + FrameScanStatus::NeedMore + } else { + FrameScanStatus::Diverged + }; + } + if &buf[..NESTED_FRAME_HEADER.len()] != NESTED_FRAME_HEADER { + return FrameScanStatus::Diverged; + } + let mut i = NESTED_FRAME_HEADER.len(); + while i < buf.len() { + match buf[i] { + 0x1b => match buf.get(i + 1) { + Some(&b'\\') => return FrameScanStatus::Complete(i + 2), + Some(_) => return FrameScanStatus::Diverged, + None => return FrameScanStatus::NeedMore, + }, + _ => i += 1, + } + } + FrameScanStatus::NeedMore +} + +#[derive(Debug, Default)] +pub struct NestedFrameExtractor { + partial_frame: Vec<u8>, +} + +impl NestedFrameExtractor { + pub fn new() -> Self { + Self::default() + } + + pub fn extract(&mut self, bytes: &[u8]) -> (Vec<u8>, Vec<Vec<u8>>) { + let mut decoded_payloads = Vec::new(); + if self.partial_frame.is_empty() && !bytes.contains(&0x1b) { + return (bytes.to_vec(), decoded_payloads); + } + let mut working = std::mem::take(&mut self.partial_frame); + working.extend_from_slice(bytes); + let mut cleaned = Vec::with_capacity(working.len()); + let mut i = 0; + while i < working.len() { + let rest = &working[i..]; + if rest[0] == 0x1b { + match frame_scan_status(rest) { + FrameScanStatus::Complete(len) => { + let encoded_payload = + &rest[NESTED_FRAME_HEADER.len()..len - NESTED_FRAME_TERMINATOR.len()]; + if let Some(payload) = decode_base64(encoded_payload) { + decoded_payloads.push(payload); + } + i += len; + continue; + }, + FrameScanStatus::NeedMore => { + let tail = rest.to_vec(); + if tail.len() > MAX_PARTIAL_FRAME_BYTES { + cleaned.extend_from_slice(&tail); + } else { + self.partial_frame = tail; + } + return (cleaned, decoded_payloads); + }, + FrameScanStatus::Diverged => {}, + } + } + cleaned.push(working[i]); + i += 1; + } + (cleaned, decoded_payloads) + } + + pub fn partial_bytes(&self) -> &[u8] { + &self.partial_frame + } + + pub fn take_partial(&mut self) -> Vec<u8> { + std::mem::take(&mut self.partial_frame) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::data::BareKey; + + fn all_message_arms() -> Vec<NestedSessionMessage> { + vec![ + NestedSessionMessage::Announce { + session_name: "guest".to_owned(), + capabilities: vec![NestedSessionCapability::NestedControl], + }, + NestedSessionMessage::FocusHost { + direction: Some(Direction::Left), + }, + NestedSessionMessage::FocusHost { direction: None }, + NestedSessionMessage::ToggleHostFullscreen { fullscreen: true }, + NestedSessionMessage::Pong, + NestedSessionMessage::Bye, + NestedSessionMessage::AnnounceAck { + ancestry: vec!["outer".to_owned(), "middle".to_owned()], + capabilities: vec![NestedSessionCapability::NestedControl], + descend_keys: vec![ + KeyWithModifier::new(BareKey::Char('o')).with_ctrl_modifier(), + KeyWithModifier::new(BareKey::Down), + ], + }, + NestedSessionMessage::FocusGained { + from_direction: Some(Direction::Right), + }, + NestedSessionMessage::FocusLost, + NestedSessionMessage::FullscreenState { fullscreen: true }, + NestedSessionMessage::AncestryUpdate { + ancestry: vec!["outer".to_owned()], + }, + NestedSessionMessage::Ping, + NestedSessionMessage::ShortcutUpdate { + ascend_keys: vec![ + KeyWithModifier::new(BareKey::Char('o')).with_ctrl_modifier(), + KeyWithModifier::new(BareKey::Up), + ], + descend_keys: vec![], + }, + ] + } + + #[test] + fn payload_roundtrip_preserves_every_arm() { + for message in all_message_arms() { + let decoded = decode_payload(&encode_payload(&message)); + assert_eq!(decoded, Some(message)); + } + } + + #[test] + fn focus_direction_roundtrip_preserves_every_direction() { + let directions = [ + None, + Some(Direction::Left), + Some(Direction::Right), + Some(Direction::Up), + Some(Direction::Down), + ]; + for direction in directions { + let focus_host = NestedSessionMessage::FocusHost { direction }; + assert_eq!( + decode_payload(&encode_payload(&focus_host)), + Some(focus_host) + ); + let focus_gained = NestedSessionMessage::FocusGained { + from_direction: direction, + }; + assert_eq!( + decode_payload(&encode_payload(&focus_gained)), + Some(focus_gained) + ); + } + } + + #[test] + fn frame_roundtrip_preserves_message() { + let message = NestedSessionMessage::Announce { + session_name: "guest".to_owned(), + capabilities: vec![NestedSessionCapability::NestedControl], + }; + let frame = encode_frame(&message); + assert!(frame.starts_with(NESTED_FRAME_HEADER)); + assert!(frame.ends_with(NESTED_FRAME_TERMINATOR)); + let encoded_payload = + &frame[NESTED_FRAME_HEADER.len()..frame.len() - NESTED_FRAME_TERMINATOR.len()]; + let payload = decode_base64(encoded_payload).unwrap(); + assert_eq!(decode_payload(&payload), Some(message)); + } + + #[test] + fn garbage_base64_is_rejected() { + assert_eq!(decode_base64(b"!!!not-base64!!!"), None); + } + + #[test] + fn truncated_payload_is_rejected() { + let payload = encode_payload(&NestedSessionMessage::Announce { + session_name: "a-long-session-name-to-truncate".to_owned(), + capabilities: vec![], + }); + assert_eq!(decode_payload(&payload[..payload.len() - 5]), None); + } + + #[test] + fn unknown_oneof_arm_is_rejected() { + let unknown_field_bytes = [0xE2, 0x03, 0x00]; + assert_eq!(decode_payload(&unknown_field_bytes), None); + } + + #[test] + fn empty_payload_is_rejected() { + assert_eq!(decode_payload(&[]), None); + } +} diff --git a/zellij-utils/src/nested_session_contract/mod.rs b/zellij-utils/src/nested_session_contract/mod.rs new file mode 100644 index 00000000..5ec943c2 --- /dev/null +++ b/zellij-utils/src/nested_session_contract/mod.rs @@ -0,0 +1,4 @@ +include!(concat!( + env!("CARGO_MANIFEST_DIR"), + "/assets/prost_nested_session/generated_nested_session_api.rs" +)); diff --git a/zellij-utils/src/nested_session_contract/nested_session_message.proto b/zellij-utils/src/nested_session_contract/nested_session_message.proto new file mode 100644 index 00000000..dfe2f62a --- /dev/null +++ b/zellij-utils/src/nested_session_contract/nested_session_message.proto @@ -0,0 +1,80 @@ +syntax = "proto3"; +package nested_session_contract; + +message NestedSessionMessage { + oneof payload { + Announce announce = 1; + FocusHost focus_host = 2; + ToggleHostFullscreen host_fullscreen = 3; + Pong pong = 4; + Bye bye = 5; + AnnounceAck announce_ack = 8; + FocusGained focus_gained = 9; + FocusLost focus_lost = 10; + FullscreenState fullscreen_state = 11; + AncestryUpdate ancestry_update = 12; + Ping ping = 13; + ShortcutUpdate shortcut_update = 14; + } +} + +enum NestedCapability { + NESTED_CAPABILITY_UNSPECIFIED = 0; + NESTED_CAPABILITY_NESTED_CONTROL = 1; +} + +enum NestedDirection { + NESTED_DIRECTION_UNSPECIFIED = 0; + NESTED_DIRECTION_LEFT = 1; + NESTED_DIRECTION_RIGHT = 2; + NESTED_DIRECTION_UP = 3; + NESTED_DIRECTION_DOWN = 4; +} + +message Announce { + string session_name = 1; + repeated NestedCapability capabilities = 2; +} + +message FocusHost { + NestedDirection direction = 1; +} + +message ToggleHostFullscreen { + bool fullscreen = 1; +} + +message Pong { +} + +message Bye { +} + +message AnnounceAck { + repeated string ancestry = 1; + repeated NestedCapability capabilities = 2; + repeated string descend_keys = 3; +} + +message ShortcutUpdate { + repeated string ascend_keys = 1; + repeated string descend_keys = 2; +} + +message FocusGained { + NestedDirection from_direction = 1; +} + +message FocusLost { +} + +message FullscreenState { + bool fullscreen = 1; +} + +message AncestryUpdate { + repeated string ancestry = 1; +} + +message Ping { +} diff --git a/zellij-utils/src/plugin_api/action.proto b/zellij-utils/src/plugin_api/action.proto index f9370961..1d896cef 100644 --- a/zellij-utils/src/plugin_api/action.proto +++ b/zellij-utils/src/plugin_api/action.proto @@ -501,6 +501,10 @@ enum ActionName { ToggleTheme = 103; FocusLastPane = 104; SetPaneFrameStyle = 105; + ToggleFocusNoUiFullscreen = 106; + FocusHostSession = 107; + ToggleHostFullscreen = 108; + FocusGuestSession = 109; } message Position { diff --git a/zellij-utils/src/plugin_api/action.rs b/zellij-utils/src/plugin_api/action.rs index f1d71222..c11b56f1 100644 --- a/zellij-utils/src/plugin_api/action.rs +++ b/zellij-utils/src/plugin_api/action.rs @@ -298,6 +298,12 @@ impl TryFrom<ProtobufAction> for Action { None => Ok(Action::ToggleFocusFullscreen), } }, + Some(ProtobufActionName::ToggleFocusNoUiFullscreen) => { + match protobuf_action.optional_payload { + Some(_) => Err("ToggleFocusNoUiFullscreen should not have a payload"), + None => Ok(Action::ToggleFocusNoUiFullscreen), + } + }, Some(ProtobufActionName::TogglePaneFrames) => match protobuf_action.optional_payload { Some(_) => Err("TogglePaneFrames should not have a payload"), None => Ok(Action::TogglePaneFrames), @@ -1092,6 +1098,20 @@ impl TryFrom<ProtobufAction> for Action { }, _ => Err("Wrong payload for Action::NewInPlacePane"), }, + Some(ProtobufActionName::FocusHostSession) => match protobuf_action.optional_payload { + Some(_) => Err("FocusHostSession should not have a payload"), + None => Ok(Action::FocusHostSession), + }, + Some(ProtobufActionName::FocusGuestSession) => match protobuf_action.optional_payload { + Some(_) => Err("FocusGuestSession should not have a payload"), + None => Ok(Action::FocusGuestSession), + }, + Some(ProtobufActionName::ToggleHostFullscreen) => { + match protobuf_action.optional_payload { + Some(_) => Err("ToggleHostFullscreen should not have a payload"), + None => Ok(Action::ToggleHostFullscreen), + } + }, _ => Err("Unknown Action"), } } @@ -1148,6 +1168,7 @@ impl TryFrom<Action> for ProtobufAction { | Action::ClearScreenByPaneId { .. } | Action::EditScrollbackByPaneId { .. } | Action::ToggleFocusFullscreenByPaneId { .. } + | Action::ToggleFocusNoUiFullscreenByPaneId { .. } | Action::TogglePaneEmbedOrFloatingByPaneId { .. } | Action::CloseFocusByPaneId { .. } | Action::RenamePaneByPaneId { .. } @@ -1323,6 +1344,10 @@ impl TryFrom<Action> for ProtobufAction { name: ProtobufActionName::ToggleFocusFullscreen as i32, optional_payload: None, }), + Action::ToggleFocusNoUiFullscreen => Ok(ProtobufAction { + name: ProtobufActionName::ToggleFocusNoUiFullscreen as i32, + optional_payload: None, + }), Action::TogglePaneFrames => Ok(ProtobufAction { name: ProtobufActionName::TogglePaneFrames as i32, optional_payload: None, @@ -1960,6 +1985,18 @@ impl TryFrom<Action> for ProtobufAction { )), }) }, + Action::FocusHostSession => Ok(ProtobufAction { + name: ProtobufActionName::FocusHostSession as i32, + optional_payload: None, + }), + Action::FocusGuestSession => Ok(ProtobufAction { + name: ProtobufActionName::FocusGuestSession as i32, + optional_payload: None, + }), + Action::ToggleHostFullscreen => Ok(ProtobufAction { + name: ProtobufActionName::ToggleHostFullscreen as i32, + optional_payload: None, + }), Action::NoOp | Action::Confirm | Action::NewInPlacePluginPane { diff --git a/zellij-utils/src/plugin_api/event.proto b/zellij-utils/src/plugin_api/event.proto index d3148edf..6814e8d8 100644 --- a/zellij-utils/src/plugin_api/event.proto +++ b/zellij-utils/src/plugin_api/event.proto @@ -511,6 +511,12 @@ message ModeUpdatePayload { optional uint32 web_server_port = 14; optional bool web_server_capability = 15; optional PaneFrameStyle pane_frame_style = 16; + optional bool session_dimmed = 17; + repeated string ancestry = 18; + optional bool host_fullscreen = 19; + repeated string nested_ascend_keys = 20; + optional bool session_ascended = 21; + repeated string nested_descend_keys = 22; } enum WebSharing { diff --git a/zellij-utils/src/plugin_api/event.rs b/zellij-utils/src/plugin_api/event.rs index 190552d4..970f5e2c 100644 --- a/zellij-utils/src/plugin_api/event.rs +++ b/zellij-utils/src/plugin_api/event.rs @@ -2020,6 +2020,26 @@ impl TryFrom<ProtobufModeUpdatePayload> for ModeInfo { .and_then(|p| ProtobufPaneFrameStyle::from_i32(p)) .map(|p| p.into()); + let session_dimmed = protobuf_mode_update_payload.session_dimmed; + + let session_ancestry = protobuf_mode_update_payload.ancestry; + + let host_fullscreen = protobuf_mode_update_payload.host_fullscreen; + + let nested_ascend_keys = protobuf_mode_update_payload + .nested_ascend_keys + .iter() + .filter_map(|key| KeyWithModifier::from_str(key).ok()) + .collect(); + + let session_ascended = protobuf_mode_update_payload.session_ascended; + + let nested_descend_keys = protobuf_mode_update_payload + .nested_descend_keys + .iter() + .filter_map(|key| KeyWithModifier::from_str(key).ok()) + .collect(); + let mode_info = ModeInfo { mode: current_mode, keybinds, @@ -2037,6 +2057,12 @@ impl TryFrom<ProtobufModeUpdatePayload> for ModeInfo { web_server_port, web_server_capability, pane_frame_style, + session_dimmed, + session_ancestry, + host_fullscreen, + nested_ascend_keys, + session_ascended, + nested_descend_keys, }; Ok(mode_info) } @@ -2065,6 +2091,20 @@ impl TryFrom<ModeInfo> for ProtobufModeUpdatePayload { let protobuf_pane_frame_style: ProtobufPaneFrameStyle = p.into(); protobuf_pane_frame_style as i32 }); + let session_dimmed = mode_info.session_dimmed; + let session_ancestry = mode_info.session_ancestry; + let host_fullscreen = mode_info.host_fullscreen; + let nested_ascend_keys = mode_info + .nested_ascend_keys + .iter() + .map(|key| key.to_kdl()) + .collect(); + let session_ascended = mode_info.session_ascended; + let nested_descend_keys = mode_info + .nested_descend_keys + .iter() + .map(|key| key.to_kdl()) + .collect(); let mut protobuf_input_mode_keybinds: Vec<ProtobufInputModeKeybinds> = vec![]; for (input_mode, input_mode_keybinds) in mode_info.keybinds { let mode: ProtobufInputMode = input_mode.try_into()?; @@ -2106,6 +2146,12 @@ impl TryFrom<ModeInfo> for ProtobufModeUpdatePayload { web_server_port, web_server_capability, pane_frame_style, + session_dimmed, + ancestry: session_ancestry, + host_fullscreen, + nested_ascend_keys, + session_ascended, + nested_descend_keys, }) } } @@ -2460,6 +2506,18 @@ fn serialize_mode_update_event_with_non_default_values() { web_server_port: Some(8082), web_server_capability: Some(true), pane_frame_style: Some(crate::input::options::PaneFrameStyle::Titles), + session_dimmed: Some(true), + session_ancestry: vec!["work".to_owned(), "prod".to_owned()], + host_fullscreen: Some(true), + nested_ascend_keys: vec![ + KeyWithModifier::new(BareKey::Char('o')).with_ctrl_modifier(), + KeyWithModifier::new(BareKey::Up), + ], + session_ascended: Some(true), + nested_descend_keys: vec![ + KeyWithModifier::new(BareKey::Char('o')).with_ctrl_modifier(), + KeyWithModifier::new(BareKey::Down), + ], }); let protobuf_event: ProtobufEvent = mode_update_event.clone().try_into().unwrap(); let serialized_protobuf_event = protobuf_event.encode_to_vec(); diff --git a/zellij-utils/src/plugin_api/plugin_command.proto b/zellij-utils/src/plugin_api/plugin_command.proto index 8d31727d..e9dff3c6 100644 --- a/zellij-utils/src/plugin_api/plugin_command.proto +++ b/zellij-utils/src/plugin_api/plugin_command.proto @@ -218,6 +218,8 @@ enum CommandName { SetPaneFrameStyle = 224; ToggleFloatingPanes = 225; NewPane = 226; + ToggleFocusNoUiFullscreen = 227; + FocusHostSession = 228; } message PluginCommand { diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs index 38c42565..3d86bc20 100644 --- a/zellij-utils/src/plugin_api/plugin_command.rs +++ b/zellij-utils/src/plugin_api/plugin_command.rs @@ -1110,6 +1110,18 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand { } Ok(PluginCommand::ToggleFocusFullscreen) }, + Some(CommandName::ToggleFocusNoUiFullscreen) => { + if protobuf_plugin_command.payload.is_some() { + return Err("ToggleFocusNoUiFullscreen should not have a payload"); + } + Ok(PluginCommand::ToggleFocusNoUiFullscreen) + }, + Some(CommandName::FocusHostSession) => { + if protobuf_plugin_command.payload.is_some() { + return Err("FocusHostSession should not have a payload"); + } + Ok(PluginCommand::FocusHostSession) + }, Some(CommandName::TogglePaneFrames) => { if protobuf_plugin_command.payload.is_some() { return Err("TogglePaneFrames should not have a payload"); @@ -3127,6 +3139,14 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand { name: CommandName::ToggleFocusFullscreen as i32, payload: None, }), + PluginCommand::ToggleFocusNoUiFullscreen => Ok(ProtobufPluginCommand { + name: CommandName::ToggleFocusNoUiFullscreen as i32, + payload: None, + }), + PluginCommand::FocusHostSession => Ok(ProtobufPluginCommand { + name: CommandName::FocusHostSession as i32, + payload: None, + }), PluginCommand::TogglePaneFrames => Ok(ProtobufPluginCommand { name: CommandName::TogglePaneFrames as i32, payload: None, diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_config_options.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_config_options.snap index 1bef8e12..cd08644a 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_config_options.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_config_options.snap @@ -58,4 +58,5 @@ Options { mobile_layout: None, mobile_threshold_cols: None, mobile_threshold_rows: None, + nested_session_handling: None, } diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_layout_options.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_layout_options.snap index 71d15cbe..26de6b99 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_layout_options.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__cli_arguments_override_layout_options.snap @@ -58,4 +58,5 @@ Options { mobile_layout: None, mobile_threshold_cols: None, mobile_threshold_rows: None, + nested_session_handling: None, } diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-3.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-3.snap index 85885291..6242e4d9 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-3.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments-3.snap @@ -56,4 +56,5 @@ Options { mobile_layout: None, mobile_threshold_cols: None, mobile_threshold_rows: None, + nested_session_handling: None, } diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap index 54404196..4f2869c9 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__default_config_with_no_cli_arguments.snap @@ -1073,6 +1073,19 @@ Config { ], KeyWithModifier { bare_key: Char( + 'f', + ), + key_modifiers: { + Shift, + }, + }: [ + ToggleFocusNoUiFullscreen, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( 'g', ), key_modifiers: { @@ -4150,6 +4163,17 @@ Config { bare_key: Char( '[', ), + key_modifiers: {}, + }: [ + FocusGuestSession, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + '[', + ), key_modifiers: { Alt, }, @@ -4160,6 +4184,17 @@ Config { bare_key: Char( ']', ), + key_modifiers: {}, + }: [ + FocusHostSession, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + ']', + ), key_modifiers: { Alt, }, @@ -4252,6 +4287,17 @@ Config { bare_key: Char( 'f', ), + key_modifiers: {}, + }: [ + ToggleHostFullscreen, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + 'f', + ), key_modifiers: { Alt, }, @@ -6035,6 +6081,7 @@ Config { mobile_layout: None, mobile_threshold_cols: None, mobile_threshold_rows: None, + nested_session_handling: None, }, themes: {}, plugins: PluginAliases { diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap index 6758d313..5353631b 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_env_vars_override_config_env_vars.snap @@ -1073,6 +1073,19 @@ Config { ], KeyWithModifier { bare_key: Char( + 'f', + ), + key_modifiers: { + Shift, + }, + }: [ + ToggleFocusNoUiFullscreen, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( 'g', ), key_modifiers: { @@ -4150,6 +4163,17 @@ Config { bare_key: Char( '[', ), + key_modifiers: {}, + }: [ + FocusGuestSession, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + '[', + ), key_modifiers: { Alt, }, @@ -4160,6 +4184,17 @@ Config { bare_key: Char( ']', ), + key_modifiers: {}, + }: [ + FocusHostSession, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + ']', + ), key_modifiers: { Alt, }, @@ -4252,6 +4287,17 @@ Config { bare_key: Char( 'f', ), + key_modifiers: {}, + }: [ + ToggleHostFullscreen, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + 'f', + ), key_modifiers: { Alt, }, @@ -6035,6 +6081,7 @@ Config { mobile_layout: None, mobile_threshold_cols: None, mobile_threshold_rows: None, + nested_session_handling: None, }, themes: {}, plugins: PluginAliases { diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap index e38dc3bc..d907d5b0 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_keybinds_override_config_keybinds.snap @@ -143,6 +143,7 @@ Config { mobile_layout: None, mobile_threshold_cols: None, mobile_threshold_rows: None, + nested_session_handling: None, }, themes: {}, plugins: PluginAliases { diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_options_override_config_options.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_options_override_config_options.snap index 58a3028b..ff54b105 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_options_override_config_options.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_options_override_config_options.snap @@ -58,4 +58,5 @@ Options { mobile_layout: None, mobile_threshold_cols: None, mobile_threshold_rows: None, + nested_session_handling: None, } diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap index c68392b2..624cf0b0 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_themes_override_config_themes.snap @@ -1073,6 +1073,19 @@ Config { ], KeyWithModifier { bare_key: Char( + 'f', + ), + key_modifiers: { + Shift, + }, + }: [ + ToggleFocusNoUiFullscreen, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( 'g', ), key_modifiers: { @@ -4150,6 +4163,17 @@ Config { bare_key: Char( '[', ), + key_modifiers: {}, + }: [ + FocusGuestSession, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + '[', + ), key_modifiers: { Alt, }, @@ -4160,6 +4184,17 @@ Config { bare_key: Char( ']', ), + key_modifiers: {}, + }: [ + FocusHostSession, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + ']', + ), key_modifiers: { Alt, }, @@ -4252,6 +4287,17 @@ Config { bare_key: Char( 'f', ), + key_modifiers: {}, + }: [ + ToggleHostFullscreen, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + 'f', + ), key_modifiers: { Alt, }, @@ -6035,6 +6081,7 @@ Config { mobile_layout: None, mobile_threshold_cols: None, mobile_threshold_rows: None, + nested_session_handling: None, }, themes: { "other-theme-from-config": Theme { diff --git a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap index 0609b74b..0cfece6e 100644 --- a/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap +++ b/zellij-utils/src/snapshots/zellij_utils__setup__setup_test__layout_ui_config_overrides_config_ui_config.snap @@ -1073,6 +1073,19 @@ Config { ], KeyWithModifier { bare_key: Char( + 'f', + ), + key_modifiers: { + Shift, + }, + }: [ + ToggleFocusNoUiFullscreen, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( 'g', ), key_modifiers: { @@ -4150,6 +4163,17 @@ Config { bare_key: Char( '[', ), + key_modifiers: {}, + }: [ + FocusGuestSession, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + '[', + ), key_modifiers: { Alt, }, @@ -4160,6 +4184,17 @@ Config { bare_key: Char( ']', ), + key_modifiers: {}, + }: [ + FocusHostSession, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + ']', + ), key_modifiers: { Alt, }, @@ -4252,6 +4287,17 @@ Config { bare_key: Char( 'f', ), + key_modifiers: {}, + }: [ + ToggleHostFullscreen, + SwitchToMode { + input_mode: Normal, + }, + ], + KeyWithModifier { + bare_key: Char( + 'f', + ), key_modifiers: { Alt, }, @@ -6035,6 +6081,7 @@ Config { mobile_layout: None, mobile_threshold_cols: None, mobile_threshold_rows: None, + nested_session_handling: None, }, themes: {}, plugins: PluginAliases { |
