Skip to content

Commit

Permalink
fix: ueberzug image adapter should respect the user's max_width and…
Browse files Browse the repository at this point in the history
… `max_height` settings (#1200)
  • Loading branch information
sxyazi committed Jun 24, 2024
1 parent f1cf136 commit 9a5b756
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions yazi-adapter/src/ueberzug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use tracing::{debug, warn};
use yazi_config::PREVIEW;
use yazi_shared::RoCell;

use crate::{Adapter, Image};
use crate::{Adapter, Dimension};

#[allow(clippy::type_complexity)]
static DEMON: RoCell<Option<UnboundedSender<Option<(PathBuf, Rect)>>>> = RoCell::new();
Expand Down Expand Up @@ -50,9 +50,16 @@ impl Ueberzug {
let ImageSize { width: w, height: h } =
tokio::task::spawn_blocking(move || imagesize::size(p)).await??;

let area = Image::pixel_area((w as u32, h as u32), max);
tx.send(Some((path.to_owned(), area)))?;
let area = Dimension::ratio()
.map(|(r1, r2)| Rect {
x: max.x,
y: max.y,
width: max.width.min((w.min(PREVIEW.max_width as _) as f64 / r1).ceil() as _),
height: max.height.min((h.min(PREVIEW.max_height as _) as f64 / r2).ceil() as _),
})
.unwrap_or(max);

tx.send(Some((path.to_owned(), area)))?;
Adapter::shown_store(area);
Ok(area)
}
Expand Down

0 comments on commit 9a5b756

Please sign in to comment.