mirror of
https://github.com/niri-wm/niri.git
synced 2026-06-24 02:01:18 +07:00
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>
This commit is contained in:
@@ -1355,6 +1355,10 @@ pub enum RelativeTo {
|
||||
TopRight,
|
||||
BottomLeft,
|
||||
BottomRight,
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, PartialEq)]
|
||||
|
||||
+14
-2
@@ -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
|
||||
})
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user