1
0
Fork 0
forked from wry/wry

it: test toplevel drag

This commit is contained in:
Julian Orth 2024-04-03 16:52:31 +02:00
parent d4f49bf947
commit 660fa92659
11 changed files with 182 additions and 4 deletions

View file

@ -7,7 +7,7 @@ use {
testrun::ParseFull,
},
utils::{buffd::MsgParser, clonecell::CloneCell},
wire::{wl_pointer::*, WlPointerId},
wire::{wl_pointer::*, WlPointerId, WlSurfaceId},
},
std::{cell::Cell, rc::Rc},
};
@ -35,14 +35,14 @@ impl TestPointer {
pub fn set_cursor(
&self,
serial: u32,
surface: &TestSurface,
surface: Option<&TestSurface>,
hotspot_x: i32,
hotspot_y: i32,
) -> TestResult {
self.tran.send(SetCursor {
self_id: self.id,
serial,
surface: surface.id,
surface: surface.map(|s| s.id).unwrap_or(WlSurfaceId::NONE),
hotspot_x,
hotspot_y,
})?;

View file

@ -13,6 +13,7 @@ use {
test_jay_compositor::TestJayCompositor, test_shm::TestShm,
test_single_pixel_buffer_manager::TestSinglePixelBufferManager,
test_subcompositor::TestSubcompositor, test_syncobj_manager::TestSyncobjManager,
test_toplevel_drag_manager::TestToplevelDragManager,
test_viewporter::TestViewporter, test_xdg_activation::TestXdgActivation,
test_xdg_base::TestXdgWmBase,
},
@ -48,6 +49,7 @@ pub struct TestRegistrySingletons {
pub wp_content_type_manager_v1: u32,
pub zwlr_data_control_manager_v1: u32,
pub zwp_linux_dmabuf_v1: u32,
pub xdg_toplevel_drag_manager_v1: u32,
}
pub struct TestRegistry {
@ -70,6 +72,7 @@ pub struct TestRegistry {
pub content_type_manager: CloneCell<Option<Rc<TestContentTypeManager>>>,
pub data_control_manager: CloneCell<Option<Rc<TestDataControlManager>>>,
pub dmabuf: CloneCell<Option<Rc<TestDmabuf>>>,
pub drag_manager: CloneCell<Option<Rc<TestToplevelDragManager>>>,
pub seats: CopyHashMap<GlobalName, Rc<WlSeatGlobal>>,
}
@ -136,6 +139,7 @@ impl TestRegistry {
wp_content_type_manager_v1,
zwlr_data_control_manager_v1,
zwp_linux_dmabuf_v1,
xdg_toplevel_drag_manager_v1,
};
self.singletons.set(Some(singletons.clone()));
Ok(singletons)
@ -216,6 +220,13 @@ impl TestRegistry {
TestDataControlManager
);
create_singleton!(get_dmabuf, dmabuf, zwp_linux_dmabuf_v1, 5, TestDmabuf);
create_singleton!(
get_drag_manager,
drag_manager,
xdg_toplevel_drag_manager_v1,
1,
TestToplevelDragManager
);
pub fn bind<O: TestObject>(
&self,

View file

@ -0,0 +1,52 @@
use {
crate::{
it::{
test_error::TestError, test_ifs::test_xdg_toplevel::TestXdgToplevel,
test_object::TestObject, test_transport::TestTransport,
},
wire::{xdg_toplevel_drag_v1::*, XdgToplevelDragV1Id},
},
std::{cell::Cell, rc::Rc},
};
pub struct TestToplevelDrag {
pub id: XdgToplevelDragV1Id,
pub tran: Rc<TestTransport>,
pub destroyed: Cell<bool>,
}
impl TestToplevelDrag {
pub fn destroy(&self) -> Result<(), TestError> {
if !self.destroyed.replace(true) {
self.tran.send(Destroy { self_id: self.id })?;
}
Ok(())
}
pub fn attach(
&self,
toplevel: &TestXdgToplevel,
x_offset: i32,
y_offset: i32,
) -> Result<(), TestError> {
self.tran.send(Attach {
self_id: self.id,
toplevel: toplevel.core.id,
x_offset,
y_offset,
})?;
Ok(())
}
}
impl Drop for TestToplevelDrag {
fn drop(&mut self) {
let _ = self.destroy();
}
}
test_object! {
TestToplevelDrag, XdgToplevelDragV1;
}
impl TestObject for TestToplevelDrag {}

View file

@ -0,0 +1,65 @@
use {
crate::{
it::{
test_error::{TestError, TestResult},
test_ifs::{test_data_source::TestDataSource, test_toplevel_drag::TestToplevelDrag},
test_object::TestObject,
test_transport::TestTransport,
},
wire::{xdg_toplevel_drag_manager_v1::*, XdgToplevelDragManagerV1Id},
},
std::{cell::Cell, rc::Rc},
};
pub struct TestToplevelDragManager {
pub id: XdgToplevelDragManagerV1Id,
pub tran: Rc<TestTransport>,
pub destroyed: Cell<bool>,
}
impl TestToplevelDragManager {
pub fn new(tran: &Rc<TestTransport>) -> Self {
Self {
id: tran.id(),
tran: tran.clone(),
destroyed: Cell::new(false),
}
}
pub fn destroy(&self) -> Result<(), TestError> {
if !self.destroyed.replace(true) {
self.tran.send(Destroy { self_id: self.id })?;
}
Ok(())
}
pub fn get_xdg_toplevel_drag(
&self,
data_source: &TestDataSource,
) -> TestResult<Rc<TestToplevelDrag>> {
let obj = Rc::new(TestToplevelDrag {
id: self.tran.id(),
tran: self.tran.clone(),
destroyed: Cell::new(false),
});
self.tran.add_obj(obj.clone())?;
self.tran.send(GetXdgToplevelDrag {
self_id: self.id,
id: obj.id,
data_source: data_source.id,
})?;
Ok(obj)
}
}
impl Drop for TestToplevelDragManager {
fn drop(&mut self) {
let _ = self.destroy();
}
}
test_object! {
TestToplevelDragManager, XdgToplevelDragManagerV1;
}
impl TestObject for TestToplevelDragManager {}