about summary refs log tree commit diff
path: root/users/tazjin/niri-reap
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@tvl.su>2024-10-02T14·04+0300
committerclbot <clbot@tvl.fyi>2024-10-02T14·35+0000
commitcd050400db8decdc08061b7450e50dc72abb58fb (patch)
treea1b1843790509fa961f37d95e09b469ecfdcab59 /users/tazjin/niri-reap
parent3606d7acc3300ec29d25e1c14c9450cf288195dd (diff)
feat(tazjin/niri-reap): improve reaping of workspaces above r/8749
Previously the script ignored workspaces that were further up, but in practice I
don't care about their order, I just want them to be gone.

To keep IDs stable, this implements a fix where the current workspace is first
moved to the first position (invisible), and windows are then reaped afterwards.

I've tried this in various combinations and it seems to work fine.

Change-Id: Ifc3eb272af761670ec83305665ec2103eb4f269e
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12564
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Autosubmit: tazjin <tazjin@tvl.su>
Diffstat (limited to 'users/tazjin/niri-reap')
-rw-r--r--users/tazjin/niri-reap/src/main.rs33
1 files changed, 25 insertions, 8 deletions
diff --git a/users/tazjin/niri-reap/src/main.rs b/users/tazjin/niri-reap/src/main.rs
index d89b18fc57cf..315a5015d413 100644
--- a/users/tazjin/niri-reap/src/main.rs
+++ b/users/tazjin/niri-reap/src/main.rs
@@ -40,21 +40,38 @@ fn reap_window(window: u64, workspace: u64) {
     reply.expect("failed to move window to workspace");
 }
 
-fn main() {
-    let workspaces = list_workspaces();
-
-    let active_workspace = workspaces
+fn get_active_workspace(workspaces: &[Workspace]) -> &Workspace {
+    workspaces
         .iter()
         .filter(|w| w.is_focused)
         .next()
-        .expect("expected an active workspace");
+        .expect("expected an active workspace")
+}
+
+fn move_workspace_up() {
+    let (result, _) = sock()
+        .send(Request::Action(Action::MoveWorkspaceUp {}))
+        .expect("failed to send workspace move command");
+
+    result.expect("failed to move workspace up");
+}
+
+fn main() {
+    let mut workspaces = list_workspaces();
+    let mut active_workspace = get_active_workspace(&workspaces);
+
+    // Ensure that the current workspace is the first one, to avoid issues with
+    // indices changing during the window moves.
+    while active_workspace.idx > 1 {
+        move_workspace_up();
+        workspaces = list_workspaces();
+        active_workspace = get_active_workspace(&workspaces);
+    }
 
     let orphan_workspaces = workspaces
         .iter()
         .filter(|w| w.output == active_workspace.output)
-        // Only select workspaces that are further down, to avoid issues with
-        // indices changing during the operation.
-        .filter(|w| w.idx > active_workspace.idx)
+        .filter(|w| w.idx > 1)
         .map(|w| w.id)
         .collect::<Vec<_>>();