diff options
Diffstat (limited to 'src/bin/mpris-icon.rs')
-rw-r--r-- | src/bin/mpris-icon.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/bin/mpris-icon.rs b/src/bin/mpris-icon.rs new file mode 100644 index 0000000..4ffaaae --- /dev/null +++ b/src/bin/mpris-icon.rs @@ -0,0 +1,52 @@ +use i3blocks::{ + dbus::{media_player2::MediaPlayer2Proxy, player::PlaybackStatus, playerctld::PlayerctldProxy}, + i3bar::{Block, Click}, + Button, Component, Error, +}; +use zbus::Connection; + +#[tokio::main] +async fn main() -> Result<(), main_error::MainError> { + i3blocks::run::<Icon>(Block { + full_text: " ".into(), + ..Default::default() + }) + .await + .map_err(Into::into) +} + +pub struct Icon; + +impl Component for Icon { + const NAME: &'static str = "icon"; + type Updater = (); + type Colorer = PlaybackStatus; + type Handler = Self; +} + +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(()) + } +} |