summaryrefslogtreecommitdiffstats
path: root/zellij-server/src/panes
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2022-12-24 15:48:04 +0100
committerGitHub <noreply@github.com>2022-12-24 15:48:04 +0100
commit799fa5de8dfd0b826be0f903796bba48a470127e (patch)
tree8c202e116b757162cadd0cc350da256b9741e248 /zellij-server/src/panes
parent17205793e4cd2da5eb431dacfc87dab574080b5b (diff)
Floating panes in layouts (#2047)
* work * tests passing * tests: floating panes in layouts * panes(plugins): floating plugins working * refactor(tab): layout applier * style(comment): remove outdated * style(fmt): rustfmt
Diffstat (limited to 'zellij-server/src/panes')
-rw-r--r--zellij-server/src/panes/floating_panes/mod.rs49
-rw-r--r--zellij-server/src/panes/tiled_panes/mod.rs22
2 files changed, 62 insertions, 9 deletions
diff --git a/zellij-server/src/panes/floating_panes/mod.rs b/zellij-server/src/panes/floating_panes/mod.rs
index fe98ee63d..47b3e2f25 100644
--- a/zellij-server/src/panes/floating_panes/mod.rs
+++ b/zellij-server/src/panes/floating_panes/mod.rs
@@ -25,7 +25,8 @@ use zellij_utils::{
data::{ModeInfo, Style},
errors::prelude::*,
input::command::RunCommand,
- pane_size::{Offset, PaneGeom, Size, Viewport},
+ input::layout::FloatingPanesLayout,
+ pane_size::{Dimension, Offset, PaneGeom, Size, Viewport},
};
const RESIZE_INCREMENT_WIDTH: usize = 5;
@@ -224,9 +225,55 @@ impl FloatingPanes {
);
floating_pane_grid.find_room_for_new_pane()
}
+ pub fn position_floating_pane_layout(
+ &mut self,
+ floating_pane_layout: &FloatingPanesLayout,
+ ) -> PaneGeom {
+ let display_area = *self.display_area.borrow();
+ let viewport = *self.viewport.borrow();
+ let floating_pane_grid = FloatingPaneGrid::new(
+ &mut self.panes,
+ &mut self.desired_pane_positions,
+ display_area,
+ viewport,
+ );
+ let mut position = floating_pane_grid.find_room_for_new_pane().unwrap(); // TODO: no unwrap
+ if let Some(x) = &floating_pane_layout.x {
+ position.x = x.to_position(display_area.cols);
+ }
+ if let Some(y) = &floating_pane_layout.y {
+ position.y = y.to_position(display_area.rows);
+ }
+ if let Some(width) = &floating_pane_layout.width {
+ position.cols = Dimension::fixed(width.to_position(display_area.cols));
+ }
+ if let Some(height) = &floating_pane_layout.height {
+ position.rows = Dimension::fixed(height.to_position(display_area.rows));
+ }
+ if position.cols.as_usize() > display_area.cols {
+ position.cols = Dimension::fixed(display_area.cols);
+ }
+ if position.rows.as_usize() > display_area.rows {
+ position.rows = Dimension::fixed(display_area.rows);
+ }
+ if position.x + position.cols.as_usize() > display_area.cols {
+ position.x = position
+ .x
+ .saturating_sub((position.x + position.cols.as_usize()) - display_area.cols);
+ }
+ if position.y + position.rows.as_usize() > display_area.rows {
+ position.y = position
+ .y
+ .saturating_sub((position.y + position.rows.as_usize()) - display_area.rows);
+ }
+ position
+ }
pub fn first_floating_pane_id(&self) -> Option<PaneId> {
self.panes.keys().next().copied()
}
+ pub fn last_floating_pane_id(&self) -> Option<PaneId> {
+ self.panes.keys().last().copied()
+ }
pub fn first_active_floating_pane_id(&self) -> Option<PaneId> {
self.active_panes.values().next().copied()
}
diff --git a/zellij-server/src/panes/tiled_panes/mod.rs b/zellij-server/src/panes/tiled_panes/mod.rs
index 726627f4b..cad53e3f1 100644
--- a/zellij-server/src/panes/tiled_panes/mod.rs
+++ b/zellij-server/src/panes/tiled_panes/mod.rs
@@ -539,10 +539,13 @@ impl TiledPanes {
viewport.cols = (viewport.cols as isize + column_difference) as usize;
display_area.cols = cols;
},
- Err(e) => {
- Err::<(), _>(anyError::msg(e))
- .context("failed to resize tab horizontally")
- .non_fatal();
+ Err(e) => match e.downcast_ref::<ZellijError>() {
+ Some(ZellijError::PaneSizeUnchanged) => {}, // ignore unchanged layout
+ _ => {
+ Err::<(), _>(anyError::msg(e))
+ .context("failed to resize tab horizontally")
+ .non_fatal();
+ },
},
};
match pane_grid.layout(SplitDirection::Vertical, rows) {
@@ -551,10 +554,13 @@ impl TiledPanes {
viewport.rows = (viewport.rows as isize + row_difference) as usize;
display_area.rows = rows;
},
- Err(e) => {
- Err::<(), _>(anyError::msg(e))
- .context("failed to resize tab vertically")
- .non_fatal();
+ Err(e) => match e.downcast_ref::<ZellijError>() {
+ Some(ZellijError::PaneSizeUnchanged) => {}, // ignore unchanged layout
+ _ => {
+ Err::<(), _>(anyError::msg(e))
+ .context("failed to resize tab vertically")
+ .non_fatal();
+ },
},
};
}