fix(home): relaunch waybar on monitor hotplug instead of SIGUSR2 reload
A real DP/HDMI unplug makes Hyprland tear down the layer-shell surfaces on the surviving monitor and not recreate them, so waybar and the wallpaper vanish there. A SIGUSR2 reload rereads waybar's config but does not recreate a bar that was already destroyed, so it left the laptop bar gone. Kill and restart waybar instead — a fresh process enumerates the current outputs and draws a bar on each — and add a settle delay before re-pushing the wallpaper so it lands on the settled geometry. Verified against a real DP-1 unplug: the LVDS-1 bar and wallpaper survive. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+1
-1
@@ -661,7 +661,7 @@ in
|
|||||||
# the ~/.local/share/bg symlink if it exists.
|
# the ~/.local/share/bg symlink if it exists.
|
||||||
"awww-daemon"
|
"awww-daemon"
|
||||||
"sh -c '[ -e \"$HOME/.local/share/bg\" ] && awww img \"$HOME/.local/share/bg\"'"
|
"sh -c '[ -e \"$HOME/.local/share/bg\" ] && awww img \"$HOME/.local/share/bg\"'"
|
||||||
# re-push wallpaper + reload waybar on monitor add/remove (media.nix)
|
# re-push wallpaper + relaunch waybar on monitor add/remove (media.nix)
|
||||||
"monitor-hotplug"
|
"monitor-hotplug"
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
+18
-8
@@ -7,7 +7,7 @@
|
|||||||
# awww-daemon and the boot-time restore from that symlink run as Hyprland
|
# awww-daemon and the boot-time restore from that symlink run as Hyprland
|
||||||
# `exec-once` (see home.nix).
|
# `exec-once` (see home.nix).
|
||||||
|
|
||||||
{ pkgs, ... }:
|
{ pkgs, config, ... }:
|
||||||
|
|
||||||
let
|
let
|
||||||
# setbg: persist the choice as an XDG-data symlink, then set it live. Startup
|
# setbg: persist the choice as an XDG-data symlink, then set it live. Startup
|
||||||
@@ -21,20 +21,30 @@ let
|
|||||||
# awww-daemon paints only the outputs present when `awww img` last ran and does
|
# 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
|
# 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
|
# (black), and a transparent foot on it then shows that black, not the
|
||||||
# wallpaper. Symmetric problem on unplug: removing an output makes Hyprland
|
# wallpaper. Symmetric problem on real DP/HDMI unplug: Hyprland drops the
|
||||||
# drop and not recreate the layer-shell surfaces on the surviving monitor, so
|
# layer-shell surfaces on the surviving monitor and does not recreate them, so
|
||||||
# its waybar and wallpaper vanish. Watch Hyprland's event socket and, on either
|
# 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
|
# add or remove, re-push the wallpaper (setbg with no arg → all current
|
||||||
# outputs) and reload waybar (SIGUSR2 rebuilds its per-output bars). Hyprland
|
# outputs) and fully relaunch waybar. A SIGUSR2 reload is not enough — it
|
||||||
# emits both `monitoradded` and `monitoraddedv2`; match only the non-v2 forms
|
# rereads config but does not recreate a bar Hyprland already tore down — so
|
||||||
# so each side fires once. Runs as a Hyprland exec-once (see home.nix).
|
# kill and restart, which enumerates the current outputs and draws a bar on
|
||||||
|
# each. The event flaps (several add/remove lines per plug); the loop is
|
||||||
|
# sequential so each pass converges to one waybar. 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).
|
||||||
|
hyprctl = "${config.wayland.windowManager.hyprland.finalPackage}/bin/hyprctl";
|
||||||
monitorHotplug = pkgs.writeShellScriptBin "monitor-hotplug" ''
|
monitorHotplug = pkgs.writeShellScriptBin "monitor-hotplug" ''
|
||||||
sock="''${XDG_RUNTIME_DIR}/hypr/''${HYPRLAND_INSTANCE_SIGNATURE}/.socket2.sock"
|
sock="''${XDG_RUNTIME_DIR}/hypr/''${HYPRLAND_INSTANCE_SIGNATURE}/.socket2.sock"
|
||||||
${pkgs.socat}/bin/socat -u UNIX-CONNECT:"$sock" - | while IFS= read -r line; do
|
${pkgs.socat}/bin/socat -u UNIX-CONNECT:"$sock" - | while IFS= read -r line; do
|
||||||
case "$line" in
|
case "$line" in
|
||||||
"monitoradded>>"* | "monitorremoved>>"*)
|
"monitoradded>>"* | "monitorremoved>>"*)
|
||||||
setbg
|
sleep 1 # let Hyprland settle the new geometry
|
||||||
${pkgs.procps}/bin/pkill -USR2 -x .waybar-wrapped || true
|
setbg # re-push wallpaper to all current outputs
|
||||||
|
${pkgs.procps}/bin/pkill -x waybar || true # relaunch waybar fresh (see comment)
|
||||||
|
i=0
|
||||||
|
while [ $i -lt 6 ] && ${pkgs.procps}/bin/pgrep -x waybar >/dev/null; do sleep 0.3; i=$((i+1)); done
|
||||||
|
${pkgs.procps}/bin/pkill -9 -x waybar || true
|
||||||
|
${hyprctl} dispatch exec waybar
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user