Skip to content

Commit

Permalink
session: Tie up portals to their corresponding sessions
Browse files Browse the repository at this point in the history
Fixes #216
  • Loading branch information
bilelmoussaoui committed Jun 19, 2024
1 parent 09339f9 commit cf99f85
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 54 deletions.
28 changes: 20 additions & 8 deletions src/desktop/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::collections::HashMap;
use futures_util::{Stream, StreamExt};
use zbus::zvariant::{DeserializeDict, OwnedFd, OwnedObjectPath, SerializeDict, Type, Value};

use super::Session;
use super::{remote_desktop::RemoteDesktop, Session};
use crate::{proxy::Proxy, Result};

#[derive(Debug, Type, SerializeDict)]
Expand Down Expand Up @@ -53,7 +53,7 @@ impl<'a> Clipboard<'a> {
///
/// See also [`RequestClipboard`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Clipboard.html#org-freedesktop-portal-clipboard-requestclipboard).
#[doc(alias = "RequestClipboard")]
pub async fn request(&self, session: &Session<'_>) -> Result<()> {
pub async fn request(&self, session: &Session<'_, RemoteDesktop<'_>>) -> Result<()> {
let options: HashMap<&str, Value<'_>> = HashMap::default();
self.0
.call_method("RequestClipboard", &(session, options))
Expand All @@ -65,7 +65,11 @@ impl<'a> Clipboard<'a> {
///
/// See also [`SetSelection`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Clipboard.html#org-freedesktop-portal-clipboard-setselection).
#[doc(alias = "SetSelection")]
pub async fn set_selection(&self, session: &Session<'_>, mime_types: &[&str]) -> Result<()> {
pub async fn set_selection(
&self,
session: &Session<'_, RemoteDesktop<'_>>,
mime_types: &[&str],
) -> Result<()> {
let options = SetSelectionOptions { mime_types };
self.0.call("SetSelection", &(session, options)).await?;

Expand All @@ -76,7 +80,11 @@ impl<'a> Clipboard<'a> {
///
/// See also [`SelectionWrite`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Clipboard.html#org-freedesktop-portal-clipboard-selectionwrite).
#[doc(alias = "SelectionWrite")]
pub async fn selection_write(&self, session: &Session<'_>, serial: u32) -> Result<OwnedFd> {
pub async fn selection_write(
&self,
session: &Session<'_, RemoteDesktop<'_>>,
serial: u32,
) -> Result<OwnedFd> {
let fd = self
.0
.call::<OwnedFd>("SelectionWrite", &(session, serial))
Expand All @@ -90,7 +98,7 @@ impl<'a> Clipboard<'a> {
#[doc(alias = "SelectionWriteDone")]
pub async fn selection_write_done(
&self,
session: &Session<'_>,
session: &Session<'_, RemoteDesktop<'_>>,
serial: u32,
success: bool,
) -> Result<()> {
Expand All @@ -103,7 +111,11 @@ impl<'a> Clipboard<'a> {
///
/// See also [`SelectionRead`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Clipboard.html#org-freedesktop-portal-clipboard-selectionread).
#[doc(alias = "SelectionRead")]
pub async fn selection_read(&self, session: &Session<'_>, mime_type: &str) -> Result<OwnedFd> {
pub async fn selection_read(
&self,
session: &Session<'_, RemoteDesktop<'_>>,
mime_type: &str,
) -> Result<OwnedFd> {
let fd = self
.0
.call::<OwnedFd>("SelectionRead", &(session, mime_type))
Expand All @@ -118,7 +130,7 @@ impl<'a> Clipboard<'a> {
#[doc(alias = "SelectionOwnerChanged")]
pub async fn receive_selection_owner_changed(
&self,
) -> Result<impl Stream<Item = (Session, SelectionOwnerChanged)>> {
) -> Result<impl Stream<Item = (Session<RemoteDesktop>, SelectionOwnerChanged)>> {
Ok(self
.0
.signal::<(OwnedObjectPath, SelectionOwnerChanged)>("SelectionOwnerChanged")
Expand All @@ -132,7 +144,7 @@ impl<'a> Clipboard<'a> {
#[doc(alias = "SelectionTransfer")]
pub async fn receive_selection_transfer(
&self,
) -> Result<impl Stream<Item = (Session, String, u32)>> {
) -> Result<impl Stream<Item = (Session<RemoteDesktop>, String, u32)>> {
Ok(self
.0
.signal::<(OwnedObjectPath, String, u32)>("SelectionTransfer")
Expand Down
10 changes: 6 additions & 4 deletions src/desktop/global_shortcuts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use zbus::zvariant::{
DeserializeDict, ObjectPath, OwnedObjectPath, OwnedValue, SerializeDict, Type,
};

use super::{HandleToken, Request, Session};
use super::{session::SessionPortal, HandleToken, Request, Session};
use crate::{desktop::session::CreateSessionResponse, proxy::Proxy, Error, WindowIdentifier};

#[derive(Clone, SerializeDict, Type, Debug, Default)]
Expand Down Expand Up @@ -224,7 +224,7 @@ impl<'a> GlobalShortcuts<'a> {
///
/// See also [`CreateSession`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.GlobalShortcuts.html#org-freedesktop-portal-globalshortcuts-createsession).
#[doc(alias = "CreateSession")]
pub async fn create_session(&self) -> Result<Session<'a>, Error> {
pub async fn create_session(&self) -> Result<Session<'a, Self>, Error> {
let options = CreateSessionOptions::default();
let (request, proxy) = futures_util::try_join!(
self.0
Expand All @@ -244,7 +244,7 @@ impl<'a> GlobalShortcuts<'a> {
#[doc(alias = "BindShortcuts")]
pub async fn bind_shortcuts(
&self,
session: &Session<'_>,
session: &Session<'_, Self>,
shortcuts: &[NewShortcut],
parent_window: &WindowIdentifier,
) -> Result<Request<BindShortcuts>, Error> {
Expand All @@ -266,7 +266,7 @@ impl<'a> GlobalShortcuts<'a> {
#[doc(alias = "ListShortcuts")]
pub async fn list_shortcuts(
&self,
session: &Session<'_>,
session: &Session<'_, Self>,
) -> Result<Request<ListShortcuts>, Error> {
let options = ListShortcutsOptions::default();
self.0
Expand Down Expand Up @@ -315,3 +315,5 @@ impl<'a> std::ops::Deref for GlobalShortcuts<'a> {
&self.0
}
}

impl SessionPortal for GlobalShortcuts<'_> {}
8 changes: 5 additions & 3 deletions src/desktop/inhibit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ use serde::Deserialize;
use serde_repr::{Deserialize_repr, Serialize_repr};
use zbus::zvariant::{DeserializeDict, ObjectPath, OwnedObjectPath, SerializeDict, Type};

use super::{HandleToken, Request, Session};
use super::{session::SessionPortal, HandleToken, Request, Session};
use crate::{desktop::session::CreateSessionResponse, proxy::Proxy, Error, WindowIdentifier};

#[derive(SerializeDict, Type, Debug, Default)]
Expand Down Expand Up @@ -167,7 +167,7 @@ impl<'a> InhibitProxy<'a> {
pub async fn create_monitor(
&self,
identifier: &WindowIdentifier,
) -> Result<Session<'a>, Error> {
) -> Result<Session<'a, Self>, Error> {
let options = CreateMonitorOptions::default();
let body = &(&identifier, &options);
let (monitor, proxy) = futures_util::try_join!(
Expand Down Expand Up @@ -238,7 +238,7 @@ impl<'a> InhibitProxy<'a> {
/// See also [`QueryEndResponse`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Inhibit.html#org-freedesktop-portal-inhibit-queryendresponse).
#[doc(alias = "QueryEndResponse")]
#[doc(alias = "xdp_portal_session_monitor_query_end_response")]
pub async fn query_end_response(&self, session: &Session<'_>) -> Result<(), Error> {
pub async fn query_end_response(&self, session: &Session<'_, Self>) -> Result<(), Error> {
self.0.call("QueryEndResponse", &(session)).await
}
}
Expand All @@ -250,3 +250,5 @@ impl<'a> std::ops::Deref for InhibitProxy<'a> {
&self.0
}
}

impl SessionPortal for InhibitProxy<'_> {}
18 changes: 10 additions & 8 deletions src/desktop/input_capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ use zbus::zvariant::{
self, DeserializeDict, ObjectPath, OwnedObjectPath, OwnedValue, SerializeDict, Type, Value,
};

use super::{HandleToken, Request, Session};
use super::{session::SessionPortal, HandleToken, Request, Session};
use crate::{proxy::Proxy, Error, WindowIdentifier};

#[derive(Serialize_repr, Deserialize_repr, PartialEq, Eq, Debug, Copy, Clone, Type)]
Expand Down Expand Up @@ -559,7 +559,7 @@ impl<'a> InputCapture<'a> {
&self,
parent_window: &WindowIdentifier,
capabilities: BitFlags<Capabilities>,
) -> Result<(Session<'_>, BitFlags<Capabilities>), Error> {
) -> Result<(Session<'_, Self>, BitFlags<Capabilities>), Error> {
let options = CreateSessionOptions {
handle_token: Default::default(),
session_handle_token: Default::default(),
Expand Down Expand Up @@ -587,7 +587,7 @@ impl<'a> InputCapture<'a> {
///
/// See also [`GetZones`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.InputCapture.html#org-freedesktop-portal-inputcapture-getzones).
#[doc(alias = "GetZones")]
pub async fn zones(&self, session: &Session<'_>) -> Result<Request<Zones>, Error> {
pub async fn zones(&self, session: &Session<'_, Self>) -> Result<Request<Zones>, Error> {
let options = GetZonesOptions::default();
self.0
.request(&options.handle_token, "GetZones", (session, &options))
Expand All @@ -602,7 +602,7 @@ impl<'a> InputCapture<'a> {
#[doc(alias = "SetPointerBarriers")]
pub async fn set_pointer_barriers(
&self,
session: &Session<'_>,
session: &Session<'_, Self>,
barriers: &[Barrier],
zone_set: u32,
) -> Result<Request<SetPointerBarriersResponse>, Error> {
Expand All @@ -621,7 +621,7 @@ impl<'a> InputCapture<'a> {
/// # Specifications
///
/// See also [`Enable`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.InputCapture.html#org-freedesktop-portal-inputcapture-enable).
pub async fn enable(&self, session: &Session<'_>) -> Result<(), Error> {
pub async fn enable(&self, session: &Session<'_, Self>) -> Result<(), Error> {
let options = EnableOptions::default();
self.0.call("Enable", &(session, &options)).await
}
Expand All @@ -631,7 +631,7 @@ impl<'a> InputCapture<'a> {
/// # Specifications
///
/// See also [`Disable`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.InputCapture.html#org-freedesktop-portal-inputcapture-disable).
pub async fn disable(&self, session: &Session<'_>) -> Result<(), Error> {
pub async fn disable(&self, session: &Session<'_, Self>) -> Result<(), Error> {
let options = DisableOptions::default();
self.0.call("Disable", &(session, &options)).await
}
Expand All @@ -643,7 +643,7 @@ impl<'a> InputCapture<'a> {
/// See also [`Release`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.InputCapture.html#org-freedesktop-portal-inputcapture-release).
pub async fn release(
&self,
session: &Session<'_>,
session: &Session<'_, Self>,
activation_id: u32,
cursor_position: (f64, f64),
) -> Result<(), Error> {
Expand All @@ -660,7 +660,7 @@ impl<'a> InputCapture<'a> {
///
/// See also [`ConnectToEIS`](https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.InputCapture.html#org-freedesktop-portal-inputcapture-connecttoeis).
#[doc(alias = "ConnectToEIS")]
pub async fn connect_to_eis(&self, session: &Session<'_>) -> Result<OwnedFd, Error> {
pub async fn connect_to_eis(&self, session: &Session<'_, Self>) -> Result<OwnedFd, Error> {
// `ConnectToEIS` doesn't take any options for now
let options: HashMap<&str, Value<'_>> = HashMap::new();
let fd = self
Expand Down Expand Up @@ -731,3 +731,5 @@ impl<'a> std::ops::Deref for InputCapture<'a> {
&self.0
}
}

impl SessionPortal for InputCapture<'_> {}
8 changes: 5 additions & 3 deletions src/desktop/location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use serde::Deserialize;
use serde_repr::Serialize_repr;
use zbus::zvariant::{DeserializeDict, ObjectPath, OwnedObjectPath, SerializeDict, Type};

use super::{HandleToken, Request, Session};
use super::{session::SessionPortal, HandleToken, Request, Session};
use crate::{proxy::Proxy, Error, WindowIdentifier};

#[cfg_attr(feature = "glib", derive(glib::Enum))]
Expand Down Expand Up @@ -238,7 +238,7 @@ impl<'a> LocationProxy<'a> {
distance_threshold: Option<u32>,
time_threshold: Option<u32>,
accuracy: Option<Accuracy>,
) -> Result<Session<'a>, Error> {
) -> Result<Session<'a, Self>, Error> {
let options = CreateSessionOptions {
distance_threshold,
time_threshold,
Expand Down Expand Up @@ -271,7 +271,7 @@ impl<'a> LocationProxy<'a> {
#[doc(alias = "xdp_portal_location_monitor_start")]
pub async fn start(
&self,
session: &Session<'_>,
session: &Session<'_, Self>,
identifier: &WindowIdentifier,
) -> Result<Request<()>, Error> {
let options = SessionStartOptions::default();
Expand All @@ -285,6 +285,8 @@ impl<'a> LocationProxy<'a> {
}
}

impl SessionPortal for LocationProxy<'_> {}

impl<'a> std::ops::Deref for LocationProxy<'a> {
type Target = zbus::Proxy<'a>;

Expand Down
Loading

0 comments on commit cf99f85

Please sign in to comment.