forge
Explore
Log in

Don't you dare go Hollow

Add default-floating-position window rule

Browse files at this commit

3c2e1554c6f1fe0d7d96094aa93f72f4ced613e5Ivan MolodetskikhParent: 744955b
niri-config/src/lib.rsmodified+15 -0
@@ -1019,6 +1019,8 @@ pub struct WindowRule {
10191019 pub block_out_from: Option<BlockOutFrom>,
10201020 #[knuffel(child, unwrap(argument))]
10211021 pub variable_refresh_rate: Option<bool>,
1022+ #[knuffel(child)]
1023+ pub default_floating_position: Option<FoIPosition>,
10221024 }
10231025
10241026 #[derive(knuffel::Decode, Debug, Default, Clone, PartialEq)]
@@ -1082,6 +1084,14 @@ pub struct BorderRule {
10821084 pub inactive_gradient: Option<Gradient>,
10831085 }
10841086
1087+#[derive(knuffel::Decode, Debug, Clone, Copy, PartialEq)]
1088+pub struct FoIPosition {
1089+ #[knuffel(property)]
1090+ pub x: FloatOrInt<-65535, 65535>,
1091+ #[knuffel(property)]
1092+ pub y: FloatOrInt<-65535, 65535>,
1093+}
1094+
10851095 #[derive(Debug, Default, PartialEq)]
10861096 pub struct Binds(pub Vec<Bind>);
10871097
@@ -3192,6 +3202,7 @@ mod tests {
31923202 open-floating false
31933203 open-focused true
31943204 default-window-height { fixed 500; }
3205+ default-floating-position x=100 y=-200
31953206
31963207 focus-ring {
31973208 off
@@ -3476,6 +3487,10 @@ mod tests {
34763487 open_floating: Some(false),
34773488 open_focused: Some(true),
34783489 default_window_height: Some(DefaultPresetSize(Some(PresetSize::Fixed(500)))),
3490+ default_floating_position: Some(FoIPosition {
3491+ x: FloatOrInt(100.),
3492+ y: FloatOrInt(-200.),
3493+ }),
34793494 focus_ring: BorderRule {
34803495 off: true,
34813496 width: Some(FloatOrInt(3.)),
src/layout/floating.rsmodified+8 -6
@@ -415,12 +415,14 @@ impl<W: LayoutElement> FloatingSpace<W> {
415415 }
416416 }
417417
418- let pos = tile
419- .floating_pos
420- .map(|pos| self.scale_by_working_area(pos))
421- .unwrap_or_else(|| {
422- center_preferring_top_left_in_area(self.working_area, tile.tile_size())
423- });
418+ let pos = tile.floating_pos.map(|pos| self.scale_by_working_area(pos));
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())
425+ });
424426
425427 let data = Data::new(self.working_area, &tile, pos);
426428 self.data.insert(idx, data);
src/layout/tile.rsmodified+5 -0
@@ -999,6 +999,11 @@ impl<W: LayoutElement> Tile<W> {
999999 &self.options
10001000 }
10011001
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+
10021007 #[cfg(test)]
10031008 pub fn view_size(&self) -> Size<f64, Logical> {
10041009 self.view_size
src/layout/workspace.rsmodified+15 -4
@@ -1123,7 +1123,9 @@ impl<W: LayoutElement> Workspace<W> {
11231123 removed.tile.stop_move_animations();
11241124
11251125 // Come up with a default floating position close to the tile position.
1126- if removed.tile.floating_pos.is_none() {
1126+ if removed.tile.floating_pos.is_none()
1127+ && removed.tile.default_floating_logical_pos().is_none()
1128+ {
11271129 let offset = if self.options.center_focused_column == CenterFocusedColumn::Always {
11281130 Point::from((0., 0.))
11291131 } else {
@@ -1214,17 +1216,26 @@ impl<W: LayoutElement> Workspace<W> {
12141216 };
12151217
12161218 let working_area_loc = self.floating.working_area().loc;
1219+ let pos = tile
1220+ .floating_pos
1221+ .map(|pos| self.floating.scale_by_working_area(pos));
1222+ let pos = pos.or_else(|| {
1223+ tile.default_floating_logical_pos()
1224+ .map(|pos| pos + working_area_loc)
1225+ });
1226+
12171227 // If there's no stored floating position, we can only set both components at once, not
12181228 // adjust.
1219- let Some(pos) = tile.floating_pos.or_else(|| {
1229+ let pos = pos.or_else(|| {
12201230 (matches!(x, PositionChange::SetFixed(_))
12211231 && matches!(y, PositionChange::SetFixed(_)))
12221232 .then_some(Point::default())
1223- }) else {
1233+ });
1234+
1235+ let Some(mut pos) = pos else {
12241236 return;
12251237 };
12261238
1227- let mut pos = self.floating.scale_by_working_area(pos);
12281239 match x {
12291240 PositionChange::SetFixed(x) => pos.x = x + working_area_loc.x,
12301241 PositionChange::AdjustFixed(x) => pos.x += x,
src/window/mod.rsmodified+11 -1
@@ -1,6 +1,8 @@
11 use std::cmp::{max, min};
22
3-use niri_config::{BlockOutFrom, BorderRule, CornerRadius, Match, PresetSize, WindowRule};
3+use niri_config::{
4+ BlockOutFrom, BorderRule, CornerRadius, FoIPosition, Match, PresetSize, WindowRule,
5+};
46 use smithay::reexports::wayland_protocols::xdg::shell::server::xdg_toplevel;
57 use smithay::utils::{Logical, Size};
68 use smithay::wayland::compositor::with_states;
@@ -41,6 +43,9 @@ pub struct ResolvedWindowRules {
4143 /// - `Some(Some(width))`: set to a particular height.
4244 pub default_height: Option<Option<PresetSize>>,
4345
46+ /// Default floating position for this window.
47+ pub default_floating_position: Option<FoIPosition>,
48+
4449 /// Output to open this window on.
4550 pub open_on_output: Option<String>,
4651
@@ -137,6 +142,7 @@ impl ResolvedWindowRules {
137142 Self {
138143 default_width: None,
139144 default_height: None,
145+ default_floating_position: None,
140146 open_on_output: None,
141147 open_on_workspace: None,
142148 open_maximized: None,
@@ -219,6 +225,10 @@ impl ResolvedWindowRules {
219225 resolved.default_height = Some(x.0);
220226 }
221227
228+ if let Some(x) = rule.default_floating_position {
229+ resolved.default_floating_position = Some(x);
230+ }
231+
222232 if let Some(x) = rule.open_on_output.as_deref() {
223233 open_on_output = Some(x);
224234 }
wiki/Configuration:-Window-Rules.mdmodified+24 -0
@@ -52,6 +52,7 @@ window-rule {
5252 block-out-from "screencast"
5353 // block-out-from "screen-capture"
5454 variable-refresh-rate true
55+ default-floating-position x=100 y=200
5556
5657 focus-ring {
5758 // off
@@ -507,6 +508,29 @@ window-rule {
507508 }
508509 ```
509510
511+#### `default-floating-position`
512+
513+<sup>Since: next release</sup>
514+
515+Set the initial position for this window when it opens on, or moves to the floating layout.
516+
517+Afterward, the window will remember its last floating position.
518+
519+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.
520+
521+The position uses logical coordinates relative to the working area.
522+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.
523+
524+```kdl
525+// Open the Firefox picture-in-picture window at the top-left corner of the screen
526+// with a small gap.
527+window-rule {
528+ match app-id="firefox$" title="^Picture-in-Picture$"
529+
530+ default-floating-position x=32 y=32
531+}
532+```
533+
510534 #### `draw-border-with-background`
511535
512536 Override whether the border and the focus ring draw with a background.