diff --git a/config.def.h b/config.def.h index 6367793..70f32ab 100644 --- a/config.def.h +++ b/config.def.h @@ -20,6 +20,8 @@ static const char *const autostart[] = { "foot", NULL, "todoodoo", NULL, "firefox", NULL, + "somebar", NULL, + "someblocks", NULL, NULL /* terminate */ }; diff --git a/dwl.c b/dwl.c index 047df5e..3cf7ef5 100644 --- a/dwl.c +++ b/dwl.c @@ -319,6 +319,7 @@ static void xytonode(double x, double y, struct wlr_surface **psurface, static void zoom(const Arg *arg); /* variables */ +static char const* autostart_runtime[256] = {NULL}; static const char broken[] = "broken"; static pid_t child_pid = -1; static int locked; @@ -405,10 +406,22 @@ autostartexec(void) { /* count entries */ for (p = autostart; *p; autostart_len++, p++) while (*++p); + /* count runtime entries */ + for (p = autostart_runtime; *p; autostart_len++, p++) + while (*++p); autostart_pids = calloc(autostart_len, sizeof(pid_t)); for (p = autostart; *p; i++, p++) { - if ((autostart_pids[i] = fork()) == 0) { + if ((autostart_pids[i] = fork()) == 0) { + setsid(); + execvp(*p, (char *const *)p); + die("dwl: execvp %s:", *p); + } + /* skip arguments */ + while (*++p); + } + for (p = autostart_runtime; *p; i++, p++) { + if ((autostart_pids[i] = fork()) == 0) { setsid(); execvp(*p, (char *const *)p); die("dwl: execvp %s:", *p); @@ -2794,10 +2807,22 @@ main(int argc, char *argv[]) { char *startup_cmd = NULL; int c; + char *path = calloc(8192, sizeof(char)); - while ((c = getopt(argc, argv, "s:hdv")) != -1) { + int autostart_runtime_idx = 0; + + strcat(path, getenv("PATH")); + while ((c = getopt(argc, argv, "e:p:s:hdv")) != -1) { if (c == 's') startup_cmd = optarg; + else if (c == 'p') { + strcat(path, ":"); + strcat(path, optarg); + } + else if (c == 'e') { + autostart_runtime[autostart_runtime_idx] = optarg; + autostart_runtime_idx++; + } else if (c == 'd') log_level = WLR_DEBUG; else if (c == 'v') @@ -2811,11 +2836,14 @@ main(int argc, char *argv[]) /* Wayland requires XDG_RUNTIME_DIR for creating its communications socket */ if (!getenv("XDG_RUNTIME_DIR")) die("XDG_RUNTIME_DIR must be set"); + if (setenv("PATH", path, 1)) + die("Failed to set PATH"); + free(path); setup(); run(startup_cmd); cleanup(); return EXIT_SUCCESS; usage: - die("Usage: %s [-v] [-d] [-s startup command]", argv[0]); + die("Usage: %s [-v] [-d] [-s startup command] [[-p path directory] ...] [[-e autostart file] ...]", argv[0]); }