aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-utils/src/plugin_api/plugin_command.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2026-06-10 16:50:55 +0200
committerGitHub <noreply@github.com>2026-06-10 16:50:55 +0200
commitb6a5ad0e5a93d9f584b3f7a0fc90f497a09cbdb0 (patch)
tree38c77a381cfb937b428752a588c09a45c81434c9 /zellij-utils/src/plugin_api/plugin_command.rs
parentfeat: PWA support for the web client (#5184) (diff)
downloadsl0ppij-b6a5ad0e5a93d9f584b3f7a0fc90f497a09cbdb0.tar.gz
sl0ppij-b6a5ad0e5a93d9f584b3f7a0fc90f497a09cbdb0.tar.xz
sl0ppij-b6a5ad0e5a93d9f584b3f7a0fc90f497a09cbdb0.zip
Mobile layout (#5241)
* phase 2+3 * initial mobile plugin (phases 4 + 5 + 6) * some bugfixes * implement stage 7 * mobile interface improvements * improve mobile pane/tab picker * more ui improvements and fixes * various mobile fixes * some mobile fixes * mobile keyboard triggering fix * some cleanups * initial plugin keyboard implementation * improve keyboard hit zones * improve keyboard * pinch resize * pinching fixes * implement scrolling + panning * initial keyboard resizing * fix: mobile first render issues * keyboard responsiveness * fix some issues with the keyboard * implement fit * fix mobile scrolling * add tilde cell to compact * improve mobile keyboard * fix starting mobile terminal font to natural keyboard size * fix mobile resize blank screen flash * shadow focus for mobile * more keyboard fixes * improve mobile status bar * fix: render plugins to mobile clients * allow opening new panes/tabs from the mobile plugin * allow configuring * fix dot slash * improve mobile native soft keyboard interaction * switch to native keyboard - initial implementation * dirty hacks, but phone keyboard works now * adjust keyboard help strip * fix cursor in mobile * fix keyboard and help line * rename keyboard to modifier bar * allow starting new session * make clicking session name bring us to new session menu * allow switching to desktop from the mobile ui * mobile welcome screen initial implementation * mobile welcome screen fixes * various welcome screen fixes * more mobile fixes * moar mobile fixes * mobile ui redesign * fix: swallowed backspace bug * switch session screen improvement * touch up some interfaces * refactor: move mobile state to own struct * refactor: move fit resizing to the server * remove dead flash code * some cleanups * refactor: clear fit on close * refactor: improve fit api * refactor: pane sync functions * refactor: mouse * refactor: break into modules * some cleanups for the sessions screen * fix scrolling and other stuff * refactor: sessions screen * refactor: panes screen * refactor: new session screen * refactor: menu screen * refactor: render * cleanups * refactor: plugin structure * remove unused welcome screen path * Rename api * refactor input.js * cleanup useless comments * fit/mobile refactoring * take out the garbage * remove more comments * remove mobile flash on startup/attach * fix: various mobile startup issues * fix space bugs * cleanup * rustfmt * fix windows build * adjust modifier bar ui * add pr
Diffstat (limited to 'zellij-utils/src/plugin_api/plugin_command.rs')
-rw-r--r--zellij-utils/src/plugin_api/plugin_command.rs223
1 files changed, 213 insertions, 10 deletions
diff --git a/zellij-utils/src/plugin_api/plugin_command.rs b/zellij-utils/src/plugin_api/plugin_command.rs
index fa77739a..42b0774f 100644
--- a/zellij-utils/src/plugin_api/plugin_command.rs
+++ b/zellij-utils/src/plugin_api/plugin_command.rs
@@ -13,9 +13,9 @@ pub use super::generated_api::api::{
get_focused_pane_info_response, get_pane_cwd_response, get_pane_pid_response,
get_pane_running_command_response, get_session_list_response, hide_floating_panes_response,
highlight_style::Style as ProtobufHighlightStyleVariant, new_tab_response,
- parse_layout_response, plugin_command::Payload, rename_layout_response,
- save_layout_response, save_session_response, show_floating_panes_response,
- BreakPanesToNewTabPayload,
+ new_tab_unfocused_response, parse_layout_response, plugin_command::Payload,
+ rename_layout_response, save_layout_response, save_session_response,
+ show_floating_panes_response, BreakPanesToNewTabPayload,
BreakPanesToNewTabResponse as ProtobufBreakPanesToNewTabResponse,
BreakPanesToTabWithIdPayload,
BreakPanesToTabWithIdResponse as ProtobufBreakPanesToTabWithIdResponse,
@@ -65,8 +65,10 @@ pub use super::generated_api::api::{
KillSessionsResponse as ProtobufKillSessionsResponse, ListTokensResponse,
LoadNewPluginPayload, MessageToPluginPayload, MovePaneWithPaneIdInDirectionPayload,
MovePaneWithPaneIdPayload, MovePayload, NewPluginArgs as ProtobufNewPluginArgs,
- NewTabPayload, NewTabResponse as ProtobufNewTabResponse,
+ NewTabPayload, NewTabResponse as ProtobufNewTabResponse, NewTabUnfocusedPayload,
+ NewTabUnfocusedResponse as ProtobufNewTabUnfocusedResponse,
NewTabsResponse as ProtobufNewTabsResponse, NewTabsWithLayoutInfoPayload,
+ NewTiledPaneInTabPayload, NewTiledPaneInTabResponse as ProtobufNewTiledPaneInTabResponse,
OpenCommandPaneBackgroundResponse as ProtobufOpenCommandPaneBackgroundResponse,
OpenCommandPaneFloatingNearPluginPayload,
OpenCommandPaneFloatingNearPluginResponse as ProtobufOpenCommandPaneFloatingNearPluginResponse,
@@ -119,13 +121,15 @@ pub use super::generated_api::api::{
ScrollToBottomInPaneIdPayload, ScrollToTopInPaneIdPayload, ScrollUpInPaneIdPayload,
SessionListSnapshot as ProtobufSessionListSnapshot, SetFloatingPanePinnedPayload,
SetPaneBorderlessPayload, SetPaneColorPayload, SetPaneRegexHighlightsPayload,
- SetSelfMouseSelectionSupportPayload, SetTimeoutPayload, ShowCursorPayload,
+ SetSelfMouseSelectionSupportPayload,
+ SetSoftKeyboardPayload as ProtobufSetSoftKeyboardPayload,
+ SetTabFitPayload as ProtobufSetTabFitPayload, SetTimeoutPayload, ShowCursorPayload,
ShowFloatingPanesPayload as ProtobufShowFloatingPanesPayload,
ShowFloatingPanesResponse as ProtobufShowFloatingPanesResponse, ShowPaneWithIdPayload,
- StackPanesPayload, SubscribePayload, SwitchSessionPayload, SwitchTabToIdPayload,
- SwitchTabToPayload, TogglePaneBorderlessPayload, TogglePaneEmbedOrEjectForPaneIdPayload,
- TogglePaneIdFullscreenPayload, UnsubscribePayload, WebRequestPayload,
- WriteCharsToPaneIdPayload, WriteToPaneIdPayload,
+ Size as ProtobufSize, StackPanesPayload, SubscribePayload, SwitchSessionPayload,
+ SwitchTabToIdPayload, SwitchTabToPayload, TogglePaneBorderlessPayload,
+ TogglePaneEmbedOrEjectForPaneIdPayload, TogglePaneIdFullscreenPayload, UnsubscribePayload,
+ WebRequestPayload, WriteCharsToPaneIdPayload, WriteToPaneIdPayload,
},
plugin_permission::PermissionType as ProtobufPermissionType,
resize::ResizeAction as ProtobufResizeAction,
@@ -141,11 +145,26 @@ use crate::data::{
};
use crate::input::actions::Action;
use crate::input::layout::PercentOrFixed;
+use crate::pane_size::Size;
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::path::PathBuf;
+fn size_from_protobuf(size: ProtobufSize) -> Size {
+ Size {
+ rows: size.rows as usize,
+ cols: size.cols as usize,
+ }
+}
+
+fn size_to_protobuf(size: Size) -> ProtobufSize {
+ ProtobufSize {
+ rows: size.rows as u32,
+ cols: size.cols as u32,
+ }
+}
+
impl Into<FloatingPaneCoordinates> for ProtobufFloatingPaneCoordinates {
fn into(self) -> FloatingPaneCoordinates {
FloatingPaneCoordinates {
@@ -900,6 +919,27 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
}),
_ => Err("Mismatched payload for NewTab"),
},
+ Some(CommandName::NewTabUnfocused) => match protobuf_plugin_command.payload {
+ Some(Payload::NewTabUnfocusedPayload(payload)) => {
+ Ok(PluginCommand::NewTabUnfocused {
+ name: payload.name,
+ cwd: payload.cwd,
+ })
+ },
+ None => Ok(PluginCommand::NewTabUnfocused {
+ name: None,
+ cwd: None,
+ }),
+ _ => Err("Mismatched payload for NewTabUnfocused"),
+ },
+ Some(CommandName::NewTiledPaneInTab) => match protobuf_plugin_command.payload {
+ Some(Payload::NewTiledPaneInTabPayload(payload)) => {
+ Ok(PluginCommand::NewTiledPaneInTab {
+ tab_position: payload.tab_position as usize,
+ })
+ },
+ _ => Err("Mismatched payload for NewTiledPaneInTab"),
+ },
Some(CommandName::GoToNextTab) => {
if protobuf_plugin_command.payload.is_some() {
return Err("GoToNextTab should not have a payload");
@@ -1448,6 +1488,38 @@ impl TryFrom<ProtobufPluginCommand> for PluginCommand {
Some(CommandName::DeleteAllDeadSessionsAndReply) => {
Ok(PluginCommand::DeleteAllDeadSessionsAndReply)
},
+ Some(CommandName::SetSoftKeyboard) => match protobuf_plugin_command.payload {
+ Some(Payload::SetSoftKeyboardPayload(payload)) => {
+ Ok(PluginCommand::SetSoftKeyboard(payload.on))
+ },
+ _ => Err("Mismatched payload for SetSoftKeyboard"),
+ },
+ Some(CommandName::SetTabFit) => match protobuf_plugin_command.payload {
+ Some(Payload::SetTabFitPayload(payload)) => {
+ let fit = match (payload.pane_id, payload.size) {
+ (Some(pane_id), Some(size)) => {
+ Some((pane_id.try_into()?, size_from_protobuf(size)))
+ },
+ (None, None) => None,
+ _ => return Err("Malformed set_tab_fit_payload payload"),
+ };
+ Ok(PluginCommand::SetTabFit {
+ tab_id: payload.tab_id as usize,
+ fit,
+ })
+ },
+ _ => Err("Mismatched payload for SetTabFit"),
+ },
+ Some(CommandName::ExitMobileMode) => match protobuf_plugin_command.payload {
+ Some(_) => Err("ExitMobileMode should have no payload, found a payload"),
+ None => Ok(PluginCommand::ExitMobileMode),
+ },
+ Some(CommandName::SetShadowFocus) => match protobuf_plugin_command.payload {
+ Some(Payload::SetShadowFocusPayload(pane_id)) => {
+ Ok(PluginCommand::SetShadowFocus(pane_id.try_into()?))
+ },
+ _ => Err("Mismatched payload for SetShadowFocus"),
+ },
Some(CommandName::DumpSessionLayout) => match protobuf_plugin_command.payload {
Some(Payload::DumpSessionLayoutPayload(payload)) => {
Ok(PluginCommand::DumpSessionLayout {
@@ -2890,6 +2962,21 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
name: CommandName::NewTab as i32,
payload: Some(Payload::NewTabPayload(NewTabPayload { name, cwd })),
}),
+ PluginCommand::NewTabUnfocused { name, cwd } => Ok(ProtobufPluginCommand {
+ name: CommandName::NewTabUnfocused as i32,
+ payload: Some(Payload::NewTabUnfocusedPayload(NewTabUnfocusedPayload {
+ name,
+ cwd,
+ })),
+ }),
+ PluginCommand::NewTiledPaneInTab { tab_position } => Ok(ProtobufPluginCommand {
+ name: CommandName::NewTiledPaneInTab as i32,
+ payload: Some(Payload::NewTiledPaneInTabPayload(
+ NewTiledPaneInTabPayload {
+ tab_position: tab_position as u32,
+ },
+ )),
+ }),
PluginCommand::GoToNextTab => Ok(ProtobufPluginCommand {
name: CommandName::GoToNextTab as i32,
payload: None,
@@ -3315,6 +3402,32 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
name: CommandName::DeleteAllDeadSessionsAndReply as i32,
payload: None,
}),
+ PluginCommand::SetSoftKeyboard(on) => Ok(ProtobufPluginCommand {
+ name: CommandName::SetSoftKeyboard as i32,
+ payload: Some(Payload::SetSoftKeyboardPayload(
+ ProtobufSetSoftKeyboardPayload { on },
+ )),
+ }),
+ PluginCommand::SetTabFit { tab_id, fit } => {
+ let (pane_id, size) = match fit {
+ Some((pane_id, size)) => {
+ (Some(pane_id.try_into()?), Some(size_to_protobuf(size)))
+ },
+ None => (None, None),
+ };
+ Ok(ProtobufPluginCommand {
+ name: CommandName::SetTabFit as i32,
+ payload: Some(Payload::SetTabFitPayload(ProtobufSetTabFitPayload {
+ tab_id: tab_id as u32,
+ pane_id,
+ size,
+ })),
+ })
+ },
+ PluginCommand::ExitMobileMode => Ok(ProtobufPluginCommand {
+ name: CommandName::ExitMobileMode as i32,
+ payload: None,
+ }),
PluginCommand::DumpSessionLayout { tab_index } => Ok(ProtobufPluginCommand {
name: CommandName::DumpSessionLayout as i32,
payload: tab_index.map(|idx| {
@@ -3437,6 +3550,10 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
name: CommandName::SendSigintToPaneId as i32,
payload: Some(Payload::SendSigintToPaneIdPayload(pane_id.try_into()?)),
}),
+ PluginCommand::SetShadowFocus(pane_id) => Ok(ProtobufPluginCommand {
+ name: CommandName::SetShadowFocus as i32,
+ payload: Some(Payload::SetShadowFocusPayload(pane_id.try_into()?)),
+ }),
PluginCommand::SendSigkillToPaneId(pane_id) => Ok(ProtobufPluginCommand {
name: CommandName::SendSigkillToPaneId as i32,
payload: Some(Payload::SendSigkillToPaneIdPayload(pane_id.try_into()?)),
@@ -4433,7 +4550,8 @@ impl TryFrom<PluginCommand> for ProtobufPluginCommand {
// Conversion implementations for tab creation response types
use crate::data::{
BreakPanesToNewTabResponse, BreakPanesToTabWithIdResponse, BreakPanesToTabWithIndexResponse,
- FocusOrCreateTabResponse, NewTabResponse, NewTabsResponse, OpenCommandPaneBackgroundResponse,
+ FocusOrCreateTabResponse, NewTabResponse, NewTabUnfocusedResponse, NewTabsResponse,
+ NewTiledPaneInTabResponse, OpenCommandPaneBackgroundResponse,
OpenCommandPaneFloatingNearPluginResponse, OpenCommandPaneFloatingResponse,
OpenCommandPaneInPlaceOfPaneIdResponse, OpenCommandPaneInPlaceOfPluginResponse,
OpenCommandPaneInPlaceResponse, OpenCommandPaneNearPluginResponse, OpenCommandPaneResponse,
@@ -4468,6 +4586,47 @@ impl From<NewTabResponse> for ProtobufNewTabResponse {
}
}
+impl TryFrom<ProtobufNewTabUnfocusedResponse> for NewTabUnfocusedResponse {
+ type Error = &'static str;
+ fn try_from(protobuf: ProtobufNewTabUnfocusedResponse) -> Result<Self, Self::Error> {
+ match protobuf.result {
+ Some(new_tab_unfocused_response::Result::TabId(id)) => Ok(Some(id as usize)),
+ Some(new_tab_unfocused_response::Result::None(_)) | None => Ok(None),
+ }
+ }
+}
+
+impl From<NewTabUnfocusedResponse> for ProtobufNewTabUnfocusedResponse {
+ fn from(response: NewTabUnfocusedResponse) -> Self {
+ match response {
+ Some(tab_id) => ProtobufNewTabUnfocusedResponse {
+ result: Some(new_tab_unfocused_response::Result::TabId(tab_id as u64)),
+ },
+ None => ProtobufNewTabUnfocusedResponse {
+ result: Some(new_tab_unfocused_response::Result::None(true)),
+ },
+ }
+ }
+}
+
+impl TryFrom<ProtobufNewTiledPaneInTabResponse> for NewTiledPaneInTabResponse {
+ type Error = &'static str;
+ fn try_from(protobuf: ProtobufNewTiledPaneInTabResponse) -> Result<Self, Self::Error> {
+ match protobuf.pane_id {
+ Some(pane_id) => Ok(Some(pane_id.try_into()?)),
+ None => Ok(None),
+ }
+ }
+}
+
+impl From<NewTiledPaneInTabResponse> for ProtobufNewTiledPaneInTabResponse {
+ fn from(response: NewTiledPaneInTabResponse) -> Self {
+ ProtobufNewTiledPaneInTabResponse {
+ pane_id: response.map(|p| p.try_into().unwrap()),
+ }
+ }
+}
+
impl TryFrom<ProtobufNewTabsResponse> for NewTabsResponse {
type Error = &'static str;
fn try_from(protobuf: ProtobufNewTabsResponse) -> Result<Self, Self::Error> {
@@ -5053,3 +5212,47 @@ impl From<OpenPluginPaneFloatingResponse> for ProtobufOpenPluginPaneFloatingResp
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::data::{PaneId, PluginCommand};
+ use crate::pane_size::Size;
+
+ #[test]
+ fn set_tab_fit_set_protobuf_round_trip() {
+ let original = PluginCommand::SetTabFit {
+ tab_id: 7,
+ fit: Some((PaneId::Terminal(3), Size { rows: 24, cols: 80 })),
+ };
+ let protobuf: ProtobufPluginCommand = original.try_into().expect("encode");
+ let decoded: PluginCommand = protobuf.try_into().expect("decode");
+ match decoded {
+ PluginCommand::SetTabFit { tab_id, fit } => {
+ assert_eq!(tab_id, 7);
+ assert_eq!(
+ fit,
+ Some((PaneId::Terminal(3), Size { rows: 24, cols: 80 }))
+ );
+ },
+ other => panic!("expected SetTabFit, got {:?}", other),
+ }
+ }
+
+ #[test]
+ fn set_tab_fit_clear_protobuf_round_trip() {
+ let original = PluginCommand::SetTabFit {
+ tab_id: 7,
+ fit: None,
+ };
+ let protobuf: ProtobufPluginCommand = original.try_into().expect("encode");
+ let decoded: PluginCommand = protobuf.try_into().expect("decode");
+ match decoded {
+ PluginCommand::SetTabFit { tab_id, fit } => {
+ assert_eq!(tab_id, 7);
+ assert_eq!(fit, None);
+ },
+ other => panic!("expected SetTabFit, got {:?}", other),
+ }
+ }
+}