aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-12-15 10:53:15 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-12-30 20:12:37 +0300
commit4add755a4d72132324be5cfd04fd119850519b5b (patch)
tree04f978e2ad6bc3ba460a219f57477fcb03a10f4a /src
parent56e249aee68cd03687dd87dc47e2d13d599e5b87 (diff)
downloadniri-4add755a4d72132324be5cfd04fd119850519b5b.tar.gz
niri-4add755a4d72132324be5cfd04fd119850519b5b.tar.bz2
niri-4add755a4d72132324be5cfd04fd119850519b5b.zip
layout/floating: Extract move_and_animate()
Diffstat (limited to 'src')
-rw-r--r--src/layout/floating.rs27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/layout/floating.rs b/src/layout/floating.rs
index 271ab314..c3cf8831 100644
--- a/src/layout/floating.rs
+++ b/src/layout/floating.rs
@@ -697,13 +697,9 @@ impl<W: LayoutElement> FloatingSpace<W> {
};
let active_idx = self.idx_of(active_id).unwrap();
- let tile = &mut self.tiles[active_idx];
- let data = &mut self.data[active_idx];
-
- let prev_pos = data.logical_pos;
- let new_pos = center_preferring_top_left_in_area(self.working_area, data.size);
- data.set_logical_pos(new_pos);
- tile.animate_move_from(prev_pos - new_pos);
+ let new_pos =
+ center_preferring_top_left_in_area(self.working_area, self.data[active_idx].size);
+ self.move_and_animate(active_idx, new_pos);
}
pub fn descendants_added(&mut self, id: &W::Id) -> bool {
@@ -907,6 +903,23 @@ impl<W: LayoutElement> FloatingSpace<W> {
rect.loc
}
+ fn move_and_animate(&mut self, idx: usize, new_pos: Point<f64, Logical>) {
+ // Moves up to this logical pixel distance are not animated.
+ const ANIMATION_THRESHOLD_SQ: f64 = 10. * 10.;
+
+ let tile = &mut self.tiles[idx];
+ let data = &mut self.data[idx];
+
+ let prev_pos = data.logical_pos;
+ data.set_logical_pos(new_pos);
+ let new_pos = data.logical_pos;
+
+ let diff = prev_pos - new_pos;
+ if diff.x * diff.x + diff.y * diff.y > ANIMATION_THRESHOLD_SQ {
+ tile.animate_move_from(prev_pos - new_pos);
+ }
+ }
+
#[cfg(test)]
pub fn working_area(&self) -> Rectangle<f64, Logical> {
self.working_area