Skip to content

Commit

Permalink
fix output scaling
Browse files Browse the repository at this point in the history
We were applying the scale on the full output resolution. This fix
divides the current resolution by the scale, so that we later may
multiply it again to get the correct final image resolution.
  • Loading branch information
LGFae committed Apr 14, 2024
1 parent a27aeff commit 42adbe9
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions daemon/src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,27 +165,49 @@ impl Wallpaper {
#[inline]
pub fn set_dimensions(&self, width: i32, height: i32) {
let mut lock = self.inner_staging.lock().unwrap();
let scale = lock.scale_factor.get();

if width <= 0 {
error!("invalid width ({width}) for output: {:?}", self.output);
} else {
lock.width = unsafe { NonZeroI32::new_unchecked(width) };
match NonZeroI32::new(width / scale) {
Some(width) => lock.width = width,
None => {
error!("dividing width {width} by scale_factor {scale} results in width 0!")
}
}

if height <= 0 {
error!("invalid height ({height}) for output: {:?}", self.output);
} else {
lock.height = unsafe { NonZeroI32::new_unchecked(height) };
match NonZeroI32::new(height / scale) {
Some(height) => lock.height = height,
None => {
error!("dividing height {height} by scale_factor {scale} results in height 0!")
}
}
}

#[inline]
pub fn set_scale(&self, scale: i32) {
if scale <= 0 {
error!("invalid scale ({scale}) for output: {:?}", self.output);
} else {
self.inner_staging.lock().unwrap().scale_factor =
unsafe { NonZeroI32::new_unchecked(scale) }
return;
}

let mut lock = self.inner_staging.lock().unwrap();
let (width, height) = (
lock.width.get() * lock.scale_factor.get(),
lock.height.get() * lock.scale_factor.get(),
);
lock.scale_factor = unsafe { NonZeroI32::new_unchecked(scale) };

match NonZeroI32::new(width / scale) {
Some(width) => lock.width = width,
None => {
error!("dividing width {width} by scale_factor {scale} results in width 0!")
}
}

match NonZeroI32::new(height / scale) {
Some(height) => lock.height = height,
None => {
error!("dividing height {height} by scale_factor {scale} results in height 0!")
}
}
}

Expand Down

0 comments on commit 42adbe9

Please sign in to comment.