i love the c programming language

This commit is contained in:
Sakooooo 2023-09-10 21:03:51 +04:00
parent 586027807d
commit 034c018e3e
Signed by: sako
GPG key ID: 3FD715D87D7725E0
3 changed files with 2221 additions and 0 deletions

View file

@ -18,6 +18,13 @@ static const char *colors[][3] = {
[SchemeSel] = { col_gray4, col_cyan, col_cyan }, [SchemeSel] = { col_gray4, col_cyan, col_cyan },
}; };
static const char *const autostart[] = {
"feh", "--bg-scale", "/home/sako/background.png", NULL,
"xsetroot", "-cursor_name", "left_ptr", NULL,
"keepassxc", NULL,
NULL /* terminate */
};
/* tagging */ /* tagging */
static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" }; static const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };

View file

@ -233,6 +233,7 @@ static int xerror(Display *dpy, XErrorEvent *ee);
static int xerrordummy(Display *dpy, XErrorEvent *ee); static int xerrordummy(Display *dpy, XErrorEvent *ee);
static int xerrorstart(Display *dpy, XErrorEvent *ee); static int xerrorstart(Display *dpy, XErrorEvent *ee);
static void zoom(const Arg *arg); static void zoom(const Arg *arg);
static void autostart_exec(void);
/* variables */ /* variables */
static const char broken[] = "broken"; static const char broken[] = "broken";
@ -274,6 +275,43 @@ static Window root, wmcheckwin;
/* compile-time check if all tags fit into an unsigned int bit array. */ /* compile-time check if all tags fit into an unsigned int bit array. */
struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
/* 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();
// https://github.com/bakkeby/dwm-flexipatch/blob/master/patch/cool_autostart.c#L23C1-L31C24
// comply with ver 6.4
/* Restore SIGCHLD sighandler to default before spawning a program */
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
sa.sa_handler = SIG_DFL;
sigaction(SIGCHLD, &sa, NULL);
execvp(*p, (char *const *)p);
fprintf(stderr, "dwm: execvp %s\n", *p);
perror(" failed");
_exit(EXIT_FAILURE);
}
/* skip arguments */
while (*++p);
}
}
/* function implementations */ /* function implementations */
void void
applyrules(Client *c) applyrules(Client *c)
@ -1258,6 +1296,16 @@ propertynotify(XEvent *e)
void void
quit(const Arg *arg) 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);
}
}
running = 0; running = 0;
} }
@ -2152,6 +2200,7 @@ main(int argc, char *argv[])
if (!(dpy = XOpenDisplay(NULL))) if (!(dpy = XOpenDisplay(NULL)))
die("dwm: cannot open display"); die("dwm: cannot open display");
checkotherwm(); checkotherwm();
autostart_exec();
setup(); setup();
#ifdef __OpenBSD__ #ifdef __OpenBSD__
if (pledge("stdio rpath proc exec", NULL) == -1) if (pledge("stdio rpath proc exec", NULL) == -1)

2165
config/dwm/dwm.c.orig Normal file

File diff suppressed because it is too large Load diff