From 52d7975c56557b19189c30f9b63f706083d0d19b Mon Sep 17 00:00:00 2001 From: Kris Yotam Date: Sat, 14 Feb 2026 17:23:46 -0600 Subject: [PATCH] Seamless dwm renew: preserve dwmblocks, monitor state, and xresources - Skip killing autostart processes on restart, let autostart_exec handle seamless handoff - Enable SEAMLESS_RESTART_PATCH to persist monitor/tag state across renew - Enable BAR_HIDEVACANTTAGS_PATCH --- dwm.c | 16 +++++++++++----- patch/cool_autostart.c | 16 ++++++++++++++++ patches.h | 4 ++-- 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/dwm.c b/dwm.c index 0df5669231ecd96f84edf006632289bcdec65626..8a279946d7ecc0eaa3ff9621ba9862de71ab0b4b 100644 --- a/dwm.c +++ b/dwm.c @@ -1327,13 +1327,19 @@ cleanup(void) #endif // SEAMLESS_RESTART_PATCH #if COOL_AUTOSTART_PATCH - /* kill child processes */ - for (i = 0; i < autostart_len; i++) { - if (0 < autostart_pids[i]) { - kill(autostart_pids[i], SIGTERM); - waitpid(autostart_pids[i], NULL, 0); + /* kill child processes, but not on restart (autostart_exec will handle it) */ + #if RESTARTSIG_PATCH + if (!restart) { + #endif // RESTARTSIG_PATCH + for (i = 0; i < autostart_len; i++) { + if (0 < autostart_pids[i]) { + kill(autostart_pids[i], SIGTERM); + waitpid(autostart_pids[i], NULL, 0); + } } + #if RESTARTSIG_PATCH } + #endif // RESTARTSIG_PATCH #endif // COOL_AUTOSTART_PATCH selmon->lt[selmon->sellt] = &foo; diff --git a/patch/cool_autostart.c b/patch/cool_autostart.c index 848f5abcde2c5f84c696cf8b205efd8312ea0b49..5f9de32f7ea8de3cabcce39346add73fc72ee568 100644 --- a/patch/cool_autostart.c +++ b/patch/cool_autostart.c @@ -16,6 +16,22 @@ autostart_exec() autostart_pids = malloc(autostart_len * sizeof(pid_t)); for (p = autostart; *p; i++, p++) { + /* kill any existing instance before starting a new one (seamless restart) */ + FILE *cmd; + char pidline[256]; + pid_t oldpid; + int len = snprintf(pidline, sizeof(pidline), "pidof -s %s", *p); + if (len > 0 && (size_t)len < sizeof(pidline) && (cmd = popen(pidline, "r"))) { + if (fgets(pidline, sizeof(pidline), cmd)) { + oldpid = (pid_t)atol(pidline); + if (oldpid > 0) { + kill(oldpid, SIGTERM); + waitpid(oldpid, NULL, WNOHANG); + } + } + pclose(cmd); + } + if ((autostart_pids[i] = fork()) == 0) { setsid(); diff --git a/patches.h b/patches.h index 21464cb8494b6e1d8e8d5a9c43e4c8cd1f0ff621..5fca83f2f856112483f564ead265d10d7a4cffa8 100644 --- a/patches.h +++ b/patches.h @@ -350,7 +350,7 @@ /* This patch prevents dwm from drawing tags with no clients (i.e. vacant) on the bar. * https://dwm.suckless.org/patches/hide_vacant_tags/ */ -#define BAR_HIDEVACANTTAGS_PATCH 0 +#define BAR_HIDEVACANTTAGS_PATCH 1 /* With this patch dwm's built-in status bar is only shown when HOLDKEY is pressed * and the bar will now overlay the display. @@ -1106,7 +1106,7 @@ * * The above is not persisted across reboots, however. */ -#define SEAMLESS_RESTART_PATCH 0 +#define SEAMLESS_RESTART_PATCH 1 /* As opposed to the original patch this only adds a rule option allowing fake fullscreen * to be enabled for applications when they start. This is intended to be used in combination