From 808d7df8d44f489680bd704d77fe23e5951cc79d Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Wed, 30 Mar 2022 07:03:14 -0700 Subject: [PATCH] gui: fixup tab bar height issue In https://github.com/wez/wezterm/pull/1779#issuecomment-1082058134 we discuss a weird case where the tab bar height is computed as 0 and then gets stuck at 0. What's happening is that the initial `TabBarState::default()` value has no items yet, and `build_fancy_tab` generates an area that occupies 0 pixels. This computed element is cached, and then the height from that is cached. When `invalidate_fancy_tab` is called, it didn't invalidate the cached height and the resultant metrics were wonky. One possible fix for this was to also invalidate the cached height, but since that height is already stored in the built fancy tab, we can remove that derived-cached value in favor of just passing down the value. refs: https://github.com/wez/wezterm/pull/1779 --- wezterm-gui/src/termwindow/mod.rs | 4 +--- wezterm-gui/src/termwindow/render.rs | 10 +++++----- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/wezterm-gui/src/termwindow/mod.rs b/wezterm-gui/src/termwindow/mod.rs index 74a914f52..04a3ed19b 100644 --- a/wezterm-gui/src/termwindow/mod.rs +++ b/wezterm-gui/src/termwindow/mod.rs @@ -305,7 +305,6 @@ pub struct TermWindow { show_scroll_bar: bool, tab_bar: TabBarState, fancy_tab_bar: Option, - fancy_tab_bar_height: Option, pub right_status: String, last_ui_item: Option, /// Tracks whether the current mouse-down event is part of click-focus. @@ -641,7 +640,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, None)? as usize } else { 0 }; @@ -729,7 +728,6 @@ impl TermWindow { show_scroll_bar: config.enable_scroll_bar, tab_bar: TabBarState::default(), fancy_tab_bar: None, - fancy_tab_bar_height: None, right_status: String::new(), last_mouse_coords: (0, -1), window_drag_position: None, diff --git a/wezterm-gui/src/termwindow/render.rs b/wezterm-gui/src/termwindow/render.rs index 303d92cfb..0e702eeea 100644 --- a/wezterm-gui/src/termwindow/render.rs +++ b/wezterm-gui/src/termwindow/render.rs @@ -442,11 +442,11 @@ impl super::TermWindow { config: &ConfigHandle, fontconfig: &wezterm_font::FontConfiguration, render_metrics: &RenderMetrics, - fancy_tab_bar_height: &Option, + 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) + Ok(tab_bar_height) } else { let font = fontconfig.title_font()?; Ok((font.metrics().cell_height.get() as f32 * 1.75).ceil()) @@ -461,7 +461,9 @@ impl super::TermWindow { &self.config, &self.fonts, &self.render_metrics, - &self.fancy_tab_bar_height, + self.fancy_tab_bar + .as_ref() + .map(|elem| elem.content_rect.size.height), ) } @@ -854,8 +856,6 @@ impl super::TermWindow { if self.fancy_tab_bar.is_none() { let palette = self.palette().clone(); let tab_bar = self.build_fancy_tab_bar(&palette)?; - self.fancy_tab_bar_height - .replace(tab_bar.content_rect.size.height); self.fancy_tab_bar.replace(tab_bar); }