aboutsummaryrefslogtreecommitdiff
path: root/src/layout/workspace.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-12-24 10:51:00 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-12-30 20:12:37 +0300
commit53e1c58cc53c3868c236cc8877816ed4aab5b7b0 (patch)
tree58135cd15e08fe8e7c89912da00fa89de4afcb22 /src/layout/workspace.rs
parent4b9ecdd11d146df44320eba12bead3e9677a2060 (diff)
downloadniri-53e1c58cc53c3868c236cc8877816ed4aab5b7b0.tar.gz
niri-53e1c58cc53c3868c236cc8877816ed4aab5b7b0.tar.bz2
niri-53e1c58cc53c3868c236cc8877816ed4aab5b7b0.zip
Remember floating window position
Diffstat (limited to 'src/layout/workspace.rs')
-rw-r--r--src/layout/workspace.rs44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/layout/workspace.rs b/src/layout/workspace.rs
index 00dc5a58..6feb7ce9 100644
--- a/src/layout/workspace.rs
+++ b/src/layout/workspace.rs
@@ -18,7 +18,7 @@ use super::scrolling::{
Column, ColumnWidth, InsertHint, InsertPosition, ScrollingSpace, ScrollingSpaceRenderElement,
};
use super::tile::{Tile, TileRenderSnapshot};
-use super::{InteractiveResizeData, LayoutElement, Options, RemovedTile};
+use super::{InteractiveResizeData, LayoutElement, Options, RemovedTile, SizeFrac};
use crate::animation::Clock;
use crate::niri_render_elements;
use crate::render_helpers::renderer::NiriRenderer;
@@ -503,7 +503,7 @@ impl<W: LayoutElement> Workspace<W> {
// If the tile is pending fullscreen, open it in the scrolling layout where it can go
// fullscreen.
if is_floating && !tile.window().is_pending_fullscreen() {
- self.add_floating_tile(tile, None, activate);
+ self.add_floating_tile(tile, activate);
} else {
self.add_tile(None, tile, activate, width, is_full_width);
}
@@ -526,14 +526,9 @@ impl<W: LayoutElement> Workspace<W> {
}
}
- pub fn add_floating_tile(
- &mut self,
- tile: Tile<W>,
- pos: Option<Point<f64, Logical>>,
- activate: bool,
- ) {
+ pub fn add_floating_tile(&mut self, tile: Tile<W>, activate: bool) {
self.enter_output_for_window(tile.window());
- self.floating.add_tile(tile, pos, activate);
+ self.floating.add_tile(tile, activate);
if activate || self.scrolling.is_empty() {
self.floating_is_active = FloatingActive::Yes;
@@ -578,7 +573,7 @@ impl<W: LayoutElement> Workspace<W> {
pub fn add_tile_right_of(
&mut self,
right_of: &W::Id,
- tile: Tile<W>,
+ mut tile: Tile<W>,
width: ColumnWidth,
is_full_width: bool,
is_floating: bool,
@@ -605,8 +600,10 @@ impl<W: LayoutElement> Workspace<W> {
let pos = render_pos
+ (right_of_tile.tile_size().to_point() - tile_size.to_point()).downscale(2.);
let pos = self.floating.clamp_within_working_area(pos, tile_size);
+ let pos = self.floating.logical_to_size_frac(pos);
+ tile.set_floating_pos(pos);
- self.floating.add_tile(tile, Some(pos), activate);
+ self.floating.add_tile(tile, activate);
if activate {
self.floating_is_active = FloatingActive::Yes;
}
@@ -1087,12 +1084,18 @@ impl<W: LayoutElement> Workspace<W> {
} else {
let mut removed = self.scrolling.remove_tile(&id, Transaction::new());
removed.tile.stop_move_animations();
- 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);
+
+ // Come up with a default floating position close to the tile position.
+ if removed.tile.floating_pos().is_none() {
+ let pos = self.floating.clamp_within_working_area(
+ render_pos + Point::from((50., 50.)),
+ removed.tile.tile_size(),
+ );
+ let pos = self.floating.logical_to_size_frac(pos);
+ removed.tile.set_floating_pos(pos);
+ }
+
+ self.floating.add_tile(removed.tile, target_is_active);
if target_is_active {
self.floating_is_active = FloatingActive::Yes;
}
@@ -1436,6 +1439,13 @@ impl<W: LayoutElement> Workspace<W> {
self.floating_is_active.get()
}
+ pub fn floating_logical_to_size_frac(
+ &self,
+ logical_pos: Point<f64, Logical>,
+ ) -> Point<f64, SizeFrac> {
+ self.floating.logical_to_size_frac(logical_pos)
+ }
+
#[cfg(test)]
pub fn scrolling(&self) -> &ScrollingSpace<W> {
&self.scrolling