feat(tazjin/niri-reap): improve reaping of workspaces above

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>
This commit is contained in:
Vincent Ambo 2024-10-02 17:04:15 +03:00 committed by clbot
parent 3606d7acc3
commit cd050400db

View file

@ -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<_>>();