mirror of
https://github.com/mintycube/dwm.git
synced 2024-10-22 14:05:45 +02:00
Adding cool autostart patch
This commit is contained in:
parent
85dd49a6a4
commit
dfe1c40563
@ -15,6 +15,8 @@ Refer to [https://dwm.suckless.org/](https://dwm.suckless.org/) for details on t
|
||||
|
||||
### Changelog:
|
||||
|
||||
2020-08-10 - Added cool autostart patch
|
||||
|
||||
2020-08-02 - Added reorganizetags 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/)
|
||||
- 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/)
|
||||
- lets you cycle through all your layouts
|
||||
|
||||
|
@ -302,6 +302,13 @@ char *statuscolors[][ColCount] = {
|
||||
};
|
||||
#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
|
||||
const char *spcmd1[] = {"st", "-n", "spterm", "-g", "120x34", NULL };
|
||||
const char *spcmd2[] = {"st", "-n", "spfm", "-g", "144x41", "-e", "ranger", NULL };
|
||||
|
44
dwm.c
44
dwm.c
@ -2274,13 +2274,21 @@ propertynotify(XEvent *e)
|
||||
void
|
||||
quit(const Arg *arg)
|
||||
{
|
||||
#if COOL_AUTOSTART_PATCH
|
||||
size_t i;
|
||||
#endif // COOL_AUTOSTART_PATCH
|
||||
#if ONLYQUITONEMPTY_PATCH
|
||||
unsigned int n;
|
||||
Window *junk = malloc(1);
|
||||
|
||||
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 (arg->i)
|
||||
restart = 1;
|
||||
@ -2298,6 +2306,16 @@ quit(const Arg *arg)
|
||||
#endif // RESTARTSIG_PATCH
|
||||
running = 0;
|
||||
#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 *
|
||||
@ -3031,9 +3049,29 @@ showhide(Client *c)
|
||||
void
|
||||
sigchld(int unused)
|
||||
{
|
||||
#if COOL_AUTOSTART_PATCH
|
||||
pid_t pid;
|
||||
#endif // COOL_AUTOSTART_PATCH
|
||||
if (signal(SIGCHLD, sigchld) == SIG_ERR)
|
||||
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));
|
||||
#endif // COOL_AUTOSTART_PATCH
|
||||
}
|
||||
|
||||
void
|
||||
@ -4009,7 +4047,9 @@ main(int argc, char *argv[])
|
||||
XrmInitialize();
|
||||
loadxrdb();
|
||||
#endif // XRDB_PATCH && !BAR_VTCOLORS_PATCH
|
||||
|
||||
#if COOL_AUTOSTART_PATCH
|
||||
autostart_exec();
|
||||
#endif // COOL_AUTOSTART_PATCH
|
||||
setup();
|
||||
#ifdef __OpenBSD__
|
||||
if (pledge("stdio rpath proc exec", NULL) == -1)
|
||||
|
28
patch/cool_autostart.c
Normal file
28
patch/cool_autostart.c
Normal 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
1
patch/cool_autostart.h
Normal file
@ -0,0 +1 @@
|
||||
static void autostart_exec(void);
|
@ -76,6 +76,9 @@
|
||||
#if CMDCUSTOMIZE_PATCH
|
||||
#include "cmdcustomize.c"
|
||||
#endif
|
||||
#if COOL_AUTOSTART_PATCH
|
||||
#include "cool_autostart.c"
|
||||
#endif
|
||||
#if CYCLELAYOUTS_PATCH
|
||||
#include "cyclelayouts.c"
|
||||
#endif
|
||||
|
@ -73,6 +73,9 @@
|
||||
#if CMDCUSTOMIZE_PATCH
|
||||
#include "cmdcustomize.h"
|
||||
#endif
|
||||
#if COOL_AUTOSTART_PATCH
|
||||
#include "cool_autostart.h"
|
||||
#endif
|
||||
#if CYCLELAYOUTS_PATCH
|
||||
#include "cyclelayouts.h"
|
||||
#endif
|
||||
|
@ -337,6 +337,12 @@
|
||||
*/
|
||||
#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.
|
||||
* https://dwm.suckless.org/patches/cyclelayouts/
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user