omarchy-hyprland-monitor-watch ran poll_clamshell_state() every 2s for the whole session, and each pass forks omarchy-hyprland-monitor-clamshell plus its hyprctl/jq/monitor-* children. Clamshell (lid) handling can only ever apply to a machine with a lid, so on desktops and VMs this was pure churn — the single largest remaining source of idle process wakeups (~3 forks/sec on an otherwise idle desktop). Gate the poll behind a new omarchy-hw-laptop helper (lid button, or a laptop DMI chassis type as a fallback). The event-driven socat watch on Hyprland monitor add/remove is unchanged, so monitor hotplug still reconciles everywhere; only the periodic lid poll is now laptop-only. Verified on a desktop: steady-state omarchy-hyprland-* forks drop from ~3/sec to zero, socat watch still present. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
52 lines
1.2 KiB
Bash
Executable File
52 lines
1.2 KiB
Bash
Executable File
#!/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
|