#!/bin/bash
# Re-apply RGB after suspend/resume. Direct-mode Corsair/Aura state is volatile and the USB
# controllers re-enumerate on wake, so restart the OpenRGB server (rgb-lavender.service is
# PartOf it and re-runs automatically). Pure user-level: watches logind's PrepareForSleep.
set -u
exec dbus-monitor --system "type='signal',interface='org.freedesktop.login1.Manager',member='PrepareForSleep'" |
while read -r line; do
  case "$line" in
    *"boolean false"*)
      sleep 3   # let USB finish re-enumerating before re-detecting
      systemctl --user restart openrgb-server.service
      ;;
  esac
done
