dwl

My patch set and modifications to dwl
git clone git://git.ethandl.dev/dwl
Log | Files | Refs | README | LICENSE

autostart-0.7.patch (4220B)


      1 From 787f7252d63945996f009828aff3c44afd0f7781 Mon Sep 17 00:00:00 2001
      2 From: =?UTF-8?q?Leonardo=20Hern=C3=A1ndez=20Hern=C3=A1ndez?=
      3  <leohdz172@proton.me>
      4 Date: Sat, 8 Jul 2023 17:11:36 -0600
      5 Subject: [PATCH] port autostart patch from dwm
      6 MIME-Version: 1.0
      7 Content-Type: text/plain; charset=UTF-8
      8 Content-Transfer-Encoding: 8bit
      9 
     10 https://dwm.suckless.org/patches/cool_autostart/
     11 Signed-off-by: Leonardo Hernández Hernández <leohdz172@proton.me>
     12 ---
     13  config.def.h |  7 +++++++
     14  dwl.c        | 59 +++++++++++++++++++++++++++++++++++++++++++++++-----
     15  2 files changed, 61 insertions(+), 5 deletions(-)
     16 
     17 diff --git a/config.def.h b/config.def.h
     18 index 22d2171..8dc6502 100644
     19 --- a/config.def.h
     20 +++ b/config.def.h
     21 @@ -20,6 +20,13 @@ static const float fullscreen_bg[]         = {0.1f, 0.1f, 0.1f, 1.0f}; /* You ca
     22  /* logging */
     23  static int log_level = WLR_ERROR;
     24  
     25 +/* Autostart */
     26 +static const char *const autostart[] = {
     27 +        "wbg", "/path/to/your/image", NULL,
     28 +        NULL /* terminate */
     29 +};
     30 +
     31 +
     32  /* NOTE: ALWAYS keep a rule declared even if you don't use rules (e.g leave at least one example) */
     33  static const Rule rules[] = {
     34  	/* app_id             title       tags mask     isfloating   monitor */
     35 diff --git a/dwl.c b/dwl.c
     36 index 5bf995e..e8b8727 100644
     37 --- a/dwl.c
     38 +++ b/dwl.c
     39 @@ -249,6 +249,7 @@ static void arrange(Monitor *m);
     40  static void arrangelayer(Monitor *m, struct wl_list *list,
     41  		struct wlr_box *usable_area, int exclusive);
     42  static void arrangelayers(Monitor *m);
     43 +static void autostartexec(void);
     44  static void axisnotify(struct wl_listener *listener, void *data);
     45  static void buttonpress(struct wl_listener *listener, void *data);
     46  static void chvt(const Arg *arg);
     47 @@ -432,6 +433,9 @@ static xcb_atom_t netatom[NetLast];
     48  /* attempt to encapsulate suck into one file */
     49  #include "client.h"
     50  
     51 +static pid_t *autostart_pids;
     52 +static size_t autostart_len;
     53 +
     54  /* function implementations */
     55  void
     56  applybounds(Client *c, struct wlr_box *bbox)
     57 @@ -580,6 +584,27 @@ arrangelayers(Monitor *m)
     58  	}
     59  }
     60  
     61 +void
     62 +autostartexec(void) {
     63 +	const char *const *p;
     64 +	size_t i = 0;
     65 +
     66 +	/* count entries */
     67 +	for (p = autostart; *p; autostart_len++, p++)
     68 +		while (*++p);
     69 +
     70 +	autostart_pids = calloc(autostart_len, sizeof(pid_t));
     71 +	for (p = autostart; *p; i++, p++) {
     72 +		if ((autostart_pids[i] = fork()) == 0) {
     73 +			setsid();
     74 +			execvp(*p, (char *const *)p);
     75 +			die("dwl: execvp %s:", *p);
     76 +		}
     77 +		/* skip arguments */
     78 +		while (*++p);
     79 +	}
     80 +}
     81 +
     82  void
     83  axisnotify(struct wl_listener *listener, void *data)
     84  {
     85 @@ -676,11 +701,21 @@ checkidleinhibitor(struct wlr_surface *exclude)
     86  void
     87  cleanup(void)
     88  {
     89 +	size_t i;
     90  #ifdef XWAYLAND
     91  	wlr_xwayland_destroy(xwayland);
     92  	xwayland = NULL;
     93  #endif
     94  	wl_display_destroy_clients(dpy);
     95 +
     96 +	/* kill child processes */
     97 +	for (i = 0; i < autostart_len; i++) {
     98 +		if (0 < autostart_pids[i]) {
     99 +			kill(autostart_pids[i], SIGTERM);
    100 +			waitpid(autostart_pids[i], NULL, 0);
    101 +		}
    102 +	}
    103 +
    104  	if (child_pid > 0) {
    105  		kill(-child_pid, SIGTERM);
    106  		waitpid(child_pid, NULL, 0);
    107 @@ -1497,18 +1532,31 @@ void
    108  handlesig(int signo)
    109  {
    110  	if (signo == SIGCHLD) {
    111 -#ifdef XWAYLAND
    112  		siginfo_t in;
    113  		/* wlroots expects to reap the XWayland process itself, so we
    114  		 * use WNOWAIT to keep the child waitable until we know it's not
    115  		 * XWayland.
    116  		 */
    117  		while (!waitid(P_ALL, 0, &in, WEXITED|WNOHANG|WNOWAIT) && in.si_pid
    118 -				&& (!xwayland || in.si_pid != xwayland->server->pid))
    119 -			waitpid(in.si_pid, NULL, 0);
    120 -#else
    121 -		while (waitpid(-1, NULL, WNOHANG) > 0);
    122 +#ifdef XWAYLAND
    123 +			   && (!xwayland || in.si_pid != xwayland->server->pid)
    124  #endif
    125 +			   ) {
    126 +			pid_t *p, *lim;
    127 +			waitpid(in.si_pid, NULL, 0);
    128 +			if (in.si_pid == child_pid)
    129 +				child_pid = -1;
    130 +			if (!(p = autostart_pids))
    131 +				continue;
    132 +			lim = &p[autostart_len];
    133 +
    134 +			for (; p < lim; p++) {
    135 +				if (*p == in.si_pid) {
    136 +					*p = -1;
    137 +					break;
    138 +				}
    139 +			}
    140 +		}
    141  	} else if (signo == SIGINT || signo == SIGTERM) {
    142  		quit(NULL);
    143  	}
    144 @@ -2224,6 +2272,7 @@ run(char *startup_cmd)
    145  		die("startup: backend_start");
    146  
    147  	/* Now that the socket exists and the backend is started, run the startup command */
    148 +	autostartexec();
    149  	if (startup_cmd) {
    150  		int piperw[2];
    151  		if (pipe(piperw) < 0)
    152 -- 
    153 2.45.2
    154