layout: Add animate arg to move_floating_window()

This commit is contained in:
Ivan Molodetskikh
2024-12-28 12:06:22 +03:00
parent 6c52077d92
commit 4ea4d2bd3b
4 changed files with 28 additions and 11 deletions
+3 -1
View File
@@ -1373,7 +1373,9 @@ impl State {
None
};
self.niri.layout.move_floating_window(window.as_ref(), x, y);
self.niri
.layout
.move_floating_window(window.as_ref(), x, y, true);
// FIXME: granular
self.niri.queue_redraw_all();
}
+18 -6
View File
@@ -839,8 +839,13 @@ impl<W: LayoutElement> FloatingSpace<W> {
}
}
fn move_to(&mut self, idx: usize, new_pos: Point<f64, Logical>) {
self.move_and_animate(idx, new_pos);
fn move_to(&mut self, idx: usize, new_pos: Point<f64, Logical>, animate: bool) {
if animate {
self.move_and_animate(idx, new_pos);
} else {
self.data[idx].set_logical_pos(new_pos);
}
self.interactive_resize_end(None);
}
@@ -851,7 +856,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
let idx = self.idx_of(active_id).unwrap();
let new_pos = self.data[idx].logical_pos + amount;
self.move_to(idx, new_pos)
self.move_to(idx, new_pos, true)
}
pub fn move_left(&mut self) {
@@ -870,7 +875,13 @@ impl<W: LayoutElement> FloatingSpace<W> {
self.move_by(Point::from((0., DIRECTIONAL_MOVE_PX)));
}
pub fn move_window(&mut self, id: Option<&W::Id>, x: PositionChange, y: PositionChange) {
pub fn move_window(
&mut self,
id: Option<&W::Id>,
x: PositionChange,
y: PositionChange,
animate: bool,
) {
let Some(id) = id.or(self.active_window_id.as_ref()) else {
return;
};
@@ -885,7 +896,8 @@ impl<W: LayoutElement> FloatingSpace<W> {
PositionChange::SetFixed(y) => new_pos.y = y + self.working_area.loc.y,
PositionChange::AdjustFixed(y) => new_pos.y += y,
}
self.move_to(idx, new_pos);
self.move_to(idx, new_pos, animate);
}
pub fn center_window(&mut self) {
@@ -895,7 +907,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
let idx = self.idx_of(active_id).unwrap();
let new_pos = center_preferring_top_left_in_area(self.working_area, self.data[idx].size);
self.move_to(idx, new_pos);
self.move_to(idx, new_pos, true);
}
pub fn descendants_added(&mut self, id: &W::Id) -> bool {
+5 -3
View File
@@ -2755,6 +2755,7 @@ impl<W: LayoutElement> Layout<W> {
id: Option<&W::Id>,
x: PositionChange,
y: PositionChange,
animate: bool,
) {
if let Some(InteractiveMoveState::Moving(move_)) = &mut self.interactive_move {
if id.is_none() || id == Some(move_.tile.window().id()) {
@@ -2771,7 +2772,7 @@ impl<W: LayoutElement> Layout<W> {
let Some(workspace) = workspace else {
return;
};
workspace.move_floating_window(id, x, y);
workspace.move_floating_window(id, x, y, animate);
}
pub fn focus_output(&mut self, output: &Output) {
@@ -4450,6 +4451,7 @@ mod tests {
x: PositionChange,
#[proptest(strategy = "arbitrary_position_change()")]
y: PositionChange,
animate: bool,
},
SetParent {
#[proptest(strategy = "1..=5usize")]
@@ -4975,9 +4977,9 @@ mod tests {
Op::SwitchFocusFloatingTiling => {
layout.switch_focus_floating_tiling();
}
Op::MoveFloatingWindow { id, x, y } => {
Op::MoveFloatingWindow { id, x, y, animate } => {
let id = id.filter(|id| layout.has_window(id));
layout.move_floating_window(id.as_ref(), x, y);
layout.move_floating_window(id.as_ref(), x, y, animate);
}
Op::SetParent {
id,
+2 -1
View File
@@ -1190,11 +1190,12 @@ impl<W: LayoutElement> Workspace<W> {
id: Option<&W::Id>,
x: PositionChange,
y: PositionChange,
animate: bool,
) {
if id.map_or(self.floating_is_active.get(), |id| {
self.floating.has_window(id)
}) {
self.floating.move_window(id, x, y);
self.floating.move_window(id, x, y, animate);
} else {
// If the target tile isn't floating, set its stored floating position.
let tile = if let Some(id) = id {