layout: Extract tile.hit(), HitType::hit_tile()

This commit is contained in:
Ivan Molodetskikh
2025-02-10 08:47:44 +03:00
parent 1d883931b4
commit 55e2ea0c3b
3 changed files with 28 additions and 27 deletions
+11 -10
View File
@@ -507,6 +507,16 @@ impl HitType {
}
self
}
pub fn hit_tile<W: LayoutElement>(
tile: &Tile<W>,
tile_pos: Point<f64, Logical>,
point: Point<f64, Logical>,
) -> Option<(&W, Self)> {
let pos_within_tile = point - tile_pos;
tile.hit(pos_within_tile)
.map(|hit| (tile.window(), hit.offset_win_pos(tile_pos)))
}
}
impl Options {
@@ -2191,16 +2201,7 @@ impl<W: LayoutElement> Layout<W> {
if let Some(InteractiveMoveState::Moving(move_)) = &self.interactive_move {
let tile_pos = move_.tile_render_location();
let pos_within_tile = pos_within_output - tile_pos;
if move_.tile.is_in_input_region(pos_within_tile) {
let win_pos = tile_pos + move_.tile.buf_loc();
return Some((move_.tile.window(), HitType::Input { win_pos }));
} else if move_.tile.is_in_activation_region(pos_within_tile) {
return Some((move_.tile.window(), HitType::Activate));
}
return None;
return HitType::hit_tile(&move_.tile, tile_pos, pos_within_output);
};
let mon = monitors.iter().find(|mon| &mon.output == output)?;
+15 -4
View File
@@ -10,8 +10,8 @@ use super::focus_ring::{FocusRing, FocusRingRenderElement};
use super::opening_window::{OpenAnimation, OpeningWindowRenderElement};
use super::shadow::Shadow;
use super::{
LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot, Options, SizeFrac,
RESIZE_ANIMATION_THRESHOLD,
HitType, LayoutElement, LayoutElementRenderElement, LayoutElementRenderSnapshot, Options,
SizeFrac, RESIZE_ANIMATION_THRESHOLD,
};
use crate::animation::{Animation, Clock};
use crate::niri_render_elements;
@@ -606,16 +606,27 @@ impl<W: LayoutElement> Tile<W> {
loc
}
pub fn is_in_input_region(&self, mut point: Point<f64, Logical>) -> bool {
fn is_in_input_region(&self, mut point: Point<f64, Logical>) -> bool {
point -= self.window_loc().to_f64();
self.window.is_in_input_region(point)
}
pub fn is_in_activation_region(&self, point: Point<f64, Logical>) -> bool {
fn is_in_activation_region(&self, point: Point<f64, Logical>) -> bool {
let activation_region = Rectangle::from_size(self.tile_size());
activation_region.contains(point)
}
pub fn hit(&self, point: Point<f64, Logical>) -> Option<HitType> {
if self.is_in_input_region(point) {
let win_pos = self.buf_loc();
Some(HitType::Input { win_pos })
} else if self.is_in_activation_region(point) {
Some(HitType::Activate)
} else {
None
}
}
pub fn request_tile_size(
&mut self,
mut size: Size<f64, Logical>,
+2 -13
View File
@@ -1468,16 +1468,7 @@ impl<W: LayoutElement> Workspace<W> {
return None;
}
let pos_within_tile = pos - tile_pos;
if tile.is_in_input_region(pos_within_tile) {
let win_pos = tile_pos + tile.buf_loc();
return Some((tile.window(), HitType::Input { win_pos }));
} else if tile.is_in_activation_region(pos_within_tile) {
return Some((tile.window(), HitType::Activate));
}
None
HitType::hit_tile(tile, tile_pos, pos)
})
}
@@ -1492,9 +1483,7 @@ impl<W: LayoutElement> Workspace<W> {
let pos_within_tile = pos - tile_pos;
if tile.is_in_input_region(pos_within_tile)
|| tile.is_in_activation_region(pos_within_tile)
{
if tile.hit(pos_within_tile).is_some() {
let size = tile.tile_size().to_f64();
let mut edges = ResizeEdge::empty();