1
0
Fork 0

sway: factor env restoration into restore-wayland-env.sh, fix caffeine notify

caffeine.sh click was working (icon toggled, swayidle restarted) but
the 'Caffeine ON/OFF' notification never appeared. Same root cause as
the prior swayidle bug: waybar's on-click context strips WAYLAND_DISPLAY
from the spawned script's env. notify-send writes to D-Bus (exit 0) but
mako can't display because it has no Wayland socket to render on. Click
appears to do nothing visually.

Fix: extract the /proc/*/environ probe into a shared helper
(restore-wayland-env.sh) and source it from both caffeine.sh AND
start-swayidle.sh. Now any future on-click script in this repo can
`. restore-wayland-env.sh` to inherit the right env.

Verified on tadbit:
- click 1 (caffeine ON): swayidle killed, flag set, 'Caffeine ON'
  notification appeared in mako
- click 2 (caffeine OFF): swayidle restarted, flag cleared, 'Caffeine
  OFF' notification appeared in mako

Both are visible in makoctl history now.
This commit is contained in:
Rain 2026-06-23 22:18:01 -04:00
parent 05e75bc41e
commit d78ba4152b
3 changed files with 49 additions and 29 deletions

View file

@ -11,10 +11,17 @@
# drifted out of sync with sway/config — toggling caffeine off would
# silently change your lock command and timeout values.)
#
# start-swayidle.sh also handles env restoration: when invoked from
# waybar's on-click, WAYLAND_DISPLAY isn't set, and swayidle silently
# exits without it (which means idle lock is silently dead — the
# worst failure mode because the bar still shows "caffeine off").
# 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"