Skip to content

Commit d0695fb

Browse files
committed
WIP Remote Desktop Portal
1 parent 3bbc180 commit d0695fb

4 files changed

Lines changed: 121 additions & 4 deletions

File tree

data/cosmic.portal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[portal]
22
DBusName=org.freedesktop.impl.portal.desktop.cosmic
3-
Interfaces=org.freedesktop.impl.portal.Access;org.freedesktop.impl.portal.FileChooser;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.Settings;org.freedesktop.impl.portal.ScreenCast
3+
Interfaces=org.freedesktop.impl.portal.Access;org.freedesktop.impl.portal.FileChooser;org.freedesktop.impl.portal.RemoteDesktop;org.freedesktop.impl.portal.Screenshot;org.freedesktop.impl.portal.Settings;org.freedesktop.impl.portal.ScreenCast
44
UseIn=cosmic

src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ mod buffer;
1111
mod documents;
1212
mod file_chooser;
1313
mod localize;
14+
mod remote_desktop;
1415
mod screencast;
1516
mod screencast_dialog;
1617
mod screencast_thread;

src/remote_desktop.rs

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
use crate::{PortalResponse, Session};
2+
use std::{
3+
collections::HashMap,
4+
env,
5+
os::{fd::OwnedFd, unix::net::UnixStream},
6+
};
7+
use zbus::zvariant;
8+
9+
#[derive(zvariant::SerializeDict, zvariant::Type)]
10+
#[zvariant(signature = "a{sv}")]
11+
struct CreateSessionResult {
12+
session_id: String,
13+
}
14+
15+
#[derive(zvariant::DeserializeDict, zvariant::Type)]
16+
#[zvariant(signature = "a{sv}")]
17+
struct SelectDevicesOptions {
18+
// Default: all
19+
types: Option<u32>,
20+
restore_data: Option<(String, u32, zvariant::OwnedValue)>,
21+
// Default: 0
22+
persist_mode: Option<u32>,
23+
}
24+
25+
#[derive(zvariant::SerializeDict, zvariant::Type)]
26+
#[zvariant(signature = "a{sv}")]
27+
struct StartResult {
28+
devices: u32,
29+
clipboard_enabled: bool,
30+
streams: Vec<(u32, HashMap<String, zvariant::OwnedValue>)>,
31+
}
32+
33+
struct SessionData {}
34+
35+
pub struct RemoteDesktop;
36+
37+
#[zbus::interface(name = "org.freedesktop.impl.portal.RemoteDesktop")]
38+
impl RemoteDesktop {
39+
async fn create_session(
40+
&self,
41+
#[zbus(connection)] connection: &zbus::Connection,
42+
handle: zvariant::ObjectPath<'_>,
43+
session_handle: zvariant::ObjectPath<'_>,
44+
app_id: String,
45+
options: HashMap<String, zvariant::OwnedValue>,
46+
) -> PortalResponse<CreateSessionResult> {
47+
connection
48+
.object_server()
49+
.at(&session_handle, Session::new(SessionData {}, |_| {}))
50+
.await
51+
.unwrap(); // XXX unwrap
52+
PortalResponse::Success(CreateSessionResult {
53+
session_id: "foo".to_string(), // XXX
54+
})
55+
}
56+
57+
// CreateSession
58+
async fn select_devices(
59+
&self,
60+
#[zbus(connection)] connection: &zbus::Connection,
61+
handle: zvariant::ObjectPath<'_>,
62+
session_handle: zvariant::ObjectPath<'_>,
63+
app_id: String,
64+
options: SelectDevicesOptions, // XXX
65+
) -> PortalResponse<HashMap<String, zvariant::OwnedValue>> {
66+
PortalResponse::Success(HashMap::new())
67+
}
68+
69+
async fn start(
70+
&self,
71+
#[zbus(connection)] connection: &zbus::Connection,
72+
handle: zvariant::ObjectPath<'_>,
73+
session_handle: zvariant::ObjectPath<'_>,
74+
app_id: String,
75+
parent_window: String,
76+
options: HashMap<String, zvariant::OwnedValue>,
77+
) -> PortalResponse<StartResult> {
78+
PortalResponse::Success(StartResult {
79+
devices: 7,
80+
clipboard_enabled: false,
81+
streams: Vec::new(),
82+
})
83+
}
84+
85+
async fn connect_to_EIS(
86+
&self,
87+
#[zbus(connection)] connection: &zbus::Connection,
88+
session_handle: zvariant::ObjectPath<'_>,
89+
app_id: String,
90+
options: HashMap<String, zvariant::OwnedValue>,
91+
) -> zvariant::Fd {
92+
println!("Connect");
93+
// TODO Dedicated mechanism to get fd, for specific "devices"
94+
if let Ok(path) = env::var("LIBEI_SOCKET") {
95+
if let Ok(socket) = UnixStream::connect(path) {
96+
return OwnedFd::from(socket).into();
97+
}
98+
}
99+
100+
todo!()
101+
//PortalResponse::Other
102+
}
103+
104+
// TODO: Notify*
105+
106+
#[zbus(property)]
107+
async fn available_device_types(&self) -> u32 {
108+
7 // XXX
109+
}
110+
111+
#[zbus(property, name = "version")]
112+
async fn version(&self) -> u32 {
113+
2
114+
}
115+
}

src/subscription.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use tokio::sync::mpsc::Receiver;
1111
use zbus::{zvariant, Connection};
1212

1313
use crate::{
14-
access::Access, config, file_chooser::FileChooser, screencast::ScreenCast,
15-
screenshot::Screenshot, wayland, ColorScheme, Contrast, Settings, ACCENT_COLOR_KEY,
16-
APPEARANCE_NAMESPACE, COLOR_SCHEME_KEY, CONTRAST_KEY, DBUS_NAME, DBUS_PATH,
14+
access::Access, config, file_chooser::FileChooser, remote_desktop::RemoteDesktop,
15+
screencast::ScreenCast, screenshot::Screenshot, wayland, ColorScheme, Contrast, Settings,
16+
ACCENT_COLOR_KEY, APPEARANCE_NAMESPACE, COLOR_SCHEME_KEY, CONTRAST_KEY, DBUS_NAME, DBUS_PATH,
1717
};
1818

1919
#[derive(Clone)]
@@ -137,6 +137,7 @@ pub(crate) async fn process_changes(
137137
.name(DBUS_NAME)?
138138
.serve_at(DBUS_PATH, Access::new(wayland_helper.clone(), tx.clone()))?
139139
.serve_at(DBUS_PATH, FileChooser::new(tx.clone()))?
140+
.serve_at(DBUS_PATH, RemoteDesktop)?
140141
.serve_at(
141142
DBUS_PATH,
142143
Screenshot::new(wayland_helper.clone(), tx.clone()),

0 commit comments

Comments
 (0)