From 79a044c66b5ffcd4a12acf7bd9c93ad08fa49fb7 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sat, 10 Aug 2024 18:46:03 +0859 Subject: [PATCH] feat: support remove all notifications --- Cargo.lock | 6 +++--- lala_bar/src/main.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 112c795..682798d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1672,7 +1672,7 @@ dependencies = [ [[package]] name = "iced_layershell" version = "0.4.0-rc1" -source = "git+https://github.com/waycrate/exwlshelleventloop#23afc29065769e335553261eab0ed88654344138" +source = "git+https://github.com/waycrate/exwlshelleventloop#793515632472aee540ab7861146f0740d8dd773a" dependencies = [ "futures", "iced", @@ -1984,7 +1984,7 @@ dependencies = [ [[package]] name = "layershellev" version = "0.4.0-rc1" -source = "git+https://github.com/waycrate/exwlshelleventloop#23afc29065769e335553261eab0ed88654344138" +source = "git+https://github.com/waycrate/exwlshelleventloop#793515632472aee540ab7861146f0740d8dd773a" dependencies = [ "bitflags 2.6.0", "log", @@ -3966,7 +3966,7 @@ dependencies = [ [[package]] name = "waycrate_xkbkeycode" version = "0.4.0-rc1" -source = "git+https://github.com/waycrate/exwlshelleventloop#23afc29065769e335553261eab0ed88654344138" +source = "git+https://github.com/waycrate/exwlshelleventloop#793515632472aee540ab7861146f0740d8dd773a" dependencies = [ "bitflags 2.6.0", "log", diff --git a/lala_bar/src/main.rs b/lala_bar/src/main.rs index 32a5275..ae72399 100644 --- a/lala_bar/src/main.rs +++ b/lala_bar/src/main.rs @@ -51,6 +51,7 @@ enum LaLaInfo { #[derive(Debug, Clone)] struct NotifyUnitWidgetInfo { uper: i32, + counter: usize, unit: NotifyUnit, } @@ -325,6 +326,26 @@ impl LalaMusicBar { } } +impl LalaMusicBar { + fn counter_up(&mut self) { + for (_, unit) in self.notifications.iter_mut() { + unit.counter += 1; + } + } + fn counter_down(&mut self, ids: &Vec) { + for id in ids { + if let Some(NotifyUnitWidgetInfo { counter, .. }) = self.notifications.remove(id) { + for (_, unit) in self.notifications.iter_mut() { + if unit.counter > counter { + unit.counter -= 1; + unit.uper -= 75; + } + } + } + } + } +} + impl MultiApplication for LalaMusicBar { type Message = Message; type Flags = (); @@ -367,9 +388,11 @@ impl MultiApplication for LalaMusicBar { self.launcherid = Some(id); } LaLaInfo::Notify(nofify) => { + self.counter_up(); self.notifications .entry(id) .or_insert(NotifyUnitWidgetInfo { + counter: 0, uper: 10, unit: nofify, }); @@ -535,6 +558,15 @@ impl MultiApplication for LalaMusicBar { return Command::batch(commands); } Message::Notify(NotifyMessage::UnitRemove(removed_id)) => { + let removed_ids: Vec = self + .notifications + .iter() + .filter(|(_, info)| { + let NotifyUnit { id, .. } = info.unit; + removed_id == id + }) + .map(|(id, _)| id.clone()) + .collect(); let mut commands: Vec<_> = self .notifications .iter() @@ -544,6 +576,18 @@ impl MultiApplication for LalaMusicBar { }) .map(|(id, _)| Command::single(Action::Window(WindowAction::Close(*id)))) .collect(); + + self.counter_down(&removed_ids); + for (id, unit) in self.notifications.iter() { + commands.push(Command::single( + LaLaShellIdAction::new( + *id, + LalaShellAction::MarginChange((unit.uper, 10, 10, 10)), + ) + .into(), + )); + } + commands.push(Command::perform(async {}, |_| Message::CheckOutput)); return Command::batch(commands);