aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartino Ferrari <manda.mgf@gmail.com>2025-03-01 18:46:27 +0100
committerGitHub <noreply@github.com>2025-03-01 17:46:27 +0000
commit36b28d9b96107441e3f8502a61f598fb666ec492 (patch)
tree237da44be4a0b4ab10a752b3585789cbebf251c5
parent66113d7d76f6cf7d06e2ccde9281ff9bafab126c (diff)
downloadniri-36b28d9b96107441e3f8502a61f598fb666ec492.tar.gz
niri-36b28d9b96107441e3f8502a61f598fb666ec492.tar.bz2
niri-36b28d9b96107441e3f8502a61f598fb666ec492.zip
Added top, left, bottom and right floating windows alignement (#1169)
* feat: added top, left, bottom, right alignement options * feat: implemented extra alignement * feat: added example * doc: updated documentation with extra alignements * doc: moved example in wiki and typo correction * fix: relative position should be positive and not negative * fixes --------- Co-authored-by: Martino Ferrari <martinogiordano.ferrari@iter.org> Co-authored-by: Ivan Molodetskikh <yalterz@gmail.com>
-rw-r--r--niri-config/src/lib.rs4
-rw-r--r--src/layout/floating.rs16
-rw-r--r--wiki/Configuration:-Window-Rules.md24
3 files changed, 41 insertions, 3 deletions
diff --git a/niri-config/src/lib.rs b/niri-config/src/lib.rs
index bc941bb7..fc5867aa 100644
--- a/niri-config/src/lib.rs
+++ b/niri-config/src/lib.rs
@@ -1355,6 +1355,10 @@ pub enum RelativeTo {
TopRight,
BottomLeft,
BottomRight,
+ Top,
+ Bottom,
+ Left,
+ Right,
}
#[derive(Debug, Default, PartialEq)]
diff --git a/src/layout/floating.rs b/src/layout/floating.rs
index 2a4054bd..4fd7c7ee 100644
--- a/src/layout/floating.rs
+++ b/src/layout/floating.rs
@@ -1206,12 +1206,24 @@ impl<W: LayoutElement> FloatingSpace<W> {
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 {
+ if relative_to == RelativeTo::TopRight
+ || relative_to == RelativeTo::BottomRight
+ || relative_to == RelativeTo::Right
+ {
pos.x = area.size.w - size.w - pos.x;
}
- if relative_to == RelativeTo::BottomLeft || relative_to == RelativeTo::BottomRight {
+ if relative_to == RelativeTo::BottomLeft
+ || relative_to == RelativeTo::BottomRight
+ || relative_to == RelativeTo::Bottom
+ {
pos.y = area.size.h - size.h - pos.y;
}
+ if relative_to == RelativeTo::Top || relative_to == RelativeTo::Bottom {
+ pos.x += area.size.w / 2.0 - size.w / 2.0
+ }
+ if relative_to == RelativeTo::Left || relative_to == RelativeTo::Right {
+ pos.y += area.size.h / 2.0 - size.h / 2.0
+ }
pos + self.working_area.loc
})
diff --git a/wiki/Configuration:-Window-Rules.md b/wiki/Configuration:-Window-Rules.md
index 591c5731..5f3d9b49 100644
--- a/wiki/Configuration:-Window-Rules.md
+++ b/wiki/Configuration:-Window-Rules.md
@@ -609,10 +609,11 @@ Afterward, the window will remember its last floating position.
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.
The position uses logical coordinates relative to the working area.
-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`.
+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`, `top`, `bottom`, `left`, or `right`.
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.
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.
+When only one side is specified (e.g. top) the window will align to the center of that side.
The coordinates change direction based on `relative-to`.
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.
@@ -628,6 +629,27 @@ window-rule {
}
```
+You can use single-side `relative-to` to get a dropdown-like effect.
+
+```kdl
+// Example: a "dropdown" terminal.
+window-rule {
+ // Match by "dropdown" app ID.
+ // You need to set this app ID when running your terminal, e.g.:
+ // spawn "alacritty" "--class" "dropdown"
+ match app-id="^dropdown$"
+
+ // Open it as floating.
+ open-floating true
+ // Anchor to the top edge of the screen.
+ default-floating-position x=0 y=0 relative-to="top"
+ // Half of the screen high.
+ default-window-height { proportion 0.5; }
+ // 80% of the screen wide.
+ default-column-width { proportion 0.8; }
+}
+```
+
#### `scroll-factor`
<sup>Since: 25.02</sup>