fix(home): keep waybar + wallpaper on surviving monitor after unplug

Hyprland drops the layer-shell surfaces on the remaining output when a
monitor is removed and does not recreate them, so waybar and the awww
wallpaper vanish on unplug. The socket2 watcher only reacted to
`monitoradded`, which masked it — reconnecting re-fired the add and
restored both. Handle `monitorremoved` too, and on either event re-push
the wallpaper and reload waybar (SIGUSR2 rebuilds its per-output bars).
Renamed `wallpaper-hotplug` to `monitor-hotplug` since it now does both.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-09 10:48:16 +02:00
co-authored by Claude Opus 4.8
parent fbf68fa4a4
commit 752ee84430
2 changed files with 15 additions and 9 deletions
+13 -7
View File
@@ -21,15 +21,21 @@ let
# awww-daemon paints only the outputs present when `awww img` last ran and does
# not repaint a monitor hotplugged afterwards — it comes up on the fill color
# (black), and a transparent foot on it then shows that black, not the
# wallpaper. Watch Hyprland's event socket and re-push the wallpaper (setbg
# with no arg → all current outputs) on each monitor-add. Hyprland emits both
# `monitoradded` and `monitoraddedv2`; match only the former so setbg fires
# once. Runs as a Hyprland exec-once (see home.nix).
wallpaperHotplug = pkgs.writeShellScriptBin "wallpaper-hotplug" ''
# wallpaper. Symmetric problem on unplug: removing an output makes Hyprland
# drop and not recreate the layer-shell surfaces on the surviving monitor, so
# its waybar and wallpaper vanish. Watch Hyprland's event socket and, on either
# add or remove, re-push the wallpaper (setbg with no arg → all current
# outputs) and reload waybar (SIGUSR2 rebuilds its per-output bars). Hyprland
# emits both `monitoradded` and `monitoraddedv2`; match only the non-v2 forms
# so each side fires once. Runs as a Hyprland exec-once (see home.nix).
monitorHotplug = pkgs.writeShellScriptBin "monitor-hotplug" ''
sock="''${XDG_RUNTIME_DIR}/hypr/''${HYPRLAND_INSTANCE_SIGNATURE}/.socket2.sock"
${pkgs.socat}/bin/socat -u UNIX-CONNECT:"$sock" - | while IFS= read -r line; do
case "$line" in
"monitoradded>>"*) setbg ;;
"monitoradded>>"* | "monitorremoved>>"*)
setbg
${pkgs.procps}/bin/pkill -USR2 -x .waybar-wrapped || true
;;
esac
done
'';
@@ -66,7 +72,7 @@ in
home.packages = with pkgs; [
setbg
wallpaperHotplug # re-push wallpaper to a hotplugged monitor (see comment above)
monitorHotplug # re-push wallpaper + reload waybar on monitor add/remove (see comment above)
awww # wayland wallpaper daemon (setbg backend)
wl-clipboard # wl-copy, for the yank binds
imagemagick # `magick`: rotate/flip binds