aboutsummaryrefslogtreecommitdiff
path: root/src/layout/mod.rs
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-08-15 10:47:27 +0300
committerIvan Molodetskikh <yalterz@gmail.com>2024-08-15 10:50:38 +0300
commit66f23c39809eef827ef7f47fab7bdbf68dd69a26 (patch)
treee8470d17649f6872be0173e248d16852af91282a /src/layout/mod.rs
parent7a6ab31ad762f1f911dafb9fc0ade83d19c66d45 (diff)
downloadniri-66f23c39809eef827ef7f47fab7bdbf68dd69a26.tar.gz
niri-66f23c39809eef827ef7f47fab7bdbf68dd69a26.tar.bz2
niri-66f23c39809eef827ef7f47fab7bdbf68dd69a26.zip
layout: Implement weighted height distribution
The intention is to make columns add up to the working area height most of the time, while still preserving the ability to have one fixed-height window. Automatic heights are now distributed according to their weight, rather than evenly. This is similar to flex-grow in CSS or fraction in Typst. Resizing one window in a column still makes that window fixed, however it changes all other windows to automatic height, computing their weights in such a way as to preserve their apparent heights.
Diffstat (limited to 'src/layout/mod.rs')
-rw-r--r--src/layout/mod.rs95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/layout/mod.rs b/src/layout/mod.rs
index 97a839c1..39fa2837 100644
--- a/src/layout/mod.rs
+++ b/src/layout/mod.rs
@@ -4263,6 +4263,101 @@ mod tests {
compute_working_area(&output, struts);
}
+ #[test]
+ fn set_window_height_recomputes_to_auto() {
+ let ops = [
+ Op::AddOutput(1),
+ Op::AddWindow {
+ id: 0,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: Default::default(),
+ },
+ Op::AddWindow {
+ id: 1,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: Default::default(),
+ },
+ Op::ConsumeOrExpelWindowLeft,
+ Op::AddWindow {
+ id: 2,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: Default::default(),
+ },
+ Op::ConsumeOrExpelWindowLeft,
+ Op::SetWindowHeight(SizeChange::SetFixed(100)),
+ Op::FocusWindowUp,
+ Op::SetWindowHeight(SizeChange::SetFixed(200)),
+ ];
+
+ check_ops(&ops);
+ }
+
+ #[test]
+ fn one_window_in_column_becomes_weight_1() {
+ let ops = [
+ Op::AddOutput(1),
+ Op::AddWindow {
+ id: 0,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: Default::default(),
+ },
+ Op::AddWindow {
+ id: 1,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: Default::default(),
+ },
+ Op::ConsumeOrExpelWindowLeft,
+ Op::AddWindow {
+ id: 2,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: Default::default(),
+ },
+ Op::ConsumeOrExpelWindowLeft,
+ Op::SetWindowHeight(SizeChange::SetFixed(100)),
+ Op::Communicate(2),
+ Op::FocusWindowUp,
+ Op::SetWindowHeight(SizeChange::SetFixed(200)),
+ Op::Communicate(1),
+ Op::CloseWindow(0),
+ Op::CloseWindow(1),
+ ];
+
+ check_ops(&ops);
+ }
+
+ #[test]
+ fn one_window_in_column_becomes_weight_1_after_fullscreen() {
+ let ops = [
+ Op::AddOutput(1),
+ Op::AddWindow {
+ id: 0,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: Default::default(),
+ },
+ Op::AddWindow {
+ id: 1,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: Default::default(),
+ },
+ Op::ConsumeOrExpelWindowLeft,
+ Op::AddWindow {
+ id: 2,
+ bbox: Rectangle::from_loc_and_size((0, 0), (100, 200)),
+ min_max_size: Default::default(),
+ },
+ Op::ConsumeOrExpelWindowLeft,
+ Op::SetWindowHeight(SizeChange::SetFixed(100)),
+ Op::Communicate(2),
+ Op::FocusWindowUp,
+ Op::SetWindowHeight(SizeChange::SetFixed(200)),
+ Op::Communicate(1),
+ Op::CloseWindow(0),
+ Op::FullscreenWindow(1),
+ ];
+
+ check_ops(&ops);
+ }
+
fn arbitrary_spacing() -> impl Strategy<Value = f64> {
// Give equal weight to:
// - 0: the element is disabled