#!/bin/bash

# omarchy:summary=Check whether an external monitor is active in Hyprland
# omarchy:hidden=true

# Hyprland stands in a FALLBACK output when no real monitor is enabled. It is
# not an external display, so counting it would keep the internal panel off
# after the last external monitor is unplugged.
#
# Exits 0 active, 1 not, 2 when the compositor cannot say.
monitors=$(hyprctl monitors all -j 2>/dev/null) || exit 2

state=$(jq 'if type != "array" then error("expected array") elif any(.[]; (.name | test("^(eDP|LVDS|DSI)-") | not) and .name != "FALLBACK" and .disabled == false) then 0 else 1 end' \
  <<<"$monitors" 2>/dev/null) || exit 2

case $state in
  0 | 1) exit "$state" ;;
  *) exit 2 ;;
esac
