diff --git a/resources/playbar.blp b/resources/playbar.blp index 9ac3ea5..12822e7 100644 --- a/resources/playbar.blp +++ b/resources/playbar.blp @@ -117,8 +117,7 @@ template $AudreyUiPlaybar: Adw.Bin { } Button { - icon-name: "media-playback-start"; - //icon-name: bind $play_pause_icon_name (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>) as ; + icon-name: bind $play_pause_icon_name (template.idle-active, template.pause) as ; valign: center; //sensitive: bind $can_press_play (template.playbin as <$AudreyPlaybin>.state as <$AudreyPlaybinState>, template.playbin as <$AudreyPlaybin>.play-queue-length) as ; diff --git a/resources/window.blp b/resources/window.blp index 0119b8e..30991b3 100644 --- a/resources/window.blp +++ b/resources/window.blp @@ -138,6 +138,7 @@ template $AudreyUiWindow: Adw.ApplicationWindow { pause: bind template.pause bidirectional; position: bind template.time-pos; duration: bind template.song as <$AudreyPlaybinSong>.duration; + idle-active: bind template.idle-active; } } } diff --git a/src/ui/playbar.rs b/src/ui/playbar.rs index d1fabf1..66910f6 100644 --- a/src/ui/playbar.rs +++ b/src/ui/playbar.rs @@ -24,6 +24,8 @@ mod imp { _mute: Cell, #[property(get, set)] _pause: Cell, + #[property(get, set)] + _idle_active: Cell, #[property(get, set)] position: Cell, @@ -153,6 +155,15 @@ mod imp { self.obj().set_mute(!self.obj().mute()); } + #[template_callback] + fn play_pause_icon_name(&self, idle_active: bool, pause: bool) -> &'static str { + match (idle_active, pause) { + (true, _) => "media-playback-start", + (false, true) => "media-playback-start", + (false, false) => "media-playback-pause", + } + } + fn window(&self) -> crate::ui::Window { self.obj().root().unwrap().dynamic_cast().unwrap() } diff --git a/src/ui/window.rs b/src/ui/window.rs index 99c78f8..78d1138 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -46,6 +46,8 @@ mod imp { _playlist_pos: (), #[property(type = f64, get = Self::time_pos)] _time_pos: (), + #[property(type = bool, get = Self::idle_active)] + _idle_active: (), } impl Default for Window { @@ -61,6 +63,7 @@ mod imp { mpv.observe_property(1, "mute").unwrap(); mpv.observe_property(2, "pause").unwrap(); mpv.observe_property(3, "playlist-pos").unwrap(); + mpv.observe_property(4, "idle-active").unwrap(); // "Useful to drain property changes before a new file is loaded." mpv.add_hook(0, "on_before_start_file", 0).unwrap(); @@ -81,6 +84,7 @@ mod imp { _pause: (), _playlist_pos: (), _time_pos: (), + _idle_active: (), } } } @@ -135,6 +139,11 @@ mod imp { window.notify("playlist-pos"); } + 4 => { + assert_eq!(event.name, "idle-active"); + window.notify("idle-active"); + } + _ => unreachable!(), }, @@ -242,6 +251,7 @@ mod imp { self.mpv.command(["stop"]).unwrap(); self.playlist_model.remove_all(); + self.set_pause(false); let api = { let api = self.api.borrow(); @@ -299,6 +309,10 @@ mod imp { .unwrap() } + fn idle_active(&self) -> bool { + self.mpv.get_property("idle-active").unwrap() + } + fn song(&self) -> Option { if self.obj().playlist_pos() < 0 { None