From 05b10525294fe010d64ca78a20505e50bc5e0918 Mon Sep 17 00:00:00 2001 From: ShootingStarDragons Date: Sun, 11 Aug 2024 13:10:13 +0859 Subject: [PATCH] chore: with upstream fix --- Cargo.lock | 6 ++-- lala_bar/Cargo.toml | 2 +- lala_bar/src/main.rs | 83 ++++++++++++++++++++++++++++++++++++++------ 3 files changed, 76 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a20fc5a..19856f3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1672,7 +1672,7 @@ dependencies = [ [[package]] name = "iced_layershell" version = "0.4.0-rc2" -source = "git+https://github.com/waycrate/exwlshelleventloop#b6b1caf6271fba6196d11d264fee64cccc20c386" +source = "git+https://github.com/waycrate/exwlshelleventloop?branch=mutiwindowcreate#c307d7f97a826577a4026c1a53c5619618c2110d" dependencies = [ "futures", "iced", @@ -1984,7 +1984,7 @@ dependencies = [ [[package]] name = "layershellev" version = "0.4.0-rc2" -source = "git+https://github.com/waycrate/exwlshelleventloop#b6b1caf6271fba6196d11d264fee64cccc20c386" +source = "git+https://github.com/waycrate/exwlshelleventloop?branch=mutiwindowcreate#c307d7f97a826577a4026c1a53c5619618c2110d" dependencies = [ "bitflags 2.6.0", "log", @@ -3966,7 +3966,7 @@ dependencies = [ [[package]] name = "waycrate_xkbkeycode" version = "0.4.0-rc2" -source = "git+https://github.com/waycrate/exwlshelleventloop#b6b1caf6271fba6196d11d264fee64cccc20c386" +source = "git+https://github.com/waycrate/exwlshelleventloop?branch=mutiwindowcreate#c307d7f97a826577a4026c1a53c5619618c2110d" dependencies = [ "bitflags 2.6.0", "log", diff --git a/lala_bar/Cargo.toml b/lala_bar/Cargo.toml index d0574f4..21bfe95 100644 --- a/lala_bar/Cargo.toml +++ b/lala_bar/Cargo.toml @@ -15,7 +15,7 @@ iced = { version = "0.12", features = [ ] } #iced_native = "0.12" iced_runtime = "0.12" -iced_layershell = { git = "https://github.com/waycrate/exwlshelleventloop", package = "iced_layershell" } +iced_layershell = { git = "https://github.com/waycrate/exwlshelleventloop", package = "iced_layershell", branch = "mutiwindowcreate" } tokio = { version = "1.39", features = ["full"] } iced_futures = "0.12.0" env_logger = "0.11.5" diff --git a/lala_bar/src/main.rs b/lala_bar/src/main.rs index 2e3f618..ee05b1e 100644 --- a/lala_bar/src/main.rs +++ b/lala_bar/src/main.rs @@ -34,6 +34,12 @@ mod zbus_mpirs; type LaLaShellIdAction = LayershellCustomActionsWithIdAndInfo; type LalaShellAction = LayershellCustomActionsWithInfo; +const BEGINNING_UP_MARGIN: i32 = 10; + +const UNIT_MARGIN: i32 = 135; + +const EXTRAINF_MARGIN: i32 = BEGINNING_UP_MARGIN + 4 * UNIT_MARGIN; + const LAUNCHER_SVG: &[u8] = include_bytes!("../../misc/launcher.svg"); const RESET_SVG: &[u8] = include_bytes!("../../misc/reset.svg"); @@ -57,6 +63,7 @@ pub fn main() -> Result<(), iced_layershell::Error> { enum LaLaInfo { Launcher, Notify(NotifyUnitWidgetInfo), + HidenInfo, } #[derive(Debug, Clone)] @@ -82,8 +89,9 @@ struct LalaMusicBar { bar_index: SliderIndex, launcher: Option, launcherid: Option, + hidenid: Option, notifications: HashMap, - hided_notifications: Vec, + hidded_notifications: Vec, sender: Sender, receiver: Arc>>, } @@ -367,8 +375,9 @@ impl MultiApplication for LalaMusicBar { bar_index: SliderIndex::Balance, launcher: None, launcherid: None, + hidenid: None, notifications: HashMap::new(), - hided_notifications: Vec::new(), + hidded_notifications: Vec::new(), sender, receiver: Arc::new(Mutex::new(receiver)), }, @@ -383,6 +392,8 @@ impl MultiApplication for LalaMusicBar { fn id_info(&self, id: iced::window::Id) -> Option { if self.launcherid.is_some_and(|tid| tid == id) { Some(LaLaInfo::Launcher) + } else if self.hidenid.is_some_and(|tid| tid == id) { + Some(LaLaInfo::HidenInfo) } else { self.notifications.get(&id).cloned().map(LaLaInfo::Notify) } @@ -396,6 +407,9 @@ impl MultiApplication for LalaMusicBar { LaLaInfo::Notify(notify) => { self.notifications.entry(id).or_insert(notify); } + LaLaInfo::HidenInfo => { + self.hidenid = Some(id); + } } } @@ -403,6 +417,9 @@ impl MultiApplication for LalaMusicBar { if self.launcherid.is_some_and(|lid| lid == id) { self.launcherid.take(); } + if self.hidenid.is_some_and(|lid| lid == id) { + self.hidenid.take(); + } self.notifications.remove(&id); } @@ -525,7 +542,7 @@ impl MultiApplication for LalaMusicBar { } Message::Notify(NotifyMessage::UnitAdd(notify)) => { let mut commands = vec![]; - for unit in self.hided_notifications.iter_mut() { + for unit in self.hidded_notifications.iter_mut() { unit.upper += 135; unit.counter += 1; } @@ -534,7 +551,7 @@ impl MultiApplication for LalaMusicBar { unit.upper += 135; unit.counter += 1; if unit.counter > 3 { - self.hided_notifications.push(unit.clone()); + self.hidded_notifications.push(unit.clone()); commands.push(Command::single(Action::Window(WindowAction::Close(*id)))); } else { commands.push(Command::single( @@ -570,6 +587,27 @@ impl MultiApplication for LalaMusicBar { ) .into(), )); + + if !self.hidded_notifications.is_empty() && self.hidenid.is_none() { + commands.push(Command::single( + LaLaShellIdAction::new( + iced::window::Id::MAIN, + LalaShellAction::NewLayerShell(( + NewLayerShellSettings { + size: Some((300, 25)), + exclusive_zone: None, + anchor: Anchor::Right | Anchor::Top, + layer: Layer::Top, + margin: Some((EXTRAINF_MARGIN, 10, 10, 10)), + keyboard_interactivity: KeyboardInteractivity::OnDemand, + use_last_output: true, + }, + LaLaInfo::HidenInfo, + )), + ) + .into(), + )); + } return Command::batch(commands); } Message::Notify(NotifyMessage::UnitRemove(removed_id)) => { @@ -615,7 +653,7 @@ impl MultiApplication for LalaMusicBar { } let remove_hided_notifications_count: Vec = self - .hided_notifications + .hidded_notifications .iter() .filter( |NotifyUnitWidgetInfo { @@ -626,7 +664,7 @@ impl MultiApplication for LalaMusicBar { .map(|NotifyUnitWidgetInfo { counter, .. }| *counter) .collect(); - self.hided_notifications.retain( + self.hidded_notifications.retain( |NotifyUnitWidgetInfo { unit: NotifyUnit { id, .. }, .. @@ -634,14 +672,14 @@ impl MultiApplication for LalaMusicBar { ); for count in remove_hided_notifications_count { - for unit in self.hided_notifications.iter_mut() { + for unit in self.hidded_notifications.iter_mut() { if unit.counter > count { unit.counter -= 1; unit.upper -= 135; } } } - for notify in self.hided_notifications.iter() { + for notify in self.hidded_notifications.iter() { if notify.counter <= 4 { commands.push(Command::single( LaLaShellIdAction::new( @@ -664,9 +702,17 @@ impl MultiApplication for LalaMusicBar { } } - self.hided_notifications + self.hidded_notifications .retain(|NotifyUnitWidgetInfo { counter, .. }| *counter > 4); + if self.hidded_notifications.is_empty() && self.hidenid.is_some() { + let hidenid = self.hidenid.unwrap(); + + commands.push(Command::single(Action::Window(WindowAction::Close( + hidenid, + )))); + } + commands.push(Command::perform(async {}, |_| Message::CheckOutput)); return Command::batch(commands); @@ -708,7 +754,7 @@ impl MultiApplication for LalaMusicBar { } let mut to_show_id = None; - for (index, notify) in self.hided_notifications.iter_mut().enumerate() { + for (index, notify) in self.hidded_notifications.iter_mut().enumerate() { notify.counter -= 1; notify.upper -= 135; if notify.counter == 3 { @@ -735,7 +781,15 @@ impl MultiApplication for LalaMusicBar { } if let Some(index) = to_show_id { - self.hided_notifications.remove(index); + self.hidded_notifications.remove(index); + } + + if self.hidded_notifications.is_empty() && self.hidenid.is_some() { + let hidenid = self.hidenid.unwrap(); + + commands.push(Command::single(Action::Window(WindowAction::Close( + hidenid, + )))); } commands.append(&mut vec![ @@ -875,6 +929,13 @@ impl MultiApplication for LalaMusicBar { } return btnwidgets; } + LaLaInfo::HidenInfo => { + return text(format!( + "hidden notifications {}", + self.hidded_notifications.len() + )) + .into(); + } } } self.main_view()