Skip to content

Commit

Permalink
WIP Remote Desktop Portal
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Sep 12, 2024
1 parent 3bbc180 commit d0695fb
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 4 deletions.
2 changes: 1 addition & 1 deletion data/cosmic.portal
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[portal]
DBusName=org.freedesktop.impl.portal.desktop.cosmic
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
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
UseIn=cosmic
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod buffer;
mod documents;
mod file_chooser;
mod localize;
mod remote_desktop;
mod screencast;
mod screencast_dialog;
mod screencast_thread;
Expand Down
115 changes: 115 additions & 0 deletions src/remote_desktop.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
use crate::{PortalResponse, Session};
use std::{
collections::HashMap,
env,
os::{fd::OwnedFd, unix::net::UnixStream},
};
use zbus::zvariant;

#[derive(zvariant::SerializeDict, zvariant::Type)]
#[zvariant(signature = "a{sv}")]
struct CreateSessionResult {
session_id: String,
}

#[derive(zvariant::DeserializeDict, zvariant::Type)]
#[zvariant(signature = "a{sv}")]
struct SelectDevicesOptions {
// Default: all
types: Option<u32>,
restore_data: Option<(String, u32, zvariant::OwnedValue)>,
// Default: 0
persist_mode: Option<u32>,
}

#[derive(zvariant::SerializeDict, zvariant::Type)]
#[zvariant(signature = "a{sv}")]
struct StartResult {
devices: u32,
clipboard_enabled: bool,
streams: Vec<(u32, HashMap<String, zvariant::OwnedValue>)>,
}

struct SessionData {}

pub struct RemoteDesktop;

#[zbus::interface(name = "org.freedesktop.impl.portal.RemoteDesktop")]
impl RemoteDesktop {
async fn create_session(
&self,
#[zbus(connection)] connection: &zbus::Connection,
handle: zvariant::ObjectPath<'_>,
session_handle: zvariant::ObjectPath<'_>,
app_id: String,
options: HashMap<String, zvariant::OwnedValue>,
) -> PortalResponse<CreateSessionResult> {
connection
.object_server()
.at(&session_handle, Session::new(SessionData {}, |_| {}))
.await
.unwrap(); // XXX unwrap
PortalResponse::Success(CreateSessionResult {
session_id: "foo".to_string(), // XXX
})
}

// CreateSession
async fn select_devices(
&self,
#[zbus(connection)] connection: &zbus::Connection,
handle: zvariant::ObjectPath<'_>,
session_handle: zvariant::ObjectPath<'_>,
app_id: String,
options: SelectDevicesOptions, // XXX
) -> PortalResponse<HashMap<String, zvariant::OwnedValue>> {
PortalResponse::Success(HashMap::new())
}

async fn start(
&self,
#[zbus(connection)] connection: &zbus::Connection,
handle: zvariant::ObjectPath<'_>,
session_handle: zvariant::ObjectPath<'_>,
app_id: String,
parent_window: String,
options: HashMap<String, zvariant::OwnedValue>,
) -> PortalResponse<StartResult> {
PortalResponse::Success(StartResult {
devices: 7,
clipboard_enabled: false,
streams: Vec::new(),
})
}

async fn connect_to_EIS(
&self,
#[zbus(connection)] connection: &zbus::Connection,
session_handle: zvariant::ObjectPath<'_>,
app_id: String,
options: HashMap<String, zvariant::OwnedValue>,
) -> zvariant::Fd {
println!("Connect");
// TODO Dedicated mechanism to get fd, for specific "devices"
if let Ok(path) = env::var("LIBEI_SOCKET") {
if let Ok(socket) = UnixStream::connect(path) {
return OwnedFd::from(socket).into();
}
}

todo!()
//PortalResponse::Other
}

// TODO: Notify*

#[zbus(property)]
async fn available_device_types(&self) -> u32 {
7 // XXX
}

#[zbus(property, name = "version")]
async fn version(&self) -> u32 {
2
}
}
7 changes: 4 additions & 3 deletions src/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use tokio::sync::mpsc::Receiver;
use zbus::{zvariant, Connection};

use crate::{
access::Access, config, file_chooser::FileChooser, screencast::ScreenCast,
screenshot::Screenshot, wayland, ColorScheme, Contrast, Settings, ACCENT_COLOR_KEY,
APPEARANCE_NAMESPACE, COLOR_SCHEME_KEY, CONTRAST_KEY, DBUS_NAME, DBUS_PATH,
access::Access, config, file_chooser::FileChooser, remote_desktop::RemoteDesktop,
screencast::ScreenCast, screenshot::Screenshot, wayland, ColorScheme, Contrast, Settings,
ACCENT_COLOR_KEY, APPEARANCE_NAMESPACE, COLOR_SCHEME_KEY, CONTRAST_KEY, DBUS_NAME, DBUS_PATH,
};

#[derive(Clone)]
Expand Down Expand Up @@ -137,6 +137,7 @@ pub(crate) async fn process_changes(
.name(DBUS_NAME)?
.serve_at(DBUS_PATH, Access::new(wayland_helper.clone(), tx.clone()))?
.serve_at(DBUS_PATH, FileChooser::new(tx.clone()))?
.serve_at(DBUS_PATH, RemoteDesktop)?
.serve_at(
DBUS_PATH,
Screenshot::new(wayland_helper.clone(), tx.clone()),
Expand Down

0 comments on commit d0695fb

Please sign in to comment.