diff --git a/docs/cli/retile.md b/docs/cli/retile.md index 2336b013..60d755f0 100644 --- a/docs/cli/retile.md +++ b/docs/cli/retile.md @@ -3,10 +3,13 @@ ``` Force the retiling of all managed windows +Every column of a workspace in the Scrolling layout goes back to the width that +scrolling-layout-columns gives. + Usage: komorebic retile Options: -h, --help - Print help + Print help (see a summary with '-h') ``` \ No newline at end of file diff --git a/docs/usage/scrolling-layout.md b/docs/usage/scrolling-layout.md index 2dac78ae..7bed3c2b 100644 --- a/docs/usage/scrolling-layout.md +++ b/docs/usage/scrolling-layout.md @@ -72,6 +72,10 @@ the focused column, by half of the [resize delta](../cli/resize-delta.md) for ea changes the width by the whole delta. Dragging an edge with the mouse does the same. Columns are as tall as the screen, so resizing a height does nothing. +[`komorebic retile`](../cli/retile.md) puts every column back to the width that +[`scrolling-layout-columns`](../cli/scrolling-layout-columns.md) gives, on the focused workspace of each monitor. The +focused column stays where it is on screen, unless it has to scroll to stay in view. + ## Windows that are out of view A window that scrolls out of view comes to rest at the edge of the screen that it left by, with 5 pixels of it still on diff --git a/komorebi/src/scrolling.rs b/komorebi/src/scrolling.rs index 97c9bc0f..5e1cf062 100644 --- a/komorebi/src/scrolling.rs +++ b/komorebi/src/scrolling.rs @@ -182,6 +182,16 @@ impl Workspace { Ok(()) } + /// Put every column back to the width that the `columns` option gives, which forgets every + /// width that was set by resizing, by a preset, or by taking the full width. + /// + /// The focused column stays where it is on screen unless it has to scroll to stay in view. + pub(crate) fn reset_scrolling_widths(&mut self) { + if let Some(space) = self.scrolling.as_mut() { + space.reset_widths(); + } + } + /// Make the focused column wider or narrower. Only the horizontal edges mean anything, since /// a column is as tall as the viewport. /// @@ -503,6 +513,47 @@ mod tests { assert!(workspace.scrolling.is_none()); } + #[test] + fn resetting_the_widths_puts_every_column_back_to_what_the_columns_option_gives() { + let mut workspace = workspace(3, 4); + workspace.layout_scrolling(&AREA, 0); + + workspace.resize_scrolling_column(OperationDirection::Left, Sizing::Increase, 200); + workspace.focus_container(1); + workspace.resize_scrolling_column(OperationDirection::Right, Sizing::Decrease, 100); + let resized = widths(&workspace.layout_scrolling(&AREA, 0)); + assert_ne!(resized, [400; 4]); + + workspace.reset_scrolling_widths(); + + assert_eq!(widths(&workspace.layout_scrolling(&AREA, 0)), [400; 4]); + } + + #[test] + fn resetting_the_widths_keeps_the_focused_column_where_it_is() { + let mut workspace = workspace(3, 6); + workspace.focus_container(3); + workspace.layout_scrolling(&AREA, 0); + workspace.focus_container(1); + workspace.resize_scrolling_column(OperationDirection::Left, Sizing::Increase, 200); + workspace.focus_container(3); + let before = workspace.layout_scrolling(&AREA, 0)[3].rect.left; + + workspace.reset_scrolling_widths(); + + assert_eq!(workspace.layout_scrolling(&AREA, 0)[3].rect.left, before); + assert_eq!(workspace.focused_container_idx(), 3); + } + + #[test] + fn resetting_the_widths_before_there_is_a_layout_does_nothing() { + let mut workspace = workspace(3, 2); + + workspace.reset_scrolling_widths(); + + assert!(workspace.scrolling.is_none()); + } + /// A workspace with a window in every container, which is how closing a window finds a container. fn workspace_of_windows(columns: usize, count: u32) -> Workspace { let mut workspace = Workspace { diff --git a/komorebi/src/window_manager.rs b/komorebi/src/window_manager.rs index f199fa1b..06fe4dff 100644 --- a/komorebi/src/window_manager.rs +++ b/komorebi/src/window_manager.rs @@ -1807,6 +1807,10 @@ impl WindowManager { for resize in &mut workspace.resize_dimensions { *resize = None; } + + // and the widths of the columns of the Scrolling layout, which are resize + // adjustments too + workspace.reset_scrolling_widths(); } if (workspace.wallpaper.is_some() || monitor_wp.is_some()) diff --git a/komorebic/src/main.rs b/komorebic/src/main.rs index 40221b1c..ba10d48c 100644 --- a/komorebic/src/main.rs +++ b/komorebic/src/main.rs @@ -1004,6 +1004,9 @@ enum SubCommand { /// Promote the window in the specified direction PromoteWindow(PromoteWindow), /// Force the retiling of all managed windows + /// + /// Every column of a workspace in the Scrolling layout goes back to the width that + /// scrolling-layout-columns gives. Retile, // /// Set the monitor index preference for a monitor identified using its size // #[clap(arg_required_else_help = true)]