diff options
| author | user <user@clank> | 2026-08-11 17:00:37 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-11 17:00:37 +0200 |
| commit | 508b5aa87ced4c7aab38bcb0e34c4158e5b4e101 (patch) | |
| tree | 511485d45371596801f25354f62bc938e882a890 /zellij-server/src/tab/swap_layouts.rs | |
| parent | sl0p: warn when the responsive layout has no swap layout to collapse into (diff) | |
| download | sl0ppij-508b5aa87ced4c7aab38bcb0e34c4158e5b4e101.tar.gz sl0ppij-508b5aa87ced4c7aab38bcb0e34c4158e5b4e101.tar.xz sl0ppij-508b5aa87ced4c7aab38bcb0e34c4158e5b4e101.zip | |
sl0p: synthesize a stack layout when none exists to collapse into
The collapse selects a swap layout by name, and a custom layout file only gets
swap layouts from a hand-written sibling "<layout>.swap.kdl". So for most
layouts there was nothing to select and the feature silently did nothing --
requiring a boilerplate file per layout to use it at all.
Now a missing layout is synthesized: every pane flattened into one stack, in
layout order. Appended rather than inserted, so it cannot shift the BASE layout
at position 0, which is what the collapse restores back to.
Synthesized lazily, at the first collapse, rather than up front: a stack sitting
in the swap cycle would let auto_layout apply it spontaneously when a pane is
added, stacking panes on a perfectly wide terminal.
Also scopes the damaged-layout guard. With no swap layouts, relayout finds
nothing applicable on the first pane added, gives up and marks the tab damaged
-- permanently, and with nothing to do with user intent. Honouring that flag
disabled the collapse for exactly the bare layouts this fallback targets, so it
is now only consulted when the tab has swap layouts the user actually defined.
Diffstat (limited to 'zellij-server/src/tab/swap_layouts.rs')
| -rw-r--r-- | zellij-server/src/tab/swap_layouts.rs | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/zellij-server/src/tab/swap_layouts.rs b/zellij-server/src/tab/swap_layouts.rs index 25e02190..54bcf8f3 100644 --- a/zellij-server/src/tab/swap_layouts.rs +++ b/zellij-server/src/tab/swap_layouts.rs @@ -17,6 +17,8 @@ pub struct SwapLayouts { current_tiled_layout_position: usize, is_floating_damaged: bool, is_tiled_damaged: bool, + /// Position of the layout synthesized for the responsive collapse, if any. + synthesized_tiled_position: Option<usize>, display_area: Rc<RefCell<Size>>, // includes all panes (including eg. the status bar and tab bar in the default layout) } @@ -81,6 +83,45 @@ impl SwapLayouts { pub fn is_tiled_damaged(&self) -> bool { self.is_tiled_damaged } + /// Append a synthesized "flatten into one stack" layout under `name`, and + /// return its position. + /// + /// A custom layout file only gets swap layouts from a hand-written sibling + /// `<layout>.swap.kdl`, so most layouts have none and the responsive + /// collapse has nothing to select. Rather than require that file, synthesize + /// the one layout the collapse actually needs. + /// + /// Appended rather than inserted so it cannot shift the position of the BASE + /// layout at 0, which is what a collapse restores back to. + pub fn append_synthesized_stack_layout(&mut self, name: &str) -> usize { + let mut constraints = BTreeMap::new(); + // MinPanes(2) because a "stack" of one pane is just that pane, and + // collapsing to it would be a no-op that still counted as collapsed + constraints.insert(LayoutConstraint::MinPanes(2), TiledPaneLayout::single_stack()); + self.swap_tiled_layouts + .push((constraints, Some(name.to_string()))); + let position = self.swap_tiled_layouts.len() - 1; + self.synthesized_tiled_position = Some(position); + position + } + /// Whether this tab has any tiled swap layout the USER defined. + /// + /// "BASE" is inserted from the tab's own layout, and the synthesized stack is + /// ours, so neither says anything about user intent. Matters because the + /// damaged flag means two different things: with user swap layouts it tracks + /// "the arrangement was changed by hand", but with none it is set on the + /// first pane added -- relayout finds nothing applicable and gives up -- and + /// then never clears, which would disable the responsive collapse entirely + /// for exactly the bare layouts it is most useful for. + pub fn has_user_defined_tiled_layouts(&self) -> bool { + self.swap_tiled_layouts + .iter() + .enumerate() + .any(|(position, (_constraints, name))| { + Some(position) != self.synthesized_tiled_position + && name.as_deref() != Some("BASE") + }) + } /// Position of the swap tiled layout with this name, if any. /// /// Used by the responsive-layout switch, which selects a layout BY NAME |
