Adding cool autostart patch

This commit is contained in:
bakkeby 2020-08-10 10:22:21 +02:00
parent 85dd49a6a4
commit dfe1c40563
8 changed files with 96 additions and 2 deletions

View File

@ -15,6 +15,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
### Changelog: ### Changelog:
2020-08-10 - Added cool autostart patch
2020-08-02 - Added reorganizetags patch 2020-08-02 - Added reorganizetags patch
2020-07-19 - Added barmodules patch - making extrabar, leftlayout, staticstatus and statusallmons patches redundant, added powerline patch 2020-07-19 - Added barmodules patch - making extrabar, leftlayout, staticstatus and statusallmons patches redundant, added powerline patch
@ -199,6 +201,10 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
- [combo](https://dwm.suckless.org/patches/combo/) - [combo](https://dwm.suckless.org/patches/combo/)
- allows you to select multiple tags by pressing all the right keys as a combo, e.g. hold MOD and press and hold 1 and 3 together to view those two tags - allows you to select multiple tags by pressing all the right keys as a combo, e.g. hold MOD and press and hold 1 and 3 together to view those two tags
- [cool_autostart](https://dwm.suckless.org/patches/cool_autostart/)
- allows dwm to execute commands from an array in the config.h file
- when dwm exits all processes from the autostart array will be killed automatically
- [cyclelayouts](https://dwm.suckless.org/patches/cyclelayouts/) - [cyclelayouts](https://dwm.suckless.org/patches/cyclelayouts/)
- lets you cycle through all your layouts - lets you cycle through all your layouts

View File

@ -302,6 +302,13 @@ char *statuscolors[][ColCount] = {
}; };
#endif // BAR_POWERLINE_STATUS_PATCH #endif // BAR_POWERLINE_STATUS_PATCH
#if COOL_AUTOSTART_PATCH
static const char *const autostart[] = {
"st", NULL,
NULL /* terminate */
};
#endif // COOL_AUTOSTART_PATCH
#if SCRATCHPADS_PATCH #if SCRATCHPADS_PATCH
const char *spcmd1[] = {"st", "-n", "spterm", "-g", "120x34", NULL }; const char *spcmd1[] = {"st", "-n", "spterm", "-g", "120x34", NULL };
const char *spcmd2[] = {"st", "-n", "spfm", "-g", "144x41", "-e", "ranger", NULL }; const char *spcmd2[] = {"st", "-n", "spfm", "-g", "144x41", "-e", "ranger", NULL };

44
dwm.c
View File

@ -2274,13 +2274,21 @@ propertynotify(XEvent *e)
void void
quit(const Arg *arg) quit(const Arg *arg)
{ {
#if COOL_AUTOSTART_PATCH
size_t i;
#endif // COOL_AUTOSTART_PATCH
#if ONLYQUITONEMPTY_PATCH #if ONLYQUITONEMPTY_PATCH
unsigned int n; unsigned int n;
Window *junk = malloc(1); Window *junk = malloc(1);
XQueryTree(dpy, root, junk, junk, &junk, &n); XQueryTree(dpy, root, junk, junk, &junk, &n);
if (n <= quit_empty_window_count) { #if COOL_AUTOSTART_PATCH
if (n - autostart_len <= quit_empty_window_count)
#else
if (n <= quit_empty_window_count)
#endif // COOL_AUTOSTART_PATCH
{
#if RESTARTSIG_PATCH #if RESTARTSIG_PATCH
if (arg->i) if (arg->i)
restart = 1; restart = 1;
@ -2298,6 +2306,16 @@ quit(const Arg *arg)
#endif // RESTARTSIG_PATCH #endif // RESTARTSIG_PATCH
running = 0; running = 0;
#endif // ONLYQUITONEMPTY_PATCH #endif // ONLYQUITONEMPTY_PATCH
#if COOL_AUTOSTART_PATCH
/* 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);
}
}
#endif // COOL_AUTOSTART_PATCH
} }
Monitor * Monitor *
@ -3031,9 +3049,29 @@ showhide(Client *c)
void void
sigchld(int unused) sigchld(int unused)
{ {
#if COOL_AUTOSTART_PATCH
pid_t pid;
#endif // COOL_AUTOSTART_PATCH
if (signal(SIGCHLD, sigchld) == SIG_ERR) if (signal(SIGCHLD, sigchld) == SIG_ERR)
die("can't install SIGCHLD handler:"); die("can't install SIGCHLD handler:");
#if COOL_AUTOSTART_PATCH
while (0 < (pid = waitpid(-1, NULL, WNOHANG))) {
pid_t *p, *lim;
if (!(p = autostart_pids))
continue;
lim = &p[autostart_len];
for (; p < lim; p++) {
if (*p == pid) {
*p = -1;
break;
}
}
}
#else
while (0 < waitpid(-1, NULL, WNOHANG)); while (0 < waitpid(-1, NULL, WNOHANG));
#endif // COOL_AUTOSTART_PATCH
} }
void void
@ -4009,7 +4047,9 @@ main(int argc, char *argv[])
XrmInitialize(); XrmInitialize();
loadxrdb(); loadxrdb();
#endif // XRDB_PATCH && !BAR_VTCOLORS_PATCH #endif // XRDB_PATCH && !BAR_VTCOLORS_PATCH
#if COOL_AUTOSTART_PATCH
autostart_exec();
#endif // COOL_AUTOSTART_PATCH
setup(); setup();
#ifdef __OpenBSD__ #ifdef __OpenBSD__
if (pledge("stdio rpath proc exec", NULL) == -1) if (pledge("stdio rpath proc exec", NULL) == -1)

28
patch/cool_autostart.c Normal file
View File

@ -0,0 +1,28 @@
/* dwm will keep pid's of processes from autostart array and kill them at quit */
static pid_t *autostart_pids;
static size_t autostart_len;
/* execute command from autostart array */
static void
autostart_exec()
{
const char *const *p;
size_t i = 0;
/* count entries */
for (p = autostart; *p; autostart_len++, p++)
while (*++p);
autostart_pids = malloc(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, "dwm: execvp %s\n", *p);
perror(" failed");
_exit(EXIT_FAILURE);
}
/* skip arguments */
while (*++p);
}
}

1
patch/cool_autostart.h Normal file
View File

@ -0,0 +1 @@
static void autostart_exec(void);

View File

@ -76,6 +76,9 @@
#if CMDCUSTOMIZE_PATCH #if CMDCUSTOMIZE_PATCH
#include "cmdcustomize.c" #include "cmdcustomize.c"
#endif #endif
#if COOL_AUTOSTART_PATCH
#include "cool_autostart.c"
#endif
#if CYCLELAYOUTS_PATCH #if CYCLELAYOUTS_PATCH
#include "cyclelayouts.c" #include "cyclelayouts.c"
#endif #endif

View File

@ -73,6 +73,9 @@
#if CMDCUSTOMIZE_PATCH #if CMDCUSTOMIZE_PATCH
#include "cmdcustomize.h" #include "cmdcustomize.h"
#endif #endif
#if COOL_AUTOSTART_PATCH
#include "cool_autostart.h"
#endif
#if CYCLELAYOUTS_PATCH #if CYCLELAYOUTS_PATCH
#include "cyclelayouts.h" #include "cyclelayouts.h"
#endif #endif

View File

@ -337,6 +337,12 @@
*/ */
#define COMBO_PATCH 0 #define COMBO_PATCH 0
/* Allow dwm to execute commands from autostart array in your config.h file. When dwm exits
* then all processes from autostart array will be killed.
* https://dwm.suckless.org/patches/cool_autostart/
*/
#define COOL_AUTOSTART_PATCH 0
/* The cyclelayouts patch lets you cycle through all your layouts. /* The cyclelayouts patch lets you cycle through all your layouts.
* https://dwm.suckless.org/patches/cyclelayouts/ * https://dwm.suckless.org/patches/cyclelayouts/
*/ */