Recover monitors Hyprland brought up with no mode (#6701)

A monitor powered off when the machine boots — a smart strip cutting AC, the PC
coming back on its own — still answers DDC, but with a partial EDID that carries
no video modes. Hyprland takes the connector as present and brings the monitor
up at 0x0. Powering it on afterwards changes nothing: the connector never
dropped at DRM level, so no hotplug fires, nothing re-reads the EDID, and the
screen stays black until a reboot.

Only a reload re-reads it. Forcing a DRM re-probe would work too but needs root,
and the kernel's cached mode list stays empty without one, so there is nothing
cheaper to poll: the reload is both the fix and the only way to learn whether it
was needed. Poll only while a monitor is in that state, back off from three
seconds to a minute, and stop as soon as one reports a mode — the machine can
sit black all night, and powering the monitor on fires no event to stop on.

Nothing will ask again if this loop gives up, so an unreadable answer is not
taken for a healthy monitor. It is also not waited on forever: a compositor that
stays silent has gone, and with it the session and any reason to keep asking.

Reloading on our own schedule means minding the reload guard, which exists to
keep Hyprland out of package-owned config mid-transaction, and which only
disables the automatic reloads. The guard can now be asked, and recovery holds
off while a transaction is in flight.

A reload lands a monitor at 0x0 the same way a boot does, so configreloaded is
watched alongside the hotplug events. The recovery's own reload comes back
through it, and a lock keeps that from stacking a second loop. Contention waits
rather than drops: a trigger arriving while a loop is exiting is the last one
that will come, and one arriving while a loop is running is answered by its next
pass anyway.

Mirrors are dropped from `hyprctl monitors`, so the check asks for all of them
and filters the disabled ones itself. Monitors turned off on purpose sit at 0x0
too, and re-applying config would fight the user over those.

The existing poll here recovers internal panels on docked laptops and never runs
on a desktop, which is where this happens.

Reported in #6668.

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
David Heinemeier Hansson
2026-08-11 13:26:24 +02:00
committed by GitHub
co-authored by Claude Opus 5
parent 9f0c4b9792
commit 3b08a85ad1
6 changed files with 391 additions and 2 deletions
+21
View File
@@ -0,0 +1,21 @@
#!/bin/bash
# omarchy:summary=Returns true when Hyprland has an enabled monitor with no mode
# 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.
#
# 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
state=$(jq 'if any(.[]; .disabled != true and (.width == 0 or .height == 0)) then 0 else 1 end' \
<<<"$monitors" 2>/dev/null)
case $state in
0 | 1) exit "$state" ;;
*) exit 2 ;;
esac
+46
View File
@@ -4,6 +4,7 @@
SOCKET="$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock"
LOCK="${XDG_RUNTIME_DIR:-/tmp}/omarchy-monitor-clamshell.lock"
MODELESS_LOCK="${XDG_RUNTIME_DIR:-/tmp}/omarchy-monitor-modeless.lock"
sync_clamshell() {
(
@@ -23,6 +24,42 @@ sync_clamshell_after_monitor_change() {
) &
}
# Powering the monitor on fires no DRM hotplug, and forcing a re-probe needs
# root, so only a reload re-reads the EDID and only a reload reveals whether it
# worked. Back off: the machine can sit like this all night. The lock keeps one
# loop running across the events that call this; the wait is for an event landing
# in the moment one is exiting, which would otherwise be the last one to come.
recover_modeless() {
(
flock -w 1 9 || exit 0
local delay=3 state reloaded unanswered=0
while true; do
omarchy-hyprland-monitor-modeless
state=$?
# A monitor reporting a mode is recovered. One the compositor cannot speak
# for is not an answer, and nothing else will ask again -- but a compositor
# that stays silent has gone, taking the session and this loop's reason
# with it.
(( state == 1 )) && break
(( state == 2 )) && (( ++unanswered > 20 )) && break
(( state == 0 )) && unanswered=0
reloaded=0
# Reloading into half-replaced package config is what the guard prevents.
if (( state == 0 )) && ! omarchy-hyprland-reload-guard paused; then
hyprctl reload >/dev/null 2>&1 || true
reloaded=1
fi
sleep "$delay"
(( reloaded )) && (( delay = delay * 2 > 60 ? 60 : delay * 2 ))
done
) 9>"$MODELESS_LOCK" &
}
poll_clamshell_state() {
while true; do
sleep 2
@@ -51,6 +88,7 @@ sync_poll_state() {
sync_clamshell_after_monitor_change
sync_poll_state
recover_modeless
# Process substitution (not a pipe) keeps this loop in the main shell, so
# sync_poll_state can start and stop the background poll as monitors come and go.
@@ -59,10 +97,18 @@ while read -r event; do
monitoradded\>\>*|monitoraddedv2\>\>*)
sync_clamshell_after_monitor_change
sync_poll_state
recover_modeless
;;
monitorremoved\>\>*|monitorremovedv2\>\>*)
sync_clamshell_after_monitor_change
sync_poll_state
recover_modeless
;;
# A reload while the monitor is unpowered leaves it at 0x0 with no hotplug
# to notice, same as at boot. Our own recovery reload lands here too, and is
# a no-op while its loop still holds the pid.
configreloaded\>\>*)
recover_modeless
;;
esac
done < <(socat -U - "UNIX-CONNECT:$SOCKET")
+5 -2
View File
@@ -7,9 +7,9 @@ set -euo pipefail
command="${1:-}"
case "$command" in
pause | resume) ;;
pause | resume | paused) ;;
*)
echo "Usage: omarchy-hyprland-reload-guard pause|resume" >&2
echo "Usage: omarchy-hyprland-reload-guard pause|resume|paused" >&2
exit 1
;;
esac
@@ -96,6 +96,9 @@ resume_instance() {
}
case "$command" in
paused)
compgen -G "$state_dir/*" >/dev/null
;;
pause)
while IFS=$'\t' read -r runtime_dir signature; do
pause_instance "$runtime_dir" "$signature"