From 752ee844305f15049ae4d59324f7b740d66bd62e Mon Sep 17 00:00:00 2001 From: Daniel Fainberg Date: Sun, 9 Aug 2026 10:48:16 +0200 Subject: [PATCH] fix(home): keep waybar + wallpaper on surviving monitor after unplug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- modules/home.nix | 4 ++-- modules/media.nix | 20 +++++++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/modules/home.nix b/modules/home.nix index 3ebbb08..8928ff4 100644 --- a/modules/home.nix +++ b/modules/home.nix @@ -661,8 +661,8 @@ in # the ~/.local/share/bg symlink if it exists. "awww-daemon" "sh -c '[ -e \"$HOME/.local/share/bg\" ] && awww img \"$HOME/.local/share/bg\"'" - # re-push the wallpaper onto monitors connected after login (media.nix) - "wallpaper-hotplug" + # re-push wallpaper + reload waybar on monitor add/remove (media.nix) + "monitor-hotplug" ]; }; }; diff --git a/modules/media.nix b/modules/media.nix index b29de0c..ded2412 100644 --- a/modules/media.nix +++ b/modules/media.nix @@ -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