Skip to content

Commit

Permalink
Add wallpaper refresh on monitor configuration change
Browse files Browse the repository at this point in the history
  • Loading branch information
kerty0 committed Nov 2, 2024
1 parent 87869b2 commit d97f993
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
18 changes: 17 additions & 1 deletion common/src/ipc/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -147,7 +151,7 @@ impl PixelFormat {
}
}

#[derive(Clone, Copy, Debug, PartialEq)]
#[derive(Clone, Copy, Debug)]
pub enum Scale {
Whole(NonZeroI32),
Fractional(NonZeroI32),
Expand Down Expand Up @@ -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!(
Expand Down
10 changes: 7 additions & 3 deletions daemon/src/wallpaper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit d97f993

Please sign in to comment.