1
0
Fork 0
forked from wry/wry
wry/src/it/test_ifs/test_compositor.rs
2022-05-03 15:54:32 +02:00

47 lines
1.2 KiB
Rust

use {
crate::{
it::{
test_error::TestError,
test_ifs::test_surface::TestSurface,
test_object::{Deleted, TestObject},
test_transport::TestTransport,
},
wire::{wl_compositor::CreateSurface, WlCompositorId},
},
std::{cell::Cell, rc::Rc},
};
pub struct TestCompositor {
pub id: WlCompositorId,
pub tran: Rc<TestTransport>,
pub deleted: Deleted,
}
impl TestCompositor {
pub async fn create_surface(&self) -> Result<Rc<TestSurface>, TestError> {
let id = self.tran.id();
self.deleted.check()?;
self.tran.send(CreateSurface {
self_id: self.id,
id,
});
self.tran.sync().await;
let client = self.tran.get_client()?;
let server = client.lookup(id)?;
let surface = Rc::new(TestSurface {
id,
tran: self.tran.clone(),
server,
destroyed: Cell::new(false),
deleted: Default::default(),
});
self.tran.add_obj(surface.clone())?;
Ok(surface)
}
}
test_object! {
TestCompositor, WlCompositor;
}
impl TestObject for TestCompositor {}