forge
Explore
Log in

Don't you dare go Hollow

Add default-floating-position relative-to property

Browse files at this commit

793e92e9d69f3640754d9ece40ddc7723cf49292Ivan MolodetskikhParent: a7c57f4
niri-config/src/lib.rsmodified+13 -1
@@ -1090,6 +1090,17 @@ pub struct FoIPosition {
1090 pub x: FloatOrInt<-65535, 65535>,1090 pub x: FloatOrInt<-65535, 65535>,
1091 #[knuffel(property)]1091 #[knuffel(property)]
1092 pub y: FloatOrInt<-65535, 65535>,1092 pub y: FloatOrInt<-65535, 65535>,
1093+ #[knuffel(property, default)]
1094+ pub relative_to: RelativeTo,
1095+}
1096+
1097+#[derive(knuffel::DecodeScalar, Debug, Default, Clone, Copy, PartialEq, Eq)]
1098+pub enum RelativeTo {
1099+ #[default]
1100+ TopLeft,
1101+ TopRight,
1102+ BottomLeft,
1103+ BottomRight,
1093 }1104 }
1094 1105
1095 #[derive(Debug, Default, PartialEq)]1106 #[derive(Debug, Default, PartialEq)]
@@ -3214,7 +3225,7 @@ mod tests {
3214 open-floating false3225 open-floating false
3215 open-focused true3226 open-focused true
3216 default-window-height { fixed 500; }3227 default-window-height { fixed 500; }
3217- default-floating-position x=100 y=-2003228+ default-floating-position x=100 y=-200 relative-to="bottom-left"
3218 3229
3219 focus-ring {3230 focus-ring {
3220 off3231 off
@@ -3502,6 +3513,7 @@ mod tests {
3502 default_floating_position: Some(FoIPosition {3513 default_floating_position: Some(FoIPosition {
3503 x: FloatOrInt(100.),3514 x: FloatOrInt(100.),
3504 y: FloatOrInt(-200.),3515 y: FloatOrInt(-200.),
3516+ relative_to: RelativeTo::BottomLeft,
3505 }),3517 }),
3506 focus_ring: BorderRule {3518 focus_ring: BorderRule {
3507 off: true,3519 off: true,
src/layout/floating.rsmodified+23 -7
@@ -2,7 +2,7 @@ use std::cmp::max;
2 use std::iter::zip;2 use std::iter::zip;
3 use std::rc::Rc;3 use std::rc::Rc;
4 4
5-use niri_config::PresetSize;5+use niri_config::{PresetSize, RelativeTo};
6 use niri_ipc::{PositionChange, SizeChange};6 use niri_ipc::{PositionChange, SizeChange};
7 use smithay::backend::renderer::gles::GlesRenderer;7 use smithay::backend::renderer::gles::GlesRenderer;
8 use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size};8 use smithay::utils::{Logical, Point, Rectangle, Scale, Serial, Size};
@@ -415,12 +415,7 @@ impl<W: LayoutElement> FloatingSpace<W> {
415 }415 }
416 }416 }
417 417
418- let pos = tile.floating_pos.map(|pos| self.scale_by_working_area(pos));418+ let pos = self.stored_or_default_tile_pos(&tile).unwrap_or_else(|| {
419- let pos = pos.or_else(|| {
420- tile.default_floating_logical_pos()
421- .map(|pos| pos + self.working_area.loc)
422- });
423- let pos = pos.unwrap_or_else(|| {
424 center_preferring_top_left_in_area(self.working_area, tile.tile_size())419 center_preferring_top_left_in_area(self.working_area, tile.tile_size())
425 });420 });
426 421
@@ -1191,6 +1186,27 @@ impl<W: LayoutElement> FloatingSpace<W> {
1191 Size::from((width, height))1186 Size::from((width, height))
1192 }1187 }
1193 1188
1189+ pub fn stored_or_default_tile_pos(&self, tile: &Tile<W>) -> Option<Point<f64, Logical>> {
1190+ let pos = tile.floating_pos.map(|pos| self.scale_by_working_area(pos));
1191+ pos.or_else(|| {
1192+ tile.window().rules().default_floating_position.map(|pos| {
1193+ let relative_to = pos.relative_to;
1194+ let size = tile.tile_size();
1195+ let area = self.working_area;
1196+
1197+ let mut pos = Point::from((pos.x.0, pos.y.0));
1198+ if relative_to == RelativeTo::TopRight || relative_to == RelativeTo::BottomRight {
1199+ pos.x = area.size.w - size.w - pos.x;
1200+ }
1201+ if relative_to == RelativeTo::BottomLeft || relative_to == RelativeTo::BottomRight {
1202+ pos.y = area.size.h - size.h - pos.y;
1203+ }
1204+
1205+ pos + self.working_area.loc
1206+ })
1207+ })
1208+ }
1209+
1194 #[cfg(test)]1210 #[cfg(test)]
1195 pub fn view_size(&self) -> Size<f64, Logical> {1211 pub fn view_size(&self) -> Size<f64, Logical> {
1196 self.view_size1212 self.view_size
src/layout/tile.rsmodified+0 -5
@@ -999,11 +999,6 @@ impl<W: LayoutElement> Tile<W> {
999 &self.options999 &self.options
1000 }1000 }
1001 1001
1002- pub fn default_floating_logical_pos(&self) -> Option<Point<f64, Logical>> {
1003- let pos = self.window().rules().default_floating_position?;
1004- Some(Point::from((pos.x.0, pos.y.0)))
1005- }
1006-
1007 #[cfg(test)]1002 #[cfg(test)]
1008 pub fn view_size(&self) -> Size<f64, Logical> {1003 pub fn view_size(&self) -> Size<f64, Logical> {
1009 self.view_size1004 self.view_size
src/layout/workspace.rsmodified+3 -10
@@ -1143,9 +1143,8 @@ impl<W: LayoutElement> Workspace<W> {
1143 removed.tile.stop_move_animations();1143 removed.tile.stop_move_animations();
1144 1144
1145 // Come up with a default floating position close to the tile position.1145 // Come up with a default floating position close to the tile position.
1146- if removed.tile.floating_pos.is_none()1146+ let stored_or_default = self.floating.stored_or_default_tile_pos(&removed.tile);
1147- && removed.tile.default_floating_logical_pos().is_none()1147+ if stored_or_default.is_none() {
1148- {
1149 let offset = if self.options.center_focused_column == CenterFocusedColumn::Always {1148 let offset = if self.options.center_focused_column == CenterFocusedColumn::Always {
1150 Point::from((0., 0.))1149 Point::from((0., 0.))
1151 } else {1150 } else {
@@ -1236,13 +1235,7 @@ impl<W: LayoutElement> Workspace<W> {
1236 };1235 };
1237 1236
1238 let working_area_loc = self.floating.working_area().loc;1237 let working_area_loc = self.floating.working_area().loc;
1239- let pos = tile1238+ let pos = self.floating.stored_or_default_tile_pos(tile);
1240- .floating_pos
1241- .map(|pos| self.floating.scale_by_working_area(pos));
1242- let pos = pos.or_else(|| {
1243- tile.default_floating_logical_pos()
1244- .map(|pos| pos + working_area_loc)
1245- });
1246 1239
1247 // If there's no stored floating position, we can only set both components at once, not1240 // If there's no stored floating position, we can only set both components at once, not
1248 // adjust.1241 // adjust.
wiki/Configuration:-Window-Rules.mdmodified+10 -3
@@ -52,7 +52,7 @@ window-rule {
52 block-out-from "screencast"52 block-out-from "screencast"
53 // block-out-from "screen-capture"53 // block-out-from "screen-capture"
54 variable-refresh-rate true54 variable-refresh-rate true
55- default-floating-position x=100 y=20055+ default-floating-position x=100 y=200 relative-to="bottom-left"
56 56
57 focus-ring {57 focus-ring {
58 // off58 // off
@@ -523,15 +523,22 @@ Afterward, the window will remember its last floating position.
523 By default, new floating windows open at the center of the screen, and windows from the tiling layout open close to their visual screen position.523 By default, new floating windows open at the center of the screen, and windows from the tiling layout open close to their visual screen position.
524 524
525 The position uses logical coordinates relative to the working area.525 The position uses logical coordinates relative to the working area.
526+By default, they are relative to the top-left corner of the working area, but you can change this by setting `relative-to` to one of these values: `top-left`, `top-right`, `bottom-left`, `bottom-right`.
527+
526 For example, if you have a bar at the top, then `x=0 y=0` will put the top-left corner of the window directly below the bar.528 For example, if you have a bar at the top, then `x=0 y=0` will put the top-left corner of the window directly below the bar.
529+If instead you write `x=0 y=0 relative-to="top-right"`, then the top-right corner of the window will align with the top-right corner of the workspace, also directly below the bar.
530+
531+The coordinates change direction based on `relative-to`.
532+For example, by default (top-left), `x=100 y=200` will put the window 100 pixels to the right and 200 pixels down from the top-left corner.
533+If you use `x=100 y=200 relative-to="bottom-left"`, it will put the window 100 pixels to the right and 200 pixels *up* from the bottom-left corner.
527 534
528 ```kdl535 ```kdl
529-// Open the Firefox picture-in-picture window at the top-left corner of the screen536+// Open the Firefox picture-in-picture window at the bottom-left corner of the screen
530 // with a small gap.537 // with a small gap.
531 window-rule {538 window-rule {
532 match app-id="firefox$" title="^Picture-in-Picture$"539 match app-id="firefox$" title="^Picture-in-Picture$"
533 540
534- default-floating-position x=32 y=32541+ default-floating-position x=32 y=32 relative-to="bottom-left"
535 }542 }
536 ```543 ```
537 544