#!/bin/bash # omarchy:summary=Watch Hyprland monitor events and recover monitor toggles when a monitor is removed SOCKET="$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" LOCK="${XDG_RUNTIME_DIR:-/tmp}/omarchy-monitor-clamshell.lock" sync_clamshell() { ( flock -n 9 || exit 0 omarchy-hyprland-monitor-clamshell ) 9>"$LOCK" } sync_clamshell_after_monitor_change() { sync_clamshell ( for delay in 1 3 7; do sleep "$delay" sync_clamshell done ) & } poll_clamshell_state() { while true; do sleep 2 sync_clamshell done } sync_clamshell_after_monitor_change # The socat watch below already reconciles clamshell state on monitor # hotplug. The periodic poll only exists to catch laptop-lid transitions, # so there is nothing for it to do on a machine that isn't a laptop. if omarchy-hw-laptop; then poll_clamshell_state & fi socat -U - "UNIX-CONNECT:$SOCKET" | while read -r event; do case "$event" in monitoradded\>\>*|monitoraddedv2\>\>*) sync_clamshell_after_monitor_change ;; monitorremoved\>\>*|monitorremovedv2\>\>*) sync_clamshell_after_monitor_change ;; esac done