Skip to content

Commit

Permalink
stop animations when output disconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
LGFae committed Aug 9, 2024
1 parent a74759d commit 3c148ff
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,27 +272,18 @@ impl Daemon {
}

fn stop_animations(&mut self, wallpapers: &[Rc<RefCell<Wallpaper>>]) {
for wallpaper in wallpapers {
for transition in self.transition_animators.iter_mut() {
if let Some(i) = transition
.wallpapers
.iter()
.position(|w| *w.borrow() == *wallpaper.borrow())
{
transition.wallpapers.swap_remove(i);
}
}
for transition in self.transition_animators.iter_mut() {
transition
.wallpapers
.retain(|w1| !wallpapers.iter().any(|w2| w1.borrow().eq(&w2.borrow())));
}

for animator in self.image_animators.iter_mut() {
if let Some(i) = animator
.wallpapers
.iter()
.position(|w| *w.borrow() == *wallpaper.borrow())
{
animator.wallpapers.swap_remove(i);
}
}
for animator in self.image_animators.iter_mut() {
animator
.wallpapers
.retain(|w1| !wallpapers.iter().any(|w2| w1.borrow().eq(&w2.borrow())));
}

self.transition_animators
.retain(|t| !t.wallpapers.is_empty());

Expand All @@ -319,9 +310,14 @@ impl wayland::interfaces::wl_registry::EvHandler for Daemon {
}

fn global_remove(&mut self, name: u32) {
self.wallpapers
.retain(|w| !w.borrow().has_output_name(name));
todo!("ALSO REMOVE FROM ANIMATIONS");
if let Some(i) = self
.wallpapers
.iter()
.position(|w| w.borrow().has_output_name(name))
{
let w = self.wallpapers.remove(i);
self.stop_animations(&[w]);
}
}
}

Expand Down

0 comments on commit 3c148ff

Please sign in to comment.