From 8f6e815c78c94bac2f78be004796a233bd8564a1 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 21 Jun 2026 15:42:24 +0200 Subject: [PATCH] Recover internal monitor before sleep Run internal monitor toggle recovery before the sleep lock path and retry recovery after Hyprland monitor removal events. This gives dock/lid-close races time to settle before suspend or external-display reconnects leave the session without a safe internal display fallback. --- bin/omarchy-hyprland-monitor-watch | 17 +++++++++++++++-- bin/omarchy-system-sleep-lock | 3 +++ test/shell.d/monitor-recovery-test.sh | 18 ++++++++++++++++++ 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100755 test/shell.d/monitor-recovery-test.sh diff --git a/bin/omarchy-hyprland-monitor-watch b/bin/omarchy-hyprland-monitor-watch index 7d0df494..7379fc68 100755 --- a/bin/omarchy-hyprland-monitor-watch +++ b/bin/omarchy-hyprland-monitor-watch @@ -4,11 +4,24 @@ SOCKET="$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" +recover_internal_monitor_toggles() { + omarchy-hyprland-monitor-internal recover + omarchy-hyprland-monitor-internal-mirror recover +} + +recover_after_monitor_removal() { + recover_internal_monitor_toggles + + ( + sleep 1 + recover_internal_monitor_toggles + ) & +} + socat -U - "UNIX-CONNECT:$SOCKET" | while read -r event; do case "$event" in monitorremoved\>\>*|monitorremovedv2\>\>*) - omarchy-hyprland-monitor-internal recover - omarchy-hyprland-monitor-internal-mirror recover + recover_after_monitor_removal ;; esac done diff --git a/bin/omarchy-system-sleep-lock b/bin/omarchy-system-sleep-lock index be3ba621..2ebf79c1 100755 --- a/bin/omarchy-system-sleep-lock +++ b/bin/omarchy-system-sleep-lock @@ -10,6 +10,9 @@ if [[ ! $wait_attempts =~ ^[0-9]+$ ]] || (( wait_attempts < 1 )); then wait_attempts=100 fi +omarchy-hyprland-monitor-internal recover >/dev/null 2>&1 || true +omarchy-hyprland-monitor-internal-mirror recover >/dev/null 2>&1 || true + omarchy-shell lock lock >/dev/null 2>&1 || exit 1 for (( attempt = 0; attempt < wait_attempts; attempt++ )); do diff --git a/test/shell.d/monitor-recovery-test.sh b/test/shell.d/monitor-recovery-test.sh new file mode 100755 index 00000000..7ff6c361 --- /dev/null +++ b/test/shell.d/monitor-recovery-test.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +monitor_watch="$ROOT/bin/omarchy-hyprland-monitor-watch" +sleep_lock="$ROOT/bin/omarchy-system-sleep-lock" + +grep -F 'recover_after_monitor_removal' "$monitor_watch" >/dev/null +grep -F 'sleep 1' "$monitor_watch" >/dev/null +grep -F 'omarchy-hyprland-monitor-internal recover' "$monitor_watch" >/dev/null +grep -F 'omarchy-hyprland-monitor-internal-mirror recover' "$monitor_watch" >/dev/null +pass "monitor watcher retries internal monitor recovery after removal" + +grep -F 'omarchy-hyprland-monitor-internal recover >/dev/null 2>&1 || true' "$sleep_lock" >/dev/null +grep -F 'omarchy-hyprland-monitor-internal-mirror recover >/dev/null 2>&1 || true' "$sleep_lock" >/dev/null +pass "sleep lock recovers internal monitor toggles before suspend"