Files
dotfiles/hyprland/.local/bin/monitor-status.sh
T

38 lines
1.1 KiB
Bash
Executable File

#!/usr/bin/env bash
# monitor-status: waybar module for external display layout.
#
# Emits a JSON update on stdout every couple of seconds so the module appears
# as soon as an external (non-eDP/HEADLESS) monitor is detected and collapses
# again when it is disconnected. Clicking the icon opens monique to manage the
# display layout.
#
# Outputs (return-type json):
# connected: { "text": "󰍹", "class": "active", "tooltip": "<monitor list>" }
# otherwise: { "text": "", "class": "hidden", "tooltip": "" }
set -uo pipefail
POLL_SECONDS=2
emit() {
local out_json
out_json="$(hyprctl monitors -j 2>/dev/null)" || {
echo '{"text":"","class":"hidden","tooltip":""}'
return
}
jq -c '
[.[] | select((.name | test("^(eDP|HEADLESS)-")) | not)] as $ext |
if ($ext | length) == 0 then
{ text: "", class: "hidden", tooltip: "" }
else
{ text: "󰍹",
class: "active",
tooltip: (($ext | map("\(.description) \(.width)x\(.height) @ \(.refreshRate | floor) Hz") | join("\n"))) }
end
' <<<"$out_json" 2>/dev/null || echo '{"text":"","class":"hidden","tooltip":""}'
}
while true; do
emit
sleep "$POLL_SECONDS"
done