blob: 4ffaaae2946d8ffc9025cc68ed2a4d5e98842e82 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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(())
}
}
|