dotfiles/packages/active-window/package.nix
Christopher Mühl 9e49bd830d
feat: add compositor-agnostic window info utilities
- active-window: Get focused window info (class, pid) for Niri/Hyprland
- active-path: Get CWD of focused terminal window

These utilities abstract compositor-specific APIs for use in scripts.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-28 01:25:45 +01:00

19 lines
651 B
Nix

{pkgs, ...}:
pkgs.writeShellApplication {
name = "active-window";
runtimeInputs = [pkgs.jq];
text = ''
if [[ -n "''${NIRI_SOCKET:-}" ]]; then
FOCUSED_ID=$(niri msg --json focused-window | jq '.id')
niri msg --json windows \
| jq --argjson id "$FOCUSED_ID" \
'[.[] | select(.id == $id)] | first
| {compositor: "niri", class: .app_id, pid: .pid}'
elif [[ -n "''${HYPRLAND_INSTANCE_SIGNATURE:-}" ]]; then
hyprctl activewindow -j \
| jq '{compositor: "hyprland", class: .class, pid: .pid}'
else
printf '{"compositor":"unknown","class":null,"pid":null}\n'
fi
'';
}