Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions bin/omarchy-hyprland-monitor-modeless
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
#!/bin/bash

# omarchy:summary=Returns true when Hyprland has an enabled monitor with no mode
# omarchy:summary=Returns true when Hyprland has an enabled monitor with no mode or no active scanout
# omarchy:hidden=true

# A monitor powered off at boot answers with a partial EDID carrying no video
# modes, so Hyprland brings it up at 0x0 and the screen stays black. Mirrors are
# absent from plain `monitors`, hence `all` plus an explicit disabled filter.
# modes (0x0), or drops link during atomic commit landing without a CRTC
# (disabled != true, present in `monitors all` but absent from active `monitors`).
#
# Exits 0 modeless, 1 not, 2 when the compositor cannot say. Nothing fires an
# event for this state, so a caller that gave up on an unanswered query would
# leave the screen black for good.
monitors=$(hyprctl monitors all -j 2>/dev/null) || exit 2
# Exits 0 modeless/stranded, 1 active/recovered, 2 when the compositor cannot say.

state=$(jq 'if any(.[]; .disabled != true and (.width == 0 or .height == 0)) then 0 else 1 end' \
<<<"$monitors" 2>/dev/null)
active_monitors=$(hyprctl monitors -j 2>/dev/null) || exit 2
all_monitors=$(hyprctl monitors all -j 2>/dev/null) || exit 2

state=$(jq -n \
--argjson active "$active_monitors" \
--argjson all "$all_monitors" \
'
($active | map(.name)) as $active_names |
if any($all[];
.disabled != true and (
.width == 0 or
.height == 0 or
(.name as $n | ($active_names | index($n) | not) and (.mirrorOf == "" or .mirrorOf == null))
)
) then 0 else 1 end
' 2>/dev/null)

case $state in
0 | 1) exit "$state" ;;
Expand Down