9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 1 | use super::*; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 2 | use proptest::prelude::*; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 3 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 4 | const AREA: Rect = Rect::new(0.0, 0.0, 1000.0, 600.0); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 5 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 6 | #[derive(Clone, Debug)] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 7 | enum Op { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 8 | Add(u8, bool), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 9 | Remove(u8), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 10 | Focus(u8), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 11 | Move(Dir), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 12 | Block(Dir), |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 13 | Merge(Dir), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 14 | View(u8), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 15 | ToggleView(u8), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 16 | Retag(u8, u8), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 17 | Float(u8), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 18 | Expand(u8), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 19 | Flip, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 20 | Resize(bool, i8), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 21 | Scratch(u8), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 22 | Summon, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 23 | Unplug, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 24 | Replug, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 25 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 26 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 27 | fn dir() -> impl Strategy<Value = Dir> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 28 | prop_oneof![ |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 29 | Just(Dir::Left), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 30 | Just(Dir::Right), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 31 | Just(Dir::Up), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 32 | Just(Dir::Down) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 33 | ] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 34 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 35 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 36 | fn op() -> impl Strategy<Value = Op> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 37 | prop_oneof![ |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 38 | 4 => (0u8..4, prop::bool::weighted(0.15)).prop_map(|(t, f)| Op::Add(t, f)), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 39 | 1 => any::<u8>().prop_map(Op::Remove), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 40 | 3 => any::<u8>().prop_map(Op::Focus), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 41 | 4 => dir().prop_map(Op::Move), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 42 | 2 => dir().prop_map(Op::Block), |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 43 | 3 => dir().prop_map(Op::Merge), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 44 | 1 => (0u8..4).prop_map(Op::View), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 45 | 2 => (0u8..4).prop_map(Op::ToggleView), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 46 | 1 => (any::<u8>(), 0u8..4).prop_map(|(w, t)| Op::Retag(w, t)), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 47 | 1 => any::<u8>().prop_map(Op::Float), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 48 | 1 => (0u8..3).prop_map(Op::Expand), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 49 | 1 => Just(Op::Flip), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 50 | 1 => (any::<bool>(), any::<i8>()).prop_map(|(a, d)| Op::Resize(a, d)), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 51 | 1 => any::<u8>().prop_map(Op::Scratch), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 52 | 1 => Just(Op::Summon), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 53 | 1 => Just(Op::Unplug), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 54 | 1 => Just(Op::Replug), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 55 | ] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 56 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 57 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 58 | fn nth(l: &Layout, i: u8) -> Option<WindowId> { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 59 | let ids: Vec<WindowId> = l.windows().map(|(id, _)| id).collect(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 60 | (!ids.is_empty()).then(|| ids[i as usize % ids.len()]) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 61 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 62 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 63 | fn apply(l: &mut Layout, tags: &[TagId], op: &Op) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 64 | let active = l.active_output(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 65 | match *op { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 66 | Op::Add(t, f) => { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 67 | let w = l.add_window( |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 68 | None, |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 69 | Some(tags[t as usize]), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 70 | f.then(|| Rect::new(10.0, 10.0, 200.0, 100.0)), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 71 | ); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 72 | if l.visible(w) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 73 | l.focus(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 74 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 75 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 76 | Op::Remove(i) => nth(l, i).into_iter().for_each(|w| l.remove_window(w)), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 77 | Op::Focus(i) => { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 78 | if let Some(w) = nth(l, i).filter(|&w| l.visible(w)) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 79 | l.focus(w); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 80 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 81 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 82 | Op::Move(d) => { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 83 | l.move_window(d); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 84 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 85 | Op::Block(d) => { |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 86 | l.move_container(d); |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 87 | } |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 88 | Op::Merge(d) => { |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 89 | l.merge_window(d); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 90 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 91 | Op::View(t) => active.into_iter().for_each(|o| l.view(o, tags[t as usize])), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 92 | Op::ToggleView(t) => active |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 93 | .into_iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 94 | .for_each(|o| l.toggle_view(o, tags[t as usize])), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 95 | Op::Retag(i, t) => nth(l, i) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 96 | .into_iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 97 | .for_each(|w| l.set_tag(w, tags[t as usize])), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 98 | Op::Float(i) => nth(l, i).into_iter().for_each(|w| l.toggle_floating(w)), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 99 | Op::Expand(s) => { |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 100 | l.expand( |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 101 | [ |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 102 | ExpandScope::Window, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 103 | ExpandScope::Container, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 104 | ExpandScope::All, |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 105 | ][s as usize], |
4444c779eb48 | atagen | 2026-10-16 12:07 UTC | 106 | ); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 107 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 108 | Op::Flip => active.into_iter().for_each(|o| l.flip(o)), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 109 | Op::Resize(h, d) => { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 110 | let axis = if h { Axis::Horizontal } else { Axis::Vertical }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 111 | l.resize(axis, f64::from(d) / 200.0); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 112 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 113 | Op::Scratch(i) => nth(l, i).into_iter().for_each(|w| l.scratchpad_add(w, "s")), |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 114 | Op::Summon => { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 115 | l.summon("s"); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 116 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 117 | Op::Unplug => { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 118 | let b = l.outputs().find(|(_, out)| out.name == "b").map(|(o, _)| o); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 119 | if let Some(o) = b { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 120 | l.remove_output(o); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 121 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 122 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 123 | Op::Replug => { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 124 | if !l.outputs().any(|(_, out)| out.name == "b") { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 125 | l.add_output("b", Rect::new(1000.0, 0.0, 800.0, 600.0)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 126 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 127 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 128 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 129 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 130 | |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 131 | /// The area a tiled window gets, zero for floating or unplaced ones. |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 132 | fn tiled_area(l: &Layout, w: WindowId) -> f64 { |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 133 | let Some(o) = l.window(w).and_then(|x| x.output) else { |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 134 | return 0.0; |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 135 | }; |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 136 | l.arrange(o) |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 137 | .tiled |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 138 | .iter() |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 139 | .find(|p| p.window == w && p.visible) |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 140 | .map_or(0.0, |p| p.rect.w * p.rect.h) |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 141 | } |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 142 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 143 | fn check_geometry(l: &Layout) { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 144 | for (o, out) in l.outputs() { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 145 | let arr = l.arrange(o); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 146 | let mut drawn: Vec<WindowId> = arr |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 147 | .tiled |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 148 | .iter() |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 149 | .filter(|p| p.visible) |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 150 | .map(|p| p.window) |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 151 | .chain(arr.floating.iter().map(|&(w, _)| w)) |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 152 | .chain(arr.fullscreen) |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 153 | .collect(); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 154 | drawn.sort(); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 155 | drawn.dedup(); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 156 | let mut visible: Vec<WindowId> = l |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 157 | .windows() |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 158 | .filter(|&(w, win)| win.output == Some(o) && l.visible(w)) |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 159 | .map(|(w, _)| w) |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 160 | .collect(); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 161 | visible.sort(); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 162 | assert_eq!(drawn, visible, "arrangement disagrees with visible()"); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 163 | let shown: Vec<Rect> = arr |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 164 | .tiled |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 165 | .iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 166 | .filter(|p| p.visible) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 167 | .map(|p| p.rect) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 168 | .collect(); |
1c8e1b4009f5 | atagen | 2026-10-16 23:19 UTC | 169 | for p in arr.tiled.iter().filter(|p| !p.visible) { |
1c8e1b4009f5 | atagen | 2026-10-16 23:19 UTC | 170 | assert!(p.rect.w * p.rect.h <= 1e-6, "hidden {:?} has area", p.rect); |
1c8e1b4009f5 | atagen | 2026-10-16 23:19 UTC | 171 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 172 | for r in &shown { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 173 | assert!(r.w >= 0.0 && r.h >= 0.0); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 174 | assert!(r.x >= out.area.x - 1e-6 && r.right() <= out.area.right() + 1e-6); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 175 | assert!(r.y >= out.area.y - 1e-6 && r.bottom() <= out.area.bottom() + 1e-6); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 176 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 177 | for (i, a) in shown.iter().enumerate() { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 178 | for b in &shown[i + 1..] { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 179 | let ox = a.right().min(b.right()) - a.x.max(b.x); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 180 | let oy = a.bottom().min(b.bottom()) - a.y.max(b.y); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 181 | assert!(ox <= 1e-6 || oy <= 1e-6, "{a:?} overlaps {b:?}"); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 182 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 183 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 184 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 185 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 186 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 187 | proptest! { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 188 | #![proptest_config(ProptestConfig::with_cases(2000))] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 189 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 190 | #[test] |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 191 | fn random_commands_keep_the_model_sound( |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 192 | ops in prop::collection::vec(op(), 1..80), |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 193 | autotile in any::<bool>(), |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 194 | ) { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 195 | let mut l = Layout { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 196 | autotile, |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 197 | ..Layout::default() |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 198 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 199 | l.add_output("a", AREA); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 200 | l.add_output("b", Rect::new(1000.0, 0.0, 800.0, 600.0)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 201 | let tags = [l.homeless(), l.tag("1"), l.tag("2"), l.tag("3")]; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 202 | for op in &ops { |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 203 | let moving = matches!(op, Op::Move(_) | Op::Merge(_) | Op::Block(_)); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 204 | let shown_before = l.focused().filter(|&w| tiled_area(&l, w) > 1.0); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 205 | apply(&mut l, &tags, op); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 206 | l.check(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 207 | check_geometry(&l); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 208 | if moving && let Some(w) = shown_before { |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 209 | prop_assert!(tiled_area(&l, w) > 1.0, "{w:?} vanished after {op:?}"); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 210 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 211 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 212 | } |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 213 | |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 214 | #[test] |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 215 | fn replugging_restores_what_unplugging_moved(ops in prop::collection::vec(op(), 1..60)) { |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 216 | let mut l = Layout::default(); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 217 | l.add_output("a", AREA); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 218 | l.add_output("b", Rect::new(1000.0, 0.0, 800.0, 600.0)); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 219 | let tags = [l.homeless(), l.tag("1"), l.tag("2"), l.tag("3")]; |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 220 | for op in &ops { |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 221 | apply(&mut l, &tags, op); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 222 | } |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 223 | let Some(b) = l.outputs().find(|(_, out)| out.name == "b").map(|(o, _)| o) else { |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 224 | return Ok(()); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 225 | }; |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 226 | let before = |l: &Layout, o| { |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 227 | let out = l.output(o).unwrap(); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 228 | (out.tree.windows().collect::<Vec<_>>(), out.floating.clone(), out.viewed.clone()) |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 229 | }; |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 230 | let was = before(&l, b); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 231 | l.remove_output(b); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 232 | let b = l.add_output("b", Rect::new(1000.0, 0.0, 800.0, 600.0)); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 233 | l.check(); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 234 | prop_assert_eq!(before(&l, b), was); |
38125b3487d7 | atagen | 2026-10-17 05:02 UTC | 235 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 236 | } |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 237 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 238 | /// The hidden-slot rules from planner.html, demo 11. |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 239 | #[test] |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 240 | fn hidden_windows_keep_their_slots() { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 241 | let (a, b, c, d, e) = (1, 2, 3, 4, 5); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 242 | let mut t: Tree<u32> = Tree::default(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 243 | t.insert_row(a); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 244 | t.insert_after(d, a); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 245 | t.insert_after(b, d); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 246 | t.insert_row(c); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 247 | t.insert_after(e, c); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 248 | t.check(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 249 | let hidden = |w: u32| w != d && w != e; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 250 | let all = |_| true; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 251 | let rect = |t: &Tree<u32>, w| { |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 252 | t.arrange(AREA, 0.0, all) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 253 | .into_iter() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 254 | .find(|p| p.0 == w) |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 255 | .unwrap() |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 256 | .1 |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 257 | }; |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 258 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 259 | assert!(t.move_window(a, Dir::Right, hidden)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 260 | assert!(rect(&t, b).x < rect(&t, d).x && rect(&t, d).x < rect(&t, a).x); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 261 | |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 262 | assert!(t.move_window(c, Dir::Up, hidden)); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 263 | t.check(); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 264 | assert_eq!(rect(&t, e).w, AREA.w, "E is demoted to a row of its own"); |
9baaafa4b167 | atagen | 2026-10-16 10:04 UTC | 265 | } |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 266 | |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 267 | /// Moving out of a row toward a lane of hidden windows joins that lane, so |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 268 | /// they share it when shown again instead of a new lane opening between. |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 269 | #[test] |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 270 | fn moving_toward_a_hidden_lane_joins_it() { |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 271 | let (a, b, c, d, e) = (1, 2, 3, 4, 5); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 272 | let mut t: Tree<u32> = Tree::default(); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 273 | t.insert_row(a); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 274 | t.insert_after(b, a); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 275 | t.insert_after(c, b); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 276 | t.insert_row(d); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 277 | t.insert_after(e, c); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 278 | let tag_two = |w: u32| w != a && w != d; |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 279 | assert!(t.move_window(e, Dir::Down, tag_two)); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 280 | t.check(); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 281 | let all = t.arrange(AREA, 0.0, |_| true); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 282 | let rect = |w| all.iter().find(|p| p.0 == w).unwrap().1; |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 283 | assert_eq!(rect(e).y, rect(d).y); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 284 | assert!(rect(d).x < rect(e).x); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 285 | assert!(rect(a).y < rect(d).y); |
60f00dd4f2be | atagen | 2026-10-16 11:50 UTC | 286 | } |
91957f0ae29e | atagen | 2026-10-17 09:24 UTC | 287 | |
91957f0ae29e | atagen | 2026-10-17 09:24 UTC | 288 | #[test] |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 289 | fn merging_steps_out_of_a_stack_before_joining_another() { |
91957f0ae29e | atagen | 2026-10-17 09:24 UTC | 290 | let (a, b, c) = (1, 2, 3); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 291 | let stacked = || { |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 292 | let mut t: Tree<u32> = Tree::default(); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 293 | t.insert_row(a); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 294 | t.insert_after(b, a); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 295 | t.insert_after(c, b); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 296 | assert!(t.merge_window(b, Dir::Left, |_| true)); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 297 | t |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 298 | }; |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 299 | let rects = |t: &Tree<u32>| { |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 300 | t.check(); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 301 | let all = t.arrange(AREA, 0.0, |_| true); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 302 | move |w| all.iter().find(|p: &&(u32, Rect)| p.0 == w).unwrap().1 |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 303 | }; |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 304 | |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 305 | let mut t = stacked(); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 306 | assert!(t.merge_window(a, Dir::Right, |_| true)); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 307 | let rect = rects(&t); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 308 | assert!(rect(b).x < rect(a).x && rect(a).x < rect(c).x); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 309 | assert_eq!(rect(a).h, AREA.h); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 310 | assert!(t.merge_window(a, Dir::Right, |_| true)); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 311 | let rect = rects(&t); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 312 | assert_eq!(rect(a).x, rect(c).x); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 313 | |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 314 | let mut t = stacked(); |
91957f0ae29e | atagen | 2026-10-17 09:24 UTC | 315 | assert!(t.merge_window(a, Dir::Up, |_| true)); |
605c44c8c5fc | atagen | 2026-10-17 09:57 UTC | 316 | let rect = rects(&t); |
91957f0ae29e | atagen | 2026-10-17 09:24 UTC | 317 | assert_eq!(rect(a).w, AREA.w); |
91957f0ae29e | atagen | 2026-10-17 09:24 UTC | 318 | assert!(rect(a).bottom() <= rect(b).y && rect(b).y == rect(c).y); |
91957f0ae29e | atagen | 2026-10-17 09:24 UTC | 319 | } |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 320 | |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 321 | /// A window alone on screen in a container of hidden ones expands among the |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 322 | /// windows it is shown beside, not inside the container nobody can see. |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 323 | #[test] |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 324 | fn expand_skips_containers_of_hidden_windows() { |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 325 | let (a, b, c) = (1, 2, 3); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 326 | let mut t: Tree<u32> = Tree::default(); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 327 | t.insert_row(a); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 328 | t.insert_after(b, a); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 329 | t.insert_after(c, b); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 330 | assert!(t.merge_window(a, Dir::Right, |_| true)); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 331 | let shown = |w: u32| w != a; |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 332 | assert!(t.toggle_expand(b, 0, 1, shown)); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 333 | assert!(t.maximized(b, shown)); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 334 | let all = t.arrange(AREA, 0.0, shown); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 335 | let rect = |w| all.iter().find(|p| p.0 == w).unwrap().1; |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 336 | assert_eq!(rect(b).w, AREA.w); |
54559daf11c3 | atagen | 2026-10-17 13:38 UTC | 337 | } |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 338 | |
e2443dec4dcd | atagen | 2026-10-18 09:58 UTC | 339 | /// Going in and out of a stack repeatedly leaves every window the size it was. |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 340 | #[test] |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 341 | fn stacking_in_and_out_does_not_drift() { |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 342 | for out in [Dir::Up, Dir::Down, Dir::Right] { |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 343 | let (a, b, c) = (1, 2, 3); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 344 | let mut t: Tree<u32> = Tree::default(); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 345 | t.insert_row(a); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 346 | t.insert_after(b, a); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 347 | t.insert_after(c, b); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 348 | assert!(t.merge_window(c, Dir::Left, |_| true)); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 349 | assert!(t.merge_window(c, out, |_| true)); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 350 | let once = t.arrange(AREA, 0.0, |_| true); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 351 | for _ in 0..8 { |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 352 | t.merge_window(c, Dir::Left, |_| true); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 353 | t.merge_window(c, out, |_| true); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 354 | } |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 355 | t.check(); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 356 | assert_eq!(t.arrange(AREA, 0.0, |_| true), once, "stepping out {out:?}"); |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 357 | } |
3b1cf5ee2ea2 | atagen | 2026-10-17 13:53 UTC | 358 | } |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 359 | |
e2443dec4dcd | atagen | 2026-10-18 09:58 UTC | 360 | /// Windows of other tags in the rows around a window must not change what |
e2443dec4dcd | atagen | 2026-10-18 09:58 UTC | 361 | /// the user sees as it moves through them, nor drift over round trips. |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 362 | #[test] |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 363 | fn moving_past_hidden_windows_does_not_drift() { |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 364 | let (a, b, h, h2) = (1, 2, 3, 4); |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 365 | let mut t: Tree<u32> = Tree::default(); |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 366 | t.insert_row(h); |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 367 | t.insert_row(a); |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 368 | t.insert_after(h2, a); |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 369 | t.insert_after(b, h2); |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 370 | let vis = |w: u32| w != h && w != h2; |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 371 | let mut once = None; |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 372 | for _ in 0..4 { |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 373 | for d in [Dir::Up, Dir::Up, Dir::Down] { |
e2443dec4dcd | atagen | 2026-10-18 09:58 UTC | 374 | t.move_window(b, d, vis); |
e2443dec4dcd | atagen | 2026-10-18 09:58 UTC | 375 | let shown = t.arrange(AREA, 0.0, vis); |
e2443dec4dcd | atagen | 2026-10-18 09:58 UTC | 376 | let r = shown.iter().find(|p| p.0 == b).unwrap().1; |
e2443dec4dcd | atagen | 2026-10-18 09:58 UTC | 377 | assert!( |
e2443dec4dcd | atagen | 2026-10-18 09:58 UTC | 378 | (r.w * r.h - AREA.w * AREA.h / 2.0).abs() < 1e-6, |
e2443dec4dcd | atagen | 2026-10-18 09:58 UTC | 379 | "{d:?} left {r:?}" |
e2443dec4dcd | atagen | 2026-10-18 09:58 UTC | 380 | ); |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 381 | } |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 382 | t.check(); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 383 | let all = t.arrange(AREA, 0.0, |_| true); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 384 | assert_eq!(*once.get_or_insert_with(|| all.clone()), all); |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 385 | } |
9c0e9500c151 | atagen | 2026-10-18 09:09 UTC | 386 | } |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 387 | |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 388 | /// Monitors sleeping together unplug one after another, so windows already |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 389 | /// moved off the first must still go home to it, not to the second. |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 390 | #[test] |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 391 | fn windows_return_to_where_they_were_first_evicted_from() { |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 392 | let mut l = Layout::default(); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 393 | let a = l.add_output("a", AREA); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 394 | l.add_output("b", Rect::new(1000.0, 0.0, 800.0, 600.0)); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 395 | let c = l.add_output("c", Rect::new(1800.0, 0.0, 800.0, 600.0)); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 396 | let w = l.add_window(Some(a), None, None); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 397 | l.remove_output(a); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 398 | let b = l.outputs().find(|(_, out)| out.name == "b").unwrap().0; |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 399 | l.remove_output(b); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 400 | assert_eq!(l.window(w).unwrap().output, Some(c)); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 401 | l.add_output("b", Rect::new(1000.0, 0.0, 800.0, 600.0)); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 402 | let a = l.add_output("a", AREA); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 403 | l.check(); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 404 | assert_eq!(l.window(w).unwrap().output, Some(a)); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 405 | assert!(l.output(a).unwrap().tree.contains(w)); |
8ffa3fa4d4a9 | atagen | 2026-10-18 09:38 UTC | 406 | } |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 407 | |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 408 | /// A stack showing one window looks like a lone window, so moving toward it |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 409 | /// swaps places instead of joining a stack the user cannot see. |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 410 | #[test] |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 411 | fn moving_toward_a_stack_showing_one_window_swaps() { |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 412 | let (a, b, h) = (1, 2, 3); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 413 | let mut t: Tree<u32> = Tree::default(); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 414 | t.insert_row(a); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 415 | t.insert_after(b, a); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 416 | t.insert_after(h, b); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 417 | assert!(t.merge_window(h, Dir::Left, |_| true)); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 418 | let vis = |w: u32| w != h; |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 419 | assert!(t.move_window(a, Dir::Right, vis)); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 420 | t.check(); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 421 | let shown = t.arrange(AREA, 0.0, vis); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 422 | let rect = |w| shown.iter().find(|p| p.0 == w).unwrap().1; |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 423 | assert!(rect(b).x < rect(a).x); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 424 | assert_eq!(rect(a).h, AREA.h); |
00c7b3db8a3f | atagen | 2026-10-18 10:19 UTC | 425 | } |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 426 | |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 427 | /// A move either changes what is on screen or changes nothing at all, and a |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 428 | /// window move never rearranges hidden windows among themselves. Steps around |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 429 | /// hidden windows used to succeed invisibly and eat the keypress. |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 430 | #[test] |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 431 | fn moves_are_seen_or_undone() { |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 432 | let dirs = [Dir::Left, Dir::Right, Dir::Up, Dir::Down]; |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 433 | let mut runner = proptest::test_runner::TestRunner::deterministic(); |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 434 | let ops = prop::collection::vec((0u8..4, 0u8..4, 0u8..4, 0u8..32), 1..14); |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 435 | for _ in 0..2000 { |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 436 | let seq = proptest::strategy::ValueTree::current(&ops.new_tree(&mut runner).unwrap()); |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 437 | let mut t: Tree<u32> = Tree::default(); |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 438 | t.insert_row(0); |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 439 | let mut n = 1; |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 440 | for &(w, d, kind, hide) in &seq { |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 441 | let vis = |x: u32| hide & (1 << x) == 0; |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 442 | if kind == 0 && n < 5 { |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 443 | t.insert_after(n, u32::from(w) % n); |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 444 | n += 1; |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 445 | continue; |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 446 | } |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 447 | let w = u32::from(w) % n; |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 448 | let shown = |t: &Tree<u32>| { |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 449 | let mut v: Vec<_> = t |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 450 | .arrange(AREA, 0.0, vis) |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 451 | .into_iter() |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 452 | .filter(|p| vis(p.0)) |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 453 | .collect(); |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 454 | v.sort_by_key(|p| p.0); |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 455 | v |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 456 | }; |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 457 | let before = shown(&t); |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 458 | let hidden = |t: &Tree<u32>| { |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 459 | let mut t = t.clone(); |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 460 | t.retain(|x| !vis(x)); |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 461 | t.shape() |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 462 | }; |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 463 | let rest = hidden(&t); |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 464 | let d = dirs[usize::from(d)]; |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 465 | let moved = match kind { |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 466 | 1 => t.merge_window(w, d, vis), |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 467 | 2 => t.move_window(w, d, vis), |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 468 | 3 => t.move_container(w, d, vis), |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 469 | _ => continue, |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 470 | }; |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 471 | t.check(); |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 472 | assert_eq!(moved, shown(&t) != before, "{seq:?}"); |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 473 | if kind != 3 { |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 474 | assert_eq!(hidden(&t), rest, "{seq:?}"); |
ae47743b5745 | atagen | 2026-10-19 03:49 UTC | 475 | } |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 476 | } |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 477 | } |
8f1f743a2f6b | atagen | 2026-10-19 03:43 UTC | 478 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 479 | |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 480 | /// A fullscreen window hides everything but its own transients, which stay |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 481 | /// reachable by focus and are not hidden when they map. |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 482 | #[test] |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 483 | fn fullscreen_leaves_its_transients_reachable() { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 484 | let mut l = Layout::default(); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 485 | let o = l.add_output("a", AREA); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 486 | let beside = l.add_window(None, None, None); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 487 | l.focus(beside); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 488 | let game = l.add_window(None, None, None); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 489 | l.focus(game); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 490 | l.toggle_fullscreen(game); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 491 | let stranger = l.add_window(None, None, None); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 492 | assert!(l.covered(stranger)); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 493 | let dialog = l.add_window(None, None, Some(Rect::new(300.0, 200.0, 200.0, 100.0))); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 494 | l.set_parent(dialog, Some(game)); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 495 | assert!(!l.covered(dialog)); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 496 | l.focus(dialog); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 497 | |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 498 | let arr = l.arrange(o); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 499 | assert_eq!(arr.fullscreen, Some(game)); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 500 | assert_eq!(arr.over, vec![dialog]); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 501 | for dir in [Dir::Left, Dir::Right, Dir::Up, Dir::Down] { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 502 | if let Some(w) = l.focus_dir(dir) { |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 503 | assert!(w == game || w == dialog, "focus walked to a covered window"); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 504 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 505 | } |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 506 | |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 507 | l.remove_window(game); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 508 | assert!(!l.covered(stranger)); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 509 | assert_eq!(l.window(dialog).and_then(|w| w.parent), None); |
b44dde08d7ac | atagen | 2026-10-19 07:38 UTC | 510 | } |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 511 | |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 512 | fn rect_of(t: &Tree<u32>, w: u32, vis: impl Fn(u32) -> bool) -> Rect { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 513 | t.arrange(AREA, 0.0, vis) |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 514 | .into_iter() |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 515 | .find(|p| p.0 == w) |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 516 | .unwrap() |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 517 | .1 |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 518 | } |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 519 | |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 520 | #[test] |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 521 | fn splitting_a_lone_window_shares_its_space() { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 522 | let (a, b, c) = (1, 2, 3); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 523 | let mut t: Tree<u32> = Tree::default(); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 524 | t.insert_row(a); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 525 | t.insert_split(b, a, Axis::Horizontal); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 526 | t.check(); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 527 | let (ra, rb) = (rect_of(&t, a, |_| true), rect_of(&t, b, |_| true)); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 528 | assert_eq!((ra.w, rb.w, ra.h), (AREA.w / 2.0, AREA.w / 2.0, AREA.h)); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 529 | assert!(ra.x < rb.x); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 530 | |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 531 | t.insert_split(c, b, Axis::Vertical); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 532 | t.check(); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 533 | let (rb, rc) = (rect_of(&t, b, |_| true), rect_of(&t, c, |_| true)); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 534 | assert_eq!( |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 535 | (rb.h, rc.h, rb.w), |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 536 | (AREA.h / 2.0, AREA.h / 2.0, AREA.w / 2.0) |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 537 | ); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 538 | assert!(rb.y < rc.y); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 539 | assert_eq!(rect_of(&t, a, |_| true), ra, "the sibling is undisturbed"); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 540 | } |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 541 | |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 542 | #[test] |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 543 | fn splitting_along_the_parents_axis_appends_a_sibling() { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 544 | let (a, b, c, d) = (1, 2, 3, 4); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 545 | let mut t: Tree<u32> = Tree::default(); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 546 | t.insert_row(a); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 547 | t.insert_split(b, a, Axis::Horizontal); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 548 | t.insert_split(c, b, Axis::Vertical); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 549 | let before = rect_of(&t, a, |_| true); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 550 | t.insert_split(d, a, Axis::Horizontal); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 551 | t.check(); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 552 | let all = |_| true; |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 553 | let (ra, rd, rb) = ( |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 554 | rect_of(&t, a, all), |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 555 | rect_of(&t, d, all), |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 556 | rect_of(&t, b, all), |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 557 | ); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 558 | assert_eq!((ra.w, rd.w), (before.w / 2.0, before.w / 2.0)); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 559 | assert!(ra.x < rd.x && rd.x < rb.x); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 560 | assert_eq!(rb.w, AREA.w / 2.0, "the neighbour keeps its share"); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 561 | } |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 562 | |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 563 | #[test] |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 564 | fn splitting_beside_hidden_windows_leaves_their_slots_alone() { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 565 | let (a, b, c, d) = (1, 2, 3, 4); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 566 | let mut t: Tree<u32> = Tree::default(); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 567 | t.insert_row(a); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 568 | t.insert_after(b, a); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 569 | t.insert_after(c, a); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 570 | let tag_one = |w: u32| w == a || w == d; |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 571 | assert_eq!(rect_of(&t, a, tag_one).h, AREA.h); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 572 | |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 573 | t.insert_split(d, a, Axis::Vertical); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 574 | t.check(); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 575 | let (ra, rd) = (rect_of(&t, a, tag_one), rect_of(&t, d, tag_one)); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 576 | assert_eq!((ra.h, rd.h, ra.w), (AREA.h / 2.0, AREA.h / 2.0, AREA.w)); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 577 | assert!(ra.y < rd.y); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 578 | |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 579 | t.insert_split(d + 1, a, Axis::Horizontal); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 580 | t.check(); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 581 | let shown = |w: u32| w == a || w == d + 1; |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 582 | let (ra, re) = (rect_of(&t, a, shown), rect_of(&t, d + 1, shown)); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 583 | assert_eq!((ra.w, re.w), (AREA.w / 2.0, AREA.w / 2.0)); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 584 | assert!(ra.x < re.x); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 585 | assert_eq!(t.windows().count(), 5, "hidden windows stay in the tree"); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 586 | } |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 587 | |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 588 | #[test] |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 589 | fn autotile_dwindles_by_the_anchors_shape() { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 590 | let mut l = Layout { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 591 | autotile: true, |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 592 | ..Layout::default() |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 593 | }; |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 594 | let o = l.add_output("a", AREA); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 595 | let tag = l.tag("1"); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 596 | l.view(o, tag); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 597 | let mut ids = Vec::new(); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 598 | for _ in 0..4 { |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 599 | let w = l.add_window(Some(o), Some(tag), None); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 600 | l.focus(w); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 601 | ids.push(w); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 602 | l.check(); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 603 | } |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 604 | let arr = l.arrange(o); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 605 | let r = |w| arr.tiled.iter().find(|p| p.window == w).unwrap().rect; |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 606 | let [a, b, c, d] = [ids[0], ids[1], ids[2], ids[3]]; |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 607 | assert!( |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 608 | r(a).x < r(b).x && r(a).h > r(b).h * 1.5, |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 609 | "{a:?} left, {b:?} right" |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 610 | ); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 611 | assert!(r(b).y < r(c).y && r(b).x == r(c).x); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 612 | assert!(r(c).x < r(d).x && r(c).y == r(d).y); |
86ef802692f5 | atagen | 2026-10-19 07:43 UTC | 613 | } |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 614 | |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 615 | #[test] |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 616 | fn urgency_skips_the_focused_window_and_ends_with_focus() { |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 617 | let mut l = Layout::default(); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 618 | let o = l.add_output("a", AREA); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 619 | let tag = l.tag("1"); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 620 | l.view(o, tag); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 621 | let a = l.add_window(Some(o), Some(tag), None); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 622 | let b = l.add_window(Some(o), Some(tag), None); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 623 | l.focus(a); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 624 | l.mark_urgent(a); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 625 | l.mark_urgent(b); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 626 | assert!(!l.window(a).unwrap().urgent); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 627 | assert!(l.window(b).unwrap().urgent); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 628 | assert!(!l.tags().any(|(_, t)| t.urgent)); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 629 | l.focus(b); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 630 | assert!(!l.window(b).unwrap().urgent); |
9fdf9584d2bd | atagen | 2026-10-19 07:38 UTC | 631 | } |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 632 | |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 633 | #[test] |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 634 | fn oversized_floats_keep_their_top_edge_and_a_strip() { |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 635 | let bounds = Rect::new(0.0, 0.0, 1000.0, 600.0); |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 636 | let huge = Rect::new(-5000.0, -300.0, 3000.0, 2000.0); |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 637 | let r = clamp_float(huge, bounds); |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 638 | assert_eq!((r.x, r.y), (-2936.0, 0.0)); |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 639 | let r = clamp_float(Rect::new(5000.0, 5000.0, 3000.0, 2000.0), bounds); |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 640 | assert_eq!((r.x, r.y), (936.0, 536.0)); |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 641 | let fits = clamp_float(Rect::new(900.0, 500.0, 300.0, 200.0), bounds); |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 642 | assert_eq!((fits.x, fits.y), (700.0, 400.0)); |
b01f4e7ab7e6 | atagen | 2026-10-19 07:44 UTC | 643 | } |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 644 | |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 645 | #[test] |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 646 | fn floats_follow_their_output_area_and_panels() { |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 647 | let mut l = Layout::default(); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 648 | let o = l.add_output("a", AREA); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 649 | let w = l.add_window(Some(o), None, Some(Rect::new(500.0, 300.0, 400.0, 300.0))); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 650 | l.set_output_area(o, Rect::new(100.0, 50.0, 500.0, 300.0)); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 651 | let r = l.window(w).unwrap().float_rect.unwrap(); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 652 | assert_eq!((r.x, r.y, r.w, r.h), (350.0, 200.0, 200.0, 150.0)); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 653 | |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 654 | l.set_reserved( |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 655 | o, |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 656 | Insets { |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 657 | top: 100.0, |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 658 | ..Insets::default() |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 659 | }, |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 660 | ); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 661 | let r = l.window(w).unwrap().float_rect.unwrap(); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 662 | let usable = l.output(o).unwrap().usable(); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 663 | assert!(r.y >= usable.y && r.bottom() <= usable.bottom()); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 664 | } |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 665 | |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 666 | #[test] |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 667 | fn floats_shrink_into_a_smaller_output_they_are_evicted_to() { |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 668 | let mut l = Layout::default(); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 669 | let a = l.add_output("a", AREA); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 670 | let b = l.add_output("b", Rect::new(1000.0, 0.0, 500.0, 300.0)); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 671 | let w = l.add_window(Some(a), None, Some(Rect::new(800.0, 400.0, 200.0, 200.0))); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 672 | l.remove_output(a); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 673 | assert_eq!(l.window(w).unwrap().output, Some(b)); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 674 | let r = l.window(w).unwrap().float_rect.unwrap(); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 675 | let usable = l.output(b).unwrap().usable(); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 676 | assert_eq!((r.w, r.h), (100.0, 100.0)); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 677 | assert!(r.x >= usable.x && r.right() <= usable.right()); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 678 | assert!(r.y >= usable.y && r.bottom() <= usable.bottom()); |
4b73e40af1e3 | atagen | 2026-10-19 07:44 UTC | 679 | } |