Skip to content

Commit

Permalink
Merge pull request #375 from kerty0/main
Browse files Browse the repository at this point in the history
Fix memory leak and stopped animation when connecting/disconnecting monitor
  • Loading branch information
LGFae authored Dec 5, 2024
2 parents 1bd7166 + 56928f7 commit 004dfd8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 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
18 changes: 13 additions & 5 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,12 @@ impl wayland::interfaces::wl_output::EvHandler for Daemon {
fn done(&mut self, sender_id: ObjectId) {
for wallpaper in self.wallpapers.iter() {
if wallpaper.borrow().has_output(sender_id) {
wallpaper
if wallpaper
.borrow_mut()
.commit_surface_changes(self.use_cache);
self.stop_animations(&[wallpaper.clone()]);
.commit_surface_changes(self.use_cache)
{
self.stop_animations(&[wallpaper.clone()]);
}
break;
}
}
Expand Down Expand Up @@ -480,8 +482,14 @@ impl wayland::interfaces::zwlr_layer_surface_v1::EvHandler for Daemon {
}

fn closed(&mut self, sender_id: ObjectId) {
self.wallpapers
.retain(|w| !w.borrow().has_layer_surface(sender_id));
if let Some(i) = self
.wallpapers
.iter()
.position(|w| w.borrow().has_layer_surface(sender_id))
{
let w = self.wallpapers.remove(i);
self.stop_animations(&[w]);
}
}
}

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 004dfd8

Please sign in to comment.