refactor: cleanup

This commit is contained in:
Nova
2024-07-28 06:14:02 -04:00
parent c09afba366
commit 98a6ad6f32
3 changed files with 55 additions and 29 deletions

View File

@@ -135,7 +135,7 @@ impl InputMethod {
pub(super) fn serialize(&self, alias_id: u64, handler: &Arc<InputHandler>) -> InputData { pub(super) fn serialize(&self, alias_id: u64, handler: &Arc<InputHandler>) -> InputData {
let mut input = self.data.lock().clone(); let mut input = self.data.lock().clone();
input.transform(&self, &handler); input.transform(self, handler);
InputData { InputData {
id: alias_id, id: alias_id,

View File

@@ -90,8 +90,7 @@ impl CompositorHandler for WaylandState {
return; return;
}; };
let mut changed = false; let mut changed = false;
surf.get_data_raw::<Mutex<ChildInfo>, _, _>(|c| { surf.with_child_info(|info| {
let mut info = c.lock();
if info.geometry.origin.x != view.offset.x if info.geometry.origin.x != view.offset.x
&& info.geometry.origin.y != view.offset.y && info.geometry.origin.y != view.offset.y
{ {

View File

@@ -49,6 +49,49 @@ impl From<Rectangle<i32, Logical>> for Geometry {
} }
} }
// pub trait ToplevelInfoExt {
// fn get_toplevel_info(&self) -> Option<ToplevelInfo>;
// fn with_toplevel_info<O, F: FnOnce(&mut ToplevelInfo) -> O>(&self, f: F) -> Option<O>;
// fn get_toplevel_state(&self) -> Option<ToplevelState>;
// fn get_app_id(&self) -> Option<String>;
// fn get_title(&self) -> Option<String>;
// }
// impl ToplevelInfoExt for WlSurface {
// fn get_toplevel_info(&self) -> Option<ToplevelInfo> {
// self.get_data_raw::<Mutex<ToplevelInfo>, _, _>(|c| c.lock().clone())
// }
// fn with_toplevel_info<O, F: FnOnce(&mut ToplevelInfo) -> O>(&self, f: F) -> Option<O> {
// self.get_data_raw::<Mutex<ToplevelInfo>, _, _>(|r| (f)(&mut r.lock()))
// }
// fn get_toplevel_state(&self) -> Option<ToplevelState> {
// self.get_data_raw::<XdgToplevelSurfaceData, _, _>(|r| r.lock().unwrap().current.clone())
// }
// fn get_app_id(&self) -> Option<String> {
// self.get_data_raw::<XdgToplevelSurfaceData, _, _>(|d| {
// d.lock().unwrap().app_id.clone().unwrap()
// })
// }
// fn get_title(&self) -> Option<String> {
// self.get_data_raw::<XdgToplevelSurfaceData, _, _>(|d| {
// d.lock().unwrap().title.clone().unwrap()
// })
// }
// }
pub trait ChildInfoExt {
fn get_child_info(&self) -> Option<ChildInfo>;
fn with_child_info<O, F: FnOnce(&mut ChildInfo) -> O>(&self, f: F) -> Option<O>;
}
impl ChildInfoExt for WlSurface {
fn get_child_info(&self) -> Option<ChildInfo> {
self.get_data_raw::<Mutex<ChildInfo>, _, _>(|c| c.lock().clone())
}
fn with_child_info<O, F: FnOnce(&mut ChildInfo) -> O>(&self, f: F) -> Option<O> {
self.get_data_raw::<Mutex<ChildInfo>, _, _>(|r| (f)(&mut r.lock()))
}
}
pub fn surface_panel_item(wl_surface: &WlSurface) -> Option<Arc<PanelItem<XdgBackend>>> { pub fn surface_panel_item(wl_surface: &WlSurface) -> Option<Arc<PanelItem<XdgBackend>>> {
let panel_item = wl_surface let panel_item = wl_surface
.get_data::<Weak<PanelItem<XdgBackend>>>() .get_data::<Weak<PanelItem<XdgBackend>>>()
@@ -226,16 +269,14 @@ impl XdgShellHandler for WaylandState {
return; return;
}; };
popup popup.wl_surface().with_child_info(|ci| {
.wl_surface() ci.geometry = positioner
.get_data_raw::<Mutex<ChildInfo>, _, _>(|ci| { .get_unconstrained_geometry(Rectangle {
ci.lock().geometry = positioner loc: (-100000, -100000).into(),
.get_unconstrained_geometry(Rectangle { size: (200000, 200000).into(),
loc: (-100000, -100000).into(), })
size: (200000, 200000).into(), .into()
}) });
.into()
});
panel_item.backend.reposition_child(popup.wl_surface()); panel_item.backend.reposition_child(popup.wl_surface());
} }
@@ -307,19 +348,9 @@ impl XdgShellHandler for WaylandState {
} }
delegate_xdg_shell!(WaylandState); delegate_xdg_shell!(WaylandState);
pub trait ChildInfoExt {
fn get_child_info(&self) -> Option<ChildInfo>;
}
impl ChildInfoExt for WlSurface {
fn get_child_info(&self) -> Option<ChildInfo> {
self.get_data_raw::<Mutex<ChildInfo>, _, _>(|c| c.lock().clone())
}
}
pub struct XdgBackend { pub struct XdgBackend {
toplevel: Mutex<Option<ToplevelSurface>>, toplevel: Mutex<Option<ToplevelSurface>>,
pub children: Mutex<FxHashMap<u64, WlSurface>>, pub children: Mutex<FxHashMap<u64, WlSurface>>,
// popups: Mutex<FxHashMap<u64, (PopupSurface, PositionerState)>>,
seat: Arc<SeatWrapper>, seat: Arc<SeatWrapper>,
} }
impl XdgBackend { impl XdgBackend {
@@ -372,10 +403,6 @@ impl XdgBackend {
panel_item.destroy_child(child_info.id); panel_item.destroy_child(child_info.id);
self.children.lock().remove(&child_info.id); self.children.lock().remove(&child_info.id);
} }
fn child_info(&self, id: u64) -> Option<ChildInfo> {
self.children.lock().get(&id).unwrap().get_child_info()
}
} }
impl Backend for XdgBackend { impl Backend for XdgBackend {
fn start_data(&self) -> Result<PanelItemInitData> { fn start_data(&self) -> Result<PanelItemInitData> {
@@ -475,8 +502,8 @@ impl Backend for XdgBackend {
let children = self let children = self
.children .children
.lock() .lock()
.keys() .values()
.map(|k| self.child_info(*k).unwrap()) .filter_map(|v| v.get_child_info())
.collect(); .collect();
Ok(PanelItemInitData { Ok(PanelItemInitData {