From bd02d33bf5f65fc2bc3918866e38f82b52b1d29a Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 1 Apr 2022 09:31:59 -0700 Subject: [PATCH] tab bar: constrain to constant height The tab bar height could vary by a couple of pixels depending on the text shown inside it, which results in visual jitter as the title bar changes. Avoid that: always return our constant reserved amount of space for the tab bar, even if it means that there are a couple of pixels "wasted". cc: @davidrios --- wezterm-gui/src/termwindow/mod.rs | 2 +- wezterm-gui/src/termwindow/render.rs | 21 +++++---------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index a0caa3ede..dd72e42df 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -639,7 +639,7 @@ impl TermWindow { // for the tab bar state. let show_tab_bar = config.enable_tab_bar && !config.hide_tab_bar_if_only_one_tab; let tab_bar_height = if show_tab_bar { - Self::tab_bar_pixel_height_impl(&config, &fontconfig, &render_metrics, None)? as usize + Self::tab_bar_pixel_height_impl(&config, &fontconfig, &render_metrics)? as usize } else { 0 }; diff --git a/wezterm-gui/src/termwindow/render.rs b/wezterm-gui/src/termwindow/render.rs index 0e702eeea..1eacb8668 100644 --- a/wezterm-gui/src/termwindow/render.rs +++ b/wezterm-gui/src/termwindow/render.rs @@ -442,29 +442,17 @@ impl super::TermWindow { config: &ConfigHandle, fontconfig: &wezterm_font::FontConfiguration, render_metrics: &RenderMetrics, - fancy_tab_bar_height: Option, ) -> anyhow::Result { if config.use_fancy_tab_bar { - if let Some(tab_bar_height) = fancy_tab_bar_height { - Ok(tab_bar_height) - } else { - let font = fontconfig.title_font()?; - Ok((font.metrics().cell_height.get() as f32 * 1.75).ceil()) - } + let font = fontconfig.title_font()?; + Ok((font.metrics().cell_height.get() as f32 * 1.75).ceil()) } else { Ok(render_metrics.cell_size.height as f32) } } pub fn tab_bar_pixel_height(&self) -> anyhow::Result { - Self::tab_bar_pixel_height_impl( - &self.config, - &self.fonts, - &self.render_metrics, - self.fancy_tab_bar - .as_ref() - .map(|elem| elem.content_rect.size.height), - ) + Self::tab_bar_pixel_height_impl(&self.config, &self.fonts, &self.render_metrics) } pub fn invalidate_fancy_tab_bar(&mut self) { @@ -472,6 +460,7 @@ impl super::TermWindow { } pub fn build_fancy_tab_bar(&self, palette: &ColorPalette) -> anyhow::Result { + let tab_bar_height = self.tab_bar_pixel_height()?; let font = self.fonts.title_font()?; let metrics = RenderMetrics::with_font_metrics(&font.metrics()); let items = self.tab_bar.items(); @@ -807,7 +796,7 @@ impl super::TermWindow { border.left.get() as f32, 0., self.dimensions.pixel_width as f32 - (border.left + border.right).get() as f32, - self.dimensions.pixel_height as f32 - (border.top + border.bottom).get() as f32, + tab_bar_height, ), metrics: &metrics, gl_state: self.render_state.as_ref().unwrap(),