aboutsummaryrefslogtreecommitdiffstats
path: root/config
diff options
context:
space:
mode:
authorThomas Irgang <info@tomirgang.de>2026-08-16 10:21:39 +0200
committerPinapelz <yukais@pinapelz.com>2026-08-29 21:41:34 -0700
commit07a1296ca25d103ff9d66c8add4687f2d038b658 (patch)
treea1ecf51a33866ad20062b5adc6410fcbcef38e12 /config
parent9423a676432fe9aa40675e4cdf94a4736e6f5a64 (diff)
fix: Keep Waybar alive when switching themes from a bar module (#96)
Switching Dark/Light from the Waybar module left the bar gone until the next login. DarkLight.sh is wired to a Waybar module on-click, so it runs inside waybar.service's cgroup. Its cleanup loop kills waybar, systemd tears down the whole unit, and every process in that cgroup goes with it - DarkLight.sh included, before it ever reaches Refresh.sh. Nothing is left to start the replacement bar. Refresh.sh had the same problem on its own: it killed waybar and relaunched it from a shell that had just been torn down. Drop waybar from the DarkLight.sh cleanup loop and let Refresh.sh own the restart, run as a transient systemd-run --user unit so it sits outside the caller's cgroup and survives the teardown. Fall back to setsid where systemd-run is unavailable. Detect systemd management via the unit's LoadState instead of is-enabled. WaybarStartup.sh starts the unit on demand and leaves it disabled, so is-enabled reports "disabled" for setups that are in fact systemd-managed. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'config')
-rwxr-xr-xconfig/hypr/scripts/DarkLight.sh6
-rwxr-xr-xconfig/hypr/scripts/Refresh.sh56
2 files changed, 35 insertions, 27 deletions
diff --git a/config/hypr/scripts/DarkLight.sh b/config/hypr/scripts/DarkLight.sh
index 913099fc..5bad2af8 100755
--- a/config/hypr/scripts/DarkLight.sh
+++ b/config/hypr/scripts/DarkLight.sh
@@ -354,7 +354,11 @@ ${SCRIPTSDIR}/WallustSwww.sh
if [ "$no_restart" -eq 0 ]; then
sleep 2
# kill process
- for pid1 in waybar rofi swaync ags swaybg; do
+ # NOTE: waybar is deliberately excluded here. This script is usually launched from a
+ # waybar module on-click, so it lives in waybar.service's cgroup. Killing waybar makes
+ # systemd tear down the whole unit, taking this script with it before Refresh.sh runs.
+ # Refresh.sh restarts waybar detached from that cgroup instead.
+ for pid1 in rofi swaync ags swaybg; do
killall "$pid1"
done
sleep 1
diff --git a/config/hypr/scripts/Refresh.sh b/config/hypr/scripts/Refresh.sh
index 79495d0f..98fbcb18 100755
--- a/config/hypr/scripts/Refresh.sh
+++ b/config/hypr/scripts/Refresh.sh
@@ -47,38 +47,42 @@ for pid in $(pidof rofi swaync ags swaybg); do
sleep 0.1
done
-# Restart waybar once (works with systemd user unit or manual launch setups)
-restart_waybar() {
- local manage_with_systemd=0
+# Does a waybar.service user unit exist? Checks LoadState rather than is-enabled: the
+# unit is usually started on demand by WaybarStartup.sh and left disabled, so is-enabled
+# reports "disabled" for a setup that is nevertheless systemd-managed.
+waybar_unit_exists() {
+ local load_state
+ command -v systemctl >/dev/null 2>&1 || return 1
+ load_state="$(systemctl --user show waybar.service --property=LoadState --value 2>/dev/null || true)"
+ [ -n "$load_state" ] && [ "$load_state" != "not-found" ]
+}
- if command -v systemctl >/dev/null 2>&1; then
- if systemctl --user --quiet is-active graphical-session.target 2>/dev/null || systemctl --user --quiet is-active wayland-session@*.target 2>/dev/null; then
- if systemctl --user --quiet is-active waybar.service 2>/dev/null || systemctl --user --quiet is-enabled waybar.service 2>/dev/null; then
- manage_with_systemd=1
- fi
- fi
- fi
+# Restart waybar once, DETACHED from this script's cgroup.
+# This script is typically invoked from a waybar module on-click (e.g. DarkLight.sh), so
+# it runs inside waybar.service's cgroup. Killing waybar from in there makes systemd tear
+# down the whole unit and every process in it - this script included - so the replacement
+# waybar never gets launched and the bar stays gone. Running the restart as a transient
+# systemd unit puts it outside that cgroup, where it survives the teardown.
+restart_waybar() {
+ local restart_cmd
- if [ "$manage_with_systemd" -eq 1 ]; then
- systemctl --user stop waybar.service >/dev/null 2>&1 || true
+ if waybar_unit_exists; then
+ restart_cmd='pkill -x waybar; pkill -x .waybar-wrapped; sleep 0.3; systemctl --user reset-failed waybar.service >/dev/null 2>&1; exec systemctl --user restart waybar.service'
+ else
+ restart_cmd='pkill -x waybar; pkill -x .waybar-wrapped; sleep 0.3; exec waybar'
fi
- pkill -x waybar >/dev/null 2>&1 || true
- pkill -x '.waybar-wrapped' >/dev/null 2>&1 || true
- sleep 0.2
- if pgrep -x waybar >/dev/null 2>&1 || pgrep -x '.waybar-wrapped' >/dev/null 2>&1; then
- pkill -9 -x waybar >/dev/null 2>&1 || true
- pkill -9 -x '.waybar-wrapped' >/dev/null 2>&1 || true
+ if command -v systemd-run >/dev/null 2>&1 &&
+ systemd-run --user --collect --quiet --no-block \
+ --setenv=WAYLAND_DISPLAY="${WAYLAND_DISPLAY:-}" \
+ --setenv=XDG_RUNTIME_DIR="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}" \
+ --setenv=HYPRLAND_INSTANCE_SIGNATURE="${HYPRLAND_INSTANCE_SIGNATURE:-}" \
+ /bin/bash -c "$restart_cmd" >/dev/null 2>&1; then
+ return 0
fi
- sleep 0.2
- if [ "$manage_with_systemd" -eq 1 ]; then
- if ! systemctl --user start waybar.service >/dev/null 2>&1; then
- waybar >/dev/null 2>&1 &
- fi
- else
- waybar >/dev/null 2>&1 &
- fi
+ # Fallback when systemd-run is unavailable: detach as far as we can.
+ setsid /bin/bash -c "$restart_cmd" >/dev/null 2>&1 &
}
restart_waybar
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage