From 2363ff6c3a05a4a64ed62817591bdb5e163467af Mon Sep 17 00:00:00 2001 From: LGUG2Z Date: Tue, 27 Oct 2026 16:03:42 -0700 Subject: [PATCH] feat(workspace): keep the width of a window that moves to another workspace A container goes from one workspace to another by being taken out of one and put into the other, with nothing between them that both could be asked, so a window that was moved started again with the default width, as did one moved to another monitor. Taking a container out of a workspace now says what its column was given, which komorebi_layouts::scrolling keeps, and the strip of the workspace that has the container next finds it there the first time it sees it, before it is made to match the list. So the window is a column of its own as wide as the column it left, whichever way it got there, and a window that moves on takes what it has where it is. Nothing is remembered for a container that no strip had been asked about. --- docs/usage/scrolling-layout.md | 3 +- komorebi/src/scrolling.rs | 86 ++++++++++++++++++++++++++++++++++ komorebi/src/workspace.rs | 3 ++ 3 files changed, 91 insertions(+), 1 deletion(-) diff --git a/docs/usage/scrolling-layout.md b/docs/usage/scrolling-layout.md index 5c56dd5e..48e979e5 100644 --- a/docs/usage/scrolling-layout.md +++ b/docs/usage/scrolling-layout.md @@ -77,6 +77,8 @@ Focus and move commands know about columns: - A column keeps its width, and a [stack](../cli/stack.md) is still one tile showing one of its windows, as in any layout. A column that you resized, or made the full width of the screen, keeps that as windows are added to it or taken out. +A window that you move to another workspace or monitor is a column of its own there, and keeps the width of the column +that it was in. ## Heights @@ -158,7 +160,6 @@ arranged above and below each other rather than side by side, none of this appli These are not done yet. -- Moving a window to another workspace or monitor makes it a column of its own with the default width. - Switching to another layout and back keeps the widths, but a column whose windows were moved past each other in the other layout is made again from the order that they are in. - Every window has a border, including the windows resting at the edges, so you may see a thin line of one at the edge diff --git a/komorebi/src/scrolling.rs b/komorebi/src/scrolling.rs index 99fdf91e..e5eb87ee 100644 --- a/komorebi/src/scrolling.rs +++ b/komorebi/src/scrolling.rs @@ -29,6 +29,8 @@ use komorebi_layouts::scrolling::ScrollingPlacement; use komorebi_layouts::scrolling::model::Options; use komorebi_layouts::scrolling::model::Viewport; use komorebi_layouts::scrolling::model::Visibility; +use komorebi_layouts::scrolling::note_departure; +use komorebi_layouts::scrolling::tell_of_arrivals; use objc2_core_foundation::CGRect; /// What the layout options of a workspace come to for the model. @@ -63,6 +65,17 @@ impl Workspace { ); } + /// Say what the column of the container at this index was given, as it is about to be taken + /// out of the workspace, for the workspace that it is put in to find. + pub(crate) fn note_scrolling_departure(&self, idx: usize) { + if let Some(space) = &self.scrolling + && let Some(container) = self.containers().get(idx) + && let Some(record) = space.column_record(&container.id) + { + note_departure(&container.id, record); + } + } + /// Make the space match the containers and the focus as they are now, for a space that is /// there to be made to match. /// @@ -80,6 +93,7 @@ impl Workspace { .map(|container| container.id.clone()); if let Some(space) = self.scrolling.as_mut() { + tell_of_arrivals(space, &ids); space.reconcile(&ids, focused.as_ref()); } } @@ -1350,6 +1364,78 @@ mod tests { assert_eq!(workspace.layout_scrolling(&AREA, 0), before); } + #[test] + fn a_window_that_is_moved_to_another_workspace_is_as_wide_as_it_was() { + let mut from = workspace_of_windows_from(3, 120, 3); + from.focus_container(1); + from.layout_scrolling(&AREA, 0); + from.resize_scrolling_column(OperationDirection::Right, Sizing::Increase, 200); + assert_eq!(widths(&from.layout_scrolling(&AREA, 0))[1], 500); + + let mut to = workspace_of_windows_from(3, 130, 2); + to.layout_scrolling(&AREA, 0); + + // the way that the window manager does it: out of one, and into the other + let idx = from.focused_container_idx(); + let container = from.remove_container_by_idx(idx).unwrap(); + to.add_container_to_back(container); + + assert_eq!(widths(&to.layout_scrolling(&AREA, 0)), [400, 400, 500]); + } + + #[test] + fn what_a_window_was_given_is_used_by_the_workspace_that_gets_it_and_by_no_other() { + let mut from = workspace_of_windows_from(3, 140, 2); + from.focus_container(0); + from.layout_scrolling(&AREA, 0); + from.resize_scrolling_column(OperationDirection::Right, Sizing::Increase, 200); + + let container = from.remove_container_by_idx(0).unwrap(); + let mut to = workspace_of_windows_from(3, 150, 1); + to.add_container_to_back(container.clone()); + assert_eq!(widths(&to.layout_scrolling(&AREA, 0)), [400, 500]); + + // a workspace that is given the same container afterwards is not told what the first one + // was, which it took + let mut other = workspace_of_windows_from(3, 155, 1); + other.add_container_to_back(container); + assert_eq!(widths(&other.layout_scrolling(&AREA, 0)), [400, 400]); + } + + #[test] + fn a_window_that_is_moved_on_takes_what_it_has_where_it_is_now() { + let mut from = workspace_of_windows_from(3, 180, 2); + from.focus_container(0); + from.layout_scrolling(&AREA, 0); + from.resize_scrolling_column(OperationDirection::Right, Sizing::Increase, 200); + + let container = from.remove_container_by_idx(0).unwrap(); + let mut to = workspace_of_windows_from(3, 190, 1); + to.add_container_to_back(container); + to.layout_scrolling(&AREA, 0); + to.resize_scrolling_column(OperationDirection::Right, Sizing::Increase, 200); + assert_eq!(widths(&to.layout_scrolling(&AREA, 0)), [400, 600]); + + let container = to.remove_container_by_idx(1).unwrap(); + let mut third = workspace_of_windows_from(3, 195, 1); + third.add_container_to_back(container); + + assert_eq!(widths(&third.layout_scrolling(&AREA, 0)), [400, 600]); + } + + #[test] + fn a_window_that_was_not_laid_out_where_it_was_has_nothing_to_take() { + let mut from = workspace_of_windows_from(3, 160, 2); + let mut to = workspace_of_windows_from(3, 170, 1); + to.layout_scrolling(&AREA, 0); + + // there was never a strip to ask + let container = from.remove_container_by_idx(0).unwrap(); + to.add_container_to_back(container); + + assert_eq!(widths(&to.layout_scrolling(&AREA, 0)), [400, 400]); + } + #[test] fn consuming_to_the_left_is_the_other_way_round() { let mut workspace = workspace_of_windows_from(3, 50, 3); diff --git a/komorebi/src/workspace.rs b/komorebi/src/workspace.rs index 339399f5..55dab6cf 100644 --- a/komorebi/src/workspace.rs +++ b/komorebi/src/workspace.rs @@ -701,6 +701,9 @@ impl Workspace { // this fn respects locked container indexes - we should use it for pretty much everything // except monocle and maximize toggles pub fn remove_container_by_idx(&mut self, idx: usize) -> Option { + // wherever it goes next, it goes as wide as it was + self.note_scrolling_departure(idx); + let container = self.containers_mut().remove_respecting_locks(idx); if idx < self.resize_dimensions.len() {