From a4e03e3d76f9927cf74cdd47550b80e67056e3b8 Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Fri, 30 Oct 2026 15:32:30 -0700 Subject: [PATCH] test(resize): cover the top edge of the lower tile of a BSP layout Dragging the edge two stacked tiles share moves it by the same amount from either tile, in the layout and in the window manager. A drag of the top edge of the lower tile that moves nothing is not for want of this. --- komorebi-layouts/src/arrangement_tests.rs | 31 ++++++++++++++ komorebi/src/window_manager.rs | 51 +++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/komorebi-layouts/src/arrangement_tests.rs b/komorebi-layouts/src/arrangement_tests.rs index 78a0dbbd..5488bdd4 100644 --- a/komorebi-layouts/src/arrangement_tests.rs +++ b/komorebi-layouts/src/arrangement_tests.rs @@ -1843,3 +1843,34 @@ mod flip_resize_adjacency_tests { } } } + +// The edge that win2 and win3 share is moved the same way whichever of the two it is dragged +// from, in a BSP layout with a tile on the left and two stacked on the right +#[test] +fn bsp_shared_edge_moves_the_same_dragged_from_either_tile() { + let area = test_area(); + let len = NonZeroUsize::new(3).unwrap(); + let layout = |dimensions: &[Option]| { + DefaultLayout::BSP.calculate(&area, len, None, None, dimensions, 0, None, &[]) + }; + let rect = |left, top, right, bottom| Rect { + left, + top, + right, + bottom, + }; + + let before = layout(&[None, None, None]); + let shared_edge = before[1].top + before[1].bottom; + assert_eq!(shared_edge, before[2].top); + + // the bottom edge of the tile above, taken down by 72 (a request of 144, as a shared edge + // is moved by half of what the layout is given) + let from_above = layout(&[None, Some(rect(0, 0, 0, 144)), None]); + assert_eq!(from_above[2].top, shared_edge + 72); + + // the top edge of the tile below, taken up by 72 + let from_below = layout(&[None, None, Some(rect(0, -144, 0, 0))]); + assert_eq!(from_below[2].top, shared_edge - 72); + assert_eq!(from_below[1].top + from_below[1].bottom, shared_edge - 72); +} diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index d10591bc..5d37a094 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -6077,4 +6077,55 @@ mod tests { assert_eq!(wm.focused_monitor().unwrap().workspaces().len(), 1); assert_eq!(wm.focused_workspace().unwrap().containers().len(), 3); } + + /// What dragging the edge that two stacked tiles share, from either of them, gives the + /// tile that is dragged: three tiles laid out as BSP, one on the left and two on the right + fn dragged_dimensions( + focused: usize, + edge: OperationDirection, + sizing: Sizing, + ) -> Vec> { + let (mut wm, _context) = setup_window_manager(); + let area = Rect { + left: 0, + top: 0, + right: 1000, + bottom: 800, + }; + let mut monitor = monitor::new( + 0, + area, + area, + "TestMonitor".to_string(), + "TestDevice".to_string(), + "TestDeviceID".to_string(), + Some("TestMonitorID".to_string()), + ); + + let workspace = monitor.focused_workspace_mut().unwrap(); + workspace.layout = Layout::Default(DefaultLayout::BSP); + for _ in 0..3 { + workspace.containers_mut().push_back(Container::default()); + } + workspace.resize_dimensions = vec![None; 3]; + workspace.focus_container(focused); + + wm.monitors_mut().push_back(monitor); + wm.resize_window(edge, sizing, 144, false).unwrap(); + + wm.focused_workspace().unwrap().resize_dimensions.clone() + } + + #[test] + fn test_resize_the_top_edge_of_the_lower_tile() { + let dragged_up = dragged_dimensions(2, OperationDirection::Up, Sizing::Increase); + assert!( + dragged_up[2].is_some() || dragged_up[1].is_some(), + "dragging the top edge of the lower tile up changed nothing: {dragged_up:?}" + ); + + // the same edge from the tile above + let dragged_down = dragged_dimensions(1, OperationDirection::Down, Sizing::Increase); + assert!(dragged_down[1].is_some(), "{dragged_down:?}"); + } }