Add wallpaper refresh on monitor configuration change

This commit is contained in:
kerty
2024-11-02 18:28:51 +03:00
parent 87869b20c4
commit 56928f7c0e
2 changed files with 24 additions and 4 deletions

View File

@@ -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!(

View File

@@ -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())