portal: implement session restoration
This commit is contained in:
parent
4f431eec5c
commit
3e3532574b
13 changed files with 436 additions and 58 deletions
|
|
@ -96,7 +96,6 @@ impl UsrJayCompositor {
|
|||
jo
|
||||
}
|
||||
|
||||
#[expect(dead_code)]
|
||||
pub fn watch_workspaces(&self) -> Rc<UsrJayWorkspaceWatcher> {
|
||||
let ww = Rc::new(UsrJayWorkspaceWatcher {
|
||||
id: self.con.id(),
|
||||
|
|
@ -143,6 +142,22 @@ impl UsrJayCompositor {
|
|||
sc
|
||||
}
|
||||
|
||||
pub fn get_toplevel(&self, id: &str) -> Rc<UsrJaySelectToplevel> {
|
||||
let sc = Rc::new(UsrJaySelectToplevel {
|
||||
id: self.con.id(),
|
||||
con: self.con.clone(),
|
||||
owner: Default::default(),
|
||||
version: self.version,
|
||||
});
|
||||
self.con.request(GetToplevel {
|
||||
self_id: self.id,
|
||||
id: sc.id,
|
||||
toplevel_id: id,
|
||||
});
|
||||
self.con.add_object(sc.clone());
|
||||
sc
|
||||
}
|
||||
|
||||
pub fn select_workspace(&self, seat: &UsrWlSeat) -> Rc<UsrJaySelectWorkspace> {
|
||||
let sc = Rc::new(UsrJaySelectWorkspace {
|
||||
id: self.con.id(),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,11 @@ use {
|
|||
object::Version,
|
||||
utils::clonecell::CloneCell,
|
||||
wire::{jay_select_workspace::*, JaySelectWorkspaceId},
|
||||
wl_usr::{usr_ifs::usr_jay_workspace::UsrJayWorkspace, usr_object::UsrObject, UsrCon},
|
||||
wl_usr::{
|
||||
usr_ifs::usr_jay_workspace::{UsrJayWorkspace, UsrJayWorkspaceOwner},
|
||||
usr_object::UsrObject,
|
||||
UsrCon,
|
||||
},
|
||||
},
|
||||
std::{convert::Infallible, rc::Rc},
|
||||
};
|
||||
|
|
@ -30,20 +34,30 @@ impl JaySelectWorkspaceEventHandler for UsrJaySelectWorkspace {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn selected(&self, ev: Selected, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
fn selected(&self, ev: Selected, slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
let tl = Rc::new(UsrJayWorkspace {
|
||||
id: ev.id,
|
||||
con: self.con.clone(),
|
||||
owner: Default::default(),
|
||||
version: self.version,
|
||||
linear_id: Default::default(),
|
||||
output: Default::default(),
|
||||
name: Default::default(),
|
||||
});
|
||||
self.con.add_object(tl.clone());
|
||||
tl.owner.set(Some(slf.clone()));
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl UsrJayWorkspaceOwner for UsrJaySelectWorkspace {
|
||||
fn done(&self, ws: &Rc<UsrJayWorkspace>) {
|
||||
ws.owner.take();
|
||||
match self.owner.get() {
|
||||
Some(owner) => owner.done(ev.output, Some(tl)),
|
||||
_ => self.con.remove_obj(&*tl),
|
||||
Some(owner) => owner.done(ws.output.get(), Some(ws.clone())),
|
||||
_ => self.con.remove_obj(&**ws),
|
||||
}
|
||||
self.con.remove_obj(self);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,11 @@ use {
|
|||
wire::{jay_workspace::*, JayWorkspaceId},
|
||||
wl_usr::{usr_object::UsrObject, UsrCon},
|
||||
},
|
||||
std::{convert::Infallible, rc::Rc},
|
||||
std::{
|
||||
cell::{Cell, RefCell},
|
||||
convert::Infallible,
|
||||
rc::Rc,
|
||||
},
|
||||
};
|
||||
|
||||
pub struct UsrJayWorkspace {
|
||||
|
|
@ -13,21 +17,20 @@ pub struct UsrJayWorkspace {
|
|||
pub con: Rc<UsrCon>,
|
||||
pub owner: CloneCell<Option<Rc<dyn UsrJayWorkspaceOwner>>>,
|
||||
pub version: Version,
|
||||
pub linear_id: Cell<u32>,
|
||||
pub output: Cell<u32>,
|
||||
pub name: RefCell<Option<String>>,
|
||||
}
|
||||
|
||||
pub trait UsrJayWorkspaceOwner {
|
||||
fn linear_id(self: Rc<Self>, ev: &LinearId) {
|
||||
let _ = ev;
|
||||
fn destroyed(&self, ws: &UsrJayWorkspace) {
|
||||
let _ = ws;
|
||||
}
|
||||
|
||||
fn name(&self, ev: &Name) {
|
||||
let _ = ev;
|
||||
fn done(&self, ws: &Rc<UsrJayWorkspace>) {
|
||||
let _ = ws;
|
||||
}
|
||||
|
||||
fn destroyed(&self) {}
|
||||
|
||||
fn done(&self) {}
|
||||
|
||||
fn output(self: Rc<Self>, ev: &Output) {
|
||||
let _ = ev;
|
||||
}
|
||||
|
|
@ -41,34 +44,31 @@ impl JayWorkspaceEventHandler for UsrJayWorkspace {
|
|||
type Error = Infallible;
|
||||
|
||||
fn linear_id(&self, ev: LinearId, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(owner) = self.owner.get() {
|
||||
owner.linear_id(&ev);
|
||||
}
|
||||
self.linear_id.set(ev.linear_id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn name(&self, ev: Name<'_>, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
*self.name.borrow_mut() = Some(ev.name.to_string());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn destroyed(&self, _ev: Destroyed, slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(owner) = self.owner.get() {
|
||||
owner.name(&ev);
|
||||
owner.destroyed(slf);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn destroyed(&self, _ev: Destroyed, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
fn done(&self, _ev: Done, slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(owner) = self.owner.get() {
|
||||
owner.destroyed();
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn done(&self, _ev: Done, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(owner) = self.owner.get() {
|
||||
owner.done();
|
||||
owner.done(slf);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn output(&self, ev: Output, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
self.output.set(ev.global_name);
|
||||
if let Some(owner) = self.owner.get() {
|
||||
owner.output(&ev);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,9 @@ impl JayWorkspaceWatcherEventHandler for UsrJayWorkspaceWatcher {
|
|||
con: self.con.clone(),
|
||||
owner: Default::default(),
|
||||
version: self.version,
|
||||
linear_id: Default::default(),
|
||||
output: Default::default(),
|
||||
name: Default::default(),
|
||||
});
|
||||
self.con.add_object(jw.clone());
|
||||
if let Some(owner) = self.owner.get() {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use {
|
|||
wire::{wl_output::*, WlOutputId},
|
||||
wl_usr::{usr_object::UsrObject, UsrCon},
|
||||
},
|
||||
std::{convert::Infallible, rc::Rc},
|
||||
std::{cell::RefCell, convert::Infallible, rc::Rc},
|
||||
};
|
||||
|
||||
pub struct UsrWlOutput {
|
||||
|
|
@ -13,6 +13,7 @@ pub struct UsrWlOutput {
|
|||
pub con: Rc<UsrCon>,
|
||||
pub owner: CloneCell<Option<Rc<dyn UsrWlOutputOwner>>>,
|
||||
pub version: Version,
|
||||
pub name: RefCell<Option<String>>,
|
||||
}
|
||||
|
||||
pub trait UsrWlOutputOwner {
|
||||
|
|
@ -71,6 +72,7 @@ impl WlOutputEventHandler for UsrWlOutput {
|
|||
}
|
||||
|
||||
fn name(&self, ev: Name<'_>, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
*self.name.borrow_mut() = Some(ev.name.to_string());
|
||||
if let Some(owner) = self.owner.get() {
|
||||
owner.name(&ev);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue