summaryrefslogtreecommitdiffstats
path: root/src/component/icon.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/component/icon.rs')
-rw-r--r--src/component/icon.rs66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/component/icon.rs b/src/component/icon.rs
new file mode 100644
index 0000000..102c787
--- /dev/null
+++ b/src/component/icon.rs
@@ -0,0 +1,66 @@
+use std::sync::Arc;
+
+use tokio::sync::{mpsc::Sender, Mutex};
+use zbus::Connection;
+
+use crate::{
+ dbus::{
+ media_player2::MediaPlayer2Proxy,
+ player::{PlaybackStatus, PlayerProxy},
+ playerctld::PlayerctldProxy,
+ },
+ i3bar::{Block, Click},
+ Error,
+};
+
+use super::{Button, Component, Update};
+
+pub struct Icon;
+
+impl Component for Icon {
+ const NAME: &'static str = "icon";
+ type Updater = Self;
+ type Colorer = PlaybackStatus;
+ type Handler = Self;
+}
+
+impl Update for Icon {
+ type Value = String;
+
+ async fn listen(tx: Sender<Self::Value>, _: PlayerProxy<'_>) -> Result<(), Error> {
+ tx.send(" 󰝚 ".into()).await.map_err(Into::into)
+ }
+
+ async fn update(value: Self::Value, block: Arc<Mutex<Block>>) -> Result<bool, Error> {
+ let mut block = block.lock().await;
+ block.full_text = value;
+ Ok(true)
+ }
+}
+
+impl Button for Icon {
+ async fn handle(conn: Connection, click: Click) -> Result<(), Error> {
+ let Some(name) = click.instance else {
+ return Ok(());
+ };
+
+ let proxy = MediaPlayer2Proxy::builder(&conn)
+ .destination(name)?
+ .build()
+ .await?;
+
+ match click.button {
+ 3 => {
+ PlayerctldProxy::builder(&conn)
+ .build()
+ .await?
+ .shift()
+ .await?;
+ }
+ 1 if proxy.can_raise().await? => proxy.raise().await?,
+ _ => {}
+ }
+
+ Ok(())
+ }
+}