Skip to content

Commit

Permalink
portal: implement session restoration
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Oct 10, 2024
1 parent 3cedf2e commit d757e70
Show file tree
Hide file tree
Showing 13 changed files with 433 additions and 55 deletions.
6 changes: 4 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ash = "0.38.0"
gpu-alloc = "0.6.0"
gpu-alloc-ash = "0.7.0"
serde = { version = "1.0.196", features = ["derive"] }
serde_json = "1.0.128"
enum-map = "2.7.3"
png = "0.17.13"
rustc-demangle = { version = "0.1.24", optional = true }
Expand Down
1 change: 1 addition & 0 deletions release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Allow X windows to scale themselves.
- Implement ext-image-capture-source-v1.
- Implement ext-image-copy-capture-v1.
- Implement screencast session restoration.

# 1.6.0 (2024-09-25)

Expand Down
1 change: 1 addition & 0 deletions src/ifs/jay_compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use {

pub const CREATE_EI_SESSION_SINCE: Version = Version(5);
pub const SCREENSHOT_SPLITUP_SINCE: Version = Version(6);
pub const GET_TOPLEVEL_SINCE: Version = Version(12);

pub struct JayCompositorGlobal {
name: GlobalName,
Expand Down
34 changes: 32 additions & 2 deletions src/portal/ptl_display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ use {
PortalState,
},
utils::{
bitflags::BitflagsExt, clonecell::CloneCell, copyhashmap::CopyHashMap,
errorfmt::ErrorFmt, hash_map_ext::HashMapExt, oserror::OsError,
bitflags::BitflagsExt,
clonecell::CloneCell,
copyhashmap::CopyHashMap,
errorfmt::ErrorFmt,
hash_map_ext::HashMapExt,
opaque::{opaque, Opaque},
oserror::OsError,
},
video::drm::Drm,
wire::{
Expand All @@ -26,6 +31,8 @@ use {
usr_jay_output::{UsrJayOutput, UsrJayOutputOwner},
usr_jay_pointer::UsrJayPointer,
usr_jay_render_ctx::UsrJayRenderCtxOwner,
usr_jay_workspace::{UsrJayWorkspace, UsrJayWorkspaceOwner},
usr_jay_workspace_watcher::{UsrJayWorkspaceWatcher, UsrJayWorkspaceWatcherOwner},
usr_linux_dmabuf::UsrLinuxDmabuf,
usr_wl_compositor::UsrWlCompositor,
usr_wl_output::{UsrWlOutput, UsrWlOutputOwner},
Expand Down Expand Up @@ -61,9 +68,11 @@ struct PortalDisplayPrelude {
shared_ids!(PortalDisplayId);
pub struct PortalDisplay {
pub id: PortalDisplayId,
pub unique_id: Opaque,
pub con: Rc<UsrCon>,
pub(super) state: Rc<PortalState>,
registry: Rc<UsrWlRegistry>,
_workspace_watcher: Rc<UsrJayWorkspaceWatcher>,
pub dmabuf: CloneCell<Option<Rc<UsrLinuxDmabuf>>>,

pub jc: Rc<UsrJayCompositor>,
Expand All @@ -75,6 +84,7 @@ pub struct PortalDisplay {

pub outputs: CopyHashMap<u32, Rc<PortalOutput>>,
pub seats: CopyHashMap<u32, Rc<PortalSeat>>,
pub workspaces: CopyHashMap<u32, Rc<UsrJayWorkspace>>,

pub windows: CopyHashMap<WlSurfaceId, Rc<WindowData>>,
pub screencasts: CopyHashMap<String, Rc<ScreencastSession>>,
Expand Down Expand Up @@ -243,6 +253,20 @@ impl UsrWlRegistryOwner for PortalDisplay {
}
}

impl UsrJayWorkspaceWatcherOwner for PortalDisplay {
fn new(self: Rc<Self>, ev: Rc<UsrJayWorkspace>, linear_id: u32) {
ev.owner.set(Some(self.clone()));
self.workspaces.set(linear_id, ev);
}
}

impl UsrJayWorkspaceOwner for PortalDisplay {
fn destroyed(&self, ws: &UsrJayWorkspace) {
self.workspaces.remove(&ws.linear_id.get());
self.con.remove_obj(ws);
}
}

impl UsrJayOutputOwner for PortalOutput {
fn destroyed(&self) {
log::info!(
Expand Down Expand Up @@ -398,12 +422,15 @@ fn finish_display_connect(dpy: Rc<PortalDisplayPrelude>) {
let comp = get!(comp_opt, WlCompositor);
let fsm = get!(fsm_opt, WpFractionalScaleManagerV1);
let vp = get!(vp_opt, WpViewporter);
let ww = jc.watch_workspaces();

let dpy = Rc::new(PortalDisplay {
id: dpy.state.id(),
unique_id: opaque(),
con: dpy.con.clone(),
state: dpy.state.clone(),
registry: dpy.registry.clone(),
_workspace_watcher: ww.clone(),
dmabuf: CloneCell::new(dmabuf_opt),
jc,
outputs: Default::default(),
Expand All @@ -416,11 +443,13 @@ fn finish_display_connect(dpy: Rc<PortalDisplayPrelude>) {
windows: Default::default(),
screencasts: Default::default(),
remote_desktop_sessions: Default::default(),
workspaces: Default::default(),
});

dpy.state.displays.set(dpy.id, dpy.clone());
dpy.con.owner.set(Some(dpy.clone()));
dpy.registry.owner.set(Some(dpy.clone()));
ww.owner.set(Some(dpy.clone()));

let jrc = dpy.jc.get_render_context();
jrc.owner.set(Some(dpy.clone()));
Expand Down Expand Up @@ -464,6 +493,7 @@ fn add_output(dpy: &Rc<PortalDisplay>, name: u32, version: u32) {
con: dpy.con.clone(),
owner: Default::default(),
version: Version(version.min(4)),
name: Default::default(),
});
dpy.con.add_object(wl.clone());
dpy.registry.request_bind(name, wl.version.0, wl.deref());
Expand Down
Loading

0 comments on commit d757e70

Please sign in to comment.