add autostrat

This commit is contained in:
Ray Andrew 2024-10-07 21:17:14 -05:00
parent 8e77981703
commit 4f7b02179b
2 changed files with 61 additions and 1 deletions

View file

@ -33,6 +33,11 @@ static const char *colors[][3] = {
[SchemeSel] = { col_gray4, col_gray2, col_cyan }, [SchemeSel] = { col_gray4, col_gray2, col_cyan },
}; };
static const char *const autostart[] = {
"dunst", NULL,
NULL /* terminate */
};
/* tagging */ /* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" }; static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" };

57
dwm.c
View file

@ -291,6 +291,7 @@ static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg); static void zoom(const Arg *arg);
static void autostart_exec(void);
static int swallow(Client *p, Client *c); static int swallow(Client *p, Client *c);
static void unswallow(Client *c); static void unswallow(Client *c);
@ -358,6 +359,34 @@ struct Pertag {
/* compile-time check if all tags fit into an unsigned int bit array. */ /* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; 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, "dwm: execvp %s\n", *p);
perror(" failed");
_exit(EXIT_FAILURE);
}
/* skip arguments */
while (*++p);
}
}
/* function implementations */ /* function implementations */
void void
applyrules(Client *c) applyrules(Client *c)
@ -1699,6 +1728,16 @@ propertynotify(XEvent *e)
void void
quit(const Arg *arg) 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; running = 0;
} }
@ -2165,6 +2204,7 @@ void
setup(void) setup(void)
{ {
int i; int i;
pid_t pid;
XSetWindowAttributes wa; XSetWindowAttributes wa;
Atom utf8string; Atom utf8string;
struct sigaction sa; struct sigaction sa;
@ -2176,7 +2216,21 @@ setup(void)
sigaction(SIGCHLD, &sa, NULL); sigaction(SIGCHLD, &sa, NULL);
/* clean up any zombies (inherited from .xinitrc etc) immediately */ /* clean up any zombies (inherited from .xinitrc etc) immediately */
while (waitpid(-1, NULL, WNOHANG) > 0); while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) {
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 */ /* init screen */
screen = DefaultScreen(dpy); screen = DefaultScreen(dpy);
@ -3198,6 +3252,7 @@ main(int argc, char *argv[])
if (!(xcon = XGetXCBConnection(dpy))) if (!(xcon = XGetXCBConnection(dpy)))
die("dwm: cannot get xcb connection\n"); die("dwm: cannot get xcb connection\n");
checkotherwm(); checkotherwm();
autostart_exec();
setup(); setup();
#ifdef __OpenBSD__ #ifdef __OpenBSD__
if (pledge("stdio rpath proc exec ps", NULL) == -1) if (pledge("stdio rpath proc exec ps", NULL) == -1)