use std::sync::Arc; use async_trait::async_trait; use enumflags2::BitFlags; use crate::{ MaybeAppID, WindowIdentifierType, backend::{ Result, request::{Request, RequestImpl}, }, desktop::{ Color, HandleToken, request::Response, screenshot::{ AvailableTargets, ColorOptions, Screenshot as ScreenshotResponse, ScreenshotOptions, }, }, zvariant::{Optional, OwnedObjectPath}, }; #[async_trait] pub trait ScreenshotImpl: RequestImpl { #[doc(alias = "AvailableTargets")] fn available_targets(&self) -> BitFlags; #[doc(alias = "Screenshot")] async fn screenshot( &self, token: HandleToken, app_id: Option, window_identifier: Option, options: ScreenshotOptions, ) -> Result; #[doc(alias = "PickColor")] async fn pick_color( &self, token: HandleToken, app_id: Option, window_identifier: Option, options: ColorOptions, ) -> Result; } pub(crate) struct ScreenshotInterface { imp: Arc, spawn: Arc, cnx: zbus::Connection, } impl ScreenshotInterface { pub fn new( imp: Arc, cnx: zbus::Connection, spawn: Arc, ) -> Self { Self { imp, cnx, spawn } } } #[zbus::interface(name = "org.freedesktop.impl.portal.Screenshot")] impl ScreenshotInterface { #[zbus(property(emits_changed_signal = "const"), name = "AvailableTargets")] fn available_targets(&self) -> u32 { self.imp.available_targets().bits() } #[zbus(property(emits_changed_signal = "const"), name = "version")] fn version(&self) -> u32 { 3 } #[zbus(name = "Screenshot")] #[zbus(out_args("response", "results"))] async fn screenshot( &self, handle: OwnedObjectPath, app_id: Optional, window_identifier: Optional, options: ScreenshotOptions, ) -> Result> { let imp = Arc::clone(&self.imp); Request::spawn( "Screenshot::Screenshot", &self.cnx, handle.clone(), Arc::clone(&self.imp), Arc::clone(&self.spawn), async move { imp.screenshot( HandleToken::try_from(&handle).unwrap(), app_id.into(), window_identifier.into(), options, ) .await }, ) .await } #[zbus(name = "PickColor")] #[zbus(out_args("response", "results"))] async fn pick_color( &self, handle: OwnedObjectPath, app_id: Optional, window_identifier: Optional, options: ColorOptions, ) -> Result> { let imp = Arc::clone(&self.imp); Request::spawn( "Screenshot::PickColor", &self.cnx, handle.clone(), Arc::clone(&self.imp), Arc::clone(&self.spawn), async move { imp.pick_color( HandleToken::try_from(&handle).unwrap(), app_id.into(), window_identifier.into(), options, ) .await }, ) .await } }