diff --git a/config/src/config.rs b/config/src/config.rs index 5073dbe68..db0c96c1c 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -546,6 +546,9 @@ pub struct Config { #[dynamic(default)] pub launch_menu: Vec, + #[dynamic(default)] + pub use_box_model_render: bool, + /// When true, watch the config file and reload it automatically /// when it is detected as changing. #[dynamic(default = "default_true")] diff --git a/wezterm-gui/src/termwindow/box_model.rs b/wezterm-gui/src/termwindow/box_model.rs index 9ddbf328f..383414a8e 100644 --- a/wezterm-gui/src/termwindow/box_model.rs +++ b/wezterm-gui/src/termwindow/box_model.rs @@ -52,7 +52,7 @@ impl Default for Float { } } -#[derive(Debug, Clone, Copy, PartialEq)] +#[derive(Debug, Clone, Copy, PartialEq, Default)] pub struct PixelDimension { pub left: f32, pub top: f32, diff --git a/wezterm-gui/src/termwindow/render.rs b/wezterm-gui/src/termwindow/render.rs index d3fd6d134..44212a4af 100644 --- a/wezterm-gui/src/termwindow/render.rs +++ b/wezterm-gui/src/termwindow/render.rs @@ -1138,11 +1138,136 @@ impl super::TermWindow { }) } + pub fn build_pane( + &mut self, + pos: &PositionedPane, + num_panes: usize, + ) -> anyhow::Result { + // First compute the bounds for the pane background + + let cell_width = self.render_metrics.cell_size.width as f32; + let cell_height = self.render_metrics.cell_size.height as f32; + let (padding_left, padding_top) = self.padding_left_top(); + let tab_bar_height = if self.show_tab_bar { + self.tab_bar_pixel_height()? + } else { + 0. + }; + let (top_bar_height, bottom_bar_height) = if self.config.tab_bar_at_bottom { + (0.0, tab_bar_height) + } else { + (tab_bar_height, 0.0) + }; + + let border = self.get_os_border(); + let top_pixel_y = top_bar_height + padding_top + border.top.get() as f32; + + // We want to fill out to the edges of the splits + let (x, width_delta) = if pos.left == 0 { + ( + 0., + padding_left + border.left.get() as f32 + (cell_width / 2.0), + ) + } else { + ( + padding_left + border.left.get() as f32 - (cell_width / 2.0) + + (pos.left as f32 * cell_width), + cell_width, + ) + }; + + let (y, height_delta) = if pos.top == 0 { + ( + (top_pixel_y - padding_top), + padding_top + (cell_height / 2.0), + ) + } else { + ( + top_pixel_y + (pos.top as f32 * cell_height) - (cell_height / 2.0), + cell_height, + ) + }; + + let background_rect = euclid::rect( + x, + y, + // Go all the way to the right edge if we're right-most + if pos.left + pos.width >= self.terminal_size.cols as usize { + self.dimensions.pixel_width as f32 - x + } else { + (pos.width as f32 * cell_width) + width_delta + }, + // Go all the way to the bottom if we're bottom-most + if pos.top + pos.height >= self.terminal_size.rows as usize { + self.dimensions.pixel_height as f32 - y + } else { + (pos.height as f32 * cell_height) + height_delta as f32 + }, + ); + + // Bounds for the terminal cells + let content_rect = euclid::rect( + padding_left + border.left.get() as f32 - (cell_width / 2.0) + + (pos.left as f32 * cell_width), + top_pixel_y + (pos.top as f32 * cell_height) - (cell_height / 2.0), + pos.width as f32 * cell_width, + pos.height as f32 * cell_height, + ); + + let palette = pos.pane.palette(); + + // TODO: visual bell background layer + // TODO: scrollbar + + Ok(ComputedElement { + item_type: None, + zindex: 0, + bounds: background_rect, + border: PixelDimension::default(), + border_rect: background_rect, + border_corners: None, + colors: ElementColors { + border: BorderColor::default(), + bg: if num_panes > 1 && self.window_background.is_empty() { + palette + .background + .to_linear() + .mul_alpha(self.config.window_background_opacity) + .into() + } else { + InheritableColor::Inherited + }, + text: InheritableColor::Inherited, + }, + hover_colors: None, + padding: background_rect, + content_rect, + baseline: 1.0, + content: ComputedElementContent::Children(vec![]), + }) + } + + fn paint_pane_opengl_new( + &mut self, + pos: &PositionedPane, + num_panes: usize, + ) -> anyhow::Result<()> { + let computed = self.build_pane(pos, num_panes)?; + let mut ui_items = computed.ui_items(); + self.ui_items.append(&mut ui_items); + let gl_state = self.render_state.as_ref().unwrap(); + self.render_element(&computed, gl_state, None) + } + pub fn paint_pane_opengl( &mut self, pos: &PositionedPane, num_panes: usize, ) -> anyhow::Result<()> { + if self.config.use_box_model_render { + return self.paint_pane_opengl_new(pos, num_panes); + } + self.check_for_dirty_lines_and_invalidate_selection(&pos.pane); /* let zone = {