mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-22 02:00:18 +07:00
Add default-floating-position relative-to property
This commit is contained in:
+23
-7
@@ -2,7 +2,7 @@ use std::cmp::max;
|
||||
use std::iter::zip;
|
||||
use std::rc::Rc;
|
||||
|
||||
use niri_config::PresetSize;
|
||||
use niri_config::{PresetSize, RelativeTo};
|
||||
use niri_ipc::{PositionChange, SizeChange};
|
||||
use smithay::backend::renderer::gles::GlesRenderer;
|
||||
use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size};
|
||||
@@ -415,12 +415,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
|
||||
}
|
||||
}
|
||||
|
||||
let pos = tile.floating_pos.map(|pos| self.scale_by_working_area(pos));
|
||||
let pos = pos.or_else(|| {
|
||||
tile.default_floating_logical_pos()
|
||||
.map(|pos| pos + self.working_area.loc)
|
||||
});
|
||||
let pos = pos.unwrap_or_else(|| {
|
||||
let pos = self.stored_or_default_tile_pos(&tile).unwrap_or_else(|| {
|
||||
center_preferring_top_left_in_area(self.working_area, tile.tile_size())
|
||||
});
|
||||
|
||||
@@ -1191,6 +1186,27 @@ impl<W: LayoutElement> FloatingSpace<W> {
|
||||
Size::from((width, height))
|
||||
}
|
||||
|
||||
pub fn stored_or_default_tile_pos(&self, tile: &Tile<W>) -> Option<Point<f64, Logical>> {
|
||||
let pos = tile.floating_pos.map(|pos| self.scale_by_working_area(pos));
|
||||
pos.or_else(|| {
|
||||
tile.window().rules().default_floating_position.map(|pos| {
|
||||
let relative_to = pos.relative_to;
|
||||
let size = tile.tile_size();
|
||||
let area = self.working_area;
|
||||
|
||||
let mut pos = Point::from((pos.x.0, pos.y.0));
|
||||
if relative_to == RelativeTo::TopRight || relative_to == RelativeTo::BottomRight {
|
||||
pos.x = area.size.w - size.w - pos.x;
|
||||
}
|
||||
if relative_to == RelativeTo::BottomLeft || relative_to == RelativeTo::BottomRight {
|
||||
pos.y = area.size.h - size.h - pos.y;
|
||||
}
|
||||
|
||||
pos + self.working_area.loc
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn view_size(&self) -> Size<f64, Logical> {
|
||||
self.view_size
|
||||
|
||||
@@ -999,11 +999,6 @@ impl<W: LayoutElement> Tile<W> {
|
||||
&self.options
|
||||
}
|
||||
|
||||
pub fn default_floating_logical_pos(&self) -> Option<Point<f64, Logical>> {
|
||||
let pos = self.window().rules().default_floating_position?;
|
||||
Some(Point::from((pos.x.0, pos.y.0)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub fn view_size(&self) -> Size<f64, Logical> {
|
||||
self.view_size
|
||||
|
||||
+3
-10
@@ -1143,9 +1143,8 @@ impl<W: LayoutElement> Workspace<W> {
|
||||
removed.tile.stop_move_animations();
|
||||
|
||||
// Come up with a default floating position close to the tile position.
|
||||
if removed.tile.floating_pos.is_none()
|
||||
&& removed.tile.default_floating_logical_pos().is_none()
|
||||
{
|
||||
let stored_or_default = self.floating.stored_or_default_tile_pos(&removed.tile);
|
||||
if stored_or_default.is_none() {
|
||||
let offset = if self.options.center_focused_column == CenterFocusedColumn::Always {
|
||||
Point::from((0., 0.))
|
||||
} else {
|
||||
@@ -1236,13 +1235,7 @@ impl<W: LayoutElement> Workspace<W> {
|
||||
};
|
||||
|
||||
let working_area_loc = self.floating.working_area().loc;
|
||||
let pos = tile
|
||||
.floating_pos
|
||||
.map(|pos| self.floating.scale_by_working_area(pos));
|
||||
let pos = pos.or_else(|| {
|
||||
tile.default_floating_logical_pos()
|
||||
.map(|pos| pos + working_area_loc)
|
||||
});
|
||||
let pos = self.floating.stored_or_default_tile_pos(tile);
|
||||
|
||||
// If there's no stored floating position, we can only set both components at once, not
|
||||
// adjust.
|
||||
|
||||
Reference in New Issue
Block a user