From 154bcc85d47139be52c2cfd6ca2bd0b5b4682727 Mon Sep 17 00:00:00 2001 From: 28allday Date: Thu, 23 Apr 2026 22:50:14 +0100 Subject: [PATCH] Also recover when HYPRLAND_INSTANCE_SIGNATURE is stale MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Walker's env can carry a stale HIS across Hyprland restarts — the variable points at a signature whose socket dir no longer exists, so hyprctl dumps a plain-text "not running" error to stdout and the TUI silently bails. Validate HIS against `$XDG_RUNTIME_DIR/hypr/$HIS/` and fall through to the `hyprctl instances` recovery path when the directory is missing, not only when HIS is unset. Same detection added to the watcher. --- motion-wallpaper-toggle | 25 +++++++++++++++++-------- motion-wallpaper-watcher | 11 ++++++----- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/motion-wallpaper-toggle b/motion-wallpaper-toggle index 6f23a9d..c3d2e09 100644 --- a/motion-wallpaper-toggle +++ b/motion-wallpaper-toggle @@ -182,19 +182,28 @@ show_header() { # ===== selection ============================================================== ensure_hyprland_env() { - # The TUI can be launched from contexts whose env doesn't carry - # HYPRLAND_INSTANCE_SIGNATURE (XDG launchers, cron, ssh). `hyprctl instances` - # still works in that case and prints the running signatures, so recover by - # picking the first one. If we can't, leave HIS unset and let the caller - # surface a friendly error. - if [ -n "${HYPRLAND_INSTANCE_SIGNATURE:-}" ]; then + # The TUI can be launched from contexts whose env doesn't carry a valid + # HYPRLAND_INSTANCE_SIGNATURE. Two failure modes: + # 1) HIS unset (fresh login shell from a non-graphical context) + # 2) HIS set but STALE — points to a previous Hyprland session whose + # socket no longer exists (seen when Walker's env carries the + # signature from an earlier login). The second case is silent but + # equally broken: hyprctl dumps a plain-text error on stdout. + # `hyprctl instances` always reports the *live* signatures, so recover + # from that. Leave HIS unchanged if we can't find a live instance. + local his="${HYPRLAND_INSTANCE_SIGNATURE:-}" + if [ -n "$his" ] && [ -d "$RUNTIME_DIR/hypr/$his" ]; then return 0 fi local sig sig="$(hyprctl instances 2>/dev/null | awk '/^instance /{sub(/:$/,"",$2); print $2; exit}')" - if [ -n "$sig" ]; then + if [ -n "$sig" ] && [ "$sig" != "$his" ]; then export HYPRLAND_INSTANCE_SIGNATURE="$sig" - log "recovered HYPRLAND_INSTANCE_SIGNATURE=$sig from hyprctl instances" + if [ -n "$his" ]; then + log "replaced stale HYPRLAND_INSTANCE_SIGNATURE ($his → $sig)" + else + log "recovered HYPRLAND_INSTANCE_SIGNATURE=$sig from hyprctl instances" + fi fi } diff --git a/motion-wallpaper-watcher b/motion-wallpaper-watcher index 67c7ed7..f9d17eb 100644 --- a/motion-wallpaper-watcher +++ b/motion-wallpaper-watcher @@ -20,15 +20,16 @@ log() { printf '[%s] watcher: %s\n' "$(date '+%Y-%m-%d %H:%M:%S')" "$*" >> "$LOG_FILE" } -if [ -z "${HYPRLAND_INSTANCE_SIGNATURE:-}" ]; then - # Recover the signature from `hyprctl instances` — same trick the toggle - # script uses when launched from an env that didn't inherit HIS. +his="${HYPRLAND_INSTANCE_SIGNATURE:-}" +if [ -z "$his" ] || [ ! -d "$RUNTIME_DIR/hypr/$his" ]; then + # HIS is missing or stale (points to a dead session). Recover from the + # live signature reported by `hyprctl instances`. sig="$(hyprctl instances 2>/dev/null | awk '/^instance /{sub(/:$/,"",$2); print $2; exit}')" if [ -n "$sig" ]; then export HYPRLAND_INSTANCE_SIGNATURE="$sig" - log "recovered HYPRLAND_INSTANCE_SIGNATURE=$sig from hyprctl instances" + log "using HYPRLAND_INSTANCE_SIGNATURE=$sig (was: ${his:-unset})" else - log "HYPRLAND_INSTANCE_SIGNATURE not set and no instance found — exiting" + log "HYPRLAND_INSTANCE_SIGNATURE not usable and no live instance found — exiting" exit 0 fi fi