Skip to content

Commit

Permalink
feat: add a common background
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Nov 8, 2024
1 parent af9b7c1 commit e952fd4
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 3 deletions.
22 changes: 22 additions & 0 deletions lala_bar/src/dbusbackend.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use futures::channel::mpsc::Sender;

use crate::Message;
use zbus::{connection, interface};
pub struct LalaBarBackend {
sender: Sender<Message>,
}

#[interface(name = "org.lalabar.Backend")]
impl LalaBarBackend {
fn toggle_bar(&mut self) {
self.sender.try_send(Message::ToggleLauncherDBus).ok();
}
}

pub async fn start_backend(sender: Sender<Message>) -> Result<zbus::Connection, zbus::Error> {
connection::Builder::session()?
.name("org.lalabar.backend")?
.serve_at("/org/lalabar/Backend", LalaBarBackend { sender })?
.build()
.await
}
40 changes: 37 additions & 3 deletions lala_bar/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use futures::channel::mpsc::{channel, Sender};
use std::sync::LazyLock;

mod aximer;
mod dbusbackend;
mod launcher;
mod zbus_mpirs;

Expand Down Expand Up @@ -112,8 +113,7 @@ impl NotifyUnitWidgetInfo {
markdown::Settings::default(),
markdown::Style::from_palette(bar.theme().palette()),
)
.map(Message::LinkClicked)
.into(),
.map(Message::LinkClicked),
None => text(notify.body.clone())
.shaping(text::Shaping::Advanced)
.into(),
Expand Down Expand Up @@ -576,6 +576,7 @@ enum Message {
SliderIndexNext,
SliderIndexPre,
ToggleLauncher,
ToggleLauncherDBus,
ToggleRightPanel,
LauncherInfo(LaunchMessage),
Notify(NotifyMessage),
Expand Down Expand Up @@ -973,6 +974,31 @@ impl MultiApplication for LalaMusicBar {
self.launcher.as_ref().unwrap().focus_input(),
]);
}
Message::ToggleLauncherDBus => {
if self.launcher.is_some() {
if let Some(id) = self.launcherid {
return iced_runtime::task::effect(Action::Window(WindowAction::Close(id)));
}
return Command::none();
}
self.launcher = Some(Launcher::new());
return Command::batch(vec![
Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: None,
margin: Some((300, 400, 300, 400)),

exclusive_zone: None,
anchor: Anchor::Left | Anchor::Bottom | Anchor::Right | Anchor::Top,
layer: Layer::Top,
keyboard_interactivity: KeyboardInteractivity::Exclusive,
use_last_output: false,
},
info: LaLaInfo::Launcher,
}),
self.launcher.as_ref().unwrap().focus_input(),
]);
}
Message::ToggleRightPanel => {
if self.right_panel.is_some() {
if let Some(id) = self.right_panel {
Expand All @@ -982,7 +1008,7 @@ impl MultiApplication for LalaMusicBar {
}
return Command::done(Message::NewLayerShell {
settings: NewLayerShellSettings {
size: Some((300, 0)),
size: Some((1000, 1000)),
exclusive_zone: Some(300),
anchor: Anchor::Right | Anchor::Bottom | Anchor::Top,
layer: Layer::Top,
Expand Down Expand Up @@ -1318,6 +1344,14 @@ impl MultiApplication for LalaMusicBar {
iced::time::every(std::time::Duration::from_secs(5)).map(|_| Message::UpdateBalance),
iced::event::listen()
.map(|event| Message::LauncherInfo(LaunchMessage::IcedEvent(event))),
iced::Subscription::run(|| {
iced::stream::channel(100, |output| async move {
use dbusbackend::start_backend;
let _conn = start_backend(output).await.expect("already registered");
pending::<()>().await;
unreachable!()
})
}),
iced::Subscription::run(|| {
iced::stream::channel(100, |mut output| async move {
use iced::futures::sink::SinkExt;
Expand Down

0 comments on commit e952fd4

Please sign in to comment.