commit 8e79f72e0af274edbf390609848cfd024dedaa8e
parent 1eb04ce4f990967542c03d323cbb0dbc47ab6265
Author: mrgrouse <bdmfegys@duck.com>
Date: Thu, 3 Jul 2025 05:55:25 -0400
successfully patch cool_autostart
Diffstat:
| M | config.def.h | | | 5 | +++++ |
| M | dwm.c | | | 91 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------- |
2 files changed, 79 insertions(+), 17 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -44,6 +44,11 @@ static Sp scratchpads[] = {
};
+static const char *const autostart[] = {
+ "st", NULL,
+ NULL /* terminate */
+};
+
/* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
diff --git a/dwm.c b/dwm.c
@@ -291,6 +291,7 @@ static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void xrdb(const Arg *arg);
static void zoom(const Arg *arg);
+static void autostart_exec(void);
/* variables */
static Systray *systray = NULL;
@@ -334,6 +335,36 @@ static Window root, wmcheckwin;
/* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
+/* dwm will keep pid's of processes from autostart array and kill them at quit */
+static pid_t *autostart_pids;
+static size_t autostart_len;
+
+/* execute command from autostart array */
+static void
+autostart_exec() {
+ const char *const *p;
+ size_t i = 0;
+
+ /* count entries */
+ for (p = autostart; *p; autostart_len++, p++)
+ while (*++p);
+
+ autostart_pids = malloc(autostart_len * sizeof(pid_t));
+ for (p = autostart; *p; i++, p++) {
+ if ((autostart_pids[i] = fork()) == 0) {
+ setsid();
+ execvp(*p, (char *const *)p);
+ fprintf(stderr, "birdwm: execvp %s\n", *p);
+ perror(" failed");
+ _exit(EXIT_FAILURE);
+ }
+ /* skip arguments */
+ while (*++p);
+ }
+}
+
+
+
/* function implementations */
void
applyrules(Client *c)
@@ -1262,12 +1293,12 @@ loadxrdb()
xrdb = XrmGetStringDatabase(resm);
if (xrdb != NULL) {
- XRDB_LOAD_COLOR("dwm.normbordercolor", normbordercolor);
- XRDB_LOAD_COLOR("dwm.normbgcolor", normbgcolor);
- XRDB_LOAD_COLOR("dwm.normfgcolor", normfgcolor);
- XRDB_LOAD_COLOR("dwm.selbordercolor", selbordercolor);
- XRDB_LOAD_COLOR("dwm.selbgcolor", selbgcolor);
- XRDB_LOAD_COLOR("dwm.selfgcolor", selfgcolor);
+ XRDB_LOAD_COLOR("birdwm.normbordercolor", normbordercolor);
+ XRDB_LOAD_COLOR("birdwm.normbgcolor", normbgcolor);
+ XRDB_LOAD_COLOR("birdwm.normfgcolor", normfgcolor);
+ XRDB_LOAD_COLOR("birdwm.selbordercolor", selbordercolor);
+ XRDB_LOAD_COLOR("birdwm.selbgcolor", selbgcolor);
+ XRDB_LOAD_COLOR("birdwm.selfgcolor", selfgcolor);
}
}
}
@@ -1533,6 +1564,16 @@ propertynotify(XEvent *e)
void
quit(const Arg *arg)
{
+ size_t i;
+
+ /* 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);
+ }
+ }
+
running = 0;
}
@@ -1887,6 +1928,7 @@ setup(void)
XSetWindowAttributes wa;
Atom utf8string;
struct sigaction sa;
+ pid_t pid;
/* do not transform children into zombies when they terminate */
sigemptyset(&sa.sa_mask);
@@ -1895,7 +1937,21 @@ setup(void)
sigaction(SIGCHLD, &sa, NULL);
/* clean up any zombies (inherited from .xinitrc etc) immediately */
- while (waitpid(-1, NULL, WNOHANG) > 0);
+ while (0 < (pid = waitpid(-1, NULL, WNOHANG))) {
+ pid_t *p, *lim;
+
+ if (!(p = autostart_pids))
+ continue;
+ lim = &p[autostart_len];
+
+ for (; p < lim; p++) {
+ if (*p == pid) {
+ *p = -1;
+ break;
+ }
+ }
+
+ }
/* init screen */
screen = DefaultScreen(dpy);
@@ -1949,7 +2005,7 @@ setup(void)
XChangeProperty(dpy, wmcheckwin, netatom[NetWMCheck], XA_WINDOW, 32,
PropModeReplace, (unsigned char *) &wmcheckwin, 1);
XChangeProperty(dpy, wmcheckwin, netatom[NetWMName], utf8string, 8,
- PropModeReplace, (unsigned char *) "dwm", 3);
+ PropModeReplace, (unsigned char *) "birdwm", 3);
XChangeProperty(dpy, root, netatom[NetWMCheck], XA_WINDOW, 32,
PropModeReplace, (unsigned char *) &wmcheckwin, 1);
/* EWMH support per view */
@@ -2020,7 +2076,7 @@ spawn(const Arg *arg)
sigaction(SIGCHLD, &sa, NULL);
execvp(((char **)arg->v)[0], (char **)arg->v);
- die("dwm: execvp '%s' failed:", ((char **)arg->v)[0]);
+ die("birdwm: execvp '%s' failed:", ((char **)arg->v)[0]);
}
}
@@ -2236,7 +2292,7 @@ updatebars(void)
.background_pixmap = ParentRelative,
.event_mask = ButtonPressMask|ExposureMask
};
- XClassHint ch = {"dwm", "dwm"};
+ XClassHint ch = {"birdwm", "birdwm"};
for (m = mons; m; m = m->next) {
if (m->barwin)
continue;
@@ -2423,7 +2479,7 @@ void
updatestatus(void)
{
if (!gettextprop(root, XA_WM_NAME, stext, sizeof(stext)))
- strcpy(stext, "dwm-"VERSION);
+ strcpy(stext, "birdwm-"VERSION);
drawbar(selmon);
updatesystray();
}
@@ -2514,7 +2570,7 @@ updatesystray(void)
XSync(dpy, False);
}
else {
- fprintf(stderr, "dwm: unable to obtain system tray.\n");
+ fprintf(stderr, "birdwm: unable to obtain system tray.\n");
free(systray);
systray = NULL;
return;
@@ -2663,7 +2719,7 @@ xerror(Display *dpy, XErrorEvent *ee)
|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
|| (ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
return 0;
- fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
+ fprintf(stderr, "birdwm: fatal error: request code=%d, error code=%d\n",
ee->request_code, ee->error_code);
return xerrorxlib(dpy, ee); /* may call exit */
}
@@ -2679,7 +2735,7 @@ xerrordummy(Display *dpy, XErrorEvent *ee)
int
xerrorstart(Display *dpy, XErrorEvent *ee)
{
- die("dwm: another window manager is already running");
+ die("birdwm: another window manager is already running");
return -1;
}
@@ -2726,16 +2782,17 @@ int
main(int argc, char *argv[])
{
if (argc == 2 && !strcmp("-v", argv[1]))
- die("dwm-"VERSION);
+ die("birdwm-"VERSION);
else if (argc != 1)
- die("usage: dwm [-v]");
+ die("usage: birdwm [-v]");
if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
fputs("warning: no locale support\n", stderr);
if (!(dpy = XOpenDisplay(NULL)))
- die("dwm: cannot open display");
+ die("birdwm: cannot open display");
checkotherwm();
XrmInitialize();
loadxrdb();
+ autostart_exec();
setup();
#ifdef __OpenBSD__
if (pledge("stdio rpath proc exec", NULL) == -1)