From 30eadb8039d2b24dfa654e7eb2c7ec02e9e6e283 Mon Sep 17 00:00:00 2001
From: Luca Bilke <luca@bil.ke>
Date: Sun, 4 Feb 2024 11:47:19 +0100
Subject: [PATCH] rework background killing

---
 .config/X11/xinitrc             | 4 +---
 .local/libexec/dwm/autostart.sh | 6 +++++-
 2 files changed, 6 insertions(+), 4 deletions(-)

diff --git a/.config/X11/xinitrc b/.config/X11/xinitrc
index 6408771e..5cc4a14b 100755
--- a/.config/X11/xinitrc
+++ b/.config/X11/xinitrc
@@ -14,7 +14,5 @@ echo "Starting DWM"
 
 dwm
 
-echo "Exited DWM, Killing $(jobs -p | awk "{print \$3}")"
-
-kill $(jobs -p | awk "{print \$3}")
+echo "Exited DWM"
 '
diff --git a/.local/libexec/dwm/autostart.sh b/.local/libexec/dwm/autostart.sh
index ed5e35d2..50daceba 100755
--- a/.local/libexec/dwm/autostart.sh
+++ b/.local/libexec/dwm/autostart.sh
@@ -1,6 +1,9 @@
 #!/bin/sh
 # This script is executed by DWM on start.
 
+SIGINT=2 SIGTERM=15
+trap 'trap - SIGTERM && kill -- -$$' $SIGINT $SIGTERM EXIT
+
 start() {
     pidof -sx "$1" || "$@" &
 }
@@ -32,9 +35,10 @@ remaps -qd
 
 start unclutter -noevents &
 start gpgconf --launch gpg-agent
-start env PATH="$HOME/.local/libexec/statusbar:$PATH" dwmblocks
 start picom
 start pipewire
 start dunst
 start checkup
 start syncthingtray
+
+killall dwmblocks; env PATH="$HOME/.local/libexec/statusbar:$PATH" dwmblocks &