wl_usr: refactor interfaces
This commit is contained in:
parent
4b3d3a50cd
commit
56290d5547
12 changed files with 121 additions and 82 deletions
|
|
@ -1,5 +1,6 @@
|
|||
use {
|
||||
crate::{
|
||||
globals::GlobalName,
|
||||
object::Version,
|
||||
utils::clonecell::CloneCell,
|
||||
wire::{JaySelectWorkspaceId, jay_select_workspace::*},
|
||||
|
|
@ -9,7 +10,7 @@ use {
|
|||
usr_object::UsrObject,
|
||||
},
|
||||
},
|
||||
std::{convert::Infallible, rc::Rc},
|
||||
std::{cell::Cell, convert::Infallible, rc::Rc},
|
||||
};
|
||||
|
||||
pub struct UsrJaySelectWorkspace {
|
||||
|
|
@ -20,7 +21,7 @@ pub struct UsrJaySelectWorkspace {
|
|||
}
|
||||
|
||||
pub trait UsrJaySelectWorkspaceOwner {
|
||||
fn done(&self, output: u32, ws: Option<Rc<UsrJayWorkspace>>);
|
||||
fn done(&self, output: GlobalName, ws: Option<Rc<UsrJayWorkspace>>);
|
||||
}
|
||||
|
||||
impl JaySelectWorkspaceEventHandler for UsrJaySelectWorkspace {
|
||||
|
|
@ -28,7 +29,7 @@ impl JaySelectWorkspaceEventHandler for UsrJaySelectWorkspace {
|
|||
|
||||
fn cancelled(&self, _ev: Cancelled, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(owner) = self.owner.get() {
|
||||
owner.done(0, None);
|
||||
owner.done(GlobalName::from_raw(0), None);
|
||||
}
|
||||
self.con.remove_obj(self);
|
||||
Ok(())
|
||||
|
|
@ -41,7 +42,7 @@ impl JaySelectWorkspaceEventHandler for UsrJaySelectWorkspace {
|
|||
owner: Default::default(),
|
||||
version: self.version,
|
||||
linear_id: Default::default(),
|
||||
output: Default::default(),
|
||||
output: Cell::new(GlobalName::from_raw(0)),
|
||||
name: Default::default(),
|
||||
});
|
||||
self.con.add_object(tl.clone());
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use {
|
||||
crate::{
|
||||
globals::GlobalName,
|
||||
object::Version,
|
||||
utils::clonecell::CloneCell,
|
||||
wire::{JayWorkspaceId, jay_workspace::*},
|
||||
|
|
@ -18,7 +19,7 @@ pub struct UsrJayWorkspace {
|
|||
pub owner: CloneCell<Option<Rc<dyn UsrJayWorkspaceOwner>>>,
|
||||
pub version: Version,
|
||||
pub linear_id: Cell<u32>,
|
||||
pub output: Cell<u32>,
|
||||
pub output: Cell<GlobalName>,
|
||||
pub name: RefCell<Option<String>>,
|
||||
}
|
||||
|
||||
|
|
@ -68,7 +69,7 @@ impl JayWorkspaceEventHandler for UsrJayWorkspace {
|
|||
}
|
||||
|
||||
fn output(&self, ev: Output, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
self.output.set(ev.global_name);
|
||||
self.output.set(GlobalName::from_raw(ev.global_name));
|
||||
if let Some(owner) = self.owner.get() {
|
||||
owner.output(&ev);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
use {
|
||||
crate::{
|
||||
globals::GlobalName,
|
||||
object::Version,
|
||||
utils::clonecell::CloneCell,
|
||||
wire::{JayWorkspaceWatcherId, jay_workspace_watcher::*},
|
||||
wl_usr::{UsrCon, usr_ifs::usr_jay_workspace::UsrJayWorkspace, usr_object::UsrObject},
|
||||
},
|
||||
std::{convert::Infallible, ops::Deref, rc::Rc},
|
||||
std::{cell::Cell, convert::Infallible, ops::Deref, rc::Rc},
|
||||
};
|
||||
|
||||
pub struct UsrJayWorkspaceWatcher {
|
||||
|
|
@ -32,7 +33,7 @@ impl JayWorkspaceWatcherEventHandler for UsrJayWorkspaceWatcher {
|
|||
owner: Default::default(),
|
||||
version: self.version,
|
||||
linear_id: Default::default(),
|
||||
output: Default::default(),
|
||||
output: Cell::new(GlobalName::from_raw(0)),
|
||||
name: Default::default(),
|
||||
});
|
||||
self.con.add_object(jw.clone());
|
||||
|
|
|
|||
|
|
@ -10,19 +10,31 @@ use {
|
|||
pub struct UsrWlCallback {
|
||||
pub id: WlCallbackId,
|
||||
pub con: Rc<UsrCon>,
|
||||
pub handler: Cell<Option<Box<dyn FnOnce()>>>,
|
||||
pub owner: Cell<Option<Rc<dyn UsrWlCallbackOwner>>>,
|
||||
pub version: Version,
|
||||
}
|
||||
|
||||
pub trait UsrWlCallbackOwner {
|
||||
fn done(self: Rc<Self>);
|
||||
}
|
||||
|
||||
impl<T> UsrWlCallbackOwner for Cell<Option<T>>
|
||||
where
|
||||
T: FnOnce() + 'static,
|
||||
{
|
||||
fn done(self: Rc<Self>) {
|
||||
if let Some(slf) = self.take() {
|
||||
slf();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl UsrWlCallback {
|
||||
pub fn new<F>(con: &Rc<UsrCon>, handler: F) -> Self
|
||||
where
|
||||
F: FnOnce() + 'static,
|
||||
{
|
||||
pub fn new(con: &Rc<UsrCon>) -> Self {
|
||||
Self {
|
||||
id: con.id(),
|
||||
con: con.clone(),
|
||||
handler: Cell::new(Some(Box::new(handler))),
|
||||
owner: Default::default(),
|
||||
version: Version(1),
|
||||
}
|
||||
}
|
||||
|
|
@ -32,8 +44,8 @@ impl WlCallbackEventHandler for UsrWlCallback {
|
|||
type Error = Infallible;
|
||||
|
||||
fn done(&self, _ev: Done, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(handler) = self.handler.take() {
|
||||
handler();
|
||||
if let Some(handler) = self.owner.take() {
|
||||
handler.done();
|
||||
}
|
||||
self.con.remove_obj(self);
|
||||
Ok(())
|
||||
|
|
@ -51,6 +63,6 @@ impl UsrObject for UsrWlCallback {
|
|||
}
|
||||
|
||||
fn break_loops(&self) {
|
||||
self.handler.take();
|
||||
self.owner.take();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use {
|
|||
ifs::wl_seat::wl_pointer::PendingScroll,
|
||||
object::Version,
|
||||
utils::clonecell::CloneCell,
|
||||
wire::{WlPointerId, wl_pointer::*},
|
||||
wire::{WlPointerId, WlSurfaceId, wl_pointer::*},
|
||||
wl_usr::{UsrCon, usr_ifs::usr_wl_surface::UsrWlSurface, usr_object::UsrObject},
|
||||
},
|
||||
std::{cell::Cell, convert::Infallible, rc::Rc},
|
||||
|
|
@ -19,34 +19,34 @@ pub struct UsrWlPointer {
|
|||
}
|
||||
|
||||
pub trait UsrWlPointerOwner {
|
||||
fn enter(&self, ev: &Enter) {
|
||||
fn enter(self: Rc<Self>, ev: &Enter) {
|
||||
let _ = ev;
|
||||
}
|
||||
|
||||
fn leave(&self, ev: &Leave) {
|
||||
fn leave(self: Rc<Self>, ev: &Leave) {
|
||||
let _ = ev;
|
||||
}
|
||||
|
||||
fn motion(&self, ev: &Motion) {
|
||||
fn motion(self: Rc<Self>, ev: &Motion) {
|
||||
let _ = ev;
|
||||
}
|
||||
|
||||
fn button(&self, ev: &Button) {
|
||||
fn button(self: Rc<Self>, ev: &Button) {
|
||||
let _ = ev;
|
||||
}
|
||||
|
||||
fn scroll(&self, ps: &PendingScroll) {
|
||||
fn scroll(self: Rc<Self>, ps: &PendingScroll) {
|
||||
let _ = ps;
|
||||
}
|
||||
}
|
||||
|
||||
impl UsrWlPointer {
|
||||
#[expect(dead_code)]
|
||||
pub fn set_cursor(&self, serial: u32, cursor: &UsrWlSurface, hot_x: i32, hot_y: i32) {
|
||||
pub fn set_cursor(&self, serial: u32, cursor: Option<&UsrWlSurface>, hot_x: i32, hot_y: i32) {
|
||||
self.con.request(SetCursor {
|
||||
self_id: self.id,
|
||||
serial,
|
||||
surface: cursor.id,
|
||||
surface: cursor.map(|c| c.id).unwrap_or(WlSurfaceId::NONE),
|
||||
hotspot_x: hot_x,
|
||||
hotspot_y: hot_y,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use {
|
||||
crate::{
|
||||
globals::GlobalName,
|
||||
object::Version,
|
||||
utils::clonecell::CloneCell,
|
||||
wire::{WlRegistryId, wl_registry::*},
|
||||
|
|
@ -16,24 +17,24 @@ pub struct UsrWlRegistry {
|
|||
}
|
||||
|
||||
pub trait UsrWlRegistryOwner {
|
||||
fn global(self: Rc<Self>, name: u32, interface: &str, version: u32) {
|
||||
fn global(self: Rc<Self>, name: GlobalName, interface: &str, version: u32) {
|
||||
let _ = name;
|
||||
let _ = interface;
|
||||
let _ = version;
|
||||
}
|
||||
|
||||
fn global_remove(&self, name: u32) {
|
||||
fn global_remove(&self, name: GlobalName) {
|
||||
let _ = name;
|
||||
}
|
||||
}
|
||||
|
||||
impl UsrWlRegistry {
|
||||
pub fn request_bind(&self, name: u32, version: u32, obj: &dyn UsrObject) {
|
||||
pub fn bind(&self, name: GlobalName, obj: &dyn UsrObject) {
|
||||
self.con.request(Bind {
|
||||
self_id: self.id,
|
||||
name,
|
||||
name: name.raw(),
|
||||
interface: obj.interface().name(),
|
||||
version,
|
||||
version: obj.version().0,
|
||||
id: obj.id(),
|
||||
});
|
||||
}
|
||||
|
|
@ -44,14 +45,14 @@ impl WlRegistryEventHandler for UsrWlRegistry {
|
|||
|
||||
fn global(&self, ev: Global<'_>, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(owner) = self.owner.get() {
|
||||
owner.global(ev.name, ev.interface, ev.version);
|
||||
owner.global(GlobalName::from_raw(ev.name), ev.interface, ev.version);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn global_remove(&self, ev: GlobalRemove, _slf: &Rc<Self>) -> Result<(), Self::Error> {
|
||||
if let Some(owner) = self.owner.get() {
|
||||
owner.global_remove(ev.name);
|
||||
owner.global_remove(GlobalName::from_raw(ev.name));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,16 +37,14 @@ impl UsrWlSurface {
|
|||
});
|
||||
}
|
||||
|
||||
pub fn frame<F>(&self, f: F)
|
||||
where
|
||||
F: FnOnce() + 'static,
|
||||
{
|
||||
let cb = Rc::new(UsrWlCallback::new(&self.con, f));
|
||||
pub fn frame(&self) -> Rc<UsrWlCallback> {
|
||||
let cb = Rc::new(UsrWlCallback::new(&self.con));
|
||||
self.con.request(Frame {
|
||||
self_id: self.id,
|
||||
callback: cb.id,
|
||||
});
|
||||
self.con.add_object(cb);
|
||||
self.con.add_object(cb.clone());
|
||||
cb
|
||||
}
|
||||
|
||||
pub fn commit(&self) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue