From 1f72089a46a965fa98c833de3c76da2fb8b6a5f7 Mon Sep 17 00:00:00 2001 From: Ivan Molodetskikh Date: Sat, 3 Feb 2024 08:42:56 +0400 Subject: Place new workspace after current when moving This feels more natural, also makes moving back and forth idempotent in most cases. --- src/layout/mod.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/layout') diff --git a/src/layout/mod.rs b/src/layout/mod.rs index 5482b29c..3dc47561 100644 --- a/src/layout/mod.rs +++ b/src/layout/mod.rs @@ -29,6 +29,7 @@ //! compromise we only keep the first workspace there, and move the rest to the primary output, //! making the primary output their original output. +use std::cmp::min; use std::mem; use std::rc::Rc; use std::time::Duration; @@ -1364,7 +1365,12 @@ impl Layout { .position(|mon| &mon.output == output) .unwrap(); let target = &mut monitors[target_idx]; - target.workspaces.insert(target.active_workspace_idx, ws); + + // Insert the workspace after the currently active one. Unless the currently active one is + // the last empty workspace, then insert before. + let target_ws_idx = min(target.active_workspace_idx + 1, target.workspaces.len() - 1); + target.workspaces.insert(target_ws_idx, ws); + target.active_workspace_idx = target_ws_idx; target.workspace_switch = None; target.clean_up_workspaces(); -- cgit