mod floating_pane_grid;
use zellij_utils::{
data::{Direction, ResizeStrategy},
position::Position,
};
use crate::resize_pty;
use crate::tab::Pane;
use floating_pane_grid::FloatingPaneGrid;
use crate::{
os_input_output::ServerOsApi,
output::{FloatingPanesStack, Output},
panes::{ActivePanes, PaneId},
plugins::PluginInstruction,
thread_bus::ThreadSenders,
ui::pane_contents_and_ui::PaneContentsAndUi,
ClientId,
};
use std::cell::RefCell;
use std::collections::{BTreeMap, HashMap, HashSet, VecDeque};
use std::rc::Rc;
use std::time::Instant;
use zellij_utils::{
data::{ModeInfo, Style},
errors::prelude::*,
input::command::RunCommand,
input::layout::FloatingPaneLayout,
pane_size::{Dimension, Offset, PaneGeom, Size, Viewport},
};
const RESIZE_INCREMENT_WIDTH: usize = 5;
const RESIZE_INCREMENT_HEIGHT: usize = 2;
pub struct FloatingPanes {
panes: BTreeMap<PaneId, Box<dyn Pane>>,
display_area: Rc<RefCell<Size>>,
viewport: Rc<RefCell<Viewport>>,
connected_clients: Rc<RefCell<HashSet<ClientId>>>,
connected_clients_in_app: Rc<RefCell<HashSet<ClientId>>>,
mode_info: Rc<RefCell<HashMap<ClientId, ModeInfo>>>,
default_mode_info: ModeInfo,
style: Style,
session_is_mirrored: bool,
desired_pane_positions: HashMap<PaneId, PaneGeom>, // this represents the positions of panes the user moved with intention, rather than by resizing the terminal window
z_indices: Vec<PaneId>,
active_panes: ActivePanes,
show_panes: bool,
pane_being_moved_with_mouse: Option<(PaneId, Position)>,
senders: ThreadSenders,
next_geoms: VecDeque<PaneGeom>, // TODO: remove this?
}
#[allow(clippy::borrowed_box)]
#[allow(clippy::too_many_arguments)]
impl FloatingPanes {
pub fn new(
display_area: Rc<RefCell<Size>>,
viewport: Rc<RefCell<Viewport>>,
connected_clients: Rc<RefCell<HashSet<ClientId>>>,
connected_clients_in_app: Rc<RefCell<HashSet<ClientId>>>,
mode_info: Rc<RefCell<HashMap<ClientId, ModeInfo>>>,
session_is_mirrored: bool,
default_mode_info: ModeInfo,
style: Style,
os_input: Box<dyn ServerOsApi>,
senders: ThreadSenders,
) -> Self {
FloatingPanes {
panes: BTreeMap::new(),
display_area,
viewport,
connected_clients,
connected_clients_in_app,
mode_info,
session_is_mirrored,
default_mode_info,
style,
desired_pane_positions: HashMap::new(),
z_indices: vec![],
show_panes: false,
active_panes: ActivePanes::new(&os_input),
pane_being_moved_with_mouse: None,
senders,
next_geoms: VecDeque::new(),
}
}
pub fn stack(&self) -> Option<FloatingPanesStack>