Skip to content

Commit

Permalink
Removed pane_id where not needed
Browse files Browse the repository at this point in the history
  • Loading branch information
e82eric committed Jun 23, 2024
1 parent 86c9efd commit 03eabc7
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 86 deletions.
17 changes: 4 additions & 13 deletions mux/src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub trait Domain: Downcast + Send + Sync {
async fn add_float_pane(
&self,
tab: TabId,
pane_id: PaneId,
_pane_id: PaneId,
command_builder: Option<CommandBuilder>,
command_dir: Option<String>
) -> anyhow::Result<Arc<dyn Pane>> {
Expand All @@ -84,18 +84,9 @@ pub trait Domain: Downcast + Send + Sync {
None => anyhow::bail!("Invalid tab id {}", tab),
};

let pane_index = match tab
.iter_panes_ignoring_zoom()
.iter()
.find(|p| p.pane.pane_id() == pane_id)
{
Some(p) => p.index,
None => anyhow::bail!("invalid pane id {}", pane_id),
};

let float_pos = tab.get_float_pos();
let pane = self.spawn_pane(float_pos.size, command_builder, command_dir) .await?;
tab.insert_float(pane_index, float_pos.size, Arc::clone(&pane))?;
let float_size = tab.get_float_size();
let pane = self.spawn_pane(float_size, command_builder, command_dir) .await?;
tab.insert_float(float_size, Arc::clone(&pane))?;
Ok(pane)
}

Expand Down
60 changes: 23 additions & 37 deletions mux/src/tab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,6 @@ pub struct PositionedSplit {
pub size: usize,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct PositionedFloat {
/// The offset from the top left corner of the containing tab to the top
/// left corner of this split, in cells.
pub left: usize,
/// The offset from the top left corner of the containing tab to the top
/// left corner of this split, in cells.
pub top: usize,
pub size: TerminalSize
}

fn is_pane(pane: &Arc<dyn Pane>, other: &Option<&Arc<dyn Pane>>) -> bool {
if let Some(other) = other {
other.pane_id() == pane.pane_id()
Expand Down Expand Up @@ -754,10 +743,10 @@ impl Tab {
self.inner.lock().compute_split_size(pane_index, request)
}

pub fn get_float_pos(
pub fn get_float_size(
&self,
) -> PositionedFloat {
self.inner.lock().get_float_pos()
) -> TerminalSize {
self.inner.lock().get_float_size()
}

/// Split the pane that has pane_index in the given direction and assign
Expand All @@ -777,13 +766,12 @@ impl Tab {

pub fn insert_float(
&self,
pane_index: usize,
float_size: TerminalSize,
pane: Arc<dyn Pane>,
) -> anyhow::Result<usize> {
) -> anyhow::Result<()> {
self.inner
.lock()
.add_float_pane(pane_index, float_size, pane)
.add_float_pane(float_size, pane)
}

pub fn get_zoomed_pane(&self) -> Option<Arc<dyn Pane>> {
Expand Down Expand Up @@ -971,19 +959,25 @@ impl TabInner {
}

fn get_float_pane(&self) -> Option<PositionedPane> {
let float_pos = self.get_float_pos();

if let Some(float_pane) = self.float_pane.as_ref() {
let root_size = self.size;
let size = self.get_float_size();

let cell_height = root_size.pixel_height / root_size.rows;
let cell_width = root_size.pixel_width / root_size.cols;
let left = ((root_size.pixel_width - size.pixel_width) / 2) / cell_width;
let top = (root_size.pixel_height - size.pixel_height) / 2 / cell_height;

Some(PositionedPane {
index: 0,
is_active: true,
is_zoomed: false,
left: float_pos.left,
top: float_pos.top,
width: float_pos.size.cols,
height: float_pos.size.rows,
pixel_width: float_pos.size.pixel_width,
pixel_height: float_pos.size.pixel_height,
left,
top,
width: size.cols,
height: size.rows,
pixel_width: size.pixel_width,
pixel_height: size.pixel_height,
pane: Arc::clone(float_pane),
is_float: true
})
Expand Down Expand Up @@ -1942,7 +1936,7 @@ impl TabInner {
None
}

fn get_float_pos(&self) -> PositionedFloat {
fn get_float_size(&self) -> TerminalSize {
let root_size = self.size;

let cell_width = root_size.pixel_width as f32 / root_size.cols as f32;
Expand All @@ -1969,18 +1963,12 @@ impl TabInner {
let cols = (pixel_width as f32 / cell_width) as usize;
let rows = (pixel_height as f32 / cell_height) as usize;

let size = TerminalSize{
TerminalSize{
rows,
cols,
pixel_width,
pixel_height,
dpi: root_size.dpi,
};

PositionedFloat{
left: (left_padding_pixels as f32 / cell_width).ceil() as usize,
top: (top_padding_pixels as f32 / cell_height).ceil() as usize,
size
}
}

Expand Down Expand Up @@ -2077,10 +2065,9 @@ impl TabInner {

fn add_float_pane(
&mut self,
pane_index: usize,
float_size: TerminalSize,
pane: Arc<dyn Pane>,
) -> anyhow::Result<usize> {
) -> anyhow::Result<()> {
if self.zoomed.is_some() {
anyhow::bail!("cannot add float while zoomed");
}
Expand All @@ -2092,10 +2079,9 @@ impl TabInner {
self.float_pane = Some(Arc::clone(&pane));
{
pane.resize(float_size)?;
self.set_active_idx(0);
}

Ok(pane_index + 1)
Ok(())
}

fn split_and_insert(
Expand Down
29 changes: 1 addition & 28 deletions wezterm-gui/src/termwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use mux::pane::{
CachePolicy, CloseReason, Pane, PaneId, Pattern as MuxPattern, PerformAssignmentResult,
};
use mux::renderable::RenderableDimensions;
use mux::tab::{PositionedFloat, PositionedPane, PositionedSplit, SplitDirection, SplitRequest, SplitSize as MuxSplitSize, Tab, TabId};
use mux::tab::{PositionedPane, PositionedSplit, SplitDirection, SplitRequest, SplitSize as MuxSplitSize, Tab, TabId};
use mux::window::WindowId as MuxWindowId;
use mux::{Mux, MuxNotification};
use mux_lua::MuxPane;
Expand Down Expand Up @@ -3353,33 +3353,6 @@ impl TermWindow {
}
}

fn get_float_pane(&mut self) -> Option<Arc<dyn Pane>> {
let mux = Mux::get();
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
Some(tab) => tab,
None => return None,
};

let tab_id = tab.tab_id();

if self.tab_state(tab_id).overlay.is_some() {
None
} else {
self.get_float_pane()
}
}

fn get_float_pos(&mut self) -> Option<PositionedFloat> {
let mux = Mux::get();
let tab = match mux.get_active_tab_for_window(self.mux_window_id) {
Some(tab) => tab,
None => return None,
};

let float_pos = tab.get_float_pos();
Some(float_pos)
}

fn pos_pane_to_pane_info(pos: &PositionedPane) -> PaneInformation {
PaneInformation {
pane_id: pos.pane.pane_id(),
Expand Down
7 changes: 3 additions & 4 deletions wezterm-gui/src/termwindow/render/paint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ impl crate::TermWindow {
let float_layer = gl_state
.layer_for_zindex(2)
.context("layer_for_zindex(2)")?;
let mut float_layers = float_layer.quad_allocator();

log::trace!("quad map elapsed {:?}", start.elapsed());
metrics::histogram!("quad.map").record(start.elapsed());
Expand Down Expand Up @@ -264,10 +263,10 @@ impl crate::TermWindow {
}

if let Some(float_pane) = self.get_float_pane_to_render() {
float_pane.pane.advise_focus();
let mut float_layers = float_layer.quad_allocator();

self.paint_pane(&float_pane, &mut float_layers).context("paint_pane")?;
let float = self.get_float_pos();
self.paint_float_border(float.unwrap(), &mut layers).context("paint_float")?;
self.paint_float_border(float_pane, &mut float_layers).context("paint_float_border")?;
}

if let Some(pane) = self.get_active_pane_or_overlay() {
Expand Down
8 changes: 4 additions & 4 deletions wezterm-gui/src/termwindow/render/split.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::termwindow::render::TripleLayerQuadAllocator;
use crate::termwindow::{UIItem, UIItemType};
use mux::pane::Pane;
use mux::tab::{PositionedFloat, PositionedSplit, SplitDirection};
use mux::tab::{PositionedPane, PositionedSplit, SplitDirection};
use std::sync::Arc;

impl crate::TermWindow {
Expand Down Expand Up @@ -81,7 +81,7 @@ impl crate::TermWindow {

pub fn paint_float_border(
&mut self,
pos: PositionedFloat,
pos: PositionedPane,
layers: &mut TripleLayerQuadAllocator,
) -> anyhow::Result<()> {
let (padding_left, padding_top) = self.padding_left_top();
Expand All @@ -93,8 +93,8 @@ impl crate::TermWindow {
let half_cell_width = cell_width as f32 / 2.0;
let pos_y = (pos.top as f32 * self.render_metrics.cell_size.height as f32) - self.render_metrics.underline_height as f32 - half_cell_height + padding_top;
let pos_x = (pos.left as f32 * self.render_metrics.cell_size.width as f32) - self.render_metrics.underline_height as f32 - half_cell_width + padding_left;
let pixel_height = (pos.size.rows as f32 * cell_height as f32) + self.render_metrics.underline_height as f32 + cell_height as f32;
let pixel_width = (pos.size.cols as f32 * cell_width as f32) + self.render_metrics.underline_height as f32 + cell_width as f32;
let pixel_height = pos.pixel_height as f32 + self.render_metrics.underline_height as f32 + cell_height as f32;
let pixel_width = pos.pixel_width as f32 + self.render_metrics.underline_height as f32 + cell_width as f32;

self.filled_rectangle(
layers,
Expand Down

0 comments on commit 03eabc7

Please sign in to comment.