| 1 |
use std::sync::Arc; |
| 2 |
|
| 3 |
use async_trait::async_trait; |
| 4 |
|
| 5 |
use crate::{ |
| 6 |
MaybeAppID, Uri, WindowIdentifierType, |
| 7 |
backend::{ |
| 8 |
Result, |
| 9 |
request::{Request, RequestImpl}, |
| 10 |
}, |
| 11 |
desktop::{HandleToken, request::ResponseType, wallpaper::WallpaperOptions}, |
| 12 |
zvariant::{Optional, OwnedObjectPath}, |
| 13 |
}; |
| 14 |
|
| 15 |
#[async_trait] |
| 16 |
pub trait WallpaperImpl: RequestImpl { |
| 17 |
#[doc(alias = "SetWallpaperURI")] |
| 18 |
async fn with_uri( |
| 19 |
&self, |
| 20 |
token: HandleToken, |
| 21 |
app_id: Option<MaybeAppID>, |
| 22 |
window_identifier: Option<WindowIdentifierType>, |
| 23 |
uri: Uri, |
| 24 |
options: WallpaperOptions, |
| 25 |
) -> Result<()>; |
| 26 |
} |
| 27 |
|
| 28 |
pub(crate) struct WallpaperInterface { |
| 29 |
imp: Arc<dyn WallpaperImpl>, |
| 30 |
spawn: Arc<dyn futures_util::task::Spawn + Send + Sync>, |
| 31 |
cnx: zbus::Connection, |
| 32 |
} |
| 33 |
|
| 34 |
impl WallpaperInterface { |
| 35 |
pub fn new( |
| 36 |
imp: Arc<dyn WallpaperImpl>, |
| 37 |
cnx: zbus::Connection, |
| 38 |
spawn: Arc<dyn futures_util::task::Spawn + Send + Sync>, |
| 39 |
) -> Self { |
| 40 |
Self { imp, cnx, spawn } |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
#[zbus::interface(name = "org.freedesktop.impl.portal.Wallpaper")] |
| 45 |
impl WallpaperInterface { |
| 46 |
#[zbus(property(emits_changed_signal = "const"), name = "version")] |
| 47 |
fn version(&self) -> u32 { |
| 48 |
1 |
| 49 |
} |
| 50 |
|
| 51 |
#[zbus(name = "SetWallpaperURI")] |
| 52 |
#[zbus(out_args("response"))] |
| 53 |
async fn set_wallpaper_uri( |
| 54 |
&self, |
| 55 |
handle: OwnedObjectPath, |
| 56 |
app_id: Optional<MaybeAppID>, |
| 57 |
window_identifier: Optional<WindowIdentifierType>, |
| 58 |
uri: Uri, |
| 59 |
options: WallpaperOptions, |
| 60 |
) -> Result<ResponseType> { |
| 61 |
let imp = Arc::clone(&self.imp); |
| 62 |
|
| 63 |
Request::spawn( |
| 64 |
"Wallpaper::SetWallpaperURI", |
| 65 |
&self.cnx, |
| 66 |
handle.clone(), |
| 67 |
Arc::clone(&self.imp), |
| 68 |
Arc::clone(&self.spawn), |
| 69 |
async move { |
| 70 |
imp.with_uri( |
| 71 |
HandleToken::try_from(&handle).unwrap(), |
| 72 |
app_id.into(), |
| 73 |
window_identifier.into(), |
| 74 |
uri, |
| 75 |
options, |
| 76 |
) |
| 77 |
.await |
| 78 |
}, |
| 79 |
) |
| 80 |
.await |
| 81 |
.map(|r| r.response_type()) |
| 82 |
} |
| 83 |
} |