From 386da5117860150b9fc916871dd1693c34600526 Mon Sep 17 00:00:00 2001 From: Bernardo Magri Date: Thu, 30 Apr 2026 19:24:25 +0100 Subject: [PATCH] fix(waybar): SIGUSR2 reload to avoid surface-recreate ghost on theme switch Theme-switching ran systemctl --user restart waybar.service, which tears down waybar's wayland layer-shell surface and creates a new one back-to-back. Hyprland needs a frame to clear the destroyed surface; the new instance attaches its surface immediately, so for a frame or two the old waybar pixels remain visible behind/under the new bar - the "artifacts and old colors on top of new" symptom most visible on the fresh compositor of the live ISO. Switch to SIGUSR2 reload, which makes waybar re-read config.jsonc and CSS (including @import-ed files like ~/.config/nomarchy/current/theme/ waybar.css that theme-switch rewrites) without destroying the surface. Full systemctl start is kept for the cold-start case. Drive-by: replace the `systemctl list-unit-files` presence check with `systemctl cat` - list-unit-files returns 0 even on no-match, so the old check would always pick the systemctl branch and never fall through to the pkill fallback on systems where waybar isn't a systemd unit. Co-Authored-By: Claude Opus 4.7 --- .../scripts/utils/nomarchy-restart-waybar | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/features/scripts/utils/nomarchy-restart-waybar b/features/scripts/utils/nomarchy-restart-waybar index 041c848..0e4f690 100755 --- a/features/scripts/utils/nomarchy-restart-waybar +++ b/features/scripts/utils/nomarchy-restart-waybar @@ -1,13 +1,22 @@ #!/bin/bash -# Waybar is provided as a Home Manager user service -# (programs.waybar.systemd.enable = true), so the right way to restart it is -# via systemd. `pkill + uwsm-app` races with HM's sd-switch on theme changes -# and sometimes lands the new waybar without a full environment, producing -# the "wrong colors after theme switch" symptom. +# Reload waybar in place when it's already running. SIGUSR2 makes waybar +# re-read its config.jsonc and CSS (including @import-ed files like +# ~/.config/nomarchy/current/theme/waybar.css that theme-switch rewrites) +# without destroying its layer-shell surface. A full systemctl restart +# tears the surface down and creates a new one back-to-back, leaving a +# frame or two where Hyprland hasn't cleared the dead surface yet — that's +# the "old on top of new with artifacts" you see after a theme switch on +# the live ISO. +if pgrep -x waybar >/dev/null; then + exec pkill -SIGUSR2 -x waybar +fi -if systemctl --user list-unit-files waybar.service >/dev/null 2>&1; then - exec systemctl --user restart waybar.service +# Not running yet — start it. Prefer the HM systemd user unit +# (programs.waybar.systemd.enable = true). `systemctl cat` returns +# non-zero when the unit doesn't exist; `list-unit-files` does not. +if systemctl --user cat waybar.service >/dev/null 2>&1; then + exec systemctl --user start waybar.service fi # Fallback for systems where waybar isn't managed by systemd.