1
0
Fork 0
forked from wry/wry

it: test subsurface positioning

This commit is contained in:
Julian Orth 2022-05-03 18:32:43 +02:00
parent fd027d9a5a
commit cbf539cbcc
17 changed files with 291 additions and 9 deletions

View file

@ -6,7 +6,8 @@ use {
test_error::TestError,
test_ifs::{
test_compositor::TestCompositor, test_jay_compositor::TestJayCompositor,
test_shm::TestShm, test_xdg_base::TestXdgWmBase,
test_shm::TestShm, test_subcompositor::TestSubcompositor,
test_xdg_base::TestXdgWmBase,
},
test_object::TestObject,
test_transport::TestTransport,
@ -27,6 +28,7 @@ pub struct TestGlobal {
pub struct TestRegistrySingletons {
pub jay_compositor: u32,
pub wl_compositor: u32,
pub wl_subcompositor: u32,
pub wl_shm: u32,
pub xdg_wm_base: u32,
}
@ -38,6 +40,7 @@ pub struct TestRegistry {
pub singletons: CloneCell<Option<Rc<TestRegistrySingletons>>>,
pub jay_compositor: CloneCell<Option<Rc<TestJayCompositor>>>,
pub compositor: CloneCell<Option<Rc<TestCompositor>>>,
pub subcompositor: CloneCell<Option<Rc<TestSubcompositor>>>,
pub shm: CloneCell<Option<Rc<TestShm>>>,
pub xdg: CloneCell<Option<Rc<TestXdgWmBase>>>,
pub seats: CopyHashMap<GlobalName, Rc<WlSeatGlobal>>,
@ -84,6 +87,7 @@ impl TestRegistry {
let singletons = singleton! {
jay_compositor,
wl_compositor,
wl_subcompositor,
wl_shm,
xdg_wm_base,
};
@ -118,6 +122,20 @@ impl TestRegistry {
Ok(jc)
}
pub async fn get_subcompositor(&self) -> Result<Rc<TestSubcompositor>, TestError> {
singleton!(self.subcompositor);
let singletons = self.get_singletons().await?;
singleton!(self.subcompositor);
let jc = Rc::new(TestSubcompositor {
id: self.tran.id(),
tran: self.tran.clone(),
destroyed: Cell::new(false),
});
self.bind(&jc, singletons.wl_subcompositor, 1)?;
self.subcompositor.set(Some(jc.clone()));
Ok(jc)
}
pub async fn get_shm(&self) -> Result<Rc<TestShm>, TestError> {
singleton!(self.shm);
let singletons = self.get_singletons().await?;

View file

@ -0,0 +1,60 @@
use {
crate::{
it::{
test_error::TestError, test_ifs::test_subsurface::TestSubsurface,
test_object::TestObject, test_transport::TestTransport,
},
wire::{wl_subcompositor::*, WlSubcompositorId, WlSurfaceId},
},
std::{cell::Cell, rc::Rc},
};
pub struct TestSubcompositor {
pub id: WlSubcompositorId,
pub tran: Rc<TestTransport>,
pub destroyed: Cell<bool>,
}
impl TestSubcompositor {
pub fn destroy(&self) -> Result<(), TestError> {
if !self.destroyed.replace(true) {
self.tran.send(Destroy { self_id: self.id })?;
}
Ok(())
}
pub async fn get_subsurface(
&self,
surface: WlSurfaceId,
parent: WlSurfaceId,
) -> Result<Rc<TestSubsurface>, TestError> {
let id = self.tran.id();
self.tran.send(GetSubsurface {
self_id: self.id,
id,
surface,
parent,
})?;
self.tran.sync().await;
let ss = Rc::new(TestSubsurface {
id,
tran: self.tran.clone(),
destroyed: Cell::new(false),
server: self.tran.get_object(id)?,
});
self.tran.add_obj(ss.clone())?;
Ok(ss)
}
}
impl Drop for TestSubcompositor {
fn drop(&mut self) {
let _ = self.destroy();
}
}
test_object! {
TestSubcompositor, WlSubcompositor;
}
impl TestObject for TestSubcompositor {}

View file

@ -0,0 +1,68 @@
use {
crate::{
ifs::wl_surface::wl_subsurface::WlSubsurface,
it::{test_error::TestError, test_object::TestObject, test_transport::TestTransport},
wire::{wl_subsurface::*, WlSubsurfaceId, WlSurfaceId},
},
std::{cell::Cell, rc::Rc},
};
pub struct TestSubsurface {
pub id: WlSubsurfaceId,
pub tran: Rc<TestTransport>,
pub destroyed: Cell<bool>,
pub server: Rc<WlSubsurface>,
}
impl TestSubsurface {
pub fn destroy(&self) -> Result<(), TestError> {
if !self.destroyed.replace(true) {
self.tran.send(Destroy { self_id: self.id })?;
}
Ok(())
}
pub fn set_position(&self, x: i32, y: i32) -> Result<(), TestError> {
self.tran.send(SetPosition {
self_id: self.id,
x,
y,
})
}
pub fn place_above(&self, surface: WlSurfaceId) -> Result<(), TestError> {
self.tran.send(PlaceAbove {
self_id: self.id,
sibling: surface,
})
}
pub fn place_below(&self, surface: WlSurfaceId) -> Result<(), TestError> {
self.tran.send(PlaceBelow {
self_id: self.id,
sibling: surface,
})
}
#[allow(dead_code)]
pub fn set_sync(&self) -> Result<(), TestError> {
self.tran.send(SetSync { self_id: self.id })
}
#[allow(dead_code)]
pub fn set_desync(&self) -> Result<(), TestError> {
self.tran.send(SetDesync { self_id: self.id })
}
}
impl Drop for TestSubsurface {
fn drop(&mut self) {
let _ = self.destroy();
}
}
test_object! {
TestSubsurface, WlSubsurface;
}
impl TestObject for TestSubsurface {}