aboutsummaryrefslogtreecommitdiff
path: root/src/layout/workspace.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-12-15 09:07:44 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-12-30 20:12:37 +0300
commitc008e1c5bcab360425780997f70818fa4252c938 (patch)
treefe8b7138ddc3b7bc9a3616cbf42cf8d8defb807e /src/layout/workspace.rs
parent1aa60f0da3e7f1a0bf50d6b88d59db6ba094d4f0 (diff)
downloadniri-c008e1c5bcab360425780997f70818fa4252c938.tar.gz
niri-c008e1c5bcab360425780997f70818fa4252c938.tar.bz2
niri-c008e1c5bcab360425780997f70818fa4252c938.zip
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.
Diffstat (limited to 'src/layout/workspace.rs')
-rw-r--r--src/layout/workspace.rs12
1 files changed, 9 insertions, 3 deletions
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<W: LayoutElement> Workspace<W> {
.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<W: LayoutElement> Workspace<W> {
} 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 {