Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix memory leak and stopped animation when connecting/disconnecting monitor #375

Merged
merged 3 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading