#!/usr/bin/env -S nu --no-config-file # Keep code on DP-2 while games is occupied; otherwise return it to DP-1. ^niri msg --json event-stream | lines | each { |line| let event = ($line | from json) if not ( ("WorkspacesChanged" in $event) or ("WorkspaceActiveWindowChanged" in $event) ) { return } let workspaces = (^niri msg --json workspaces | from json) let games = ($workspaces | where name == "games") let code = ($workspaces | where name == "code") if ($games | is-empty) or ($code | is-empty) { return } let target = if $games.0.active_window_id == null { "DP-1" } else { "DP-2" } let target_exists = ($workspaces | any { |ws| $ws.output == $target }) if ($code.0.output not-in ["DP-1" "DP-2"]) { return } if ($code.0.output == $target) or not $target_exists { return } ^niri msg action do-screen-transition --delay-ms 100 | ignore ^niri msg action move-workspace-to-monitor --reference code $target | ignore } | ignore