autostart-0.7.patch 4.1 KB

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