Dotfiles/desktopenvs/hyprlua/scripts/orbit-menu.sh

42 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Toggle the orbit-menu radial popup. Forwards a verb to the resident daemon over
# D-Bus; if the daemon isn't running yet, starts it first. Mirrors menu-toggle.sh.
#
# orbit-menu.sh power -> open straight into the Power ring (sleep/reboot/
# poweroff/soft-reboot); re-press to close
# orbit-menu.sh menu -> open the 5-category root; re-press to close
#
# (No `set -e`: a non-zero `busctl` in the wait loop is expected and must not
# abort the script before it forwards the verb.)
BUS="eu.abdelbaki.orbitmenu"
OBJ="/eu/abdelbaki/orbitmenu"
APP="${HOME}/.config/orbit-menu/main.py"
case "${1:-menu}" in
power) VERB="--power"; ACTION="power" ;;
*) VERB="--menu"; ACTION="menu" ;;
esac
registered() { busctl --user list 2>/dev/null | grep -q "$BUS"; }
if registered; then
# Fast path: activate directly over D-Bus instead of cold-starting a second
# python3 + PyGObject + GTK4 process just to forward one verb.
exec gdbus call --session --dest "$BUS" --object-path "$OBJ" \
--method org.gtk.Actions.Activate "$ACTION" "[]" "{}" >/dev/null
fi
# Not registered yet: start the daemon and wait for it to come up, then retry.
"${HOME}/.config/scripts/orbit-menu-start.sh" >/dev/null 2>&1 &
for _ in $(seq 1 25); do
if registered; then
exec "$0" "$@"
fi
sleep 0.2
done
# Still not registered after 5s: fall back to becoming the primary instance
# ourselves (Gio single-instance handles the routing either way).
exec python3 "$APP" "$VERB"