diff options
| author | ProsperousPotato <ProsperousPotato@users.noreply.github.com> | 2025-08-16 14:39:10 +0100 |
|---|---|---|
| committer | ProsperousPotato <ProsperousPotato@users.noreply.github.com> | 2025-08-16 14:39:10 +0100 |
| commit | dd26b19364b95fe727204a18c9e471eda54e66da (patch) | |
| tree | 35c5d0c700f5e6c45b31ede5cb56bd9420a93599 | |
| parent | f29f6c5e03b94c5d62f03e0ad1fe0d00f10b28dd (diff) | |
add autostart patch
| -rw-r--r-- | config.h | 9 | ||||
| -rw-r--r-- | config.mk | 2 | ||||
| -rw-r--r-- | dwm.c | 56 |
3 files changed, 60 insertions, 7 deletions
@@ -18,8 +18,12 @@ static const char *colors[][4] = { [SchemeSel] = { col_gray1, col_gray2, col_gray2, col_float }, }; +static const char *const autostart[] = { + NULL +}; + /* tagging */ -static const char *tags[] = { "1", "2", "3", "4", "5" }; +static const char *tags[] = { "0", "1", "2", "3", "4" }; static const Rule rules[] = { /* xprop(1): @@ -32,9 +36,6 @@ static const Rule rules[] = { { "steam", "steamwebhelper", "Steam", 0, 0, 0, 0, -1 }, { "steam", NULL, "Steam Settings", 0, 1, 0, 0, -1 }, { "qemu-system-x86_64","qemu-system-x86_64",NULL, 0, 1, 0, 0, -1 }, - { "Virt-manager",NULL, NULL, 0, 0, 0, 0, -1 }, - { "qBittorrent", NULL, NULL, 0, 1, 0, 0, -1 }, - { "qBittorrent", "qbittorrent", NULL, 0, 1, 0, 0, -1 }, { "St", "st", NULL, 0, 0, 1, 1, -1 }, { "stfloat", NULL, NULL, 0, 1, 1, 1, -1 }, { "STARTER", NULL, NULL, 0, 1, 1, 1, -1 }, @@ -17,7 +17,7 @@ XINERAMAFLAGS = -DXINERAMA # freetype FREETYPELIBS = -lfontconfig -lXft FREETYPEINC = /usr/include/freetype2 -# OpenBSD (uncomment) +# OpenBSD FREETYPEINC = ${X11INC}/freetype2 MANPREFIX = ${PREFIX}/man KVMLIB = -lkvm @@ -236,6 +236,7 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee); static void zoom(const Arg *arg); static void togglemouse(const Arg *arg); static void quicksearch(const Arg *arg); +static void autostart_exec(void); static pid_t getparentprocess(pid_t p); static int isdescprocess(pid_t p, pid_t c); @@ -277,6 +278,9 @@ static Window root, wmcheckwin; static xcb_connection_t *xcon; +static pid_t *autostart_pids; +static size_t autostart_len; + /* configuration, allows nested code to access above variables */ #include "config.h" @@ -1226,7 +1230,15 @@ void quit(const Arg *arg) { if(arg->i) restart = 1; - running = 0; + size_t i; + + 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; } Monitor * @@ -1512,6 +1524,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); @@ -1520,7 +1533,22 @@ setup(void) sigaction(SIGCHLD, &sa, NULL); /* clean up any zombies (inherited from .xinitrc etc) immediately */ - while (waitpid(-1, NULL, WNOHANG) > 0); + // 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; + } + } + } + signal(SIGHUP, sighup); signal(SIGTERM, sigterm); @@ -2222,6 +2250,29 @@ zoom(const Arg *arg) XWarpPointer(dpy, None, selmon->sel->win, 0, 0, 0, 0, selmon->sel->w/2, selmon->sel->h/2); } +static void +autostart_exec() { + const char *const *p; + size_t i = 0; + + 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, "dwm: execvp %s\n", *p); + perror(" failed"); + _exit(EXIT_FAILURE); + } + + while (*++p); + } +} + int main(int argc, char *argv[]) { @@ -2236,6 +2287,7 @@ main(int argc, char *argv[]) if (!(xcon = XGetXCBConnection(dpy))) die("dwm: cannot get xcb connection\n"); checkotherwm(); + autostart_exec(); setup(); #ifdef __OpenBSD__ if (pledge("stdio rpath proc exec ps", NULL) == -1) |
