diff --git a/yazi-adaptor/src/ueberzug.rs b/yazi-adaptor/src/ueberzug.rs index 21ae8924..99a75877 100644 --- a/yazi-adaptor/src/ueberzug.rs +++ b/yazi-adaptor/src/ueberzug.rs @@ -1,4 +1,4 @@ -use std::{cmp::max, path::PathBuf, process::Stdio}; +use std::{path::PathBuf, process::Stdio}; use anyhow::Result; use ratatui::prelude::Rect; @@ -33,17 +33,6 @@ impl Ueberzug { Ok(tx) } - fn adjust_rect(mut rect: Rect) -> Rect { - let cfg = &PREVIEW.ueberzug; - rect.x = max((rect.x as f64 / cfg.scale_down_factor + cfg.x_offset) as i32, 0) as u16; - rect.y = max((rect.y as f64 / cfg.scale_down_factor + cfg.y_offset) as i32, 0) as u16; - rect.width = - max((rect.width as f64 / cfg.scale_down_factor + cfg.width_offset) as i32, 0) as u16; - rect.height = - max((rect.height as f64 / cfg.scale_down_factor + cfg.height_offset) as i32, 0) as u16; - return rect; - } - fn create_demon(adaptor: Adaptor) -> Result { Ok( Command::new("ueberzug") @@ -55,12 +44,24 @@ impl Ueberzug { ) } + fn adjust_rect(mut rect: Rect) -> Rect { + let scale = PREVIEW.ueberzug_scale; + let (x, y, w, h) = PREVIEW.ueberzug_offset; + + rect.x = 0f64.max(rect.x as f64 * scale + x) as u16; + rect.y = 0f64.max(rect.y as f64 * scale + y) as u16; + rect.width = 0f64.max(rect.width as f64 * scale + w) as u16; + rect.height = 0f64.max(rect.height as f64 * scale + h) as u16; + rect + } + async fn send_command(child: &mut Child, cmd: Option<(PathBuf, Rect)>) -> Result<()> { let stdin = child.stdin.as_mut().unwrap(); if let Some((path, tmp_rect)) = cmd { debug!("ueberzug rect before adjustment: {:?}", tmp_rect); let rect = Self::adjust_rect(tmp_rect); debug!("ueberzug rect after adjustment: {:?}", rect); + let s = format!( r#"{{"action":"add","identifier":"yazi","x":{},"y":{},"max_width":{},"max_height":{},"path":"{}"}}{}"#, rect.x, diff --git a/yazi-config/preset/yazi.toml b/yazi-config/preset/yazi.toml index f62d2cc1..c234909b 100644 --- a/yazi-config/preset/yazi.toml +++ b/yazi-config/preset/yazi.toml @@ -9,20 +9,12 @@ show_hidden = false show_symlink = true [preview] -tab_size = 2 -max_width = 600 -max_height = 900 -cache_dir = "" - - [preview.ueberzug] - # Scale down the coordinate and size of image preview that is incorrectly scaled - # up by ueberzugpp in Wayland (tested under Hyprland). Example usage: if your - # monitor has a 2.0 scale factor, you should pass 2.0 here. - scale_down_factor = 1.0 - x_offset = 0.0 - y_offset = 0.0 - width_offset = 0.0 - height_offset = 0.0 +tab_size = 2 +max_width = 600 +max_height = 900 +cache_dir = "" +ueberzug_scale = 1 +ueberzug_offset = [ 0, 0, 0, 0 ] [opener] edit = [ diff --git a/yazi-config/src/preview/preview.rs b/yazi-config/src/preview/preview.rs index 149c0d57..f3fa595d 100644 --- a/yazi-config/src/preview/preview.rs +++ b/yazi-config/src/preview/preview.rs @@ -23,7 +23,8 @@ pub struct Preview { pub cache_dir: PathBuf, - pub ueberzug: UeberzugPreview, + pub ueberzug_scale: f64, + pub ueberzug_offset: (f64, f64, f64, f64), } impl Default for Preview { @@ -40,7 +41,8 @@ impl Default for Preview { cache_dir: Option, - ueberzug: UeberzugPreview, + ueberzug_scale: f64, + ueberzug_offset: (f64, f64, f64, f64), } let preview = toml::from_str::(&MERGED_YAZI).unwrap().preview; @@ -55,7 +57,8 @@ impl Default for Preview { cache_dir, - ueberzug: preview.ueberzug, + ueberzug_scale: preview.ueberzug_scale, + ueberzug_offset: preview.ueberzug_offset, } } }