aboutsummaryrefslogtreecommitdiffstats
path: root/zellij-server/src/tab/mod.rs
diff options
context:
space:
mode:
authorAram Drevekenin <aram@poor.dev>2022-03-18 10:32:43 +0100
committerGitHub <noreply@github.com>2022-03-18 10:32:43 +0100
commitab74b9974ac73dbae9dfdd4f87f8a3c0bf89e69e (patch)
tree165a49ba935694a11f8816b2e68a401b6ddf23e3 /zellij-server/src/tab/mod.rs
parentUpdate `rust-toolchain` (#1236) (diff)
downloadsl0ppij-ab74b9974ac73dbae9dfdd4f87f8a3c0bf89e69e.tar.gz
sl0ppij-ab74b9974ac73dbae9dfdd4f87f8a3c0bf89e69e.tar.xz
sl0ppij-ab74b9974ac73dbae9dfdd4f87f8a3c0bf89e69e.zip
refactor(tab): move tiled panes to their own module (#1239)
* work * tests passing * simplify render state * move more stuff to state * moved tiled panes outside * move files around * style(fmt): rustfmt
Diffstat (limited to 'zellij-server/src/tab/mod.rs')
-rw-r--r--zellij-server/src/tab/mod.rs1591
1 files changed, 350 insertions, 1241 deletions
diff --git a/zellij-server/src/tab/mod.rs b/zellij-server/src/tab/mod.rs
index e33141f6..18a6ef72 100644
--- a/zellij-server/src/tab/mod.rs
+++ b/zellij-server/src/tab/mod.rs
@@ -3,9 +3,6 @@
mod clipboard;
mod copy_command;
-pub mod floating_pane_grid;
-pub mod pane_resizer;
-pub mod tiled_pane_grid;
use copy_command::CopyCommand;
use zellij_utils::input::options::Clipboard;
@@ -13,37 +10,33 @@ use zellij_utils::position::{Column, Line};
use zellij_utils::{position::Position, serde, zellij_tile};
use crate::ui::pane_boundaries_frame::FrameParams;
-use tiled_pane_grid::{split, TiledPaneGrid};
use self::clipboard::ClipboardProvider;
use crate::{
os_input_output::ServerOsApi,
output::{CharacterChunk, Output},
- panes::FloatingPanes,
+ panes::{FloatingPanes, TiledPanes},
panes::{LinkHandler, PaneId, PluginPane, TerminalPane},
pty::{ClientOrTabIndex, PtyInstruction, VteBytes},
thread_bus::ThreadSenders,
- ui::boundaries::Boundaries,
- ui::pane_contents_and_ui::PaneContentsAndUi,
wasm_vm::PluginInstruction,
ClientId, ServerInstruction,
};
use serde::{Deserialize, Serialize};
use std::cell::RefCell;
-use std::cmp::Reverse;
use std::os::unix::io::RawFd;
use std::rc::Rc;
use std::sync::mpsc::channel;
use std::time::Instant;
use std::{
- collections::{BTreeMap, HashMap, HashSet},
+ collections::{HashMap, HashSet},
str,
};
use zellij_tile::data::{Event, InputMode, ModeInfo, Palette, PaletteColor};
use zellij_utils::{
input::{
command::TerminalAction,
- layout::{Direction, Layout, Run},
+ layout::{Layout, Run},
parse_keys,
},
pane_size::{Offset, PaneGeom, Size, Viewport},
@@ -69,48 +62,24 @@ pub const MIN_TERMINAL_WIDTH: usize = 5;
const MAX_PENDING_VTE_EVENTS: usize = 7000;
-fn pane_content_offset(position_and_size: &PaneGeom, viewport: &Viewport) -> (usize, usize) {
- // (columns_offset, rows_offset)
- // if the pane is not on the bottom or right edge on the screen, we need to reserve one space
- // from its content to leave room for the boundary between it and the next pane (if it doesn't
- // draw its own frame)
- let columns_offset = if position_and_size.x + position_and_size.cols.as_usize() < viewport.cols
- {
- 1
- } else {
- 0
- };
- let rows_offset = if position_and_size.y + position_and_size.rows.as_usize() < viewport.rows {
- 1
- } else {
- 0
- };
- (columns_offset, rows_offset)
-}
-
pub(crate) struct Tab {
pub index: usize,
pub position: usize,
pub name: String,
- panes: BTreeMap<PaneId, Box<dyn Pane>>,
+ tiled_panes: TiledPanes,
floating_panes: FloatingPanes,
- pub panes_to_hide: HashSet<PaneId>,
- pub active_panes: HashMap<ClientId, PaneId>,
max_panes: Option<usize>,
viewport: Rc<RefCell<Viewport>>, // includes all non-UI panes
display_area: Rc<RefCell<Size>>, // includes all panes (including eg. the status bar and tab bar in the default layout)
- fullscreen_is_active: bool,
os_api: Box<dyn ServerOsApi>,
pub senders: ThreadSenders,
synchronize_is_active: bool,
should_clear_display_before_rendering: bool,
- mode_info: HashMap<ClientId, ModeInfo>,
+ mode_info: Rc<RefCell<HashMap<ClientId, ModeInfo>>>,
default_mode_info: ModeInfo,
pub colors: Palette,
- connected_clients_in_app: Rc<RefCell<HashSet<ClientId>>>, // TODO: combine this and connected_clients
- connected_clients: HashSet<ClientId>,
+ connected_clients: Rc<RefCell<HashSet<ClientId>>>,
draw_pane_frames: bool,
- session_is_mirrored: bool,
pending_vte_events: HashMap<RawFd, Vec<VteBytes>>,
pub selecting_with_mouse: bool, // this is only pub for the tests TODO: remove this once we combine write_text_to_clipboard with render
link_handler: Rc<RefCell<LinkHandler>>,
@@ -303,7 +272,7 @@ impl Tab {
os_api: Box<dyn ServerOsApi>,
senders: ThreadSenders,
max_panes: Option<usize>,
- mode_info: ModeInfo,
+ default_mode_info: ModeInfo,
colors: Palette,
draw_pane_frames: bool,
connected_clients_in_app: Rc<RefCell<HashSet<ClientId>>>,
@@ -312,8 +281,6 @@ impl Tab {
copy_command: Option<String>,
copy_clipboard: Clipboard,
) -> Self {
- let panes = BTreeMap::new();
-
let name = if name.is_empty() {
format!("Tab #{}", index + 1)
} else {
@@ -325,7 +292,31 @@ impl Tab {
let viewport: Viewport = display_area.into();
let viewport = Rc::new(RefCell::new(viewport));
let display_area = Rc::new(RefCell::new(display_area));
- let floating_panes = FloatingPanes::new(display_area.clone(), viewport.clone());
+ let connected_clients = Rc::new(RefCell::new(connected_clients));
+ let mode_info = Rc::new(RefCell::new(HashMap::new()));
+
+ let tiled_panes = TiledPanes::new(
+ display_area.clone(),
+ viewport.clone(),
+ connected_clients.clone(),
+ connected_clients_in_app.clone(),
+ mode_info.clone(),
+ session_is_mirrored,
+ draw_pane_frames,
+ default_mode_info.clone(),
+ colors,
+ os_api.clone(),
+ );
+ let floating_panes = FloatingPanes::new(
+ display_area.clone(),
+ viewport.clone(),
+ connected_clients.clone(),
+ connected_clients_in_app.clone(),
+ mode_info.clone(),
+ session_is_mirrored,
+ default_mode_info.clone(),
+ colors,
+ );
let clipboard_provider = match copy_command {
Some(command) => ClipboardProvider::Command(CopyCommand::new(command)),
@@ -335,26 +326,21 @@ impl Tab {
Tab {
index,
position,
- panes,
+ tiled_panes,
floating_panes,
name,
max_panes,
- panes_to_hide: HashSet::new(),
- active_panes: HashMap::new(),
viewport,
display_area,
- fullscreen_is_active: false,
synchronize_is_active: false,
os_api,
senders,
should_clear_display_before_rendering: false,
- mode_info: HashMap::new(),
- default_mode_info: mode_info,
+ mode_info,
+ default_mode_info,
colors,
draw_pane_frames,
- session_is_mirrored,
pending_vte_events: HashMap::new(),
- connected_clients_in_app,
connected_clients,
selecting_with_mouse: false,
link_handler: Rc::new(RefCell::new(LinkHandler::new())),
@@ -370,7 +356,11 @@ impl Tab {
tab_index: usize,
client_id: ClientId,
) {
- // TODO: this should be an attribute on Screen instead of full_screen_ws
+ if self.tiled_panes.has_panes() {
+ log::error!(
+ "Applying a layout to a tab with existing panes - this is not yet supported!"
+ );
+ }
let (viewport_cols, viewport_rows) = {
let viewport = self.viewport.borrow();
(viewport.cols, viewport.rows)
@@ -379,26 +369,9 @@ impl Tab {
free_space.cols.set_inner(viewport_cols);
free_space.rows.set_inner(viewport_rows);
- self.panes_to_hide.clear();
let positions_in_layout = layout.position_panes_in_space(&free_space);
- let mut positions_and_size = positions_in_layout.iter();
- for (pane_kind, terminal_pane) in &mut self.panes {
- // for now the layout only supports terminal panes
- if let PaneId::Terminal(pid) = pane_kind {
- match positions_and_size.next() {
- Some(&(_, position_and_size)) => {
- terminal_pane.reset_size_and_position_override();
- terminal_pane.set_geom(position_and_size);
- }
- None => {
- // we filled the entire layout, no room for this pane
- // TODO: handle active terminal
- self.panes_to_hide.insert(PaneId::Terminal(*pid));
- }
- }
- }
- }
+ let positions_and_size = positions_in_layout.iter();
let mut new_pids = new_pids.iter();
let mut focus_pane_id: Option<PaneId> = None;
@@ -425,7 +398,8 @@ impl Tab {
layout.pane_name.clone().unwrap_or_default(),
);
new_plugin.set_borderless(layout.borderless);
- self.panes.insert(PaneId::Plugin(pid), Box::new(new_plugin));
+ self.tiled_panes
+ .add_pane_with_existing_geom(PaneId::Plugin(pid), Box::new(new_plugin));
set_focus_pane_id(layout, PaneId::Plugin(pid));
} else {
// there are still panes left to fill, use the pids we received in this method
@@ -440,8 +414,8 @@ impl Tab {
self.link_handler.clone(),
);
new_pane.set_borderless(layout.borderless);
- self.panes
- .insert(PaneId::Terminal(*pid), Box::new(new_pane));
+ self.tiled_panes
+ .add_pane_with_existing_geom(PaneId::Terminal(*pid), Box::new(new_pane));
set_focus_pane_id(layout, PaneId::Terminal(*pid));
}
}
@@ -460,59 +434,35 @@ impl Tab {
*display_area
};
self.resize_whole_tab(display_area);
- let boundary_geom: Vec<_> = self
- .panes
- .values()
- .filter_map(|p| {
- let geom = p.position_and_size();
- if geom.cols.is_fixed() || geom.rows.is_fixed() {
- Some(geom.into())
- } else {
- None
- }
- })
- .collect();
- for geom in boundary_geom {
+ let boundary_geoms = self.tiled_panes.fixed_pane_geoms();
+ for geom in boundary_geoms {
self.offset_viewport(&geom)
}
- self.set_pane_frames(self.draw_pane_frames);
-
- let mut active_pane = |pane_id: PaneId| {
- let connected_clients: Vec<ClientId> = self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, pane_id);
- }
- };
+ self.tiled_panes.set_pane_frames(self.draw_pane_frames);
+ self.should_clear_display_before_rendering = true;
if let Some(pane_id) = focus_pane_id {
self.focus_pane_id = Some(pane_id);
- active_pane(pane_id);
+ self.tiled_panes.focus_pane(pane_id, client_id);
} else {
// This is the end of the nasty viewport hack...
- let next_selectable_pane_id = self
- .panes
- .iter()
- .filter(|(_id, pane)| pane.selectable())
- .map(|(id, _)| id.to_owned())
- .next();
+ let next_selectable_pane_id = self.tiled_panes.first_selectable_pane_id();
match next_selectable_pane_id {
Some(active_pane_id) => {
- active_pane(active_pane_id);
+ self.tiled_panes.focus_pane(active_pane_id, client_id);
}
None => {
// this is very likely a configuration error (layout with no selectable panes)
- self.active_panes.clear();
+ self.tiled_panes.clear_active_panes();
}
}
}
}
pub fn update_input_modes(&mut self) {
// this updates all plugins with the client's input mode
- for client_id in &self.connected_clients {
- let mode_info = self
- .mode_info
- .get(client_id)
- .unwrap_or(&self.default_mode_info);
+ let mode_infos = self.mode_info.borrow();
+ for client_id in self.connected_clients.borrow().iter() {
+ let mode_info = mode_infos.get(client_id).unwrap_or(&self.default_mode_info);
self.senders
.send_to_plugin(PluginInstruction::Update(
None,
@@ -523,64 +473,58 @@ impl Tab {
}
}
pub fn add_client(&mut self, client_id: ClientId, mode_info: Option<ModeInfo>) {
- let first_connected_client = self.connected_clients.iter().next();
- match first_connected_client {
- Some(first_client_id) => {
- let first_active_pane_id = *self.active_panes.get(first_client_id).unwrap();
- if self.floating_panes.panes_are_visible() {
- if let Some(first_active_floating_pane_id) =
- self.floating_panes.first_active_floating_pane_id()
- {
- self.floating_panes
- .focus_pane(first_active_floating_pane_id, client_id);
- }
- }
- self.connected_clients.insert(client_id);
- self.active_panes.insert(client_id, first_active_pane_id);
- self.mode_info.insert(
- client_id,
- mode_info.unwrap_or_else(|| self.default_mode_info.clone()),
- );
+ let other_clients_exist_in_tab = { !self.connected_clients.borrow().is_empty() };
+ if other_clients_exist_in_tab {
+ if let Some(first_active_floating_pane_id) =
+ self.floating_panes.first_active_floating_pane_id()
+ {
+ self.floating_panes
+ .focus_pane(first_active_floating_pane_id, client_id);
}
- None => {
- let mut pane_ids: Vec<PaneId> = self.panes.keys().copied().collect();
- if pane_ids.is_empty() {
- // no panes here, bye bye
- return;
- }
- self.active_panes.insert(
- client_id,
- self.focus_pane_id.unwrap_or_else(|| {
- pane_ids.sort(); // TODO: make this predictable
- pane_ids.retain(|p| !self.panes_to_hide.contains(p));
- *pane_ids.get(0).unwrap()
- }),
- );
- self.connected_clients.insert(client_id);
- self.mode_info.insert(
- client_id,
- mode_info.unwrap_or_else(|| self.default_mode_info.clone()),
- );
+ if let Some(first_active_tiled_pane_id) = self.tiled_panes.first_active_pane_id() {
+ self.tiled_panes
+ .focus_pane(first_active_tiled_pane_id, client_id);
+ }
+ self.connected_clients.borrow_mut().insert(client_id);
+ self.mode_info.borrow_mut().insert(
+ client_id,
+ mode_info.unwrap_or_else(|| self.default_mode_info.clone()),
+ );
+ } else {
+ let mut pane_ids: Vec<PaneId> = self.tiled_panes.pane_ids().copied().collect();
+ if pane_ids.is_empty() {
+ // no panes here, bye bye
+ return;
}
+ let focus_pane_id = self.focus_pane_id.unwrap_or_else(|| {
+ pane_ids.sort(); // TODO: make this predictable
+ pane_ids.retain(|p| !self.tiled_panes.panes_to_hide_contains(*p));
+ *pane_ids.get(0).unwrap()
+ });
+ self.tiled_panes.focus_pane(focus_pane_id, client_id);
+ self.connected_clients.borrow_mut().insert(client_id);
+ self.mode_info.borrow_mut().insert(
+ client_id,
+ mode_info.unwrap_or_else(|| self.default_mode_info.clone()),
+ );
}
- // TODO: we might be able to avoid this, we do this so that newly connected clients will
- // necessarily get a full render
self.set_force_render();
self.update_input_modes();
}
pub fn change_mode_info(&mut self, mode_info: ModeInfo, client_id: ClientId) {
- self.mode_info.insert(client_id, mode_info);
+ self.mode_info.borrow_mut().insert(client_id, mode_info);
}
pub fn add_multiple_clients(&mut self, client_ids_to_mode_infos: Vec<(ClientId, ModeInfo)>) {
for (client_id, client_mode_info) in client_ids_to_mode_infos {
self.add_client(client_id, None);
- self.mode_info.insert(client_id, client_mode_info);
+ self.mode_info
+ .borrow_mut()
+ .insert(client_id, client_mode_info);
}
}
pub fn remove_client(&mut self, client_id: ClientId) {
self.focus_pane_id = None;
- self.active_panes.remove(&client_id);
- self.connected_clients.remove(&client_id);
+ self.connected_clients.borrow_mut().remove(&client_id);
self.set_force_render();
}
pub fn drain_connected_clients(
@@ -589,8 +533,8 @@ impl Tab {
) -> Vec<(ClientId, ModeInfo)> {
// None => all clients
let mut client_ids_to_mode_infos = vec![];
- let clients_to_drain =
- clients_to_drain.unwrap_or_else(|| self.connected_clients.drain().collect());
+ let clients_to_drain = clients_to_drain
+ .unwrap_or_else(|| self.connected_clients.borrow_mut().drain().collect());
for client_id in clients_to_drain {
client_ids_to_mode_infos.push(self.drain_single_client(client_id));
}
@@ -599,63 +543,32 @@ impl Tab {
pub fn drain_single_client(&mut self, client_id: ClientId) -> (ClientId, ModeInfo) {
let client_mode_info = self
.mode_info
+ .borrow_mut()
.remove(&client_id)
.unwrap_or_else(|| self.default_mode_info.clone());
- self.connected_clients.remove(&client_id);
+ self.connected_clients.borrow_mut().remove(&client_id);
(client_id, client_mode_info)
}
pub fn has_no_connected_clients(&self) -> bool {
- self.connected_clients.is_empty()
+ self.connected_clients.borrow().is_empty()
}
pub fn toggle_pane_embed_or_floating(&mut self, client_id: ClientId) {
if self.floating_panes.panes_are_visible() {
if let Some(focused_floating_pane_id) = self.floating_panes.active_pane_id(client_id) {
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let terminal_id_and_split_direction = pane_grid.find_room_for_new_pane();
- if let Some((terminal_id_to_split, split_direction)) =
- terminal_id_and_split_direction
- {
+ if self.tiled_panes.has_room_for_new_pane() {
// this unwrap is safe because floating panes should not be visible if there are no floating panes
- let mut floating_pane_to_embed =
- self.close_pane(focused_floating_pane_id).unwrap();
- let pane_to_split = self.panes.get_mut(&terminal_id_to_split).unwrap();
- let size_of_both_panes = pane_to_split.position_and_size();
- if let Some((first_geom, second_geom)) =
- split(split_direction, &size_of_both_panes)
- {
- pane_to_split.set_geom(first_geom);
- floating_pane_to_embed.set_geom(second_geom);
- self.panes
- .insert(focused_floating_pane_id, floating_pane_to_embed);
- // ¯\_(ツ)_/¯
- let relayout_direction = match split_direction {
- Direction::Vertical => Direction::Horizontal,
- Direction::Horizontal => Direction::Vertical,
- };
- self.relayout_tab(relayout_direction);
- }
- if self.session_is_mirrored {
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes
- .insert(client_id, focused_floating_pane_id);
- }
- } else {
- self.active_panes
- .insert(client_id, focused_floating_pane_id);
- }
+ let floating_pane_to_embed = self.close_pane(focused_floating_pane_id).unwrap();
+ self.tiled_panes
+ .insert_pane(focused_floating_pane_id, floating_pane_to_embed);
+ self.should_clear_display_before_rendering = true;
+ self.tiled_panes
+ .focus_pane(focused_floating_pane_id, client_id);
self.floating_panes.toggle_show_panes(false);
}
}
- } else if let Some(focused_pane_id) = self.active_panes.get(&client_id).copied() {
+ } else if let Some(focused_pane_id) = self.tiled_panes.focused_pane_id(client_id) {
if let Some(new_pane_geom) = self.floating_panes.find_room_for_new_pane() {
- if self.get_selectable_panes().count() <= 1 {
+ if self.get_selectable_tiled_panes().count() <= 1 {
// don't close the only pane on screen...
return;
}
@@ -665,14 +578,8 @@ impl Tab {
embedded_pane_to_float.set_active_at(Instant::now());
self.floating_panes
.add_pane(focused_pane_id, embedded_pane_to_float);
+ self.floating_panes.focus_pane(focused_pane_id, client_id);
self.floating_panes.toggle_show_panes(true);
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.floating_panes.focus_pane(focused_pane_id, client_id);
- }
- self.floating_panes.set_force_render();
}
}
}
@@ -733,165 +640,102 @@ impl Tab {
new_pane.set_content_offset(Offset::frame(1)); // floating panes always have a frame
resize_pty!(new_pane, self.os_api);
self.floating_panes.add_pane(pid, Box::new(new_pane));
- // move all clients to new floating pane
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.floating_panes.focus_pane(pid, client_id);
- }
+ self.floating_panes.focus_pane_for_all_clients(pid);
}
}
} else {
- if self.fullscreen_is_active {
- self.unset_fullscreen();
+ if self.tiled_panes.fullscreen_is_active() {
+ self.tiled_panes.unset_fullscreen();
}
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let terminal_id_and_split_direction = pane_grid.find_room_for_new_pane();
- if let Some((terminal_id_to_split, split_direction)) = terminal_id_and_split_direction {
- let next_terminal_position = self.get_next_terminal_position();
- let terminal_to_split = self.panes.get_mut(&terminal_id_to_split).unwrap();
- let terminal_ws = terminal_to_split.position_and_size();
+ if self.tiled_panes.has_room_for_new_pane() {
if let PaneId::Terminal(term_pid) = pid {
- if let Some((first_winsize, second_winsize)) =
- split(split_direction, &terminal_ws)
- {
- let new_terminal = TerminalPane::new(
- term_pid,
- second_winsize,
- self.colors,
- next_terminal_position,
- String::new(),
- self.link_handler.clone(),
- );
- terminal_to_split.set_geom(first_winsize);
- self.panes.insert(pid, Box::new(new_terminal));
- // ¯\_(ツ)_/¯
- let relayout_direction = match split_direction {
- Direction::Vertical => Direction::Horizontal,
- Direction::Horizontal => Direction::Vertical,
- };
- self.relayout_tab(relayout_direction);
- }
- }
- if let Some(client_id) = client_id {
- if self.session_is_mirrored {
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, pid);
- }
- } else {
- self.active_panes.insert(client_id, pid);
+ let next_terminal_position = self.get_next_terminal_position();
+ let new_terminal = TerminalPane::new(
+ term_pid,
+ PaneGeom::default(), // the initial size will be set later
+ self.colors,
+ next_terminal_position,
+ String::new(),
+ self.link_handler.clone(),
+ );
+ self.tiled_panes.insert_pane(pid, Box::new(new_terminal));
+ self.should_clear_display_before_rendering = true;
+ if let Some(client_id) = client_id {
+ self.tiled_panes.focus_pane(pid, client_id);
}
}
}
}
}
pub fn horizontal_split(&mut self, pid: PaneId, client_id: ClientId) {
+ if self.floating_panes.panes_are_visible() {
+ return;
+ }
self.close_down_to_max_terminals();
- if self.fullscreen_is_active {
+ if self.tiled_panes.fullscreen_is_active() {
self.toggle_active_pane_fullscreen(client_id);
}
- if let PaneId::Terminal(term_pid) = pid {
- let next_terminal_position = self.get_next_terminal_position();
- let active_pane_id = &self.get_active_pane_id(client_id).unwrap();
- let active_pane = self.panes.get_mut(active_pane_id).unwrap();
- if active_pane.rows() < MIN_TERMINAL_HEIGHT * 2 {
- self.senders
- .send_to_pty(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty
- .unwrap();
- return;
- }
- let terminal_ws = active_pane.position_and_size();
- if let Some((top_winsize, bottom_winsize)) = split(Direction::Horizontal, &terminal_ws)
- {
+ if self.tiled_panes.can_split_pane_horizontally(client_id) {
+ if let PaneId::Terminal(term_pid) = pid {
+ let next_terminal_position = self.get_next_terminal_position();
let new_terminal = TerminalPane::new(
term_pid,
- bottom_winsize,
+ PaneGeom::default(), // the initial size will be set later
self.colors,
next_terminal_position,
String::new(),
self.link_handler.clone(),
);
- active_pane.set_geom(top_winsize);
- self.panes.insert(pid, Box::new(new_terminal));
-
- if self.session_is_mirrored {
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, pid);
- }
- } else {
- self.active_panes.insert(client_id, pid);
- }
-
- self.relayout_tab(Direction::Vertical);
+ self.tiled_panes
+ .split_pane_horizontally(pid, Box::new(new_terminal), client_id);
+ self.should_clear_display_before_rendering = true;
+ self.tiled_panes.focus_pane(pid, client_id);
}
}
}
pub fn vertical_split(&mut self, pid: PaneId, client_id: ClientId) {
+ if self.floating_panes.panes_are_visible() {
+ return;
+ }
self.close_down_to_max_terminals();
- if self.fullscreen_is_active {
+ if self.tiled_panes.fullscreen_is_active() {
self.toggle_active_pane_fullscreen(client_id);
}
- if let PaneId::Terminal(term_pid) = pid {
- // TODO: check minimum size of active terminal
- let next_terminal_position = self.get_next_terminal_position();
- let active_pane_id = &self.get_active_pane_id(client_id).unwrap();
- let active_pane = self.panes.get_mut(active_pane_id).unwrap();
- if active_pane.cols() < MIN_TERMINAL_WIDTH * 2 {
- self.senders
- .send_to_pty(PtyInstruction::ClosePane(pid)) // we can't open this pane, close the pty
- .unwrap();
- return;
- }
- let terminal_ws = active_pane.position_and_size();
- if let Some((left_winsize, right_winsize)) = split(Direction::Vertical, &terminal_ws) {
+ if self.tiled_panes.can_split_pane_vertically(client_id) {
+ if let PaneId::Terminal(term_pid) = pid {
+ let next_terminal_position = self.get_next_terminal_position();
let new_terminal = TerminalPane::new(
term_pid,
- right_winsize,
+ PaneGeom::default(), // the initial size will be set later
self.colors,
next_terminal_position,
String::new(),
self.link_handler.clone(),
);
- active_pane.set_geom(left_winsize);
- self.panes.insert(pid, Box::new(new_terminal));
+ self.tiled_panes
+ .split_pane_vertically(pid, Box::new(new_terminal), client_id);
+ self.should_clear_display_before_rendering = true;
+ self.tiled_panes.focus_pane(pid, client_id);
}
- if self.session_is_mirrored {
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, pid);
- }
- } else {
- self.active_panes.insert(client_id, pid);
- }
-
- self.relayout_tab(Direction::Horizontal);
}
}
- pub fn has_active_panes(&self) -> bool {
- // a tab without active panes is a dead tab and should close
- // a pane can be active even if there are no connected clients,
- // we remember that pane for one the client focuses the tab next
- !self.active_panes.is_empty()
- }
pub fn get_active_pane(&self, client_id: ClientId) -> Option<&dyn Pane> {
- self.get_active_pane_id(client_id)
- .and_then(|ap| self.panes.get(&ap).map(Box::as_ref))
+ self.get_active_pane_id(client_id).and_then(|ap| {
+ if self.floating_panes.panes_are_visible() {
+ self.floating_panes.get_pane(ap).map(Box::as_ref)
+ } else {
+ self.tiled_panes.get_pane(ap).map(Box::as_ref)
+ }
+ })
}
pub fn get_active_pane_mut(&mut self, client_id: ClientId) -> Option<&mut Box<dyn Pane>> {
- self.get_active_pane_id(client_id)
- .and_then(|ap| self.panes.get_mut(&ap))
+ self.get_active_pane_id(client_id).and_then(|ap| {
+ if self.floating_panes.panes_are_visible() {
+ self.floating_panes.get_pane_mut(ap)
+ } else {
+ self.tiled_panes.get_pane_mut(ap)
+ }
+ })
}
pub fn get_active_pane_or_floating_pane_mut(
&mut self,
@@ -903,26 +747,29 @@ impl Tab {
self.get_active_pane_mut(client_id)
}
}
- fn get_active_pane_id(&self, client_id: ClientId) -> Option<PaneId> {
- // TODO: why do we need this?
- self.active_panes.get(&client_id).copied()
+ pub fn get_active_pane_id(&self, client_id: ClientId) -> Option<PaneId> {
+ if self.floating_panes.panes_are_visible() {
+ self.floating_panes.get_active_pane_id(client_id)
+ } else {
+ self.tiled_panes.get_active_pane_id(client_id)
+ }
}
fn get_active_terminal_id(&self, client_id: ClientId) -> Option<RawFd> {
- if let Some(PaneId::Terminal(pid)) = self.active_panes.get(&client_id).copied() {
+ if let Some(PaneId::Terminal(pid)) = self.get_active_pane_id(client_id) {
Some(pid)
} else {
None
}
}
pub fn has_terminal_pid(&self, pid: RawFd) -> bool {
- self.panes.contains_key(&PaneId::Terminal(pid))
+ self.tiled_panes.panes_contain(&PaneId::Terminal(pid))
|| self.floating_panes.panes_contain(&PaneId::Terminal(pid))
}
pub fn handle_pty_bytes(&mut self, pid: RawFd, bytes: VteBytes) {
if let Some(terminal_output) = self
- .panes
- .get_mut(&PaneId::Terminal(pid))
- .or_else(|| self.floating_panes.get_mut(&PaneId::Terminal(pid)))
+ .tiled_panes
+ .get_pane_mut(PaneId::Terminal(pid))
+ .or_else(|| self.floating_panes.get_pane_mut(PaneId::Terminal(pid)))
{
// If the pane is scrolled buffer the vte events
if terminal_output.is_scrolled() {
@@ -949,9 +796,9 @@ impl Tab {
}
fn process_pty_bytes(&mut self, pid: RawFd, bytes: VteBytes) {
if let Some(terminal_output) = self
- .panes
- .get_mut(&PaneId::Terminal(pid))
- .or_else(|| self.floating_panes.get_mut(&PaneId::Terminal(pid)))
+ .tiled_panes
+ .get_pane_mut(PaneId::Terminal(pid))
+ .or_else(|| self.floating_panes.get_pane_mut(PaneId::Terminal(pid)))
{
terminal_output.handle_pty_bytes(bytes);
let messages_to_pty = terminal_output.drain_messages_to_pty();
@@ -969,10 +816,10 @@ impl Tab {
pub fn write_to_active_terminal(&mut self, input_bytes: Vec<u8>, client_id: ClientId) {
let pane_id = if self.floating_panes.panes_are_visible() {
self.floating_panes
- .active_pane_id(client_id)
- .unwrap_or_else(|| *self.active_panes.get(&client_id).unwrap())
+ .get_active_pane_id(client_id)
+ .unwrap_or_else(|| self.tiled_panes.get_active_pane_id(client_id).unwrap())
} else {
- *self.active_panes.get(&client_id).unwrap()
+ self.tiled_panes.get_active_pane_id(client_id).unwrap()
};
self.write_to_pane_id(input_bytes, pane_id);
}
@@ -996,7 +843,7 @@ impl Tab {
let active_terminal = self
.floating_panes
.get(&pane_id)
- .unwrap_or_else(|| self.panes.get(&pane_id).unwrap());
+ .unwrap_or_else(|| self.tiled_panes.get_pane(pane_id).unwrap());
let adjusted_input = active_terminal.adjust_input_to_terminal(input_bytes);
self.os_api
.write_to_tty_stdin(active_terminal_id, &adjusted_input)
@@ -1021,15 +868,15 @@ impl Tab {
// (x, y)
let active_pane_id = if self.floating_panes.panes_are_visible() {
self.floating_panes
- .active_pane_id(client_id)
- .or_else(|| self.active_panes.get(&client_id).copied())?
+ .get_active_pane_id(client_id)
+ .or_else(|| self.tiled_panes.get_active_pane_id(client_id))?
} else {
- self.active_panes.get(&client_id).copied()?
+ self.tiled_panes.get_active_pane_id(client_id)?
};
let active_terminal = &self
.floating_panes
.get(&active_pane_id)
- .or_else(|| self.panes.get(&active_pane_id))?;
+ .or_else(|| self.tiled_panes.get_pane(active_pane_id))?;
active_terminal
.cursor_coordinates()
.map(|(x_in_terminal, y_in_terminal)| {
@@ -1038,98 +885,20 @@ impl Tab {
(x, y)
})
}
- pub fn unset_fullscreen(&mut self) {
- if self.fullscreen_is_active {
- let first_client_id = self.connected_clients.iter().next().unwrap(); // this is a temporary hack until we fix the ui for multiple clients
- let active_pane_id = self.active_panes.get(first_client_id).unwrap();
- for terminal_id in &self.panes_to_hide {
- let pane = self.panes.get_mut(terminal_id).unwrap();
- pane.set_should_render(true);
- pane.set_should_render_boundaries(true);
- }
- let viewport_pane_ids: Vec<_> = self
- .get_embedded_pane_ids()
- .into_iter()
- .filter(|id| !self.is_inside_viewport(id))
- .collect();
- for pid in viewport_pane_ids {
- let viewport_pane = self.panes.get_mut(&pid).unwrap();
- viewport_pane.reset_size_and_position_override();
- }
- self.panes_to_hide.clear();
- let active_terminal = self.panes.get_mut(active_pane_id).unwrap();
- active_terminal.reset_size_and_position_override();
- self.set_force_render();
- let display_area = *self.display_area.borrow();
- self.resize_whole_tab(display_area);
- self.toggle_fullscreen_is_active();
- }
- }
pub fn toggle_active_pane_fullscreen(&mut self, client_id: ClientId) {
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- if self.fullscreen_is_active {
- self.unset_fullscreen();
- } else {
- let panes = self.get_panes();
- let pane_ids_to_hide = panes.filter_map(|(&id, _pane)| {
- if id != active_pane_id && self.is_inside_viewport(&id) {
- Some(id)
- } else {
- None
- }
- });
- self.panes_to_hide = pane_ids_to_hide.collect();
- if self.panes_to_hide.is_empty() {
- // nothing to do, pane is already as fullscreen as it can be, let's bail
- return;
- } else {
- // For all of the panes outside of the viewport staying on the fullscreen
- // screen, switch them to using override positions as well so that the resize
- // system doesn't get confused by viewport and old panes that no longer line up
- let viewport_pane_ids: Vec<_> = self
- .get_embedded_pane_ids()
- .into_iter()
- .filter(|id| !self.is_inside_viewport(id))
- .collect();
- for pid in viewport_pane_ids {
- let viewport_pane = self.panes.get_mut(&pid).unwrap();
- viewport_pane.get_geom_override(viewport_pane.position_and_size());
- }
- let active_terminal = self.panes.get_mut(&active_pane_id).unwrap();
- let viewport = { *self.viewport.borrow() };
- let full_screen_geom = PaneGeom {
- x: viewport.x,
- y: viewport.y,
- ..Default::default()
- };
- active_terminal.get_geom_override(full_screen_geom);
- }
- let active_panes: Vec<ClientId> = self.active_panes.keys().copied().collect();
- for client_id in active_panes {
- self.active_panes.insert(client_id, active_pane_id);
- }
- self.set_force_render();
- let display_area = *self.display_area.borrow();
- self.resize_whole_tab(display_area);
- self.toggle_fullscreen_is_active();
- }
+ if self.floating_panes.panes_are_visible() {
+ return;
}
+ self.tiled_panes.toggle_active_pane_fullscreen(client_id);
}
pub fn is_fullscreen_active(&self) -> bool {
- self.fullscreen_is_active
+ self.tiled_panes.fullscreen_is_active()
}
pub fn are_floating_panes_visible(&self) -> bool {
self.floating_panes.panes_are_visible()
}
- pub fn toggle_fullscreen_is_active(&mut self) {
- self.fullscreen_is_active = !self.fullscreen_is_active;
- }
pub fn set_force_render(&mut self) {
- for pane in self.panes.values_mut() {
- pane.set_should_render(true);
- pane.set_should_render_boundaries(true);
- pane.render_full_viewport();
- }
+ self.tiled_panes.set_force_render();
self.floating_panes.set_force_render();
}
pub fn is_sync_panes_active(&self) -> bool {
@@ -1139,187 +908,83 @@ impl Tab {
self.synchronize_is_active = !self.synchronize_is_active;
}
pub fn mark_active_pane_for_rerender(&mut self, client_id: ClientId) {
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- self.panes
- .get_mut(&active_pane_id)
- .unwrap()
- .set_should_render(true)
- }
- }
- pub fn set_pane_frames(&mut self, draw_pane_frames: bool) {
- self.draw_pane_frames = draw_pane_frames;
- self.should_clear_display_before_rendering = true;
- let viewport = *self.viewport.borrow();
- for pane in self.panes.values_mut() {
- if !pane.borderless() {
- pane.set_frame(draw_pane_frames);
- }
-
- #[allow(clippy::if_same_then_else)]
- if draw_pane_frames & !pane.borderless() {
- // there's definitely a frame around this pane, offset its contents
- pane.set_content_offset(Offset::frame(1));
- } else if draw_pane_frames && pane.borderless() {
- // there's no frame around this pane, and the tab isn't handling the boundaries
- // between panes (they each draw their own frames as they please)
- // this one doesn't - do not offset its content
- pane.set_content_offset(Offset::default());
- } else if !is_inside_viewport(&viewport, pane) {
- // this pane is outside the viewport and has no border - it should not have an offset
- pane.set_content_offset(Offset::default());
- } else {
- // no draw_pane_frames and this pane should have a separation to other panes
- // according to its position in the viewport (eg. no separation if its at the
- // viewport bottom) - offset its content accordingly
- let position_and_size = pane.current_geom();
- let (pane_columns_offset, pane_rows_offset) =
- pane_content_offset(&position_and_size, &viewport);
- pane.set_content_offset(Offset::shift(pane_rows_offset, pane_columns_offset));
- }
-
- resize_pty!(pane, self.os_api);
+ if let Some(active_pane) = self.get_active_pane_mut(client_id) {
+ active_pane.set_should_render(true);
}
- self.floating_panes.set_pane_frames(&mut self.os_api);
}
fn update_active_panes_in_pty_thread(&self) {
// this is a bit hacky and we should ideally not keep this state in two different places at
// some point
- for &connected_client in &self.connected_clients {
+ let connected_clients: Vec<ClientId> =
+ { self.connected_clients.borrow().iter().copied().collect() };
+ for client_id in connected_clients {
self.senders
.send_to_pty(PtyInstruction::UpdateActivePane(
- self.active_panes.get(&connected_client).copied(),
- connected_client,
+ self.get_active_pane_id(client_id),
+ client_id,
))
.unwrap();
}
}
pub fn render(&mut self, output: &mut Output, overlay: Option<String>) {
- if self.connected_clients.is_empty() || self.active_panes.is_empty() {
+ let connected_clients: HashSet<ClientId> =
+ { self.connected_clients.borrow().iter().copied().collect() };
+ if connected_clients.is_empty() || !self.tiled_panes.has_active_panes() {
return;
}
self.update_active_panes_in_pty_thread();
- let floating_panes_stack = if self.floating_panes.panes_are_visible() {
- Some(self.floating_panes.stack())
- } else {
- None
- };
+
+ let floating_panes_stack = self.floating_panes.stack();
output.add_clients(
- &self.connected_clients,
+ &connected_clients,
self.link_handler.clone(),
floating_panes_stack,
);
- let mut client_id_to_boundaries: HashMap<ClientId, Boundaries> = HashMap::new();
+
self.hide_cursor_and_clear_display_as_needed(output);
- let active_non_floating_panes = self.active_non_floating_panes();
- // render panes and their frames
- for (kind, pane) in self.panes.iter_mut() {
- if !self.panes_to_hide.contains(&pane.pid()) {
- let mut active_panes = if self.floating_panes.panes_are_visible() {
- active_non_floating_panes.clone()
- } else {
- self.active_panes.clone()
- };
- let multiple_users_exist_in_session =
- { self.connected_clients_in_app.borrow().len() > 1 };
- active_panes.retain(|c_id, _| self.connected_clients.contains(c_id));
- let mut pane_contents_and_ui = PaneContentsAndUi::new(
- pane,
- output,
- self.colors,
- &active_panes,
- multiple_users_exist_in_session,
- None,
- );
- for &client_id in &self.connected_clients {
- let client_mode = self
- .mode_info
- .get(&client_id)
- .unwrap_or(&self.default_mode_info)
- .mode;
- if let PaneId::Plugin(..) = kind {
- pane_contents_and_ui.render_pane_contents_for_client(client_id);
- }
- if self.draw_pane_frames {
- pane_contents_and_ui.render_pane_frame(
- client_id,
- client_mode,
- self.session_is_mirrored,
- );
- } else {
- let boundaries = client_id_to_boundaries
- .entry(client_id)
- .or_insert_with(|| Boundaries::new(*self.viewport.borrow()));
- pane_contents_and_ui.render_pane_boundaries(
- client_id,
- client_mode,
- boundaries,
- self.session_is_mirrored,
- );
- }
- pane_contents_and_ui.render_terminal_title_if_needed(client_id, client_mode);
- // this is done for panes that don't have their own cursor (eg. panes of
- // another user)
- pane_contents_and_ui.render_fake_cursor_if_needed(client_id);
- }
- if let PaneId::Terminal(..) = kind {
- pane_contents_and_ui.render_pane_contents_to_multiple_clients(
- self.connected_clients.iter().copied(),
- );
- }
- }
- }
+ self.tiled_panes.render(output);
if self.floating_panes.panes_are_visible() && self.floating_panes.has_active_panes() {
- self.floating_panes.render(
- &self.connected_clients_in_app,
- &self.connected_clients,
- &self.mode_info,
- &self.default_mode_info,
- self.session_is_mirrored,
- output,
- self.colors,
- );
- }
- // render boundaries if needed
- for (client_id, boundaries) in &mut client_id_to_boundaries {
- // TODO: add some conditional rendering here so this isn't rendered for every character
- output.add_character_chunks_to_client(*client_id, boundaries.render(), None);
+ self.floating_panes.render(output);
}
+
// FIXME: Once clients can be distinguished
if let Some(overlay_vte) = &overlay {
output.add_post_vte_instruction_to_multiple_clients(
- self.connected_clients.iter().copied(),
+ connected_clients.iter().copied(),
overlay_vte,
);
}
+
self.render_cursor(output);
}
- fn active_non_floating_panes(&self) -> HashMap<ClientId, PaneId> {
- let mut active_non_floating_panes = self.active_panes.clone();
- active_non_floating_panes.retain(|c_id, _| !self.floating_panes.active_panes_contain(c_id));
- active_non_floating_panes
- }
fn hide_cursor_and_clear_display_as_needed(&mut self, output: &mut Output) {
let hide_cursor = "\u{1b}[?25l";
+ let connected_clients: Vec<ClientId> =
+ { self.connected_clients.borrow().iter().copied().collect() };
output.add_pre_vte_instruction_to_multiple_clients(
- self.connected_clients.iter().copied(),
+ connected_clients.iter().copied(),
hide_cursor,
);
if self.should_clear_display_before_rendering {
let clear_display = "\u{1b}[2J";
output.add_pre_vte_instruction_to_multiple_clients(
- self.connected_clients.iter().copied(),
+ connected_clients.iter().copied(),
clear_display,
);
self.should_clear_display_before_rendering = false;
}
}
fn render_cursor(&self, output: &mut Output) {
- for &client_id in &self.connected_clients {
+ let connected_clients: Vec<ClientId> =
+ { self.connected_clients.borrow().iter().copied().collect() };
+ for client_id in connected_clients {
match self.get_active_terminal_cursor_position(client_id) {
Some((cursor_position_x, cursor_position_y)) => {
let show_cursor = "\u{1b}[?25h";
- let change_cursor_shape =
- self.get_active_pane(client_id).unwrap().cursor_shape_csi();
+ let change_cursor_shape = self
+ .get_active_pane(client_id)
+ .map(|ap| ap.cursor_shape_csi())
+ .unwrap_or_default();
let goto_cursor_position = &format!(
"\u{1b}[{};{}H\u{1b}[m{}",
cursor_position_y + 1,
@@ -1336,83 +1001,43 @@ impl Tab {
}
}
}
- fn get_panes(&self) -> impl Iterator<Item = (&PaneId, &Box<dyn Pane>)> {
- self.panes.iter()
+ fn get_tiled_panes(&self) -> impl Iterator<Item = (&PaneId, &Box<dyn Pane>)> {
+ self.tiled_panes.get_panes()
}
- fn get_selectable_panes(&self) -> impl Iterator<Item = (&PaneId, &Box<dyn Pane>)> {
- self.panes.iter().filter(|(_, p)| p.selectable())
+ fn get_selectable_tiled_panes(&self) -> impl Iterator<Item = (&PaneId, &Box<dyn Pane>)> {
+ self.get_tiled_panes().filter(|(_, p)| p.selectable())
}
fn get_next_terminal_position(&self) -> usize {
- self.panes
- .iter()
+ let tiled_panes_count = self
+ .tiled_panes
+ .get_panes()
.filter(|(k, _)| match k {
PaneId::Plugin(_) => false,
PaneId::Terminal(_) => true,
})
- .count()
- + 1
- }
- fn has_selectable_panes(&self) -> bool {
- let mut all_terminals = self.get_selectable_panes();
- all_terminals.next().is_some()
- }
- fn next_active_pane(&self, panes: &[PaneId]) -> Option<PaneId> {
- let mut panes: Vec<_> = panes
- .iter()
- .map(|p_id| self.panes.get(p_id).unwrap())
- .collect();
- panes.sort_by_key(|b| Reverse(b.active_at()));
-
- panes.iter().find(|pane| pane.selectable()).map(|p| p.pid())
+ .count();
+ let floating_panes_count = self
+ .floating_panes
+ .get_panes()
+ .filter(|(k, _)| match k {
+ PaneId::Plugin(_) => false,
+ PaneId::Terminal(_) => true,
+ })
+ .count();
+ tiled_panes_count + floating_panes_count + 1
}
- pub fn relayout_tab(&mut self, direction: Direction) {
- let mut pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let result = match direction {
- Direction::Horizontal => {
- pane_grid.layout(direction, (*self.display_area.borrow()).cols)
- }
- Direction::Vertical => pane_grid.layout(direction, (*self.display_area.borrow()).rows),
- };
- if let Err(e) = &result {
- log::error!("{:?} relayout of the tab failed: {}", direction, e);
- }
- self.set_pane_frames(self.draw_pane_frames);
+ pub fn has_selectable_panes(&self) -> bool {
+ let selectable_tiled_panes = self.tiled_panes.get_panes().filter(|(_, p)| p.selectable());
+ let selectable_floating_panes = self
+ .floating_panes
+ .get_panes()
+ .filter(|(_, p)| p.selectable());
+ selectable_tiled_panes.count() > 0 || selectable_floating_panes.count() > 0
}
pub fn resize_whole_tab(&mut self, new_screen_size: Size) {
self.floating_panes.resize(new_screen_size);
- {
- // this is blocked out to appease the borrow checker
- let mut display_area = self.display_area.borrow_mut();
- let mut viewport = self.viewport.borrow_mut();
- let panes = self
- .panes
- .iter_mut()
- .filter(|(pid, _)| !self.panes_to_hide.contains(pid));
- let Size { rows, cols } = new_screen_size;
- let mut pane_grid = TiledPaneGrid::new(panes, *display_area, *viewport);
- if pane_grid.layout(Direction::Horizontal, cols).is_ok() {
- let column_difference = cols as isize - display_area.cols as isize;
- // FIXME: Should the viewport be an Offset?
- viewport.cols = (viewport.cols as isize + column_difference) as usize;
- display_area.cols = cols;
- } else {
- log::error!("Failed to horizontally resize the tab!!!");
- }
- if pane_grid.layout(Direction::Vertical, rows).is_ok() {
- let row_difference = rows as isize - display_area.rows as isize;
- viewport.rows = (viewport.rows as isize + row_difference) as usize;
- display_area.rows = rows;
- } else {
- log::error!("Failed to vertically resize the tab!!!");
- }
-
- self.should_clear_display_before_rendering = true;
- }
- self.set_pane_frames(self.draw_pane_frames);
+ self.tiled_panes.resize(new_screen_size);
+ self.should_clear_display_before_rendering = true;
}
pub fn resize_left(&mut self, client_id: ClientId) {
if self.floating_panes.panes_are_visible() {
@@ -1423,17 +1048,8 @@ impl Tab {
self.set_force_render(); // we force render here to make sure the panes under the floating pane render and don't leave "garbage" incase of a decrease
return;
}
- }
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- let mut pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- pane_grid.resize_pane_left(&active_pane_id);
- for pane in self.panes.values_mut() {
- resize_pty!(pane, self.os_api);
- }
+ } else {
+ self.tiled_panes.resize_active_pane_left(client_id);
}
}
pub fn resize_right(&mut self, client_id: ClientId) {
@@ -1445,17 +1061,8 @@ impl Tab {
self.set_force_render(); // we force render here to make sure the panes under the floating pane render and don't leave "garbage" incase of a decrease
return;
}
- }
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- let mut pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- pane_grid.resize_pane_right(&active_pane_id);
- for pane in self.panes.values_mut() {
- resize_pty!(pane, self.os_api);
- }
+ } else {
+ self.tiled_panes.resize_active_pane_right(client_id);
}
}
pub fn resize_down(&mut self, client_id: ClientId) {
@@ -1467,17 +1074,8 @@ impl Tab {
self.set_force_render(); // we force render here to make sure the panes under the floating pane render and don't leave "garbage" incase of a decrease
return;
}
- }
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- let mut pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- pane_grid.resize_pane_down(&active_pane_id);
- for pane in self.panes.values_mut() {
- resize_pty!(pane, self.os_api);
- }
+ } else {
+ self.tiled_panes.resize_active_pane_down(client_id);
}
}
pub fn resize_up(&mut self, client_id: ClientId) {
@@ -1489,17 +1087,8 @@ impl Tab {
self.set_force_render(); // we force render here to make sure the panes under the floating pane render and don't leave "garbage" incase of a decrease
return;
}
- }
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- let mut pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- pane_grid.resize_pane_up(&active_pane_id);
- for pane in self.panes.values_mut() {
- resize_pty!(pane, self.os_api);
- }
+ } else {
+ self.tiled_panes.resize_active_pane_up(client_id);
}
}
pub fn resize_increase(&mut self, client_id: ClientId) {
@@ -1511,17 +1100,8 @@ impl Tab {
self.set_force_render(); // we force render here to make sure the panes under the floating pane render and don't leave "garbage" incase of a decrease
return;
}
- }
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- let mut pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- pane_grid.resize_increase(&active_pane_id);
- for pane in self.panes.values_mut() {
- resize_pty!(pane, self.os_api);
- }
+ } else {
+ self.tiled_panes.resize_active_pane_increase(client_id);
}
}
pub fn resize_decrease(&mut self, client_id: ClientId) {
@@ -1533,408 +1113,109 @@ impl Tab {
self.set_force_render(); // we force render here to make sure the panes under the floating pane render and don't leave "garbage" incase of a decrease
return;
}
- }
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- let mut pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- pane_grid.resize_decrease(&active_pane_id);
- for pane in self.panes.values_mut() {
- resize_pty!(pane, self.os_api);
- }
+ } else {
+ self.tiled_panes.resize_active_pane_decrease(client_id);
}
}
fn set_pane_active_at(&mut self, pane_id: PaneId) {
- if let Some(pane) = self.panes.get_mut(&pane_id) {
+ if let Some(pane) = self.tiled_panes.get_pane_mut(pane_id) {
+ pane.set_active_at(Instant::now());
+ } else if let Some(pane) = self.floating_panes.get_pane_mut(pane_id) {
pane.set_active_at(Instant::now());
}
}
-
- pub fn move_focus(&mut self, client_id: ClientId) {
- if !self.has_selectable_panes() {
- return;
- }
- if self.fullscreen_is_active {
- return;
- }
- let current_active_pane_id = self.get_active_pane_id(client_id).unwrap();
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let next_active_pane_id = pane_grid.next_selectable_pane_id(&current_active_pane_id);
- let connected_clients: Vec<ClientId> = self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, next_active_pane_id);
- }
- self.set_pane_active_at(next_active_pane_id);
- }
pub fn focus_next_pane(&mut self, client_id: ClientId) {
if !self.has_selectable_panes() {
return;
}
- if self.fullscreen_is_active {
+ if self.tiled_panes.fullscreen_is_active() {
return;
}
- let active_pane_id = self.get_active_pane_id(client_id).unwrap();
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let next_active_pane_id = pane_grid.next_selectable_pane_id(&active_pane_id);
- let connected_clients: Vec<ClientId> = self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, next_active_pane_id);
- }
- self.set_pane_active_at(next_active_pane_id);
+ self.tiled_panes.focus_next_pane(client_id);
}
pub fn focus_previous_pane(&mut self, client_id: ClientId) {
if !self.has_selectable_panes() {
return;
}
- if self.fullscreen_is_active {
+ if self.tiled_panes.fullscreen_is_active() {
return;
}
- let active_pane_id = self.get_active_pane_id(client_id).unwrap();
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let next_active_pane_id = pane_grid.previous_selectable_pane_id(&active_pane_id);
- let connected_clients: Vec<ClientId> = self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, next_active_pane_id);
- }
- self.set_pane_active_at(next_active_pane_id);
+ self.tiled_panes.focus_previous_pane(client_id);
}
// returns a boolean that indicates whether the focus moved
pub fn move_focus_left(&mut self, client_id: ClientId) -> bool {
if self.floating_panes.panes_are_visible() {
- self.floating_panes
- .move_focus_left(client_id, &self.connected_clients)
+ self.floating_panes.move_focus_left(
+ client_id,
+ &self.connected_clients.borrow().iter().copied().collect(),
+ )
} else {
if !self.has_selectable_panes() {
return false;
}
- if self.fullscreen_is_active {
+ if self.tiled_panes.fullscreen_is_active() {
return false;
}
- let active_pane_id = self.get_active_pane_id(client_id);
- let updated_active_pane = if let Some(active_pane_id) = active_pane_id {
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let next_index = pane_grid.next_selectable_pane_id_to_the_left(&active_pane_id);
- match next_index {
- Some(p) => {
- // render previously active pane so that its frame does not remain actively
- // colored
- let previously_active_pane = self
- .panes
- .get_mut(self.active_panes.get(&client_id).unwrap())
- .unwrap();
-
- previously_active_pane.set_should_render(true);
- // we render the full viewport to remove any ui elements that might have been
- // there before (eg. another user's cursor)
- previously_active_pane.render_full_viewport();
-
- let next_active_pane = self.panes.get_mut(&p).unwrap();
- next_active_pane.set_should_render(true);
- // we render the full viewport to remove any ui elements that might have been
- // there before (eg. another user's cursor)
- next_active_pane.render_full_viewport();
-
- if self.session_is_mirrored {
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, p);
- }
- } else {
- self.active_panes.insert(client_id, p);
- }
- self.set_pane_active_at(p);
-
- return true;
- }
- None => Some(active_pane_id),
- }
- } else {
- active_pane_id
- };
- match updated_active_pane {
- Some(updated_active_pane) => {
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, updated_active_pane);
- }
- self.set_pane_active_at(updated_active_pane);
- }
- None => {
- // TODO: can this happen?
- self.active_panes.clear();
- }
- }
-
- false
+ self.tiled_panes.move_focus_left(client_id)
}
}
- pub fn move_focus_down(&mut self, client_id: ClientId) {
+ pub fn move_focus_down(&mut self, client_id: ClientId) -> bool {
if self.floating_panes.panes_are_visible() {
- self.floating_panes
- .move_focus_down(client_id, &self.connected_clients);
+ self.floating_panes.move_focus_down(
+ client_id,
+ &self.connected_clients.borrow().iter().copied().collect(),
+ )
} else {
if !self.has_selectable_panes() {
- return;
- }
- if self.fullscreen_is_active {
- return;
+ return false;
}
- let active_pane_id = self.get_active_pane_id(client_id);
- let updated_active_pane = if let Some(active_pane_id) = active_pane_id {
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let next_index = pane_grid.next_selectable_pane_id_below(&active_pane_id);
- match next_index {
- Some(p) => {
- // render previously active pane so that its frame does not remain actively
- // colored
- let previously_active_pane = self
- .panes
- .get_mut(self.active_panes.get(&client_id).unwrap())
- .unwrap();
- previously_active_pane.set_should_render(true);
- // we render the full viewport to remove any ui elements that might have been
- // there before (eg. another user's cursor)
- previously_active_pane.render_full_viewport();
- let next_active_pane = self.panes.get_mut(&p).unwrap();
- next_active_pane.set_should_render(true);
- // we render the full viewport to remove any ui elements that might have been
- // there before (eg. another user's cursor)
- next_active_pane.render_full_viewport();
-
- Some(p)
- }
- None => Some(active_pane_id),
- }
- } else {
- active_pane_id
- };
- match updated_active_pane {
- Some(updated_active_pane) => {
- if self.session_is_mirrored {
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, updated_active_pane);
- }
- self.set_pane_active_at(updated_active_pane);
- } else {
- self.active_panes.insert(client_id, updated_active_pane);
- self.set_pane_active_at(updated_active_pane);
- }
- }
- None => {
- // TODO: can this happen?
- self.active_panes.clear();
- }
+ if self.tiled_panes.fullscreen_is_active() {
+ return false;
}
+ self.tiled_panes.move_focus_down(client_id)
}
}
- pub fn move_focus_up(&mut self, client_id: ClientId) {
+ pub fn move_focus_up(&mut self, client_id: ClientId) -> bool {
if self.floating_panes.panes_are_visible() {
- self.floating_panes
- .move_focus_up(client_id, &self.connected_clients);
+ self.floating_panes.move_focus_up(
+ client_id,
+ &self.connected_clients.borrow().iter().copied().collect(),
+ )
} else {
if !self.has_selectable_panes() {
- return;
- }
- if self.fullscreen_is_active {
- return;
+ return false;
}
- let active_pane_id = self.get_active_pane_id(client_id);
- let updated_active_pane = if let Some(active_pane_id) = active_pane_id {
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let next_index = pane_grid.next_selectable_pane_id_above(&active_pane_id);
- match next_index {
- Some(p) => {
- // render previously active pane so that its frame does not remain actively
- // colored
- let previously_active_pane = self
- .panes
- .get_mut(self.active_panes.get(&client_id).unwrap())
- .unwrap();
- previously_active_pane.set_should_render(true);
- // we render the full viewport to remove any ui elements that might have been
- // there before (eg. another user's cursor)
- previously_active_pane.render_full_viewport();
- let next_active_pane = self.panes.get_mut(&p).unwrap();
- next_active_pane.set_should_render(true);
- // we render the full viewport to remove any ui elements that might have been
- // there before (eg. another user's cursor)
- next_active_pane.render_full_viewport();
-
- Some(p)
- }
- None => Some(active_pane_id),
- }
- } else {
- active_pane_id
- };
- match updated_active_pane {
- Some(updated_active_pane) => {
- if self.session_is_mirrored {
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, updated_active_pane);
- }
- self.set_pane_active_at(updated_active_pane);
- } else {
- self.active_panes.insert(client_id, updated_active_pane);
- self.set_pane_active_at(updated_active_pane);
- }
- }
- None => {
- // TODO: can this happen?
- self.active_panes.clear();
- }
+ if self.tiled_panes.fullscreen_is_active() {
+ return false;
}
+ self.tiled_panes.move_focus_up(client_id)
}
}
// returns a boolean that indicates whether the focus moved
pub fn move_focus_right(&mut self, client_id: ClientId) -> bool {
if self.floating_panes.panes_are_visible() {
- self.floating_panes
- .move_focus_right(client_id, &self.connected_clients)
+ self.floating_panes.move_focus_right(
+ client_id,
+ &self.connected_clients.borrow().iter().copied().collect(),
+ )
} else {
if !self.has_selectable_panes() {
return false;
}
- if self.fullscreen_is_active {
+ if self.tiled_panes.fullscreen_is_active() {
return false;
}
- let active_pane_id = self.get_active_pane_id(client_id);
- let updated_active_pane = if let Some(active_pane_id) = active_pane_id {
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let next_index = pane_grid.next_selectable_pane_id_to_the_right(&active_pane_id);
- match next_index {
- Some(p) => {
- // render previously active pane so that its frame does not remain actively
- // colored
- let previously_active_pane = self
- .panes
- .get_mut(self.active_panes.get(&client_id).unwrap())
- .unwrap();
- previously_active_pane.set_should_render(true);
- // we render the full viewport to remove any ui elements that might have been
- // there before (eg. another user's cursor)
- previously_active_pane.render_full_viewport();
- let next_active_pane = self.panes.get_mut(&p).unwrap();
- next_active_pane.set_should_render(true);
- // we render the full viewport to remove any ui elements that might have been
- // there before (eg. another user's cursor)
- next_active_pane.render_full_viewport();
-
- if self.session_is_mirrored {
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, p);
- }
- } else {
- self.active_panes.insert(client_id, p);
- }
- self.set_pane_active_at(p);
- return true;
- }
- None => Some(active_pane_id),
- }
- } else {
- active_pane_id
- };
- match updated_active_pane {
- Some(updated_active_pane) => {
- if self.session_is_mirrored {
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, updated_active_pane);
- }
- self.set_pane_active_at(updated_active_pane);
- } else {
- self.active_panes.insert(client_id, updated_active_pane);
- self.set_pane_active_at(updated_active_pane);
- }
- }
- None => {
- // TODO: can this happen?
- self.active_panes.clear();
- }
- }
- false
+ self.tiled_panes.move_focus_right(client_id)
}
}
pub fn move_active_pane(&mut self, client_id: ClientId) {
if !self.has_selectable_panes() {
return;
}
- if self.fullscreen_is_active {
+ if self.tiled_panes.fullscreen_is_active() {
return;
}
- let active_pane_id = self.get_active_pane_id(client_id).unwrap();
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let new_position_id = pane_grid.next_selectable_pane_id(&active_pane_id);
- let current_position = self.panes.get(&active_pane_id).unwrap();
- let prev_geom = current_position.position_and_size();
- let prev_geom_override = current_position.geom_override();
-
- let new_position = self.panes.get_mut(&new_position_id).unwrap();
- let next_geom = new_position.position_and_size();
- let next_geom_override = new_position.geom_override();
- new_position.set_geom(prev_geom);
- if let Some(geom) = prev_geom_override {
- new_position.get_geom_override(geom);
- }
- resize_pty!(new_position, self.os_api);
- new_position.set_should_render(true);
-
- let current_position = self.panes.get_mut(&active_pane_id).unwrap();
- current_position.set_geom(next_geom);
- if let Some(geom) = next_geom_override {
- current_position.get_geom_override(geom);
- }
- resize_pty!(current_position, self.os_api);
- current_position.set_should_render(true);
+ self.tiled_panes.move_active_pane(client_id);
}
pub fn move_active_pane_down(&mut self, client_id: ClientId) {
if self.floating_panes.panes_are_visible() {
@@ -1944,41 +1225,10 @@ impl Tab {
if !self.has_selectable_panes() {
return;
}
- if self.fullscreen_is_active {
+ if self.tiled_panes.fullscreen_is_active() {
return;
}
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let next_index = pane_grid.next_selectable_pane_id_below(&active_pane_id);
- if let Some(p) = next_index {
- let active_pane_id = self.active_panes.get(&client_id).unwrap();
- let current_position = self.panes.get(active_pane_id).unwrap();
- let prev_geom = current_position.position_and_size();
- let prev_geom_override = current_position.geom_override();
-
- let new_position = self.panes.get_mut(&p).unwrap();
- let next_geom = new_position.position_and_size();
- let next_geom_override = new_position.geom_override();
- new_position.set_geom(prev_geom);
- if let Some(geom) = prev_geom_override {
- new_position.get_geom_override(geom);
- }
- resize_pty!(new_position, self.os_api);
- new_position.set_should_render(true);
-
- let current_position = self.panes.get_mut(active_pane_id).unwrap();
- current_position.set_geom(next_geom);
- if let Some(geom) = next_geom_override {
- current_position.get_geom_override(geom);
- }
- resize_pty!(current_position, self.os_api);
- current_position.set_should_render(true);
- }
- }
+ self.tiled_panes.move_active_pane_down(client_id);
}
}
pub fn move_active_pane_up(&mut self, client_id: ClientId) {
@@ -1989,41 +1239,10 @@ impl Tab {
if !self.has_selectable_panes() {
return;
}
- if self.fullscreen_is_active {
+ if self.tiled_panes.fullscreen_is_active() {
return;
}
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let next_index = pane_grid.next_selectable_pane_id_above(&active_pane_id);
- if let Some(p) = next_index {
- let active_pane_id = self.active_panes.get(&client_id).unwrap();
- let current_position = self.panes.get(active_pane_id).unwrap();
- let prev_geom = current_position.position_and_size();
- let prev_geom_override = current_position.geom_override();
-
- let new_position = self.panes.get_mut(&p).unwrap();
- let next_geom = new_position.position_and_size();
- let next_geom_override = new_position.geom_override();
- new_position.set_geom(prev_geom);
- if let Some(geom) = prev_geom_override {
- new_position.get_geom_override(geom);
- }
- resize_pty!(new_position, self.os_api);
- new_position.set_should_render(true);
-
- let current_position = self.panes.get_mut(active_pane_id).unwrap();
- current_position.set_geom(next_geom);
- if let Some(geom) = next_geom_override {
- current_position.get_geom_override(geom);
- }
- resize_pty!(current_position, self.os_api);
- current_position.set_should_render(true);
- }
- }
+ self.tiled_panes.move_active_pane_up(client_id);
}
}
pub fn move_active_pane_right(&mut self, client_id: ClientId) {
@@ -2034,41 +1253,10 @@ impl Tab {
if !self.has_selectable_panes() {
return;
}
- if self.fullscreen_is_active {
+ if self.tiled_panes.fullscreen_is_active() {
return;
}
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let next_index = pane_grid.next_selectable_pane_id_to_the_right(&active_pane_id);
- if let Some(p) = next_index {
- let active_pane_id = self.active_panes.get(&client_id).unwrap();
- let current_position = self.panes.get(active_pane_id).unwrap();
- let prev_geom = current_position.position_and_size();
- let prev_geom_override = current_position.geom_override();
-
- let new_position = self.panes.get_mut(&p).unwrap();
- let next_geom = new_position.position_and_size();
- let next_geom_override = new_position.geom_override();
- new_position.set_geom(prev_geom);
- if let Some(geom) = prev_geom_override {
- new_position.get_geom_override(geom);
- }
- resize_pty!(new_position, self.os_api);
- new_position.set_should_render(true);
-
- let current_position = self.panes.get_mut(active_pane_id).unwrap();
- current_position.set_geom(next_geom);
- if let Some(geom) = next_geom_override {
- current_position.get_geom_override(geom);
- }
- resize_pty!(current_position, self.os_api);
- current_position.set_should_render(true);
- }
- }
+ self.tiled_panes.move_active_pane_right(client_id);
}
}
pub fn move_active_pane_left(&mut self, client_id: ClientId) {
@@ -2079,46 +1267,15 @@ impl Tab {
if !self.has_selectable_panes() {
return;
}
- if self.fullscreen_is_active {
+ if self.tiled_panes.fullscreen_is_active() {
return;
}
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
- let pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- let next_index = pane_grid.next_selectable_pane_id_to_the_left(&active_pane_id);
- if let Some(p) = next_index {
- let active_pane_id = self.active_panes.get(&client_id).unwrap();
- let current_position = self.panes.get(active_pane_id).unwrap();
- let prev_geom = current_position.position_and_size();
- let prev_geom_override = current_position.geom_override();
-
- let new_position = self.panes.get_mut(&p).unwrap();
- let next_geom = new_position.position_and_size();
- let next_geom_override = new_position.geom_override();
- new_position.set_geom(prev_geom);
- if let Some(geom) = prev_geom_override {
- new_position.get_geom_override(geom);
- }
- resize_pty!(new_position, self.os_api);
- new_position.set_should_render(true);
-
- let current_position = self.panes.get_mut(active_pane_id).unwrap();
- current_position.set_geom(next_geom);
- if let Some(geom) = next_geom_override {
- current_position.get_geom_override(geom);
- }
- resize_pty!(current_position, self.os_api);
- current_position.set_should_render(true);
- }
- }
+ self.tiled_panes.move_active_pane_left(client_id);
}
}
fn close_down_to_max_terminals(&mut self) {
if let Some(max_panes) = self.max_panes {
- let terminals = self.get_embedded_pane_ids();
+ let terminals = self.get_tiled_pane_ids();
for &pid in terminals.iter().skip(max_panes - 1) {
self.senders
.send_to_pty(PtyInstruction::ClosePane(pid))
@@ -2127,22 +1284,22 @@ impl Tab {
}
}
}
- pub fn get_embedded_pane_ids(&self) -> Vec<PaneId> {
- self.get_panes().map(|(&pid, _)| pid).collect()
+ pub fn get_tiled_pane_ids(&self) -> Vec<PaneId> {
+ self.get_tiled_panes().map(|(&pid, _)| pid).collect()
}
pub fn get_all_pane_ids(&self) -> Vec<PaneId> {
// this is here just as a naming thing to make things more explicit
self.get_static_and_floating_pane_ids()
}
pub fn get_static_and_floating_pane_ids(&self) -> Vec<PaneId> {
- self.panes
- .keys()
+ self.tiled_panes
+ .pane_ids()
.chain(self.floating_panes.pane_ids())
.copied()
.collect()
}
pub fn set_pane_selectable(&mut self, id: PaneId, selectable: bool) {
- if let Some(pane) = self.panes.get_mut(&id) {
+ if let Some(pane) = self.tiled_panes.get_pane_mut(id) {
pane.set_selectable(selectable);
if !selectable {
// there are some edge cases in which this causes a hard crash when there are no
@@ -2156,23 +1313,7 @@ impl Tab {
// solve it by adding a "dangling_clients" struct to Tab which we would fill with
// the relevant client ids in this case and drain as soon as a new selectable pane
// is opened
- self.move_clients_out_of_pane(id);
- }
- }
- }
- fn move_clients_out_of_pane(&mut self, pane_id: PaneId) {
- let active_panes: Vec<(ClientId, PaneId)> = self
- .active_panes
- .iter()
- .map(|(cid, pid)| (*cid, *pid))
- .collect();
- for (client_id, active_pane_id) in active_panes {
- if active_pane_id == pane_id {
- self.active_panes.insert(
- client_id,
- self.next_active_pane(&self.get_embedded_pane_ids())
- .unwrap(),
- );
+ self.tiled_panes.move_clients_out_of_pane(id);
}
}
}
@@ -2187,29 +1328,13 @@ impl Tab {
self.floating_panes.set_force_render();
closed_pane
} else {
- if self.fullscreen_is_active {
- self.unset_fullscreen();
- }
- let mut pane_grid = TiledPaneGrid::new(
- &mut self.panes,
- *self.display_area.borrow(),
- *self.viewport.borrow(),
- );
- if pane_grid.fill_space_over_pane(id) {
- // successfully filled space over pane
- let closed_pane = self.panes.remove(&id);
- self.move_clients_out_of_pane(id);
- for pane in self.panes.values_mut() {
- resize_pty!(pane, self.os_api);
- }
- closed_pane
- } else {
- self.panes.remove(&id);
- // this is a bit of a roundabout way to say: this is the last pane and so the tab
- // should be destroyed
- self.active_panes.clear();
- None
+ if self.tiled_panes.fullscreen_is_active() {
+ self.tiled_panes.unset_fullscreen();
}
+ let closed_pane = self.tiled_panes.remove_pane(id);
+ self.set_force_render();
+ self.tiled_panes.set_force_render();
+ closed_pane
}
}
pub fn close_focused_pane(&mut self, client_id: ClientId) {
@@ -2222,7 +1347,7 @@ impl Tab {
return;
}
}
- if let Some(active_pane_id) = self.get_active_pane_id(client_id) {
+ if let Some(active_pane_id) = self.tiled_panes.get_active_pane_id(client_id) {
self.close_pane(active_pane_id);
self.senders
.send_to_pty(PtyInstruction::ClosePane(active_pane_id))
@@ -2343,27 +1468,34 @@ impl Tab {
) -> Option<&mut Box<dyn Pane>> {
if self.floating_panes.panes_are_visible() {
if let Some(pane_id) = self.floating_panes.get_pane_id_at(point, search_selectable) {
- return self.floating_panes.get_mut(&pane_id);
+ return self.floating_panes.get_pane_mut(pane_id);
}
}
if let Some(pane_id) = self.get_pane_id_at(point, search_selectable) {
- self.panes.get_mut(&pane_id)
+ self.tiled_panes.get_pane_mut(pane_id)
} else {
None
}
}
fn get_pane_id_at(&self, point: &Position, search_selectable: bool) -> Option<PaneId> {
- if self.fullscreen_is_active && self.is_position_inside_viewport(point) {
- let first_client_id = self.connected_clients.iter().next().unwrap(); // TODO: instead of doing this, record the pane that is in fullscreen
- return self.get_active_pane_id(*first_client_id);
+ if self.tiled_panes.fullscreen_is_active() && self.is_position_inside_viewport(point) {
+ let first_client_id = {
+ self.connected_clients
+ .borrow()
+ .iter()
+ .copied()
+ .next()
+ .unwrap()
+ }; // TODO: instead of doing this, record the pane that is in fullscreen
+ return self.tiled_panes.get_active_pane_id(first_client_id);
}
if search_selectable {
- self.get_selectable_panes()
+ self.get_selectable_tiled_panes()
.find(|(_, p)| p.contains(point))
.map(|(&id, _)| id)
} else {
- self.get_panes()
+ self.get_tiled_panes()
.find(|(_, p)| p.contains(point))
.map(|(&id, _)| id)
}
@@ -2417,27 +1549,13 @@ impl Tab {
fn focus_pane_at(&mut self, point: &Position, client_id: ClientId) {
if self.floating_panes.panes_are_visible() {
if let Some(clicked_pane) = self.floating_panes.get_pane_id_at(point, true) {
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.floating_panes.focus_pane(clicked_pane, client_id);
- }
+ self.floating_panes.focus_pane(clicked_pane, client_id);
self.set_pane_active_at(clicked_pane);
return;
}
}
if let Some(clicked_pane) = self.get_pane_id_at(point, true) {
- if self.session_is_mirrored {
- // move all clients
- let connected_clients: Vec<ClientId> =
- self.connected_clients.iter().copied().collect();
- for client_id in connected_clients {
- self.active_panes.insert(client_id, clicked_pane);
- }
- } else {
- self.active_panes.insert(client_id, clicked_pane);
- }
+ self.tiled_panes.focus_pane(clicked_pane, client_id);
self.set_pane_active_at(clicked_pane);
if self.floating_panes.panes_are_visible() {
self.floating_panes.toggle_show_panes(false);
@@ -2534,8 +1652,10 @@ impl Tab {
fn write_selection_to_clipboard(&self, selection: &str) {
let mut output = Output::default();
- output.add_clients(&self.connected_clients, self.link_handler.clone(), None);
- let client_ids = self.connected_clients.iter().copied();
+ let connected_clients: HashSet<ClientId> =
+ { self.connected_clients.borrow().iter().copied().collect() };
+ output.add_clients(&connected_clients, self.link_handler.clone(), None);
+ let client_ids = connected_clients.iter().copied();
let clipboard_event =
match self
.clipboard_provider
@@ -2557,11 +1677,6 @@ impl Tab {
.send_to_plugin(PluginInstruction::Update(None, None, clipboard_event))
.unwrap();
}
- fn is_inside_viewport(&self, pane_id: &PaneId) -> bool {
- // this is mostly separated to an outside function in order to allow us to pass a clone to
- // it sometimes when we need to get around the borrow checker
- is_inside_viewport(&*self.viewport.borrow(), self.panes.get(pane_id).unwrap())
- }
fn offset_viewport(&mut self, position_and_size: &Viewport) {
let mut viewport = self.viewport.borrow_mut();
if position_and_size.x == viewport.x
@@ -2587,7 +1702,7 @@ impl Tab {
}
pub fn visible(&self, visible: bool) {
- let pids_in_this_tab = self.panes.keys().filter_map(|p| match p {
+ let pids_in_this_tab = self.tiled_panes.pane_ids().filter_map(|p| match p {
PaneId::Plugin(pid) => Some(pid),
_ => None,
});
@@ -2605,8 +1720,8 @@ impl Tab {
pub fn update_active_pane_name(&mut self, buf: Vec<u8>, client_id: ClientId) {
if let Some(active_terminal_id) = self.get_active_terminal_id(client_id) {
let active_terminal = self
- .panes
- .get_mut(&PaneId::Terminal(active_terminal_id))
+ .tiled_panes
+ .get_pane_mut(PaneId::Terminal(active_terminal_id))
.unwrap();
// It only allows printable unicode, delete and backspace keys.
@@ -2631,21 +1746,15 @@ impl Tab {
&& line <= viewport.y + viewport.rows
&& column <= viewport.x + viewport.cols
}
-}
-
-#[allow(clippy::borrowed_box)]
-pub fn is_inside_viewport(viewport: &Viewport, pane: &Box<dyn Pane>) -> bool {
- let pane_position_and_size = pane.current_geom();
- pane_position_and_size.y >= viewport.y
- && pane_position_and_size.y + pane_position_and_size.rows.as_usize()
- <= viewport.y + viewport.rows
-}
-pub fn pane_geom_is_inside_viewport(viewport: &Viewport, geom: &PaneGeom) -> bool {
- geom.y >= viewport.y
- && geom.y + geom.rows.as_usize() <= viewport.y + viewport.rows
- && geom.x >= viewport.x
- && geom.x + geom.cols.as_usize() <= viewport.x + viewport.cols
+ pub fn set_pane_frames(&mut self, should_set_pane_frames: bool) {
+ self.tiled_panes.set_pane_frames(should_set_pane_frames);
+ self.should_clear_display_before_rendering = true;
+ self.set_force_render();
+ }
+ pub fn panes_to_hide_count(&self) -> usize {
+ self.tiled_panes.panes_to_hide_count()
+ }
}
#[cfg(test)]