#!/bin/bash # Reports whether the *presence-detect daemon* is currently holding the idle # inhibitor (i.e. the camera saw motion and is auto-keeping the screen awake), # as opposed to a manual caffeine toggle. # # The lock is shared with caffeine.sh, so PID_FILE alone can't tell the two # sources apart. OWNED_FLAG is touched only by presence-detect.sh when it starts # the inhibitor and cleared by both a manual caffeine toggle and the daemon's # own release — so "PID alive AND OWNED_FLAG present" uniquely means the daemon # owns the lock right now. # # Prints "true" when presence-detect owns the lock, else "false". Used by the # Eww caffeine widget to highlight itself in the Active Hot Pink accent. 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