#!/bin/bash
# Toggle idle inhibit via systemd-inhibit (swayidle respects the logind idle hint).
PID_FILE="/tmp/caffeine-inhibit.pid"

if [[ -f "$PID_FILE" ]] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
    kill "$(cat "$PID_FILE")"
    rm -f "$PID_FILE"
    notify-send -t 2000 "Caffeine" "Idle inhibit OFF"
else
    systemd-inhibit --what=idle:sleep \
        --who="caffeine" \
        --why="Caffeine mode active" \
        --mode=block \
        sleep infinity &
    echo $! > "$PID_FILE"
    notify-send -t 2000 "Caffeine" "Idle inhibited"
fi
