From 41ea5e523020211eea2ae2ffa46ed52d2aaac08e Mon Sep 17 00:00:00 2001 From: Ottatop Date: Sat, 2 Sep 2023 16:51:39 -0500 Subject: [PATCH] Ignore non-rendered windows for input --- src/input.rs | 19 +++++++++++++++++-- src/render.rs | 2 +- src/tag.rs | 1 + src/window.rs | 8 ++++++++ 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/input.rs b/src/input.rs index 9e66cf4..dd6b8ef 100644 --- a/src/input.rs +++ b/src/input.rs @@ -73,6 +73,7 @@ impl State { } } + /// Get the [`FocusTarget`] under `point`. pub fn surface_under

(&self, point: P) -> Option<(FocusTarget, Point)> where P: Into>, @@ -114,8 +115,22 @@ impl State { }) .or_else(|| { self.space - .element_under(point) - .map(|(window, loc)| (window.clone().into(), loc)) + .elements() + .rev() + .filter(|win| win.is_on_active_tag(self.space.outputs())) + .find_map(|win| { + let loc = self + .space + .element_location(win) + .expect("called elem loc on unmapped win") + - win.geometry().loc; + + if win.is_in_input_region(&(point - loc.to_f64())) { + Some((win.clone().into(), loc)) + } else { + None + } + }) }) .or_else(|| { layers diff --git a/src/render.rs b/src/render.rs index 3c5ae6c..3be0410 100644 --- a/src/render.rs +++ b/src/render.rs @@ -226,7 +226,7 @@ where Tag::tag_render_elements(&tags, windows, space, renderer); let mut output_render_elements = - Vec::>>::new(); + Vec::>>::new(); output_render_elements.extend( custom_render_elements diff --git a/src/tag.rs b/src/tag.rs index 536da3a..0acd870 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -141,6 +141,7 @@ impl Tag { }) }) .flat_map(|win| { + // subtract win.geometry().loc to align decorations correctly let loc = (space.element_location(win).unwrap_or((0, 0).into()) - win.geometry().loc) .to_physical(1); diff --git a/src/window.rs b/src/window.rs index f05578b..e83a215 100644 --- a/src/window.rs +++ b/src/window.rs @@ -249,6 +249,14 @@ impl WindowElement { self.with_state(|st| st.tags.first().and_then(|tag| tag.output(state))) } + /// RefCell Safety: This uses RefCells on both `self` and everything in `outputs`. + pub fn is_on_active_tag<'a>(&self, outputs: impl IntoIterator) -> bool { + let mut tags = outputs.into_iter().flat_map(|op| { + op.with_state(|state| state.focused_tags().cloned().collect::>()) + }); + self.with_state(|state| state.tags.iter().any(|tag| tags.any(|tag2| tag == &tag2))) + } + /// Returns `true` if the window element is [`Wayland`]. /// /// [`Wayland`]: WindowElement::Wayland