From c008e1c5bcab360425780997f70818fa4252c938 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sun, 15 Dec 2024 09:07:44 +0300 Subject: floating: Implement smarter clamping for window location A small part of the window always remains on-screen regardless of the working area changes. Interactive move lets the user position the window anywhere; automatic actions like toggle-window-floating and dialog opening try to put the window fully on-screen. The size-fraction canonical floating window position remains unclamped, and clamping happens when recomputing the logical position. --- src/layout/workspace.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/layout/workspace.rs') diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs index 65ff7863..bfecfcde 100644 --- a/src/layout/workspace.rs +++ b/src/layout/workspace.rs @@ -572,11 +572,14 @@ impl Workspace { .tiles_with_render_positions() .find(|(tile, _)| tile.window().id() == right_of) .unwrap(); + // Position the new tile in the center above the right_of tile. Think a dialog // opening on top of a window. + let tile_size = tile.tile_size(); let pos = render_pos - + (right_of_tile.tile_size().to_point() - tile.tile_size().to_point()) - .downscale(2.); + + (right_of_tile.tile_size().to_point() - tile_size.to_point()).downscale(2.); + let pos = self.floating.clamp_within_working_area(pos, tile_size); + self.floating.add_tile(tile, Some(pos), activate); if activate { self.floating_is_active = true; @@ -929,7 +932,10 @@ impl Workspace { } else { let mut removed = self.scrolling.remove_tile(&id, Transaction::new()); removed.tile.stop_move_animations(); - let pos = render_pos + Point::from((50., 50.)); + let pos = self.floating.clamp_within_working_area( + render_pos + Point::from((50., 50.)), + removed.tile.tile_size(), + ); self.floating .add_tile(removed.tile, Some(pos), target_is_active); if target_is_active { -- cgit