mirror of
https://github.com/LinuxBeginnings/swww.git
synced 2026-01-12 07:21:01 -03:00
Merge pull request #375 from kerty0/main
Fix memory leak and stopped animation when connecting/disconnecting monitor
This commit is contained in:
@@ -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!(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user