allow passing path and executables for autostart purposes

via -p and -e parameters respectively
This commit is contained in:
Tobias Berger 2024-01-24 23:08:41 +01:00
parent b0d65d8d17
commit 5629572623
Signed by: toby
GPG key ID: 2D05EFAB764D6A88
2 changed files with 33 additions and 3 deletions

View file

@ -20,6 +20,8 @@ static const char *const autostart[] = {
"foot", NULL, "foot", NULL,
"todoodoo", NULL, "todoodoo", NULL,
"firefox", NULL, "firefox", NULL,
"somebar", NULL,
"someblocks", NULL,
NULL /* terminate */ NULL /* terminate */
}; };

32
dwl.c
View file

@ -319,6 +319,7 @@ static void xytonode(double x, double y, struct wlr_surface **psurface,
static void zoom(const Arg *arg); static void zoom(const Arg *arg);
/* variables */ /* variables */
static char const* autostart_runtime[256] = {NULL};
static const char broken[] = "broken"; static const char broken[] = "broken";
static pid_t child_pid = -1; static pid_t child_pid = -1;
static int locked; static int locked;
@ -405,6 +406,9 @@ autostartexec(void) {
/* count entries */ /* count entries */
for (p = autostart; *p; autostart_len++, p++) for (p = autostart; *p; autostart_len++, p++)
while (*++p); while (*++p);
/* count runtime entries */
for (p = autostart_runtime; *p; autostart_len++, p++)
while (*++p);
autostart_pids = calloc(autostart_len, sizeof(pid_t)); autostart_pids = calloc(autostart_len, sizeof(pid_t));
for (p = autostart; *p; i++, p++) { for (p = autostart; *p; i++, p++) {
@ -416,6 +420,15 @@ autostartexec(void) {
/* skip arguments */ /* skip arguments */
while (*++p); 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);
}
/* skip arguments */
while (*++p);
}
} }
void void
@ -2794,10 +2807,22 @@ main(int argc, char *argv[])
{ {
char *startup_cmd = NULL; char *startup_cmd = NULL;
int c; 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') if (c == 's')
startup_cmd = optarg; 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') else if (c == 'd')
log_level = WLR_DEBUG; log_level = WLR_DEBUG;
else if (c == 'v') else if (c == 'v')
@ -2811,11 +2836,14 @@ main(int argc, char *argv[])
/* Wayland requires XDG_RUNTIME_DIR for creating its communications socket */ /* Wayland requires XDG_RUNTIME_DIR for creating its communications socket */
if (!getenv("XDG_RUNTIME_DIR")) if (!getenv("XDG_RUNTIME_DIR"))
die("XDG_RUNTIME_DIR must be set"); die("XDG_RUNTIME_DIR must be set");
if (setenv("PATH", path, 1))
die("Failed to set PATH");
free(path);
setup(); setup();
run(startup_cmd); run(startup_cmd);
cleanup(); cleanup();
return EXIT_SUCCESS; return EXIT_SUCCESS;
usage: 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]);
} }