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.
36 lines
1.8 KiB
Bash
Executable file
36 lines
1.8 KiB
Bash
Executable file
#!/bin/bash
|
|
# start-swayidle.sh — canonical swayidle startup for the Sway session.
|
|
#
|
|
# Single source of truth for the swayidle command. Invoked from:
|
|
# 1. ~/.config/sway/config: exec $HOME/.config/sway/start-swayidle.sh
|
|
# 2. ~/.config/sway/caffeine.sh: after killall swayidle, to re-arm
|
|
#
|
|
# Why a wrapper instead of inlining the command in sway/config? Because
|
|
# caffeine.sh needs to RESTART swayidle after killing it, and the restart
|
|
# must use the same timeouts and lock command as the original. Hardcoding
|
|
# it twice drifts (see git log — swayidle line in caffeine.sh got out of
|
|
# sync with the one in sway/config, so toggling caffeine off would
|
|
# silently change your lock command and timeout values).
|
|
#
|
|
# Env: this script is run by:
|
|
# - sway at session start, with the full Wayland/Sway env (correct)
|
|
# - caffeine.sh from waybar's on-click, with NO Wayland env (broken — see below)
|
|
# When run from caffeine.sh, swayidle needs WAYLAND_DISPLAY to talk to the
|
|
# compositor. The shared helper restore-wayland-env.sh probes /proc for
|
|
# an already-running Wayland client and inherits WAYLAND_DISPLAY / DISPLAY /
|
|
# DBUS_SESSION_BUS_ADDRESS / XDG_RUNTIME_DIR from it. This is the same
|
|
# trick `dbus-update-activation-environment` uses internally, just per-process.
|
|
#
|
|
# Returns: never. Runs as the foreground process; sway's exec replaces the
|
|
# shell with this script, and swayidle takes over. When started from
|
|
# caffeine.sh, the script is backgrounded (&) and this function returns.
|
|
set -e
|
|
|
|
# shellcheck source=restore-wayland-env.sh
|
|
source "$HOME/.config/sway/restore-wayland-env.sh"
|
|
|
|
exec swayidle -w \
|
|
timeout 300 "$HOME/.config/sway/lock-fancy.sh" \
|
|
timeout 600 'swaymsg "output * power off"' \
|
|
resume 'swaymsg "output * power on"' \
|
|
before-sleep "$HOME/.config/sway/lock-fancy.sh"
|