Dotfiles/desktopenvs/hyprlua/scripts/caffeine-manual-status.sh

19 lines
763 B
Bash
Executable File

#!/bin/bash
# Reports the MANUAL-INHIBIT input for the Eww caffeine widget: whether a manual
# caffeine toggle currently holds the shared idle lock.
#
# The lock is shared with presence-detect.sh, so "PID alive" alone can't tell the
# two sources apart. OWNED_FLAG is present only while the daemon owns the lock, so
# "PID alive AND OWNED_FLAG absent" uniquely means a manual caffeine session holds
# it. (For the PRESENCE input — camera sees you — see presence-status.sh.)
#
# Prints "true" for a manual caffeine session, else "false".
PID_FILE="/tmp/caffeine-inhibit.pid"
OWNED_FLAG="/tmp/presence-inhibit-owned"
if [[ -f "$PID_FILE" ]] && kill -0 "$(cat "$PID_FILE")" 2>/dev/null && [[ ! -f "$OWNED_FLAG" ]]; then
echo "true"
else
echo "false"
fi