1
0
Fork 0
forked from wry/wry

portal: implement RemoteDesktop portal

This commit is contained in:
Julian Orth 2024-07-24 17:57:48 +02:00
parent 40e87f8f91
commit 665127e6c0
22 changed files with 994 additions and 35 deletions

View file

@ -4,6 +4,7 @@ use {
client::{Client, ClientCaps, ClientError, CAP_JAY_COMPOSITOR},
globals::{Global, GlobalName},
ifs::{
jay_ei_session_builder::JayEiSessionBuilder,
jay_idle::JayIdle,
jay_input::JayInput,
jay_log_file::JayLogFile,
@ -30,6 +31,8 @@ use {
thiserror::Error,
};
pub const CREATE_EI_SESSION_SINCE: Version = Version(5);
pub struct JayCompositorGlobal {
name: GlobalName,
}
@ -66,7 +69,7 @@ impl Global for JayCompositorGlobal {
}
fn version(&self) -> u32 {
4
5
}
fn required_caps(&self) -> ClientCaps {
@ -377,6 +380,19 @@ impl JayCompositorRequestHandler for JayCompositor {
seat.global.select_workspace(selector);
Ok(())
}
fn create_ei_session(&self, req: CreateEiSession, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let obj = Rc::new(JayEiSessionBuilder {
id: req.id,
client: self.client.clone(),
tracker: Default::default(),
version: self.version,
app_id: Default::default(),
});
track!(self.client, obj);
self.client.add_client_obj(&obj)?;
Ok(())
}
}
object_base! {

81
src/ifs/jay_ei_session.rs Normal file
View file

@ -0,0 +1,81 @@
use {
crate::{
client::{Client, ClientError, ClientId},
leaks::Tracker,
object::{Object, Version},
wire::{
jay_ei_session::{Created, Destroyed, Failed, JayEiSessionRequestHandler, Release},
JayEiSessionId,
},
},
std::rc::Rc,
thiserror::Error,
uapi::OwnedFd,
};
pub struct JayEiSession {
pub id: JayEiSessionId,
pub client: Rc<Client>,
pub ei_client_id: Option<ClientId>,
pub tracker: Tracker<Self>,
pub version: Version,
}
impl JayEiSession {
pub fn send_created(&self, fd: &Rc<OwnedFd>) {
self.client.event(Created {
self_id: self.id,
fd: fd.clone(),
});
}
pub fn send_failed(&self, reason: &str) {
self.client.event(Failed {
self_id: self.id,
reason,
});
}
fn send_destroyed(&self) {
self.client.event(Destroyed { self_id: self.id });
}
fn kill(&self, send_destroyed: bool) {
if let Some(id) = self.ei_client_id {
self.client.state.ei_clients.shutdown(id);
}
if send_destroyed {
self.send_destroyed();
}
}
}
impl JayEiSessionRequestHandler for JayEiSession {
type Error = JayEiSessionError;
fn release(&self, _req: Release, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.kill(false);
self.client.remove_obj(self)?;
Ok(())
}
}
object_base! {
self = JayEiSession;
version = self.version;
}
impl Object for JayEiSession {
fn break_loops(&self) {
self.kill(false);
}
}
simple_add_obj!(JayEiSession);
#[derive(Debug, Error)]
pub enum JayEiSessionError {
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(JayEiSessionError, ClientError);

View file

@ -0,0 +1,97 @@
use {
crate::{
client::{Client, ClientError},
ei::ei_client::EiClientError,
ifs::jay_ei_session::JayEiSession,
leaks::Tracker,
object::{Object, Version},
utils::{errorfmt::ErrorFmt, oserror::OsError},
wire::{
jay_ei_session_builder::{Commit, JayEiSessionBuilderRequestHandler, SetAppId},
JayEiSessionBuilderId,
},
},
std::{cell::RefCell, rc::Rc},
thiserror::Error,
uapi::c,
};
pub struct JayEiSessionBuilder {
pub id: JayEiSessionBuilderId,
pub client: Rc<Client>,
pub tracker: Tracker<Self>,
pub version: Version,
pub app_id: RefCell<Option<String>>,
}
impl JayEiSessionBuilderRequestHandler for JayEiSessionBuilder {
type Error = JayEiSessionBuilderError;
fn commit(&self, req: Commit, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.client.remove_obj(self)?;
let app_id = self.app_id.borrow().clone();
if app_id.is_none() {
return Err(JayEiSessionBuilderError::NoAppId);
}
let res = (move || {
let con = uapi::socketpair(c::AF_UNIX, c::SOCK_STREAM | c::SOCK_CLOEXEC, 0);
let (server, client) = match con {
Ok(w) => w,
Err(e) => return Err(JayEiSessionBuilderError::SocketPair(e.into())),
};
let ei_client_id = self
.client
.state
.ei_clients
.spawn2(&self.client.state, Rc::new(server), None, app_id)
.map_err(JayEiSessionBuilderError::SpawnClient)?
.id;
Ok((ei_client_id, Rc::new(client)))
})();
let obj = Rc::new(JayEiSession {
id: req.id,
client: self.client.clone(),
ei_client_id: res.as_ref().ok().map(|v| v.0),
tracker: Default::default(),
version: self.version,
});
track!(self.client, obj);
self.client.add_client_obj(&obj)?;
match res {
Ok((_, fd)) => obj.send_created(&fd),
Err(e) => {
let e = format!("Could not spawn client: {}", ErrorFmt(e));
log::error!("{}", e);
obj.send_failed(&e);
}
}
Ok(())
}
fn set_app_id(&self, req: SetAppId<'_>, _slf: &Rc<Self>) -> Result<(), Self::Error> {
*self.app_id.borrow_mut() = Some(req.app_id.to_string());
Ok(())
}
}
object_base! {
self = JayEiSessionBuilder;
version = self.version;
}
impl Object for JayEiSessionBuilder {}
simple_add_obj!(JayEiSessionBuilder);
#[derive(Debug, Error)]
pub enum JayEiSessionBuilderError {
#[error(transparent)]
ClientError(Box<ClientError>),
#[error("Could not create a socketpair")]
SocketPair(#[source] OsError),
#[error("Could not spawn a new client")]
SpawnClient(#[source] EiClientError),
#[error("Commit called without app-id")]
NoAppId,
}
efrom!(JayEiSessionBuilderError, ClientError);