#!/bin/bash
GTK_THEME=cyberqueer

monitorsum=$(niri msg outputs | grep -c "Scale:" || echo 1)

# niri doesn't expose a simple "focused output index" via IPC — default to 0
actmon=0

statecon=$(eww active-windows 2>/dev/null | grep "bar$actmon" || true)

if [ "$statecon" != '' ]; then
    for i in $(seq 1 "$monitorsum"); do
        declare -i curmon=$i-1
        if [ "$curmon" -eq "$actmon" ]; then
            /usr/bin/eww open --toggle "bar$curmon"
        fi
    done
else
    for i in $(seq 1 "$monitorsum"); do
        declare -i curmon=$i-1
        if [ "$curmon" -eq "$actmon" ]; then
            /usr/bin/eww open bar --id "bar$curmon" --arg monitor=$curmon
        fi
    done
fi
