aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIvan Molodetskikh <yalterz@gmail.com>2024-02-03 08:42:56 +0400
committerIvan Molodetskikh <yalterz@gmail.com>2024-02-03 08:42:56 +0400
commit1f72089a46a965fa98c833de3c76da2fb8b6a5f7 (patch)
tree27fc603541d6e36c902a870069df7abbf61cac8c /src
parentfbe902091533c211a8e61905951fdd113fbca11e (diff)
downloadniri-1f72089a46a965fa98c833de3c76da2fb8b6a5f7.tar.gz
niri-1f72089a46a965fa98c833de3c76da2fb8b6a5f7.tar.bz2
niri-1f72089a46a965fa98c833de3c76da2fb8b6a5f7.zip
Place new workspace after current when moving
This feels more natural, also makes moving back and forth idempotent in most cases.
Diffstat (limited to 'src')
-rw-r--r--src/layout/mod.rs8
1 files changed, 7 insertions, 1 deletions
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<W: LayoutElement> Layout<W> {
.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();