Skip to content

A modern terminal with a built-in multiplexer: close it and your sessions keep running. Run shells and tons of AI agents across your machines, then pick them up from desktop, browser, TUI and more. Written in Rust with no UI framework: interface drawn straight on the GPU. No Electron, GPUI or webview.

Fix DPI handling, corner radius snapping, and window decoration logic

RoversXa32abe3220b3
diff --git a/wezterm-font/src/lib.rs b/wezterm-font/src/lib.rs
index 2d868d9b..35bfdebf 100644
--- a/wezterm-font/src/lib.rs
+++ b/wezterm-font/src/lib.rs
@@ -1031,6 +1031,12 @@ impl FontConfigInner {
self.pane_select_font.borrow_mut().take();
self.char_select_font.borrow_mut().take();
self.command_palette_font.borrow_mut().take();
+ // Sized entity fonts are rasterized for the DPI that was active
+ // when they were cached. Reusing them after moving a window
+ // between Retina and non-Retina displays leaves the custom UI
+ // text at the old backing scale while its controls use the new
+ // scale.
+ self.entity_font_overrides.borrow_mut().clear();
}
(prior_font, prior_dpi)
@@ -1239,3 +1245,31 @@ impl FontConfiguration {
self.inner.match_style(config, attrs)
}
}
+
+#[cfg(all(test, target_os = "macos"))]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn dpi_change_invalidates_sized_entity_font_cache() -> anyhow::Result<()> {
+ let fonts = FontConfiguration::new(Some(ConfigHandle::default_config()), 144)?;
+
+ let retina = fonts.title_font_with_size(15.0)?;
+ assert_eq!(retina.dpi, 144);
+ let retina_id = retina.id();
+ assert!(Rc::ptr_eq(&retina, &fonts.title_font_with_size(15.0)?));
+
+ fonts.change_scaling(1.0, 72);
+ let standard = fonts.title_font_with_size(15.0)?;
+ assert_eq!(standard.dpi, 72);
+ assert_ne!(standard.id(), retina_id);
+ assert!(Rc::ptr_eq(&standard, &fonts.title_font_with_size(15.0)?));
+
+ fonts.change_scaling(1.0, 144);
+ let retina_again = fonts.title_font_with_size(15.0)?;
+ assert_eq!(retina_again.dpi, 144);
+ assert_ne!(retina_again.id(), standard.id());
+
+ Ok(())
+ }
+}
diff --git a/wezterm-gui/src/termwindow/ui/right_sidebar.rs b/wezterm-gui/src/termwindow/ui/right_sidebar.rs
index b43dcb9c..9c32f324 100644
--- a/wezterm-gui/src/termwindow/ui/right_sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/right_sidebar.rs
@@ -3765,7 +3765,7 @@ impl crate::TermWindow {
muted_fg,
content_x,
content_top,
- content_width,
+ filter_width,
self.ui_px(FILE_FILTER_HEIGHT),
Some(SvgIcon::Search),
"Filter files",
@@ -3774,6 +3774,17 @@ impl crate::TermWindow {
UIItemType::RightSidebarFileFilter,
false,
)?;
+ self.paint_files_preview_header_icon_button(
+ layers,
+ chrome,
+ foreground,
+ muted_fg,
+ refresh_x,
+ refresh_y,
+ refresh_size,
+ SvgIcon::RotateCcw,
+ UIItemType::RightSidebarFileRefresh,
+ )?;
self.paint_right_sidebar_file_top_fade(
layers,
chrome,
diff --git a/wezterm-gui/src/termwindow/ui/sidebar.rs b/wezterm-gui/src/termwindow/ui/sidebar.rs
index 52c7bd39..5f531783 100644
--- a/wezterm-gui/src/termwindow/ui/sidebar.rs
+++ b/wezterm-gui/src/termwindow/ui/sidebar.rs
@@ -2365,7 +2365,7 @@ impl crate::TermWindow {
color: LinearRgba,
radius: f32,
) -> anyhow::Result<()> {
- let radius = radius.min(rect.width() / 2.0).min(rect.height() / 2.0);
+ let radius = snapped_rounded_corner_radius(rect, radius);
// Sub-pixel radii round down to a 0px corner sprite (which panics when
// building its pixmap), so fall back to a plain rectangle below ~1px.
if !(radius >= 1.0) {
@@ -2699,9 +2699,19 @@ fn ellipsize_cut_byte(glyphs: &[(f32, usize)], text_len: usize, budget: f32) ->
cut
}
+/// Corner sprites are cached at integral physical-pixel sizes. Keep the quad
+/// geometry on that same grid so fractional radii cannot expose the joins
+/// between the four corners and the center rectangles on 1x displays.
+fn snapped_rounded_corner_radius(rect: RectF, radius: f32) -> f32 {
+ radius
+ .min(rect.width() / 2.0)
+ .min(rect.height() / 2.0)
+ .floor()
+}
+
#[cfg(test)]
mod tests {
- use super::ellipsize_cut_byte;
+ use super::{ellipsize_cut_byte, snapped_rounded_corner_radius};
// Build (advance, cluster) pairs for an ASCII or per-char string where every
// char is one glyph of `advance` px and the cluster is its byte offset.
@@ -2746,4 +2756,14 @@ mod tests {
let glyphs = glyphs_per_char(text, 10.0);
assert_eq!(ellipsize_cut_byte(&glyphs, text.len(), 5.0), 0);
}
+
+ #[test]
+ fn rounded_corner_radius_matches_integral_corner_sprite_size() {
+ let odd_height = euclid::rect(0.0, 0.0, 215.0, 33.0);
+ let even_height = euclid::rect(0.0, 0.0, 215.0, 34.0);
+
+ assert_eq!(snapped_rounded_corner_radius(odd_height, 999.0), 16.0);
+ assert_eq!(snapped_rounded_corner_radius(even_height, 999.0), 17.0);
+ assert_eq!(snapped_rounded_corner_radius(even_height, 10.75), 10.0);
+ }
}
diff --git a/wezterm-input-types/src/lib.rs b/wezterm-input-types/src/lib.rs
index b6fcab74..9c629252 100644
--- a/wezterm-input-types/src/lib.rs
+++ b/wezterm-input-types/src/lib.rs
@@ -2149,6 +2149,18 @@ impl Default for WindowDecorations {
}
}
+impl WindowDecorations {
+ /// Whether the platform should render a title bar separate from the
+ /// application-provided integrated title buttons.
+ ///
+ /// Treat integrated buttons as authoritative when both flags are present
+ /// so that an imported or legacy configuration cannot produce two title
+ /// bars.
+ pub fn shows_separate_title_bar(self) -> bool {
+ self.contains(Self::TITLE) && !self.contains(Self::INTEGRATED_BUTTONS)
+ }
+}
+
#[derive(Debug, FromDynamic, ToDynamic, PartialEq, Eq, Clone, Copy)]
pub enum IntegratedTitleButton {
Hide,
@@ -2330,6 +2342,19 @@ impl Default for UIKeyCapRendering {
mod test {
use super::*;
+ #[test]
+ fn integrated_window_buttons_suppress_a_separate_title_bar() {
+ assert!((WindowDecorations::TITLE | WindowDecorations::RESIZE).shows_separate_title_bar());
+ assert!(
+ !(WindowDecorations::RESIZE | WindowDecorations::INTEGRATED_BUTTONS)
+ .shows_separate_title_bar()
+ );
+ assert!(!(WindowDecorations::TITLE
+ | WindowDecorations::RESIZE
+ | WindowDecorations::INTEGRATED_BUTTONS)
+ .shows_separate_title_bar());
+ }
+
#[test]
fn encode_issue_3220() {
let flags =
diff --git a/window/src/os/wayland/frame.rs b/window/src/os/wayland/frame.rs
index 614f24d1..dbd01ffb 100644
--- a/window/src/os/wayland/frame.rs
+++ b/window/src/os/wayland/frame.rs
@@ -23,7 +23,6 @@ use wayland_client::protocol::{
use wayland_client::{Attached, DispatchData, Main};
use wezterm_color_types::SrgbaTuple;
use wezterm_font::{FontConfiguration, FontMetrics, GlyphInfo, RasterizedGlyph};
-use wezterm_input_types::WindowDecorations;
fn color_to_paint(c: RgbaColor) -> Paint<'static> {
let mut paint = Paint::default();
@@ -520,7 +519,7 @@ impl ConceptFrame {
self.config
.config
.window_decorations
- .contains(WindowDecorations::TITLE)
+ .shows_separate_title_bar()
}
}
}
diff --git a/window/src/os/x11/window.rs b/window/src/os/x11/window.rs
index 2f7cff01..be4d4b33 100644
--- a/window/src/os/x11/window.rs
+++ b/window/src/os/x11/window.rs
@@ -1294,12 +1294,14 @@ impl XWindowInner {
const FUNC_MAXIMIZE: u32 = 1 << 4;
const FUNC_CLOSE: u32 = 1 << 5;
- let decorations = if decorations == WindowDecorations::TITLE | WindowDecorations::RESIZE {
+ let decorations = if decorations.contains(WindowDecorations::INTEGRATED_BUTTONS) {
+ // Integrated title buttons live in ThinkTerm's own header. Never
+ // ask the window manager for another title bar, even if a legacy
+ // configuration also contains TITLE.
+ FUNC_RESIZE
+ } else if decorations == WindowDecorations::TITLE | WindowDecorations::RESIZE {
FUNC_ALL
- } else if decorations == WindowDecorations::RESIZE
- || decorations == WindowDecorations::INTEGRATED_BUTTONS
- || decorations == WindowDecorations::INTEGRATED_BUTTONS | WindowDecorations::RESIZE
- {
+ } else if decorations == WindowDecorations::RESIZE {
FUNC_RESIZE
} else if decorations == WindowDecorations::TITLE {
FUNC_MOVE | FUNC_MINIMIZE | FUNC_MAXIMIZE | FUNC_CLOSE