From 231e50b3fccd1a519f51e77442b2225699c66eab Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Sat, 31 Oct 2026 17:15:39 -0700 Subject: [PATCH] test(core): tiling arithmetic of update_shared as native checks of the e2e layouts The Windows e2e scenarios layouts (111 checks), flipping, layout_flip, padding, closing, minimizing, floating, stacks, tiling and tiling_off assert where the tiles of a workspace are. Since the consolidation every daemon gets those tiles from komorebi-core's Workspace::update_shared, so they can be checked on the stub platform on Linux (and on the Mac Mini for macOS) instead of in a guest. crates/komorebi-core/tests/e2e_layouts.rs (6 tests) runs update_shared on a StubPlatform workspace for the 8 layouts of the scenario, 1 to 8 containers and three padding settings: one tile per container, inside the work area, not on each other; workspace padding moves tiles 40 px in, container padding shrinks every tile, and back as it was; each of the three flips equals the plain tiles mirrored (as a set); removing a container (what a closed, minimized or floated window does) leaves the others at least as much room; two containers, one a stack of two, are two tiles; with tiling off nothing is placed in any layout. Each test names the e2e checks it mirrors. They protect Windows, KDE and macOS alike. Platform dependent: the stub adds no border and no frame adjustment, so the Windows border of 7 px (windows_padding) and each daemon's own adjust_layout stay e2e only, as does the OS frame matching the tile. Verified: cargo test -p komorebi-core --test e2e_layouts, 6 passed (native Linux; macOS crates run later on the Mini). No source change, no bug found. --- crates/komorebi-core/tests/e2e_layouts.rs | 244 ++++++++++++++++++++++ 1 file changed, 244 insertions(+) create mode 100644 crates/komorebi-core/tests/e2e_layouts.rs diff --git a/crates/komorebi-core/tests/e2e_layouts.rs b/crates/komorebi-core/tests/e2e_layouts.rs new file mode 100644 index 00000000..fb0bc47f --- /dev/null +++ b/crates/komorebi-core/tests/e2e_layouts.rs @@ -0,0 +1,244 @@ +//! What the Windows `layouts`, `flipping`, `layout_flip`, `padding`, `closing`, `tiling` and +//! `stacks` scenarios (shared with KDE, and the only place macOS-or-Windows tiling used to be +//! checked) assert about where `Workspace::update_shared` puts the windows, run on the stub +//! platform: the tiles the shared code hands to the platform (`latest_layout`, which the scenarios +//! compare the OS frames with) for every layout, count, padding and flip. +//! +//! These protect all three daemons (Windows, KDE, macOS: each calls `update_shared`). Platform +//! choice: the stub platform adds no border and adjusts nothing, so a daemon's own `adjust_layout` +//! (the Windows border of 7 px, macOS or KDE frame corrections) is NOT covered and stays e2e +//! (`windows_padding`). +//! +//! The Windows fixture `kfw-tiled.json` of the e2e library is the same state shape these +//! workspaces serialize to (see `state_roundtrip.rs`). + +mod common; + +use common::*; +use komorebi_core::Workspace; +use komorebi_layouts::Axis; +use komorebi_layouts::DefaultLayout; +use komorebi_layouts::Layout; +use komorebi_layouts::Rect; + +const LAYOUTS: [DefaultLayout; 8] = [ + DefaultLayout::BSP, + DefaultLayout::Columns, + DefaultLayout::Rows, + DefaultLayout::VerticalStack, + DefaultLayout::HorizontalStack, + DefaultLayout::UltrawideVerticalStack, + DefaultLayout::Grid, + DefaultLayout::RightMainVerticalStack, +]; + +const AREA: Rect = Rect { + left: 0, + top: 0, + right: 1920, + bottom: 1080, +}; + +fn workspace( + layout: DefaultLayout, + ids: &[u32], + container_padding: Option, + workspace_padding: Option, + flip: Option, +) -> Workspace { + let mut workspace = workspace_of(ids); + workspace.layout = Layout::Default(layout); + workspace.layout_flip = flip; + workspace.globals.work_area = AREA; + workspace.globals.container_padding = container_padding; + workspace.globals.workspace_padding = workspace_padding; + workspace +} + +fn tiles( + layout: DefaultLayout, + count: u32, + container_padding: Option, + workspace_padding: Option, + flip: Option, +) -> Vec { + fresh(); + let ids: Vec = (1..=count).collect(); + let mut workspace = workspace(layout, &ids, container_padding, workspace_padding, flip); + workspace.update_shared().unwrap(); + workspace.latest_layout.clone() +} + +fn inside(r: &Rect, a: &Rect) -> bool { + r.left >= a.left + && r.top >= a.top + && r.left + r.right <= a.left + a.right + && r.top + r.bottom <= a.top + a.bottom +} + +fn overlap(a: &Rect, b: &Rect) -> bool { + a.left < b.left + b.right + && b.left < a.left + a.right + && a.top < b.top + b.bottom + && b.top < a.top + a.bottom +} + +fn area(r: &Rect) -> i64 { + i64::from(r.right) * i64::from(r.bottom) +} + +// mirrors: layouts / , windows: every window is where the layout says +// mirrors: layouts / ... inside the work area +// mirrors: layouts / ... and not on each other +// mirrors: tiling / every window is where the layout says; and do not overlap +#[test] +fn every_layout_tiles_every_container_inside_the_work_area_and_off_the_others() { + for layout in LAYOUTS { + for count in 1..=8 { + for (cp, wp) in [(None, None), (Some(10), Some(20)), (Some(0), Some(0))] { + let t = tiles(layout, count, cp, wp, None); + assert_eq!(t.len(), count as usize, "{layout} {count}"); + for (i, r) in t.iter().enumerate() { + assert!( + inside(r, &AREA), + "{layout} {count} {cp:?}/{wp:?}: {i} {r:?}" + ); + assert!( + r.right > 0 && r.bottom > 0, + "{layout} {count}: {i} is empty" + ); + for (j, o) in t.iter().enumerate().skip(i + 1) { + assert!(!overlap(r, o), "{layout} {count}: {i} {r:?} over {j} {o:?}"); + } + } + } + } + } +} + +// mirrors: padding / a workspace padding 40 px more moves the windows 40 px in from the edge +// mirrors: padding / a container padding 30 px more leaves the windows less room +// mirrors: padding / with the padding as it was, the windows are as far from the edge as they were +#[test] +fn the_workspace_padding_moves_the_tiles_in_and_the_container_padding_shrinks_them() { + for layout in LAYOUTS { + let base = tiles(layout, 3, None, None, None); + let more = tiles(layout, 3, None, Some(40), None); + let edge = |t: &[Rect]| t.iter().map(|r| r.left).min().unwrap(); + assert_eq!( + edge(&more), + edge(&base) + 40, + "{layout}: workspace padding 40" + ); + assert!(inside(more.first().unwrap(), &AREA)); + + let padded = tiles(layout, 3, Some(30), None, None); + for (a, b) in base.iter().zip(&padded) { + assert!( + area(b) < area(a), + "{layout}: container padding 30 did not shrink {a:?}" + ); + } + + assert_eq!( + base, + tiles(layout, 3, None, None, None), + "{layout}: back as it was" + ); + } +} + +// mirrors: flipping / after 'flip-layout horizontal' every window is where the mirror of its place is +// mirrors: flipping / flipped again, every window is where it was +// mirrors: layout_flip /