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,
"todoodoo", NULL,
"firefox", NULL,
"somebar", NULL,
"someblocks", NULL,
NULL /* terminate */
};

34
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);
/* 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]);
}