atagen

monolith

public
Star0
Watch0

Commit b001ce7817ed

tarball

atagen <boss@atagen.co>2026-10-19 09:24 UTC

3 files changed+24-3
layout: keep shown scratchpads centred on their output

A scratchpad kept wherever its float rect last pointed, so a resize, a move between outputs or a rescale left it off centre. Its rect now only supplies the size, shrunk to fit, and arrange always centres it on the output's usable area.
Modified file: crates/layout/src/lib.rs+7 additions−2 deletions
@@ -784,7 +784,7 @@ impl Layout {
784784 && sp.output == Some(o)
785785 && let Some(r) = self.windows[sp.windows[i]].float_rect
786786 {
787- floating.push((sp.windows[i], r));
787+ floating.push((sp.windows[i], centre_in(out.usable(), r.w, r.h)));
788788 }
789789 }
790790 let fullscreen = self
@@ -936,7 +936,12 @@ fn inset(r: Rect, by: f64) -> Rect {
936936 }
937937
938938 fn centred(area: Rect, frac: f64) -> Rect {
939- let (w, h) = (area.w * frac, area.h * frac);
939+ centre_in(area, area.w * frac, area.h * frac)
940+}
941+
942+/// A w by h rect centred in area, shrunk to fit it.
943+pub(crate) fn centre_in(area: Rect, w: f64, h: f64) -> Rect {
944+ let (w, h) = (w.min(area.w), h.min(area.h));
940945 Rect::new(
941946 area.x + (area.w - w) / 2.0,
942947 area.y + (area.h - h) / 2.0,
Modified file: crates/layout/src/scratchpad.rs+2 additions−1 deletions
@@ -1,4 +1,4 @@
1-use crate::{Layout, Scratchpad, WindowId, centred, translate};
1+use crate::{Layout, Scratchpad, WindowId, centre_in, centred, translate};
22
33 impl Layout {
44 /// Adds a window to a named scratchpad, creating it. Scratchpad windows
@@ -62,6 +62,7 @@ impl Layout {
6262 };
6363 win.output = Some(o);
6464 }
65+ win.float_rect = win.float_rect.map(|r| centre_in(usable, r.w, r.h));
6566 self.focus(w);
6667 Some(w)
6768 }
Modified file: crates/layout/src/tests.rs+15 additions
@@ -714,3 +714,18 @@ fn dragging_a_split_moves_just_that_split() {
714714 assert!(rect(&l, b).h > 1.0);
715715 l.check();
716716 }
717+
718+#[test]
719+fn scratchpads_stay_centred_whatever_their_rect() {
720+ let mut l = Layout::default();
721+ let o = l.add_output("a", AREA);
722+ let w = l.add_window(Some(o), None, Some(Rect::new(10.0, 20.0, 300.0, 200.0)));
723+ l.scratchpad_add(w, "s");
724+ l.summon("s");
725+ l.set_float_rect(w, Rect::new(0.0, 0.0, 500.0, 5000.0));
726+ let r = l.arrange(o).floating.iter().find(|p| p.0 == w).unwrap().1;
727+ let area = l.output(o).unwrap().usable();
728+ assert_eq!((r.w, r.h), (500.0, area.h));
729+ assert_eq!(r.x + r.w / 2.0, area.x + area.w / 2.0);
730+ assert_eq!(r.y, area.y);
731+}