diff --git a/src/nodes/input/method.rs b/src/nodes/input/method.rs index d5a738f..784e4cc 100644 --- a/src/nodes/input/method.rs +++ b/src/nodes/input/method.rs @@ -135,7 +135,7 @@ impl InputMethod { pub(super) fn serialize(&self, alias_id: u64, handler: &Arc) -> InputData { let mut input = self.data.lock().clone(); - input.transform(&self, &handler); + input.transform(self, handler); InputData { id: alias_id, diff --git a/src/wayland/compositor.rs b/src/wayland/compositor.rs index 6f94d7b..5199185 100644 --- a/src/wayland/compositor.rs +++ b/src/wayland/compositor.rs @@ -90,8 +90,7 @@ impl CompositorHandler for WaylandState { return; }; let mut changed = false; - surf.get_data_raw::, _, _>(|c| { - let mut info = c.lock(); + surf.with_child_info(|info| { if info.geometry.origin.x != view.offset.x && info.geometry.origin.y != view.offset.y { diff --git a/src/wayland/xdg_shell.rs b/src/wayland/xdg_shell.rs index 42b2d8d..48448ff 100644 --- a/src/wayland/xdg_shell.rs +++ b/src/wayland/xdg_shell.rs @@ -49,6 +49,49 @@ impl From> for Geometry { } } +// pub trait ToplevelInfoExt { +// fn get_toplevel_info(&self) -> Option; +// fn with_toplevel_info O>(&self, f: F) -> Option; +// fn get_toplevel_state(&self) -> Option; + +// fn get_app_id(&self) -> Option; +// fn get_title(&self) -> Option; +// } +// impl ToplevelInfoExt for WlSurface { +// fn get_toplevel_info(&self) -> Option { +// self.get_data_raw::, _, _>(|c| c.lock().clone()) +// } +// fn with_toplevel_info O>(&self, f: F) -> Option { +// self.get_data_raw::, _, _>(|r| (f)(&mut r.lock())) +// } +// fn get_toplevel_state(&self) -> Option { +// self.get_data_raw::(|r| r.lock().unwrap().current.clone()) +// } + +// fn get_app_id(&self) -> Option { +// self.get_data_raw::(|d| { +// d.lock().unwrap().app_id.clone().unwrap() +// }) +// } +// fn get_title(&self) -> Option { +// self.get_data_raw::(|d| { +// d.lock().unwrap().title.clone().unwrap() +// }) +// } +// } +pub trait ChildInfoExt { + fn get_child_info(&self) -> Option; + fn with_child_info O>(&self, f: F) -> Option; +} +impl ChildInfoExt for WlSurface { + fn get_child_info(&self) -> Option { + self.get_data_raw::, _, _>(|c| c.lock().clone()) + } + fn with_child_info O>(&self, f: F) -> Option { + self.get_data_raw::, _, _>(|r| (f)(&mut r.lock())) + } +} + pub fn surface_panel_item(wl_surface: &WlSurface) -> Option>> { let panel_item = wl_surface .get_data::>>() @@ -226,16 +269,14 @@ impl XdgShellHandler for WaylandState { return; }; - popup - .wl_surface() - .get_data_raw::, _, _>(|ci| { - ci.lock().geometry = positioner - .get_unconstrained_geometry(Rectangle { - loc: (-100000, -100000).into(), - size: (200000, 200000).into(), - }) - .into() - }); + popup.wl_surface().with_child_info(|ci| { + ci.geometry = positioner + .get_unconstrained_geometry(Rectangle { + loc: (-100000, -100000).into(), + size: (200000, 200000).into(), + }) + .into() + }); panel_item.backend.reposition_child(popup.wl_surface()); } @@ -307,19 +348,9 @@ impl XdgShellHandler for WaylandState { } delegate_xdg_shell!(WaylandState); -pub trait ChildInfoExt { - fn get_child_info(&self) -> Option; -} -impl ChildInfoExt for WlSurface { - fn get_child_info(&self) -> Option { - self.get_data_raw::, _, _>(|c| c.lock().clone()) - } -} - pub struct XdgBackend { toplevel: Mutex>, pub children: Mutex>, - // popups: Mutex>, seat: Arc, } impl XdgBackend { @@ -372,10 +403,6 @@ impl XdgBackend { panel_item.destroy_child(child_info.id); self.children.lock().remove(&child_info.id); } - - fn child_info(&self, id: u64) -> Option { - self.children.lock().get(&id).unwrap().get_child_info() - } } impl Backend for XdgBackend { fn start_data(&self) -> Result { @@ -475,8 +502,8 @@ impl Backend for XdgBackend { let children = self .children .lock() - .keys() - .map(|k| self.child_info(*k).unwrap()) + .values() + .filter_map(|v| v.get_child_info()) .collect(); Ok(PanelItemInitData {