summaryrefslogtreecommitdiff
path: root/dwm.c
diff options
context:
space:
mode:
authorLignum Crucis2026-05-15 17:13:35 -0300
committerLignum Crucis2026-05-15 17:13:35 -0300
commitb707695288e362e0584bb4a40228f6387e468753 (patch)
tree6690313ff2d58674441dd842402d5abb217be2d6 /dwm.c
parent046dbdc11d277f9561c454d22e142ed2f8c8d6e8 (diff)
patch: autostart
sound system wasn't working so i thought it was necessary; also, removes clutter from xinit ig
Diffstat (limited to 'dwm.c')
-rw-r--r--dwm.c64
1 files changed, 60 insertions, 4 deletions
diff --git a/dwm.c b/dwm.c
index f59b538..919b9dc 100644
--- a/dwm.c
+++ b/dwm.c
@@ -251,6 +251,7 @@ static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg);
+static void autostart_exec(void);
/* variables */
static const char broken[] = "broken";
@@ -307,6 +308,36 @@ struct Pertag {
/* 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, "dwm: execvp %s\n", *p);
+ perror(" failed");
+ _exit(EXIT_FAILURE);
+ }
+ /* skip arguments */
+ while (*++p);
+ }
+}
+
+
+
/* function implementations */
void
applyrules(Client *c)
@@ -1223,9 +1254,8 @@ monocle(Monitor *m)
for (c = m->clients; c; c = c->next)
if (ISVISIBLE(c))
n++;
- // remove override monocle symbol
- /* if (n > 0)
- snprintf(m->ltsymbol, sizeof m->ltsymbol, "[%d]", n); */
+ if (n > 0)
+ snprintf(m->ltsymbol, sizeof m->ltsymbol, "m-%d", n);
for (c = nexttiled(m->clients); c; c = nexttiled(c->next))
resize(c, m->wx, m->wy, m->ww, m->wh, 0, 0);
}
@@ -1363,6 +1393,16 @@ propertynotify(XEvent *e)
void
quit(const Arg *arg)
{
+ size_t n;
+
+ /* kill child processes */
+ for (n = 0; n < autostart_len; n++) {
+ if (0 < autostart_pids[n]) {
+ kill(autostart_pids[n], SIGTERM);
+ waitpid(autostart_pids[n], NULL, 0);
+ }
+ }
+
if(arg->i) restart = 1;
running = 0;
}
@@ -1753,6 +1793,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);
@@ -1761,7 +1802,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;
+ }
+ }
+
+ }
signal(SIGHUP, sighup);
signal(SIGTERM, sigterm);
@@ -2460,6 +2515,7 @@ main(int argc, char *argv[])
if (!(dpy = XOpenDisplay(NULL)))
die("dwm: cannot open display");
checkotherwm();
+ autostart_exec();
setup();
#ifdef __OpenBSD__
if (pledge("stdio rpath proc exec", NULL) == -1)