#!/bin/sh
# powermenu: written by Wren Linux parts/power-menu.sh
# Lock, suspend, log out, reboot or power off, picked from a small menu.
# Escape closes it without doing anything.
# the theme's menu colors (bin/theme), else black and white
bg=$("$HOME/.local/bin/theme" get WMENU_BG 2>/dev/null) || bg=000000
fg=$("$HOME/.local/bin/theme" get WMENU_TEXT 2>/dev/null) || fg=ffffff
choice=$(printf '%s\n' Lock Suspend "Log out" Reboot "Power off" |
    wmenu -p "Power:" -f 'monospace 12' -N "$bg" -n "$fg" -M "$bg" -m "$fg" -S "$fg" -s "$bg") || exit 0
# shellcheck disable=SC2046  # the lock color: one word, checked (no inner quotes: sway's copy can't have them)
case $choice in
    # wren-lock: locks, then runs the on-lock programs (vault, KeePassXC);
    # without it, the same as LOCK_CMD in lib/sway.sh (test.sh checks)
    Lock)
        if [ -x "$HOME/.local/bin/wren-lock" ]; then exec "$HOME/.local/bin/wren-lock"; fi
        exec swaylock -f -c $(~/.local/bin/theme get LOCK 2>/dev/null || echo 000000) ;;
    Suspend) exec systemctl suspend ;;
    "Log out") exec swaymsg exit ;;
    Reboot) exec systemctl reboot ;;
    "Power off") exec systemctl poweroff ;;
esac
