Skip to content

Commit

Permalink
src: Fix zbus crate paths
Browse files Browse the repository at this point in the history
  • Loading branch information
eNV25 committed Feb 15, 2024
1 parent 57aa02a commit 2fec492
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 41 deletions.
4 changes: 2 additions & 2 deletions src/llb.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{collections::HashMap, future::Future};

use zbus::{fdo, zvariant, SignalContext};
use zbus::{fdo, zvariant, object_server::SignalContext};

pub trait Block: Sized + Future {
fn block_lite(self) -> <Self as Future>::Output {
Expand All @@ -13,7 +13,7 @@ pub trait Block: Sized + Future {

impl<F: Future> Block for F {}

pub fn properties_changed<I: zbus::Interface>(
pub fn properties_changed<I: zbus::object_server::Interface>(
ctxt: &SignalContext<'_>,
changed_properties: &HashMap<&str, &zvariant::Value<'_>>,
) -> zbus::Result<()> {
Expand Down
70 changes: 35 additions & 35 deletions src/mpris2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![allow(clippy::ignored_unit_patterns)] // for dbus_interface macro
#![allow(clippy::ignored_unit_patterns)] // for interface macro

use std::{
collections::{hash_map, HashMap},
Expand All @@ -13,9 +13,9 @@ use data_encoding::BASE64;
use smol::{future::FutureExt, process::Command, Timer};
use url::Url;
use zbus::{
dbus_interface, fdo,
interface, fdo,
object_server::SignalContext,
zvariant::{ObjectPath, Value},
SignalContext,
};

use crate::Block;
Expand Down Expand Up @@ -52,19 +52,19 @@ pub fn time_from_secs(secs: f64) -> i64 {
}

#[allow(clippy::unused_self)]
#[dbus_interface(name = "org.mpris.MediaPlayer2")]
#[interface(name = "org.mpris.MediaPlayer2")]
impl Root {
#[dbus_interface(property)]
#[zbus(property)]
fn desktop_entry(self) -> &'static str {
"mpv"
}

#[dbus_interface(property)]
#[zbus(property)]
fn identity(self) -> &'static str {
"mpv Media Player"
}

#[dbus_interface(property)]
#[zbus(property)]
fn supported_mime_types(self) -> Vec<String> {
env::var("XDG_DATA_DIRS")
.unwrap_or_else(|_| "/usr/local/share:/usr/share".to_owned())
Expand All @@ -86,14 +86,14 @@ impl Root {
.unwrap_or_default()
}

#[dbus_interface(property)]
#[zbus(property)]
fn supported_uri_schemes(self) -> fdo::Result<Vec<String>> {
get!(self, "protocol-list")
.ok_or_else(|| fdo::Error::Failed("cannot get protocol-list".into()))
.map(|x| x.split(',').map(str::to_owned).collect())
}

#[dbus_interface(property)]
#[zbus(property)]
fn can_quit(self) -> bool {
true
}
Expand All @@ -102,38 +102,38 @@ impl Root {
Ok(command!(self, "quit")?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn can_raise(self) -> bool {
false
}

//fn raise(self) {}

#[dbus_interface(property)]
#[zbus(property)]
fn can_set_fullscreen(self) -> bool {
true
}

#[dbus_interface(property)]
#[zbus(property)]
fn fullscreen(self) -> fdo::Result<bool> {
Ok(get!(self, "fullscreen", bool)?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn set_fullscreen(self, fullscreen: bool) -> zbus::Result<()> {
Ok(set!(self, "fullscreen", bool, fullscreen)?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn has_track_list(self) -> bool {
false
}
}

#[allow(clippy::unused_self)]
#[dbus_interface(name = "org.mpris.MediaPlayer2.Player")]
#[interface(name = "org.mpris.MediaPlayer2.Player")]
impl Player {
#[dbus_interface(property)]
#[zbus(property)]
fn can_go_next(self) -> bool {
true
}
Expand All @@ -142,7 +142,7 @@ impl Player {
Ok(command!(self, "playlist-next")?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn can_go_previous(self) -> bool {
true
}
Expand All @@ -151,7 +151,7 @@ impl Player {
Ok(command!(self, "playlist-prev")?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn can_pause(self) -> bool {
true
}
Expand All @@ -164,7 +164,7 @@ impl Player {
Ok(command!(self, "cycle", "pause")?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn can_play(self) -> bool {
true
}
Expand All @@ -173,7 +173,7 @@ impl Player {
Ok(set!(self, "pause", bool, false)?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn can_seek(self) -> fdo::Result<bool> {
Ok(get!(self, "seekable", bool)?)
}
Expand All @@ -183,15 +183,15 @@ impl Player {
Ok(command!(self, "seek", offset.as_str())?)
}

#[dbus_interface(signal)]
#[zbus(signal)]
pub async fn seeked(ctxt: &SignalContext<'_>, position: i64) -> zbus::Result<()>;

fn open_uri(self, mut uri: String) -> fdo::Result<()> {
uri.push('\0');
Ok(command!(self, "loadfile", uri.as_str())?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn can_control(self) -> bool {
true
}
Expand All @@ -200,17 +200,17 @@ impl Player {
Ok(command!(self, "stop")?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn playback_status(self) -> fdo::Result<&'static str> {
playback_status_from(self.0, None, None, None)
}

#[dbus_interface(property)]
#[zbus(property)]
fn loop_status(self) -> fdo::Result<&'static str> {
loop_status_from(self.0, None, None)
}

#[dbus_interface(property)]
#[zbus(property)]
fn set_loop_status(self, loop_status: &str) -> zbus::Result<()> {
set!(
self,
Expand All @@ -231,52 +231,52 @@ impl Player {
Ok(())
}

#[dbus_interface(property)]
#[zbus(property)]
fn rate(self) -> fdo::Result<f64> {
Ok(get!(self, "speed", f64)?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn set_rate(self, rate: f64) -> zbus::Result<()> {
Ok(set!(self, "speed", f64, rate)?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn minimum_rate(self) -> fdo::Result<f64> {
Ok(get!(self, "option-info/speed/min", f64)?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn maximum_rate(self) -> fdo::Result<f64> {
Ok(get!(self, "option-info/speed/max", f64)?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn shuffle(self) -> fdo::Result<bool> {
Ok(get!(self, "shuffle", bool)?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn set_shuffle(self, shuffle: bool) -> zbus::Result<()> {
Ok(set!(self, "shuffle", bool, shuffle)?)
}

#[dbus_interface(property)]
#[zbus(property)]
pub fn metadata(self) -> fdo::Result<HashMap<&'static str, Value<'static>>> {
metadata(self.0)
}

#[dbus_interface(property)]
#[zbus(property)]
fn volume(self) -> fdo::Result<f64> {
Ok(get!(self, "volume", f64)? / 100.0)
}

#[dbus_interface(property)]
#[zbus(property)]
fn set_volume(self, volume: f64) -> zbus::Result<()> {
Ok(set!(self, "volume", f64, volume * 100.0)?)
}

#[dbus_interface(property)]
#[zbus(property)]
fn position(self) -> fdo::Result<i64> {
Ok(time_from_secs(get!(self, "playback-time", f64)?))
}
Expand Down
9 changes: 5 additions & 4 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub extern "C" fn mpv_open_cplugin(mpv: MPVHandle) -> c_int {
const PATH: ObjectPath<'_> = ObjectPath::from_static_str_unchecked(PATH_STR);
let pid = process::id();
let name = format!("org.mpris.MediaPlayer2.mpv.instance{pid}");
let connection = zbus::ConnectionBuilder::session()?
let connection = zbus::connection::Builder::session()?
.name(WellKnownName::from_string_unchecked(name))?
.serve_at(PATH, crate::mpris2::Root(mpv))?
.serve_at(PATH, crate::mpris2::Player(mpv))?
Expand All @@ -58,7 +58,8 @@ pub extern "C" fn mpv_open_cplugin(mpv: MPVHandle) -> c_int {
}
.block();
})?;
zbus::Result::Ok(zbus::SignalContext::from_parts(connection, PATH))
let connection = zbus::object_server::SignalContext::from_parts(connection, PATH);
zbus::Result::Ok(connection)
})() {
Ok(ctxt) => ctxt,
Err(err) => {
Expand All @@ -74,7 +75,7 @@ pub extern "C" fn mpv_open_cplugin(mpv: MPVHandle) -> c_int {
0
}

fn main_loop(mpv: MPVHandle, ctxt: &zbus::SignalContext, name: &str) {
fn main_loop(mpv: MPVHandle, ctxt: &zbus::object_server::SignalContext, name: &str) {
macro_rules! data {
($source:expr, bool) => {
data!($source, std::ffi::c_int) != 0
Expand Down Expand Up @@ -245,7 +246,7 @@ impl State {
fn signal_changed(
mpv: MPVHandle,
mut state: State,
ctxt: &zbus::SignalContext<'_>,
ctxt: &zbus::object_server::SignalContext<'_>,
root: &mut Vec<(&str, zvariant::Value<'_>)>,
player: &mut Vec<(&str, zvariant::Value<'_>)>,
) -> impl Iterator<Item = zbus::Result<()>> {
Expand Down

0 comments on commit 2fec492

Please sign in to comment.