#!/usr/bin/env bash

# omarchy:summary=Reload sway so its config re-reads the theme's sway.conf (used by the Omarchy theme switching).
# omarchy:hidden=true

# Every process in a sway session inherits SWAYSOCK. A caller from outside the
# session (ssh, a TTY) has none, so look for the socket the way omarchy-shell
# recovers WAYLAND_DISPLAY. No socket means no sway, and nothing to reload.
if [[ -z ${SWAYSOCK:-} ]]; then
  SWAYSOCK=$(ls -t "${XDG_RUNTIME_DIR:-/run/user/$UID}"/sway-ipc.*.sock 2>/dev/null | head -n1)
  [[ -n $SWAYSOCK ]] || exit 0
  export SWAYSOCK
fi

omarchy-cmd-present swaymsg || exit 0

# A reload restarts the bars sway started, so a bar reading the theme's
# waybar.css picks the new palette up too.
swaymsg reload >/dev/null 2>&1 || true
