Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Remote Desktop Portal #94

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -8,9 +8,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, Debug)]
Expand Down Expand Up @@ -78,6 +78,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