From d97f993ebe1b8bfc2ec0aa5e26b6e36e853b3b49 Mon Sep 17 00:00:00 2001 From: kerty Date: Sat, 2 Nov 2024 18:28:51 +0300 Subject: [PATCH] Add wallpaper refresh on monitor configuration change --- common/src/ipc/types.rs | 18 +++++++++++++++++- daemon/src/wallpaper.rs | 10 +++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/common/src/ipc/types.rs b/common/src/ipc/types.rs index 083277f..0195a6c 100644 --- a/common/src/ipc/types.rs +++ b/common/src/ipc/types.rs @@ -86,6 +86,10 @@ impl BgImg { Self::Img(s) => 4 + s.len() } } + + pub fn is_set(&self) -> bool { + matches!(self, Self::Img(_)) + } } impl fmt::Display for BgImg { @@ -147,7 +151,7 @@ impl PixelFormat { } } -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug)] pub enum Scale { Whole(NonZeroI32), Fractional(NonZeroI32), @@ -183,6 +187,18 @@ impl Scale { } } +impl PartialEq for Scale { + fn eq(&self, other: &Self) -> bool { + (match self { + Self::Whole(i) => i.get() * 120, + Self::Fractional(f) => f.get(), + }) == (match other { + Self::Whole(i) => i.get() * 120, + Self::Fractional(f) => f.get(), + }) + } +} + impl fmt::Display for Scale { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( diff --git a/daemon/src/wallpaper.rs b/daemon/src/wallpaper.rs index 13234f3..67ab413 100644 --- a/daemon/src/wallpaper.rs +++ b/daemon/src/wallpaper.rs @@ -182,8 +182,7 @@ impl Wallpaper { pub fn set_scale(&mut self, scale: Scale) { let staging = &mut self.inner_staging; - if matches!(staging.scale_factor, Scale::Fractional(_)) && matches!(scale, Scale::Whole(_)) - { + if staging.scale_factor == scale { return; } @@ -219,7 +218,12 @@ impl Wallpaper { let inner = &mut self.inner; let staging = &self.inner_staging; - if inner.name != staging.name && use_cache { + if (inner.name != staging.name && use_cache) + || (self.img.is_set() + && (inner.scale_factor != staging.scale_factor + || inner.width != staging.width + || inner.height != staging.height)) + { let name = staging.name.clone().unwrap_or("".to_string()); std::thread::Builder::new() .name("cache loader".to_string())