Ignore non-rendered windows for input

This commit is contained in:
Ottatop 2023-09-02 16:51:39 -05:00
parent 15e03b6c17
commit 41ea5e5230
4 changed files with 27 additions and 3 deletions

View file

@ -73,6 +73,7 @@ impl State {
} }
} }
/// Get the [`FocusTarget`] under `point`.
pub fn surface_under<P>(&self, point: P) -> Option<(FocusTarget, Point<i32, Logical>)> pub fn surface_under<P>(&self, point: P) -> Option<(FocusTarget, Point<i32, Logical>)>
where where
P: Into<Point<f64, Logical>>, P: Into<Point<f64, Logical>>,
@ -114,8 +115,22 @@ impl State {
}) })
.or_else(|| { .or_else(|| {
self.space self.space
.element_under(point) .elements()
.map(|(window, loc)| (window.clone().into(), loc)) .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(|| { .or_else(|| {
layers layers

View file

@ -226,7 +226,7 @@ where
Tag::tag_render_elements(&tags, windows, space, renderer); Tag::tag_render_elements(&tags, windows, space, renderer);
let mut output_render_elements = let mut output_render_elements =
Vec::<OutputRenderElements<_, WaylandSurfaceRenderElement<_>>>::new(); Vec::<OutputRenderElements<R, WaylandSurfaceRenderElement<R>>>::new();
output_render_elements.extend( output_render_elements.extend(
custom_render_elements custom_render_elements

View file

@ -141,6 +141,7 @@ impl Tag {
}) })
}) })
.flat_map(|win| { .flat_map(|win| {
// subtract win.geometry().loc to align decorations correctly
let loc = (space.element_location(win).unwrap_or((0, 0).into()) let loc = (space.element_location(win).unwrap_or((0, 0).into())
- win.geometry().loc) - win.geometry().loc)
.to_physical(1); .to_physical(1);

View file

@ -249,6 +249,14 @@ impl WindowElement {
self.with_state(|st| st.tags.first().and_then(|tag| tag.output(state))) 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<Item = &'a Output>) -> bool {
let mut tags = outputs.into_iter().flat_map(|op| {
op.with_state(|state| state.focused_tags().cloned().collect::<Vec<_>>())
});
self.with_state(|state| state.tags.iter().any(|tag| tags.any(|tag2| tag == &tag2)))
}
/// Returns `true` if the window element is [`Wayland`]. /// Returns `true` if the window element is [`Wayland`].
/// ///
/// [`Wayland`]: WindowElement::Wayland /// [`Wayland`]: WindowElement::Wayland