From c5a1d2e5f899a0d12833eef20f540d0869db462d Mon Sep 17 00:00:00 2001 From: cwills Date: Sun, 3 Dec 2023 21:41:29 -0500 Subject: [PATCH] spawn cmds on specific tags at startup --- config.def.h | 13 +++++++++++++ dwm.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 2 deletions(-) diff --git a/config.def.h b/config.def.h index 9efa774..4aac448 100644 --- a/config.def.h +++ b/config.def.h @@ -60,6 +60,19 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn() static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL }; static const char *termcmd[] = { "st", NULL }; +static const char *termcmd2[] = { "xterm", NULL }; +static const char *browsercmd[] = {"librewolf", NULL}; +static const char *keepassxccmd[] = {"keepassxc", NULL}; +static const char *emacscmd[] = {"emacs", NULL}; + +Autostarttag autostarttaglist[] = { + {.cmd = browsercmd, .tags = 1 << 0 }, + {.cmd = keepassxccmd, .tags = 1 << 4 }, + {.cmd = emacscmd, .tags = 1 << 7 }, + {.cmd = termcmd2, .tags = 1 << 8 }, + {.cmd = NULL, .tags = 0 }, +}; + static const Key keys[] = { /* modifier key function argument */ { MODKEY, XK_p, spawn, {.v = dmenucmd } }, diff --git a/dwm.c b/dwm.c index f1d86b2..000ff46 100644 --- a/dwm.c +++ b/dwm.c @@ -141,6 +141,11 @@ typedef struct { int monitor; } Rule; +typedef struct { + const char **cmd; + unsigned int tags; +} Autostarttag; + /* function declarations */ static void applyrules(Client *c); static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact); @@ -206,6 +211,8 @@ static void setup(void); static void seturgent(Client *c, int urg); static void showhide(Client *c); static void spawn(const Arg *arg); +static void autostarttagsspawner(void); +static void applyautostarttags(Client *c); static void tag(const Arg *arg); static void tagmon(const Arg *arg); static void tile(Monitor *m); @@ -267,6 +274,9 @@ static Display *dpy; static Drw *drw; static Monitor *mons, *selmon; static Window root, wmcheckwin; +static unsigned int autostarttags = 0; +static int autostartcomplete = 0; +static int autostartcmdscomplete = 0; /* configuration, allows nested code to access above variables */ #include "config.h" @@ -1050,7 +1060,11 @@ manage(Window w, XWindowAttributes *wa) c->tags = t->tags; } else { c->mon = selmon; - applyrules(c); + if (autostarttags) { + applyautostarttags(c); + } else { + applyrules(c); + } } if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww) @@ -1385,9 +1399,12 @@ run(void) XEvent ev; /* main event loop */ XSync(dpy, False); - while (running && !XNextEvent(dpy, &ev)) + while (running && !XNextEvent(dpy, &ev)){ + if (!(autostartcomplete || autostarttags)) + autostarttagsspawner(); if (handler[ev.type]) handler[ev.type](&ev); /* call handler */ + } } void @@ -1676,6 +1693,33 @@ tag(const Arg *arg) } } +void +autostarttagsspawner(void) +{ + int i; + Arg arg; + + for (i = autostartcmdscomplete; i < LENGTH(autostarttaglist) ; i++){ + autostartcmdscomplete += 1; + autostarttags = autostarttaglist[i].tags; + arg.v = autostarttaglist[i].cmd ; + spawn(&arg); + return; + } + autostartcomplete = 1; + return; +} + +void +applyautostarttags(Client *c) +{ + if (!c) + return; + c->tags = autostarttags; + autostarttags = 0; + return; +} + void tagmon(const Arg *arg) { -- 2.30.2