Skip to content

Commit

Permalink
wayland: implement wl-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Sep 13, 2024
1 parent a740855 commit 37845c9
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use {
jay_damage_tracking::JayDamageTrackingGlobal,
org_kde_kwin_server_decoration_manager::OrgKdeKwinServerDecorationManagerGlobal,
wl_compositor::WlCompositorGlobal,
wl_fixes::WlFixesGlobal,
wl_output::WlOutputGlobal,
wl_registry::WlRegistry,
wl_seat::{
Expand Down Expand Up @@ -197,6 +198,7 @@ impl Globals {
add_singleton!(ZwpPointerGesturesV1Global);
add_singleton!(ZwpTabletManagerV2Global);
add_singleton!(JayDamageTrackingGlobal);
add_singleton!(WlFixesGlobal);
}

pub fn add_backend_singletons(&self, backend: &Rc<dyn Backend>) {
Expand Down
1 change: 1 addition & 0 deletions src/ifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod wl_callback;
pub mod wl_compositor;
pub mod wl_display;
pub mod wl_drm;
pub mod wl_fixes;
pub mod wl_output;
pub mod wl_region;
pub mod wl_registry;
Expand Down
90 changes: 90 additions & 0 deletions src/ifs/wl_fixes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
use {
crate::{
client::{Client, ClientError},
globals::{Global, GlobalName},
leaks::Tracker,
object::{Object, Version},
wire::{wl_fixes::*, WlFixesId},
},
std::rc::Rc,
thiserror::Error,
};

pub struct WlFixesGlobal {
pub name: GlobalName,
}

impl WlFixesGlobal {
pub fn new(name: GlobalName) -> Self {
Self { name }
}

fn bind_(
self: Rc<Self>,
id: WlFixesId,
client: &Rc<Client>,
version: Version,
) -> Result<(), WlFixesError> {
let mgr = Rc::new(WlFixes {
id,
client: client.clone(),
tracker: Default::default(),
version,
});
track!(client, mgr);
client.add_client_obj(&mgr)?;
Ok(())
}
}

global_base!(WlFixesGlobal, WlFixes, WlFixesError);

simple_add_global!(WlFixesGlobal);

impl Global for WlFixesGlobal {
fn singleton(&self) -> bool {
true
}

fn version(&self) -> u32 {
1
}
}

pub struct WlFixes {
pub id: WlFixesId,
pub client: Rc<Client>,
pub tracker: Tracker<Self>,
pub version: Version,
}

impl WlFixesRequestHandler for WlFixes {
type Error = WlFixesError;

fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.client.remove_obj(self)?;
Ok(())
}

fn destroy_registry(&self, req: DestroyRegistry, _slf: &Rc<Self>) -> Result<(), Self::Error> {
let registry = self.client.lookup(req.registry)?;
self.client.remove_obj(&*registry)?;
Ok(())
}
}

object_base! {
self = WlFixes;
version = self.version;
}

impl Object for WlFixes {}

simple_add_obj!(WlFixes);

#[derive(Debug, Error)]
pub enum WlFixesError {
#[error(transparent)]
ClientError(Box<ClientError>),
}
efrom!(WlFixesError, ClientError);
1 change: 1 addition & 0 deletions src/it/test_ifs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub mod test_viewport;
pub mod test_viewporter;
pub mod test_virtual_keyboard;
pub mod test_virtual_keyboard_manager;
pub mod test_wl_fixes;
pub mod test_xdg_activation;
pub mod test_xdg_activation_token;
pub mod test_xdg_base;
Expand Down
7 changes: 6 additions & 1 deletion src/it/test_ifs/test_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ use {
test_toplevel_drag_manager::TestToplevelDragManager,
test_viewporter::TestViewporter,
test_virtual_keyboard_manager::TestVirtualKeyboardManager,
test_xdg_activation::TestXdgActivation, test_xdg_base::TestXdgWmBase,
test_wl_fixes::TestWlFixes, test_xdg_activation::TestXdgActivation,
test_xdg_base::TestXdgWmBase,
},
test_object::TestObject,
test_transport::TestTransport,
Expand Down Expand Up @@ -58,6 +59,7 @@ pub struct TestRegistrySingletons {
pub zwp_virtual_keyboard_manager_v1: u32,
pub zwp_input_method_manager_v2: u32,
pub zwp_text_input_manager_v3: u32,
pub wl_fixes: u32,
}

pub struct TestRegistry {
Expand Down Expand Up @@ -85,6 +87,7 @@ pub struct TestRegistry {
pub virtual_keyboard_manager: CloneCell<Option<Rc<TestVirtualKeyboardManager>>>,
pub input_method_manager: CloneCell<Option<Rc<TestInputMethodManager>>>,
pub text_input_manager: CloneCell<Option<Rc<TestTextInputManager>>>,
pub wl_fixes: CloneCell<Option<Rc<TestWlFixes>>>,
pub seats: CopyHashMap<GlobalName, Rc<WlSeatGlobal>>,
}

Expand Down Expand Up @@ -156,6 +159,7 @@ impl TestRegistry {
zwp_virtual_keyboard_manager_v1,
zwp_input_method_manager_v2,
zwp_text_input_manager_v3,
wl_fixes,
};
self.singletons.set(Some(singletons.clone()));
Ok(singletons)
Expand Down Expand Up @@ -271,6 +275,7 @@ impl TestRegistry {
1,
TestTextInputManager
);
create_singleton!(get_wl_fixes, wl_fixes, wl_fixes, 1, TestWlFixes);

pub fn bind<O: TestObject>(
&self,
Expand Down
38 changes: 38 additions & 0 deletions src/it/test_ifs/test_wl_fixes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use {
crate::{
it::{
test_error::TestResult, test_ifs::test_registry::TestRegistry, test_object::TestObject,
test_transport::TestTransport,
},
wire::{wl_fixes::*, WlFixesId},
},
std::rc::Rc,
};

pub struct TestWlFixes {
pub id: WlFixesId,
pub tran: Rc<TestTransport>,
}

impl TestWlFixes {
pub fn new(tran: &Rc<TestTransport>) -> Self {
Self {
id: tran.id(),
tran: tran.clone(),
}
}

pub fn destroy_registry(&self, registry: &TestRegistry) -> TestResult {
self.tran.send(DestroyRegistry {
self_id: self.id,
registry: registry.id,
})?;
Ok(())
}
}

test_object! {
TestWlFixes, WlFixes;
}

impl TestObject for TestWlFixes {}
1 change: 1 addition & 0 deletions src/it/test_transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ impl TestTransport {
virtual_keyboard_manager: Default::default(),
input_method_manager: Default::default(),
text_input_manager: Default::default(),
wl_fixes: Default::default(),
seats: Default::default(),
});
self.send(wl_display::GetRegistry {
Expand Down
2 changes: 2 additions & 0 deletions src/it/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ mod t0039_alpha_modifier;
mod t0040_virtual_keyboard;
mod t0041_input_method;
mod t0042_toplevel_select;
mod t0043_destroy_registry;

pub trait TestCase: Sync {
fn name(&self) -> &'static str;
Expand Down Expand Up @@ -135,5 +136,6 @@ pub fn tests() -> Vec<&'static dyn TestCase> {
t0040_virtual_keyboard,
t0041_input_method,
t0042_toplevel_select,
t0043_destroy_registry,
}
}
31 changes: 31 additions & 0 deletions src/it/tests/t0043_destroy_registry.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use {
crate::it::{test_error::TestResult, testrun::TestRun},
std::rc::Rc,
};

testcase!();

async fn test(run: Rc<TestRun>) -> TestResult {
let client = run.create_client().await?;
let wl_fixes = client.registry.get_wl_fixes().await?;

let registry1 = client.tran.get_registry();

client.sync().await;
let before = client.server.objects.registries.len();

wl_fixes.destroy_registry(&registry1)?;

client.sync().await;
let after = client.server.objects.registries.len();

tassert_eq!(before, after + 1);

let registry2 = client.tran.get_registry();
client.sync().await;

tassert_eq!(registry1.id, registry2.id);
tassert!(registry2.globals.is_not_empty());

Ok(())
}
7 changes: 7 additions & 0 deletions wire/wl_fixes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
request destroy {

}

request destroy_registry {
registry: id(wl_registry),
}

0 comments on commit 37845c9

Please sign in to comment.