1
0
Fork 0
gnu-plus-dotfiles/dot_config/sway/caffeine.sh
rain 27ae3a3b18 sway: drop -t 2000/-t 3000 from notify-send, source restore-wayland-env in toggle-dropdown/wifi-menu
The actual cause of 'caffeine notification doesn't show' was the
-t 2000 timeout: the notification popped for 2 seconds and self-cleared
before the user could see it. Manual notify-send from a terminal (no
-t flag) used mako's default-timeout=5000 and was visible — so the user
saw my test notifications but not their own clicks.

Fix: drop the -t flag everywhere so mako config owns the duration.
Added: source restore-wayland-env.sh in toggle-dropdown.sh and
wifi-menu.sh — same env-loss pattern as caffeine.sh, would have
been next on the bug list.

Verified on tadbit: -t 2000 notification visible at +0.5s, gone at
+2.5s (user missed it). No -t flag: visible at +0.5s, gone at +5.5s
(visible long enough to read).
2026-06-23 22:24:16 -04:00

43 lines
1.9 KiB
Bash
Executable file

#!/bin/bash
# caffeine.sh — toggle caffeine mode by killing/restarting swayidle
# When ON: kill swayidle (no idle lock/screen-off)
# When OFF: restart swayidle with the same timeouts as the Sway session
#
# The "restart" path calls start-swayidle.sh, which is the SAME script
# Sway's config uses (`exec $HOME/.config/sway/start-swayidle.sh`).
# Single source of truth: if you change timeouts, change them in
# start-swayidle.sh and both the session start AND the toggle share them.
# (Earlier this script hardcoded the swayidle command itself, and it
# drifted out of sync with sway/config — toggling caffeine off would
# silently change your lock command and timeout values.)
#
# At top: source restore-wayland-env.sh to inherit WAYLAND_DISPLAY (and
# friends) from a running Wayland client. waybar's on-click context
# strips these, so without this:
# - notify-send writes to D-Bus (exits 0) but mako can't display
# (no Wayland socket to render on)
# - the click appears to silently do nothing
# This is the SAME bug start-swayidle.sh had for swayidle itself —
# fixed in both places via the shared helper.
# shellcheck source=restore-wayland-env.sh
source "$HOME/.config/sway/restore-wayland-env.sh"
FLAG="/tmp/caffeine-inhibit"
if [ -f "$FLAG" ]; then
# Turn OFF caffeine — restart swayidle
rm -f "$FLAG"
killall swayidle 2>/dev/null
"$HOME/.config/sway/start-swayidle.sh" &
# No -t flag → mako's `default-timeout` (currently 5000ms) controls duration.
# Earlier this used -t 2000 (2 seconds) but that vanished faster than the
# user could see it — the click "appeared to do nothing" because the
# notification popped and self-cleared in 2s. mako config owns the timeout.
notify-send "☕ Caffeine OFF" "Idle sleep enabled" 2>/dev/null
else
# Turn ON caffeine — kill swayidle
touch "$FLAG"
killall swayidle 2>/dev/null
notify-send "☕ Caffeine ON" "Idle sleep disabled" 2>/dev/null
fi