dwl/patches/autostart.patch

133 lines
3.6 KiB
Diff
Raw Normal View History

From 744a6ce137f30b4b4ab9271bfb5ea5b1ccf4423c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?=
<leohdz172@protonmail.com>
Date: Wed, 9 Feb 2022 07:02:47 -0600
Subject: [PATCH] apply autostart patch from dwm
https://dwm.suckless.org/patches/cool_autostart/
---
config.def.h | 6 ++++++
dwl.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++-
2 files changed, 58 insertions(+), 1 deletion(-)
diff --git a/config.def.h b/config.def.h
index 29c6dbf8..35372a68 100644
--- a/config.def.h
+++ b/config.def.h
@@ -86,6 +86,12 @@ LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE
static const enum libinput_config_accel_profile accel_profile = LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE;
static const double accel_speed = 0.0;
+/* Autostart */
+static const char *const autostart[] = {
+ "sh", "-c", "swaybg --image /xap/local/background", NULL,
+ NULL /* terminate */
+};
+
/* If you want to use the windows key change this to WLR_MODIFIER_LOGO */
#define MODKEY WLR_MODIFIER_ALT
#define TAGKEYS(KEY,SKEY,TAG) \
diff --git a/dwl.c b/dwl.c
index 40ea05a6..514ec4b0 100644
--- a/dwl.c
+++ b/dwl.c
@@ -213,6 +213,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 chvt(const Arg *arg);
@@ -379,6 +380,9 @@ static Atom netatom[NetLast];
/* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
+static pid_t *autostart_pids;
+static size_t autostart_len;
+
/* function implementations */
void
applybounds(Client *c, struct wlr_box *bbox)
@@ -403,6 +407,29 @@ applybounds(Client *c, struct wlr_box *bbox)
c->geom.y = bbox->y;
}
+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);
+ fprintf(stderr, "dwl: execvp %s\n", *p);
+ perror(" failed");
+ _exit(EXIT_FAILURE);
+ }
+ /* skip arguments */
+ while (*++p);
+ }
+}
+
void
applyexclusive(struct wlr_box *usable_area,
uint32_t anchor, int32_t exclusive,
@@ -1721,6 +1748,16 @@ printstatus(void)
void
quit(const Arg *arg)
{
+ size_t i;
+
+ /* 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);
+ }
+ }
+
wl_display_terminate(dpy);
}
@@ -1808,6 +1845,7 @@ run(char *startup_cmd)
setenv("WAYLAND_DISPLAY", socket, 1);
/* Now that the socket exists, run the startup command */
+ autostartexec();
if (startup_cmd) {
int piperw[2];
if (pipe(piperw) < 0)
@@ -2183,11 +2221,24 @@ sigchld(int unused)
* setting our own disposition for SIGCHLD.
*/
pid_t pid;
+
if (signal(SIGCHLD, sigchld) == SIG_ERR)
die("can't install SIGCHLD handler:");
- while (0 < (pid = waitpid(-1, NULL, WNOHANG)))
+ while (0 < (pid = waitpid(-1, NULL, WNOHANG))) {
+ pid_t *p, *lim;
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;
+ }
+ }
+ }
}
void