diff --git a/src/mpris/player.rs b/src/mpris/player.rs index a4a334a..38a087c 100644 --- a/src/mpris/player.rs +++ b/src/mpris/player.rs @@ -114,8 +114,7 @@ impl PlayerProxy { fn playback_status(&self) -> &str { if mpv::get_property_bool!(self.ctx(), "idle-active\0") || (mpv::get_property_string!(self.ctx(), "keep-open\0") != "no" - && (mpv::get_property_int!(self.ctx(), "percent-pos\0") == 100 - || mpv::get_property_int!(self.ctx(), "duration\0") == 0)) + && mpv::get_property_bool!(self.ctx(), "eof-reached\0")) { "Stopped" } else if mpv::get_property_bool!(self.ctx(), "pause\0") { diff --git a/src/plugin.rs b/src/plugin.rs index 8a17768..b2a4420 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -28,21 +28,18 @@ pub extern "C" fn mpv_open_cplugin(ctx: *mut mpv_handle) -> c_int { }) .expect("dbus session connection and server setup"); - let root_ref = smol::block_on( + let root = smol::block_on( connection .object_server() .interface::<_, mpris::RootProxy>("/org/mpris/MediaPlayer2"), ) .expect("MediaPlayer2 interface reference"); - let root_sigctxt = root_ref.signal_context(); - - let player_ref = smol::block_on( + let player = smol::block_on( connection .object_server() .interface::<_, mpris::PlayerProxy>("/org/mpris/MediaPlayer2"), ) .expect("MediaPlayer2.Player interface reference"); - let player_sigctxt = player_ref.signal_context(); // These properties and those handled in the main loop // must be kept in sync with the implementations in the @@ -52,6 +49,7 @@ pub extern "C" fn mpv_open_cplugin(ctx: *mut mpv_handle) -> c_int { ctx, "seekable\0", "idle-active\0", + "eof-reached\0", "pause\0", "loop-file\0", "loop-playlist\0", @@ -76,7 +74,7 @@ pub extern "C" fn mpv_open_cplugin(ctx: *mut mpv_handle) -> c_int { MPV_EVENT_PLAYBACK_RESTART if mp_seeking => smol::block_on(async { mp_seeking = false; _ = mpris::PlayerProxy::seeked( - player_ref.signal_context(), + player.signal_context(), (mpv::get_property_float!(ctx, "playback-time\0") * 1E6) as i64, ) .await; @@ -90,35 +88,24 @@ pub extern "C" fn mpv_open_cplugin(ctx: *mut mpv_handle) -> c_int { let prop = unsafe { CStr::from_ptr(data.name) } .to_str() .unwrap_or_default(); - let root = root_ref.get().await; - let player = player_ref.get().await; - match prop { - "seekable" => { - _ = player.can_seek_changed(player_sigctxt).await; - } - "idle-active" | "pause" => { - _ = player.playback_status_changed(player_sigctxt).await; - } - "loop-file" | "loop-playlist" => { - _ = player.loop_status_changed(player_sigctxt).await; - } - "speed" => { - _ = player.rate_changed(player_sigctxt).await; - } - "shuffle" => { - _ = player.shuffle_changed(player_sigctxt).await; - } - "metadata" => { - _ = player.metadata_changed(player_sigctxt).await; - } - "volume" => { - _ = player.volume_changed(player_sigctxt).await; - } - "fullscreen" => { - _ = root.fullscreen_changed(root_sigctxt).await; - } - _ => {} + macro_rules! changed { + ($iface:expr, $method:ident) => { + $iface.get().await.$method($iface.signal_context()).await + }; } + _ = match prop { + "seekable" => changed!(player, can_seek_changed), + "idle-active" | "eof-reached" | "pause" => { + changed!(player, playback_status_changed) + } + "loop-file" | "loop-playlist" => changed!(player, loop_status_changed), + "speed" => changed!(player, rate_changed), + "shuffle" => changed!(player, shuffle_changed), + "metadata" => changed!(player, metadata_changed), + "volume" => changed!(player, volume_changed), + "fullscreen" => changed!(root, fullscreen_changed), + _ => Ok(()), + }; }), _ => {} }