From 03eabc7ca957533130bdda16f5f14121d32c2386 Mon Sep 17 00:00:00 2001 From: Eric Nelson Date: Sun, 23 Jun 2024 07:51:51 -0700 Subject: [PATCH] Removed pane_id where not needed --- mux/src/domain.rs | 17 ++---- mux/src/tab.rs | 60 +++++++++------------- wezterm-gui/src/termwindow/mod.rs | 29 +---------- wezterm-gui/src/termwindow/render/paint.rs | 7 ++- wezterm-gui/src/termwindow/render/split.rs | 8 +-- 5 files changed, 35 insertions(+), 86 deletions(-) diff --git a/mux/src/domain.rs b/mux/src/domain.rs index 98bf4fe755a..e7e5a3e700f 100644 --- a/mux/src/domain.rs +++ b/mux/src/domain.rs @@ -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, command_dir: Option ) -> anyhow::Result> { @@ -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) } diff --git a/mux/src/tab.rs b/mux/src/tab.rs index 6a95d4d2c58..616b062ad4a 100644 --- a/mux/src/tab.rs +++ b/mux/src/tab.rs @@ -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, other: &Option<&Arc>) -> bool { if let Some(other) = other { other.pane_id() == pane.pane_id() @@ -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 @@ -777,13 +766,12 @@ impl Tab { pub fn insert_float( &self, - pane_index: usize, float_size: TerminalSize, pane: Arc, - ) -> anyhow::Result { + ) -> 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> { @@ -971,19 +959,25 @@ impl TabInner { } fn get_float_pane(&self) -> Option { - 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 }) @@ -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; @@ -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 } } @@ -2077,10 +2065,9 @@ impl TabInner { fn add_float_pane( &mut self, - pane_index: usize, float_size: TerminalSize, pane: Arc, - ) -> anyhow::Result { + ) -> anyhow::Result<()> { if self.zoomed.is_some() { anyhow::bail!("cannot add float while zoomed"); } @@ -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( diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index c5c3ef643ba..39cec992af9 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -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; @@ -3353,33 +3353,6 @@ impl TermWindow { } } - fn get_float_pane(&mut self) -> Option> { - 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 { - 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(), diff --git a/wezterm-gui/src/termwindow/render/paint.rs b/wezterm-gui/src/termwindow/render/paint.rs index 56bbb0108ff..7c94cd514c0 100644 --- a/wezterm-gui/src/termwindow/render/paint.rs +++ b/wezterm-gui/src/termwindow/render/paint.rs @@ -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()); @@ -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() { diff --git a/wezterm-gui/src/termwindow/render/split.rs b/wezterm-gui/src/termwindow/render/split.rs index 5dc82099304..0efbbf202fb 100644 --- a/wezterm-gui/src/termwindow/render/split.rs +++ b/wezterm-gui/src/termwindow/render/split.rs @@ -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 { @@ -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(); @@ -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,