diff --git a/patches/autostart/README.md b/patches/autostart/README.md index e0c8074..3b78219 100644 --- a/patches/autostart/README.md +++ b/patches/autostart/README.md @@ -5,6 +5,7 @@ Note: Commands from array are executed using execvp(). So if you need to execute ### Download - [git branch](https://codeberg.org/sevz/dwl/src/branch/autostart) +- [autostart_main-5fd19fe](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/autostart/autostart_main-5fd19fe.patch) - [autostart-wlroots-next-f4249db.patch](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/autostart/autostart-wlroots-next-f4249db.patch) - [autostart-0.8.patch](https://codeberg.org/dwl/dwl-patches/raw/branch/main/patches/autostart/autostart-0.8.patch) diff --git a/patches/autostart/autostart-0.8.patch b/patches/autostart/autostart_0.8.patch similarity index 100% rename from patches/autostart/autostart-0.8.patch rename to patches/autostart/autostart_0.8.patch diff --git a/patches/autostart/autostart_main-5fd19fe.patch b/patches/autostart/autostart_main-5fd19fe.patch new file mode 100644 index 0000000..7787301 --- /dev/null +++ b/patches/autostart/autostart_main-5fd19fe.patch @@ -0,0 +1,128 @@ +diff --git a/config.def.h b/config.def.h +index 572984b..0697b66 100644 +--- a/config.def.h ++++ b/config.def.h +@@ -20,6 +20,12 @@ static const float fullscreen_bg[] = {0.0f, 0.0f, 0.0f, 1.0f}; /* You ca + /* logging */ + static int log_level = WLR_ERROR; + ++/* Autostart */ ++static const char *const autostart[] = { ++ "wbg", "/path/to/your/image", NULL, ++ NULL /* terminate */ ++}; ++ + static const Rule rules[] = { + /* app_id title tags mask isfloating monitor */ + { "Gimp_EXAMPLE", NULL, 0, 1, -1 }, /* Start on currently visible tags floating, not tiled */ +diff --git a/dwl.c b/dwl.c +index f902ace..36496b3 100644 +--- a/dwl.c ++++ b/dwl.c +@@ -263,6 +263,7 @@ static void arrange(Monitor *m); + static void arrangelayer(Monitor *m, struct wl_list *list, + struct wlr_box *usable_area, int exclusive); + static void arrangelayers(Monitor *m); ++static void autostartexec(void); + static void axisnotify(struct wl_listener *listener, void *data); + static void buttonpress(struct wl_listener *listener, void *data); + static void capturerequest(struct wl_listener *listener, void *data); +@@ -471,6 +472,9 @@ static struct wl_listener xwayland_ready = {.notify = xwaylandready}; + static struct wlr_xwayland *xwayland; + #endif + ++static pid_t *autostart_pids; ++static size_t autostart_len; ++ + /* configuration, allows nested code to access above variables */ + #include "config.h" + +@@ -630,6 +634,27 @@ arrangelayers(Monitor *m) + } + } + ++void ++autostartexec(void) { ++ const char *const *p; ++ size_t i = 0; ++ ++ /* count entries */ ++ for (p = autostart; *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) { ++ setsid(); ++ execvp(*p, (char *const *)p); ++ die("dwl: execvp %s:", *p); ++ } ++ /* skip arguments */ ++ while (*++p); ++ } ++} ++ + void + axisnotify(struct wl_listener *listener, void *data) + { +@@ -767,12 +792,23 @@ checkidleinhibitor(struct wlr_surface *exclude) + void + cleanup(void) + { ++ size_t i; ++ + cleanuplisteners(); + #ifdef XWAYLAND + wlr_xwayland_destroy(xwayland); + xwayland = NULL; + #endif + wl_display_destroy_clients(dpy); ++ ++ /* 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); ++ } ++ } ++ + if (child_pid > 0) { + kill(-child_pid, SIGTERM); + waitpid(child_pid, NULL, 0); +@@ -1646,10 +1682,25 @@ gpureset(struct wl_listener *listener, void *data) + void + handlesig(int signo) + { +- if (signo == SIGCHLD) +- while (waitpid(-1, NULL, WNOHANG) > 0); +- else if (signo == SIGINT || signo == SIGTERM) ++ if (signo == SIGCHLD) { ++ pid_t pid, *p, *lim; ++ while ((pid = waitpid(-1, NULL, WNOHANG)) > 0) { ++ if (pid == child_pid) ++ child_pid = -1; ++ if (!(p = autostart_pids)) ++ continue; ++ lim = &p[autostart_len]; ++ ++ for (; p < lim; p++) { ++ if (*p == pid) { ++ *p = -1; ++ break; ++ } ++ } ++ } ++ } else if (signo == SIGINT || signo == SIGTERM) { + quit(NULL); ++ } + } + + void +@@ -2365,6 +2416,7 @@ run(char *startup_cmd) + die("startup: backend_start"); + + /* Now that the socket exists and the backend is started, run the startup command */ ++ autostartexec(); + if (startup_cmd) { + int piperw[2]; + if (pipe(piperw) < 0) diff --git a/patches/autostart/autostart-wlroots-next-f4249db.patch b/patches/autostart/autostart_wlroots-next-f4249db.patch similarity index 100% rename from patches/autostart/autostart-wlroots-next-f4249db.patch rename to patches/autostart/autostart_wlroots-next-f4249db.patch