From ec2715a354e6d95c8ea98b87b1d7ef3ce029946e Mon Sep 17 00:00:00 2001 From: Jet Spark Date: Sun, 16 Oct 2022 23:44:08 +0800 Subject: [PATCH] Fix background cover algorithm --- wezterm-gui/src/termwindow/background.rs | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/wezterm-gui/src/termwindow/background.rs b/wezterm-gui/src/termwindow/background.rs index fe6f07403..23798045e 100644 --- a/wezterm-gui/src/termwindow/background.rs +++ b/wezterm-gui/src/termwindow/background.rs @@ -430,6 +430,7 @@ impl crate::TermWindow { let pixel_width = self.dimensions.pixel_width as f32; let pixel_height = self.dimensions.pixel_height as f32; + let pixel_aspect = pixel_width / pixel_height; let tex_width = sprite.coords.width() as f32; let tex_height = sprite.coords.height() as f32; @@ -474,23 +475,10 @@ impl crate::TermWindow { }; // Compute the smallest aspect-preserved size that will fit the space - let (min_aspect_width, min_aspect_height) = if aspect >= 1.0 { - // Width is the longest side - if tex_height > pixel_height { - ( - (tex_width * pixel_height / tex_height).floor(), - pixel_height, - ) - } else { - (tex_width, tex_height) - } + let (min_aspect_width, min_aspect_height) = if pixel_aspect > aspect { + (pixel_width, (pixel_width / aspect).floor()) } else { - // Height is the longest side - if tex_width > pixel_width { - (pixel_width, (tex_height * pixel_width / tex_width).floor()) - } else { - (tex_width, tex_height) - } + ((pixel_height * aspect).floor(), pixel_height) }; let width = match layer.def.width {