feat(presence-detect): tint caffeine eww widget hot pink while presence holds the lock

Add presence-status.sh reporting true only when the daemon (not a manual
caffeine toggle) owns the shared idle lock, via the existing OWNED_FLAG.
Wire it into all three eww bars: the caffeine button gains a
.caffeine-presence class → the #E40046 Active accent used elsewhere, so
camera-driven auto-awake is visually distinct from a manual session.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
main
Amir Alexander Abdelbaki 2026-07-11 02:09:44 +02:00
parent defa69faab
commit dc9cf6d830
7 changed files with 69 additions and 9 deletions

View File

@ -75,7 +75,13 @@ tooltip {
.workspace-active { .workspace-active {
color: #E40046; color: #E40046;
}
// caffeine widget while the presence-detect daemon holds the idle lock:
// tint it the Active Hot Pink accent used for highlights everywhere else.
.caffeine-presence {
color: #E40046;
} }
menuitem { menuitem {

View File

@ -118,9 +118,15 @@
(defpoll caffeine-active :interval "2s" (defpoll caffeine-active :interval "2s"
"~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine-status.sh") "~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine-status.sh")
; presence-active poll — true only when the presence-detect daemon (not a manual
; caffeine toggle) is holding the idle lock, i.e. the camera currently sees you.
(defpoll presence-active :interval "2s"
"~/Dotfiles/desktopenvs/hyprlua/scripts/presence-status.sh")
(defwidget caffeine [] (defwidget caffeine []
(button :class "music" (button :class {presence-active == "true" ? "music caffeine-presence" : "music"}
:onclick "~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine.sh" :onclick "~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine.sh"
:tooltip {caffeine-active == "true" ? "Caffeine: ON" : "Caffeine: OFF"} :tooltip {presence-active == "true" ? "Caffeine: ON (presence)"
: caffeine-active == "true" ? "Caffeine: ON" : "Caffeine: OFF"}
{caffeine-active == "true" ? "☕" : "󰅺"})) {caffeine-active == "true" ? "☕" : "󰅺"}))

View File

@ -83,6 +83,12 @@ tooltip {
} }
// caffeine widget while the presence-detect daemon holds the idle lock:
// tint it the Active Hot Pink accent used for highlights everywhere else.
.caffeine-presence {
color: #E40046;
}
// astal-menu launcher button accent-coloured icon, highlight on hover // astal-menu launcher button accent-coloured icon, highlight on hover
.menu-launcher { .menu-launcher {
color: #E40046; color: #E40046;

View File

@ -164,9 +164,15 @@
(defpoll caffeine-active :interval "2s" (defpoll caffeine-active :interval "2s"
"~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine-status.sh") "~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine-status.sh")
; presence-active poll — true only when the presence-detect daemon (not a manual
; caffeine toggle) is holding the idle lock, i.e. the camera currently sees you.
(defpoll presence-active :interval "2s"
"~/Dotfiles/desktopenvs/hyprlua/scripts/presence-status.sh")
(defwidget caffeine [] (defwidget caffeine []
(button :class "music" (button :class {presence-active == "true" ? "music caffeine-presence" : "music"}
:onclick "~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine.sh" :onclick "~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine.sh"
:tooltip {caffeine-active == "true" ? "Caffeine: ON" : "Caffeine: OFF"} :tooltip {presence-active == "true" ? "Caffeine: ON (presence)"
: caffeine-active == "true" ? "Caffeine: ON" : "Caffeine: OFF"}
{caffeine-active == "true" ? "☕" : "󰅺"})) {caffeine-active == "true" ? "☕" : "󰅺"}))

View File

@ -75,7 +75,13 @@ tooltip {
.workspace-active { .workspace-active {
color: #E40046; color: #E40046;
}
// caffeine widget while the presence-detect daemon holds the idle lock:
// tint it the Active Hot Pink accent used for highlights everywhere else.
.caffeine-presence {
color: #E40046;
} }
menuitem { menuitem {

View File

@ -206,11 +206,20 @@
(defpoll caffeine-active :interval "2s" (defpoll caffeine-active :interval "2s"
"~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine-status.sh") "~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine-status.sh")
; presence-active poll — true only when the presence-detect daemon (not a manual
; caffeine toggle) is holding the idle lock, i.e. the camera currently sees you.
; Used to tint the caffeine widget in the Active Hot Pink accent.
(defpoll presence-active :interval "2s"
"~/Dotfiles/desktopenvs/hyprlua/scripts/presence-status.sh")
; caffeine widget — a button that toggles the caffeine idle-inhibit lock. ; caffeine widget — a button that toggles the caffeine idle-inhibit lock.
; ☕ = caffeine is ON (screen won't sleep), 󰅺 = caffeine is OFF (normal idle). ; ☕ = caffeine is ON (screen won't sleep), 󰅺 = caffeine is OFF (normal idle).
; Tooltip shows the current state for clarity. ; When presence detection is the reason the lock is held, the widget also turns
; the Active Hot Pink accent (.caffeine-presence) so auto-awake is distinct from
; a manual caffeine session. Tooltip shows the current state for clarity.
(defwidget caffeine [] (defwidget caffeine []
(button :class "music" (button :class {presence-active == "true" ? "music caffeine-presence" : "music"}
:onclick "~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine.sh" :onclick "~/Dotfiles/desktopenvs/hyprlua/scripts/caffeine.sh"
:tooltip {caffeine-active == "true" ? "Caffeine: ON" : "Caffeine: OFF"} :tooltip {presence-active == "true" ? "Caffeine: ON (presence)"
: caffeine-active == "true" ? "Caffeine: ON" : "Caffeine: OFF"}
{caffeine-active == "true" ? "☕" : "󰅺"})) {caffeine-active == "true" ? "☕" : "󰅺"}))

View File

@ -0,0 +1,21 @@
#!/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