aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBrooks J Rady <b.j.rady@gmail.com>2021-01-06 00:36:34 +0000
committerBrooks J Rady <b.j.rady@gmail.com>2021-01-06 00:36:34 +0000
commitd25df96eef25b18cedd78670f76984a05a5432d9 (patch)
tree7fc0ae237b02d1d9e92a3587d66aed7ef68a9337 /src
parentUpdate message (diff)
downloadsl0ppij-d25df96eef25b18cedd78670f76984a05a5432d9.tar.gz
sl0ppij-d25df96eef25b18cedd78670f76984a05a5432d9.tar.xz
sl0ppij-d25df96eef25b18cedd78670f76984a05a5432d9.zip
Acutually pass combined position and size
Diffstat (limited to 'src')
-rw-r--r--src/tab.rs106
-rw-r--r--src/terminal_pane/terminal_pane.rs14
-rw-r--r--src/tests/utils.rs4
3 files changed, 41 insertions, 83 deletions
diff --git a/src/tab.rs b/src/tab.rs
index 02b32492..d3ce232a 100644
--- a/src/tab.rs
+++ b/src/tab.rs
@@ -30,6 +30,7 @@ fn split_vertically_with_gap(rect: &PositionAndSize) -> (PositionAndSize, Positi
} else {
first_rect.columns = width_of_each_half;
}
+ second_rect.x = first_rect.x + first_rect.columns + 1;
second_rect.columns = width_of_each_half;
(first_rect, second_rect)
}
@@ -43,6 +44,7 @@ fn split_horizontally_with_gap(rect: &PositionAndSize) -> (PositionAndSize, Posi
} else {
first_rect.rows = height_of_each_half;
}
+ second_rect.y = first_rect.y + first_rect.rows + 1;
second_rect.rows = height_of_each_half;
(first_rect, second_rect)
}
@@ -152,7 +154,7 @@ impl Tab {
pane_id: Option<RawFd>,
) -> Self {
let panes = if let Some(pid) = pane_id {
- let new_terminal = TerminalPane::new(pid, *full_screen_ws, 0, 0);
+ let new_terminal = TerminalPane::new(pid, *full_screen_ws);
os_api.set_terminal_size_using_fd(
new_terminal.pid,
new_terminal.columns() as u16,
@@ -233,13 +235,7 @@ impl Tab {
} else {
// there are still panes left to fill, use the pids we received in this method
let pid = new_pids.next().unwrap(); // if this crashes it means we got less pids than there are panes in this layout
- let mut new_terminal = TerminalPane::new(
- *pid,
- self.full_screen_ws,
- position_and_size.x,
- position_and_size.y,
- );
- new_terminal.change_pos_and_size(position_and_size);
+ let mut new_terminal = TerminalPane::new(*pid, *position_and_size);
self.os_api.set_terminal_size_using_fd(
new_terminal.pid,
new_terminal.columns() as u16,
@@ -273,9 +269,7 @@ impl Tab {
self.toggle_active_terminal_fullscreen();
}
if !self.has_terminal_panes() {
- let x = 0;
- let y = 0;
- let new_terminal = TerminalPane::new(pid, self.full_screen_ws, x, y);
+ let new_terminal = TerminalPane::new(pid, self.full_screen_ws);
self.os_api.set_terminal_size_using_fd(
new_terminal.pid,
new_terminal.columns() as u16,
@@ -312,9 +306,7 @@ impl Tab {
};
if terminal_to_split.rows() * CURSOR_HEIGHT_WIDTH_RATIO > terminal_to_split.columns() {
let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
- let bottom_half_y = terminal_ws.y + top_winsize.rows + 1;
- let new_terminal =
- TerminalPane::new(pid, bottom_winsize, terminal_ws.x, bottom_half_y);
+ let new_terminal = TerminalPane::new(pid, bottom_winsize);
self.os_api.set_terminal_size_using_fd(
new_terminal.pid,
bottom_winsize.columns as u16,
@@ -331,9 +323,7 @@ impl Tab {
self.active_terminal = Some(pid);
} else {
let (left_winszie, right_winsize) = split_vertically_with_gap(&terminal_ws);
- let right_side_x = (terminal_ws.x + left_winszie.columns + 1) as usize;
- let new_terminal =
- TerminalPane::new(pid, right_winsize, right_side_x, terminal_ws.y);
+ let new_terminal = TerminalPane::new(pid, right_winsize);
self.os_api.set_terminal_size_using_fd(
new_terminal.pid,
right_winsize.columns as u16,
@@ -358,9 +348,7 @@ impl Tab {
self.toggle_active_terminal_fullscreen();
}
if !self.has_terminal_panes() {
- let x = 0;
- let y = 0;
- let new_terminal = TerminalPane::new(pid, self.full_screen_ws, x, y);
+ let new_terminal = TerminalPane::new(pid, self.full_screen_ws);
self.os_api.set_terminal_size_using_fd(
new_terminal.pid,
new_terminal.columns() as u16,
@@ -371,37 +359,26 @@ impl Tab {
self.active_terminal = Some(pid);
} else {
// TODO: check minimum size of active terminal
- let (active_terminal_ws, active_terminal_x, active_terminal_y) = {
- let active_terminal = &self.get_active_terminal().unwrap();
- (
- PositionAndSize {
- rows: active_terminal.rows(),
- columns: active_terminal.columns(),
- x: 0,
- y: 0,
- },
- active_terminal.x(),
- active_terminal.y(),
- )
+ let active_terminal_id = &self.get_active_terminal_id().unwrap();
+ let active_terminal = self
+ .panes
+ .get_mut(&PaneKind::Terminal(*active_terminal_id))
+ .unwrap();
+ let terminal_ws = PositionAndSize {
+ x: active_terminal.x(),
+ y: active_terminal.y(),
+ rows: active_terminal.rows(),
+ columns: active_terminal.columns(),
};
- let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&active_terminal_ws);
- let bottom_half_y = active_terminal_y + top_winsize.rows + 1;
- let new_terminal =
- TerminalPane::new(pid, bottom_winsize, active_terminal_x, bottom_half_y);
+ let (top_winsize, bottom_winsize) = split_horizontally_with_gap(&terminal_ws);
+ let new_terminal = TerminalPane::new(pid, bottom_winsize);
self.os_api.set_terminal_size_using_fd(
new_terminal.pid,
bottom_winsize.columns as u16,
bottom_winsize.rows as u16,
);
- {
- let active_terminal_id = &self.get_active_terminal_id().unwrap();
- let active_terminal = &mut self
- .panes
- .get_mut(&PaneKind::Terminal(*active_terminal_id))
- .unwrap();
- active_terminal.change_pos_and_size(&top_winsize);
- }
+ active_terminal.change_pos_and_size(&top_winsize);
self.panes
.insert(PaneKind::Terminal(pid), Box::new(new_terminal));
@@ -421,9 +398,7 @@ impl Tab {
self.toggle_active_terminal_fullscreen();
}
if !self.has_terminal_panes() {
- let x = 0;
- let y = 0;
- let new_terminal = TerminalPane::new(pid, self.full_screen_ws, x, y);
+ let new_terminal = TerminalPane::new(pid, self.full_screen_ws);
self.os_api.set_terminal_size_using_fd(
new_terminal.pid,
new_terminal.columns() as u16,
@@ -434,37 +409,26 @@ impl Tab {
self.active_terminal = Some(pid);
} else {
// TODO: check minimum size of active terminal
- let (active_terminal_ws, active_terminal_x, active_terminal_y) = {
- let active_terminal = &self.get_active_terminal().unwrap();
- (
- PositionAndSize {
- rows: active_terminal.rows(),
- columns: active_terminal.columns(),
- x: 0,
- y: 0,
- },
- active_terminal.x(),
- active_terminal.y(),
- )
+ let active_terminal_id = &self.get_active_terminal_id().unwrap();
+ let active_terminal = self
+ .panes
+ .get_mut(&PaneKind::Terminal(*active_terminal_id))
+ .unwrap();
+ let terminal_ws = PositionAndSize {
+ x: active_terminal.x(),
+ y: active_terminal.y(),
+ rows: active_terminal.rows(),
+ columns: active_terminal.columns(),
};
- let (left_winszie, right_winsize) = split_vertically_with_gap(&active_terminal_ws);
- let right_side_x = active_terminal_x + left_winszie.columns + 1;
- let new_terminal =
- TerminalPane::new(pid, right_winsize, right_side_x, active_terminal_y);
+ let (left_winszie, right_winsize) = split_vertically_with_gap(&terminal_ws);
+ let new_terminal = TerminalPane::new(pid, right_winsize);
self.os_api.set_terminal_size_using_fd(
new_terminal.pid,
right_winsize.columns as u16,
right_winsize.rows as u16,
);
- {
- let active_terminal_id = &self.get_active_terminal_id().unwrap();
- let active_terminal = &mut self
- .panes
- .get_mut(&PaneKind::Terminal(*active_terminal_id))
- .unwrap();
- active_terminal.change_pos_and_size(&left_winszie);
- }
+ active_terminal.change_pos_and_size(&left_winszie);
self.panes
.insert(PaneKind::Terminal(pid), Box::new(new_terminal));
diff --git a/src/terminal_pane/terminal_pane.rs b/src/terminal_pane/terminal_pane.rs
index 65b33e15..70711a0e 100644
--- a/src/terminal_pane/terminal_pane.rs
+++ b/src/terminal_pane/terminal_pane.rs
@@ -59,7 +59,8 @@ impl Pane for TerminalPane {
self.mark_for_rerender();
}
fn change_pos_and_size(&mut self, position_and_size: &PositionAndSize) {
- self.position_and_size = *position_and_size;
+ self.position_and_size.columns = position_and_size.columns;
+ self.position_and_size.rows = position_and_size.rows;
self.reflow_lines();
self.mark_for_rerender();
}
@@ -261,15 +262,10 @@ impl Pane for TerminalPane {
}
impl TerminalPane {
- pub fn new(pid: RawFd, ws: PositionAndSize, x: usize, y: usize) -> TerminalPane {
- let scroll = Scroll::new(ws.columns, ws.rows);
+ pub fn new(pid: RawFd, position_and_size: PositionAndSize) -> TerminalPane {
+ let scroll = Scroll::new(position_and_size.columns, position_and_size.rows);
let pending_styles = CharacterStyles::new();
- let position_and_size = PositionAndSize {
- x,
- y,
- rows: ws.rows,
- columns: ws.columns,
- };
+
TerminalPane {
pid,
scroll,
diff --git a/src/tests/utils.rs b/src/tests/utils.rs
index a107dce4..a58f800b 100644
--- a/src/tests/utils.rs
+++ b/src/tests/utils.rs
@@ -7,9 +7,7 @@ pub fn get_output_frame_snapshots(
) -> Vec<String> {
let mut vte_parser = vte::Parser::new();
let main_pid = 0;
- let x = 0;
- let y = 0;
- let mut terminal_output = TerminalPane::new(main_pid, *win_size, x, y);
+ let mut terminal_output = TerminalPane::new(main_pid, *win_size);
let mut snapshots = vec![];
for frame in output_frames.iter() {