diff options
| author | user <user@clank> | 2026-08-08 19:49:23 +0200 |
|---|---|---|
| committer | user <user@clank> | 2026-08-12 19:34:18 +0200 |
| commit | 925097bcb9056196709d7fbeae7ab9d4fe3da603 (patch) | |
| tree | c76e10141d93f885478f98af0d725637714e7a8f | |
| parent | sl0p: configurable pane title alignment (diff) | |
| download | sl0ppi-925097bcb9056196709d7fbeae7ab9d4fe3da603.tar.gz sl0ppi-925097bcb9056196709d7fbeae7ab9d4fe3da603.tar.xz sl0ppi-925097bcb9056196709d7fbeae7ab9d4fe3da603.zip | |
sl0p: configurable pane gap (outer) and padding (inner)
Adds `ui { pane_frames { gap N; padding N } }`, both defaulting to 0 so
stock configs are unaffected.
gap - cells each pane gives up on every side, leaving real empty
terminal between neighbouring panes (WM-style outer gaps).
Two adjacent panes therefore show 2*gap between them.
padding - cells between a pane's frame and its content; breathing room
inside the pane without moving the frame.
Design: the pane KEEPS its allocated PaneGeom. Only two things move:
1. the drawn frame, via Viewport::inset(gap), reusing the existing
frame_geom_override mechanism already used for stacked panes;
2. the content, via Offset::expanded_by(gap + padding) inside
set_content_offset.
Because the allocation is untouched, the kasuari resize solver and mouse
hit-testing need no changes at all, and a click landing in a gap still
resolves to the owning pane. Content position, size and cursor are all
derived from content_offset, so widening it in one place keeps every
consumer consistent.
Viewport::inset refuses to shrink a pane below a frame's minimum viable
extent (two borders + one content cell) rather than emitting a degenerate
or zero-sized frame. Negative KDL values clamp to 0 instead of wrapping.
Tests cover: inset identity/shrink/recentre, the containment invariant
(an inset frame never escapes its allocation), small-pane refusal, and
the key safety property that content inset by gap+border+padding lands
strictly inside the frame drawn at inset(gap).
| -rw-r--r-- | sl0ppij/zellij-client/src/web_client/server_listener.rs | 2 | ||||
| -rw-r--r-- | sl0ppij/zellij-server/src/lib.rs | 4 | ||||
| -rw-r--r-- | sl0ppij/zellij-server/src/panes/plugin_pane.rs | 9 | ||||
| -rw-r--r-- | sl0ppij/zellij-server/src/panes/terminal_pane.rs | 12 | ||||
| -rw-r--r-- | sl0ppij/zellij-utils/src/data.rs | 12 | ||||
| -rw-r--r-- | sl0ppij/zellij-utils/src/input/config.rs | 2 | ||||
| -rw-r--r-- | sl0ppij/zellij-utils/src/input/theme.rs | 6 | ||||
| -rw-r--r-- | sl0ppij/zellij-utils/src/kdl/mod.rs | 33 | ||||
| -rw-r--r-- | sl0ppij/zellij-utils/src/pane_size.rs | 133 | ||||
| -rw-r--r-- | sl0ppij/zellij-utils/src/plugin_api/event.rs | 2 | ||||
| -rw-r--r-- | sl0ppij/zellij-utils/src/plugin_api/style.rs | 2 |
11 files changed, 211 insertions, 6 deletions
diff --git a/sl0ppij/zellij-client/src/web_client/server_listener.rs b/sl0ppij/zellij-client/src/web_client/server_listener.rs index 5d75343..71ef537 100644 --- a/sl0ppij/zellij-client/src/web_client/server_listener.rs +++ b/sl0ppij/zellij-client/src/web_client/server_listener.rs @@ -84,6 +84,8 @@ pub fn zellij_server_listener( rounded_corners: config.ui.pane_frames.rounded_corners, hide_session_name: config.ui.pane_frames.hide_session_name, pane_title_alignment: config.ui.pane_frames.title_alignment, + pane_gap: config.ui.pane_frames.gap, + pane_padding: config.ui.pane_frames.padding, }, }; diff --git a/sl0ppij/zellij-server/src/lib.rs b/sl0ppij/zellij-server/src/lib.rs index 38b83ad..319a106 100644 --- a/sl0ppij/zellij-server/src/lib.rs +++ b/sl0ppij/zellij-server/src/lib.rs @@ -1001,6 +1001,8 @@ pub fn start_server_impl( rounded_corners: config.ui.pane_frames.rounded_corners, hide_session_name: config.ui.pane_frames.hide_session_name, pane_title_alignment: config.ui.pane_frames.title_alignment, + pane_gap: config.ui.pane_frames.gap, + pane_padding: config.ui.pane_frames.padding, }, }; @@ -1185,6 +1187,8 @@ pub fn start_server_impl( rounded_corners: config.ui.pane_frames.rounded_corners, hide_session_name: config.ui.pane_frames.hide_session_name, pane_title_alignment: config.ui.pane_frames.title_alignment, + pane_gap: config.ui.pane_frames.gap, + pane_padding: config.ui.pane_frames.padding, }, }; diff --git a/sl0ppij/zellij-server/src/panes/plugin_pane.rs b/sl0ppij/zellij-server/src/panes/plugin_pane.rs index 1d1f1d2..4d30cb4 100644 --- a/sl0ppij/zellij-server/src/panes/plugin_pane.rs +++ b/sl0ppij/zellij-server/src/panes/plugin_pane.rs @@ -24,7 +24,7 @@ use zellij_utils::data::PaneContents; use zellij_utils::data::{ BareKey, KeyWithModifier, PermissionStatus, PermissionType, PluginPermission, }; -use zellij_utils::pane_size::{Offset, SizeInPixels}; +use zellij_utils::pane_size::{Offset, SizeInPixels, Viewport}; use zellij_utils::position::Position; use zellij_utils::{ channels::SenderWithContext, @@ -465,8 +465,11 @@ impl Pane for PluginPane { }; let is_pinned = frame_geom.is_pinned; + // see the matching comment in terminal_pane.rs: the frame is drawn + // inset from the pane's allocated geometry to produce the outer gap + let frame_viewport = Viewport::from(frame_geom).inset(self.style.pane_gap); let mut frame = PaneFrame::new( - frame_geom.into(), + frame_viewport, grid.scrollback_position_and_length(), pane_title, frame_params, @@ -712,7 +715,7 @@ impl Pane for PluginPane { self.frame.clear(); } fn set_content_offset(&mut self, offset: Offset) { - self.content_offset = offset; + self.content_offset = offset.expanded_by(self.style.pane_gap + self.style.pane_padding); self.resize_grids(); } diff --git a/sl0ppij/zellij-server/src/panes/terminal_pane.rs b/sl0ppij/zellij-server/src/panes/terminal_pane.rs index 9181df9..ab17c7c 100644 --- a/sl0ppij/zellij-server/src/panes/terminal_pane.rs +++ b/sl0ppij/zellij-server/src/panes/terminal_pane.rs @@ -22,7 +22,7 @@ use vte; use zellij_utils::data::PaneContents; use zellij_utils::input::command::RunCommand; use zellij_utils::input::mouse::{MouseEvent, MouseEventType}; -use zellij_utils::pane_size::Offset; +use zellij_utils::pane_size::{Offset, Viewport}; use zellij_utils::{ data::{ BareKey, InputMode, KeyWithModifier, Palette, PaletteColor, PaneId as ZellijUtilsPaneId, @@ -574,8 +574,14 @@ impl Pane for TerminalPane { .frame_geom_override .unwrap_or_else(|| self.current_geom()); let is_pinned = frame_geom.is_pinned; + // Draw the frame inset from the pane's allocated geometry. The pane + // keeps its real PaneGeom, so the resize solver and mouse hit-testing + // are untouched; only the drawn frame moves inward, leaving empty + // cells between neighbouring panes. Content is inset to match in + // set_content_offset(). + let frame_viewport = Viewport::from(frame_geom).inset(self.style.pane_gap); let mut frame = PaneFrame::new( - frame_geom.into(), + frame_viewport, self.grid.scrollback_position_and_length(), pane_title, frame_params, @@ -929,7 +935,7 @@ impl Pane for TerminalPane { } fn set_content_offset(&mut self, offset: Offset) { - self.content_offset = offset; + self.content_offset = offset.expanded_by(self.style.pane_gap + self.style.pane_padding); self.reflow_lines(); } diff --git a/sl0ppij/zellij-utils/src/data.rs b/sl0ppij/zellij-utils/src/data.rs index f4ce534..c6603e7 100644 --- a/sl0ppij/zellij-utils/src/data.rs +++ b/sl0ppij/zellij-utils/src/data.rs @@ -1423,6 +1423,18 @@ pub struct Style { /// the committed prost assets. Defaults to Left when coming back from a /// ProtobufStyle. pub pane_title_alignment: PaneTitleAlignment, + /// OUTER gap: cells each pane gives up on every side, leaving empty + /// terminal between neighbouring panes. Two adjacent panes therefore show + /// 2 * pane_gap cells between them, and there is a gap at the screen edge. + /// The pane keeps its allocated PaneGeom - only the drawn frame and the + /// content are inset - so the resize solver and mouse hit-testing are + /// unaffected and clicks inside a gap still resolve to the owning pane. + /// + /// Like pane_title_alignment, not carried over the plugin protobuf boundary. + pub pane_gap: usize, + /// INNER padding: cells between a pane's frame and its content. Purely + /// cosmetic breathing room inside the pane; does not move the frame. + pub pane_padding: usize, } #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Deserialize, Serialize)] diff --git a/sl0ppij/zellij-utils/src/input/config.rs b/sl0ppij/zellij-utils/src/input/config.rs index 9387aef..546d39d 100644 --- a/sl0ppij/zellij-utils/src/input/config.rs +++ b/sl0ppij/zellij-utils/src/input/config.rs @@ -1408,6 +1408,8 @@ mod config_test { rounded_corners: true, hide_session_name: true, title_alignment: Default::default(), + gap: Default::default(), + padding: Default::default(), }, }; assert_eq!(config.ui, expected_ui_config, "Ui config defined in config"); diff --git a/sl0ppij/zellij-utils/src/input/theme.rs b/sl0ppij/zellij-utils/src/input/theme.rs index 0930bc1..949a875 100644 --- a/sl0ppij/zellij-utils/src/input/theme.rs +++ b/sl0ppij/zellij-utils/src/input/theme.rs @@ -27,6 +27,10 @@ pub struct FrameConfig { pub rounded_corners: bool, pub hide_session_name: bool, pub title_alignment: crate::data::PaneTitleAlignment, + /// outer gap between panes, in cells (see Style::pane_gap) + pub gap: usize, + /// inner padding between a pane's frame and its content (see Style::pane_padding) + pub padding: usize, } impl FrameConfig { @@ -35,6 +39,8 @@ impl FrameConfig { merged.rounded_corners = other.rounded_corners; merged.hide_session_name = other.hide_session_name; merged.title_alignment = other.title_alignment; + merged.gap = other.gap; + merged.padding = other.padding; merged } } diff --git a/sl0ppij/zellij-utils/src/kdl/mod.rs b/sl0ppij/zellij-utils/src/kdl/mod.rs index bc188ae..6589d30 100644 --- a/sl0ppij/zellij-utils/src/kdl/mod.rs +++ b/sl0ppij/zellij-utils/src/kdl/mod.rs @@ -2482,6 +2482,17 @@ macro_rules! kdl_children_property_first_arg_as_bool { } #[macro_export] +macro_rules! kdl_children_property_first_arg_as_i64 { + ( $kdl_node:expr, $property_name:expr ) => { + $kdl_node + .children() + .and_then(|c| c.get($property_name)) + .and_then(|p| p.entries().iter().next()) + .and_then(|p| p.value().as_i64()) + }; +} + +#[macro_export] macro_rules! kdl_property_first_arg_as_i64 { ( $kdl_node:expr, $property_name:expr ) => { $kdl_node @@ -5535,10 +5546,20 @@ impl UiConfig { }, None => crate::data::PaneTitleAlignment::default(), }; + // negative values are meaningless here and would wrap on `as usize`, + // so clamp at 0 rather than silently producing a gigantic inset + let gap = kdl_children_property_first_arg_as_i64!(pane_frames, "gap") + .unwrap_or(0) + .max(0) as usize; + let padding = kdl_children_property_first_arg_as_i64!(pane_frames, "padding") + .unwrap_or(0) + .max(0) as usize; let frame_config = FrameConfig { rounded_corners, hide_session_name, title_alignment, + gap, + padding, }; ui_config.pane_frames = frame_config; } @@ -5575,6 +5596,18 @@ impl UiConfig { )); frame_config_children.nodes_mut().push(title_alignment); } + if self.pane_frames.gap > 0 { + has_ui_config = true; + let mut gap = KdlNode::new("gap"); + gap.push(KdlValue::Base10(self.pane_frames.gap as i64)); + frame_config_children.nodes_mut().push(gap); + } + if self.pane_frames.padding > 0 { + has_ui_config = true; + let mut padding = KdlNode::new("padding"); + padding.push(KdlValue::Base10(self.pane_frames.padding as i64)); + frame_config_children.nodes_mut().push(padding); + } if has_ui_config { frame_config.set_children(frame_config_children); ui_config_children.nodes_mut().push(frame_config); diff --git a/sl0ppij/zellij-utils/src/pane_size.rs b/sl0ppij/zellij-utils/src/pane_size.rs index 454e73c..1326a85 100644 --- a/sl0ppij/zellij-utils/src/pane_size.rs +++ b/sl0ppij/zellij-utils/src/pane_size.rs @@ -55,6 +55,34 @@ pub struct Viewport { } impl Viewport { + /// Shrink this viewport by `by` cells on every side, keeping it centred in + /// the space it started from. Used to draw a pane's frame inset from the + /// geometry the pane was actually allocated, which is what produces a + /// visible gap between neighbouring panes. + /// + /// Refuses to inset a viewport that is too small to survive it: a frame + /// needs at least its two borders plus a cell of content in each axis, so + /// below that we return the viewport untouched rather than emit a + /// degenerate (or zero-sized) frame. + pub fn inset(&self, by: usize) -> Viewport { + const MIN_FRAMED_EXTENT: usize = 3; // left border + 1 content cell + right border + if by == 0 { + return *self; + } + let shrink = by.saturating_mul(2); + if self.cols < shrink.saturating_add(MIN_FRAMED_EXTENT) + || self.rows < shrink.saturating_add(MIN_FRAMED_EXTENT) + { + return *self; + } + Viewport { + x: self.x.saturating_add(by), + y: self.y.saturating_add(by), + cols: self.cols.saturating_sub(shrink), + rows: self.rows.saturating_sub(shrink), + } + } + pub fn has_positive_size(&self) -> bool { self.rows > 0 && self.cols > 0 } @@ -425,6 +453,25 @@ impl Display for PaneGeom { } impl Offset { + /// Grow this offset by `by` cells on every side. + /// + /// Used to push a pane's content inward for the outer gap (so the content + /// stays inside the inset frame) and for the inner padding (breathing room + /// between the frame and the content). Content position and size, and the + /// cursor, are all derived from content_offset, so widening it here is + /// enough to keep every consumer consistent. + pub fn expanded_by(&self, by: usize) -> Self { + if by == 0 { + return *self; + } + Self { + top: self.top.saturating_add(by), + bottom: self.bottom.saturating_add(by), + left: self.left.saturating_add(by), + right: self.right.saturating_add(by), + } + } + pub fn frame(size: usize) -> Self { Self { top: size, @@ -512,3 +559,89 @@ impl From<&Size> for PaneGeom { } } } + +#[cfg(test)] +mod gap_and_padding_tests { + use super::*; + + fn vp(x: usize, y: usize, cols: usize, rows: usize) -> Viewport { + Viewport { x, y, cols, rows } + } + + #[test] + fn inset_zero_is_identity() { + let v = vp(0, 0, 80, 24); + assert_eq!(v.inset(0), v); + } + + #[test] + fn inset_shrinks_and_recentres() { + let v = vp(10, 5, 80, 24).inset(1); + assert_eq!((v.x, v.y, v.cols, v.rows), (11, 6, 78, 22)); + let v = vp(10, 5, 80, 24).inset(2); + assert_eq!((v.x, v.y, v.cols, v.rows), (12, 7, 76, 20)); + } + + #[test] + fn inset_keeps_the_pane_inside_its_allocation() { + // the inset frame must never escape the geometry it was given, or it + // would overdraw a neighbouring pane + let (x, y, cols, rows) = (10, 5, 80, 24); + for by in 0..12 { + let v = vp(x, y, cols, rows).inset(by); + assert!(v.x >= x, "by={} moved x left", by); + assert!(v.y >= y, "by={} moved y up", by); + assert!(v.x + v.cols <= x + cols, "by={} overflowed right edge", by); + assert!(v.y + v.rows <= y + rows, "by={} overflowed bottom edge", by); + } + } + + #[test] + fn inset_refuses_to_collapse_small_panes() { + // too small to hold two borders plus a content cell: left untouched + // rather than emitting a zero-sized or inverted frame + for (cols, rows) in [(4, 24), (24, 4), (1, 1), (4, 4)] { + let v = vp(0, 0, cols, rows); + assert_eq!(v.inset(1), v, "{}x{} should be left alone", cols, rows); + } + // 5x5 is exactly the threshold for by=1 (2*1 + 3): it survives, and + // insets down to a still-legal 3x3 frame (two borders + one cell) + assert_eq!(vp(0, 0, 5, 5).inset(1), vp(1, 1, 3, 3)); + assert_eq!(vp(0, 0, 6, 6).inset(1), vp(1, 1, 4, 4)); + // a bigger gap needs a correspondingly bigger pane to survive + assert_eq!(vp(0, 0, 6, 6).inset(2), vp(0, 0, 6, 6)); + assert_eq!(vp(0, 0, 7, 7).inset(2), vp(2, 2, 3, 3)); + } + + #[test] + fn expanded_by_grows_every_side() { + let o = Offset::frame(1).expanded_by(2); + assert_eq!((o.top, o.bottom, o.left, o.right), (3, 3, 3, 3)); + let o = Offset::default().expanded_by(0); + assert_eq!((o.top, o.bottom, o.left, o.right), (0, 0, 0, 0)); + } + + #[test] + fn frame_and_content_insets_agree() { + // The invariant that makes gaps safe: content inset by (gap + border + + // padding) must land strictly inside the frame drawn at inset(gap). + let (gap, padding) = (1usize, 1usize); + let alloc = vp(0, 0, 40, 20); + let frame = alloc.inset(gap); + let content = Offset::frame(1).expanded_by(gap + padding); + let content_x = alloc.x + content.left; + let content_y = alloc.y + content.top; + let content_cols = alloc.cols.saturating_sub(content.left + content.right); + let content_rows = alloc.rows.saturating_sub(content.top + content.bottom); + assert!(content_x > frame.x, "content must start inside the frame border"); + assert!(content_y > frame.y, "content must start inside the frame border"); + assert!( + content_x + content_cols < frame.x + frame.cols, + "content must end inside the frame border" + ); + assert!( + content_y + content_rows < frame.y + frame.rows, + "content must end inside the frame border" + ); + } +} diff --git a/sl0ppij/zellij-utils/src/plugin_api/event.rs b/sl0ppij/zellij-utils/src/plugin_api/event.rs index 0189d11..f4bb352 100644 --- a/sl0ppij/zellij-utils/src/plugin_api/event.rs +++ b/sl0ppij/zellij-utils/src/plugin_api/event.rs @@ -2493,6 +2493,8 @@ fn serialize_mode_update_event_with_non_default_values() { rounded_corners: true, hide_session_name: false, pane_title_alignment: Default::default(), + pane_gap: Default::default(), + pane_padding: Default::default(), }, capabilities: PluginCapabilities { arrow_fonts: false }, session_name: Some("my awesome test session".to_owned()), diff --git a/sl0ppij/zellij-utils/src/plugin_api/style.rs b/sl0ppij/zellij-utils/src/plugin_api/style.rs index 2f3ff29..46c3ce8 100644 --- a/sl0ppij/zellij-utils/src/plugin_api/style.rs +++ b/sl0ppij/zellij-utils/src/plugin_api/style.rs @@ -26,6 +26,8 @@ impl TryFrom<ProtobufStyle> for Style { // alignment, and adding a proto field would mean regenerating the // committed prost assets. pane_title_alignment: Default::default(), + pane_gap: Default::default(), + pane_padding: Default::default(), }) } } |
