23 lines
876 B
Bash
Executable File
23 lines
876 B
Bash
Executable File
#!/bin/bash
|
|
# Toggle idle inhibit via systemd-inhibit (swayidle respects the logind idle hint).
|
|
# This lock is shared with presence-detect.sh, which also inhibits idle while
|
|
# motion is detected — OWNED_FLAG marks lock ownership between the two, so clear
|
|
# it on every manual toggle: this action is always a manual takeover of the lock.
|
|
PID_FILE="/tmp/caffeine-inhibit.pid"
|
|
OWNED_FLAG="/tmp/presence-inhibit-owned"
|
|
|
|
if [[ -f "$PID_FILE" ]] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null; then
|
|
kill "$(cat "$PID_FILE")"
|
|
rm -f "$PID_FILE" "$OWNED_FLAG"
|
|
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"
|
|
rm -f "$OWNED_FLAG"
|
|
notify-send -t 2000 "Caffeine" "Idle inhibited"
|
|
fi
|