[wiki] [sites] [dwm][patch][autostarttags] add patch || cwills
commit 9a76d90d71246ca325accf54e2e27493678f3ba9
Author: cwills <cwills.dev_AT_gmail.com>
Date: Mon Dec 4 00:55:26 2023 -0500
[dwm][patch][autostarttags] add patch
This patch allows one to specify a map of commands to tags in config.h such
that each cmd is launched on the specified tag during startup.
diff --git a/dwm.suckless.org/patches/autostarttags/dwm-autostarttags-6.4.diff b/dwm.suckless.org/patches/autostarttags/dwm-autostarttags-6.4.diff
new file mode 100644
index 00000000..880a3667
--- /dev/null
+++ b/dwm.suckless.org/patches/autostarttags/dwm-autostarttags-6.4.diff
_AT_@ -0,0 +1,133 @@
+From c5a1d2e5f899a0d12833eef20f540d0869db462d Mon Sep 17 00:00:00 2001
+From: cwills <cwills.dev_AT_gmail.com>
+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
+_AT_@ -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
+_AT_@ -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);
+_AT_@ -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);
+_AT_@ -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"
+_AT_@ -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)
+_AT_@ -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
+_AT_@ -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
+
diff --git a/dwm.suckless.org/patches/autostarttags/index.md b/dwm.suckless.org/patches/autostarttags/index.md
new file mode 100644
index 00000000..3bfcab33
--- /dev/null
+++ b/dwm.suckless.org/patches/autostarttags/index.md
_AT_@ -0,0 +1,34 @@
+autostarttags
+=============
+
+Description
+-----------
+Allow dwm to execute commands on specific tags during startup from an
+`autostarttaglist` array in your config.h file. The `rules` array is bypassed for
+commands in the `autostarttaglist` array. This allows you to initialize your session
+with applications on different tags without having to use any keybindings.
+
+Example
+-------
+
+ static const char *browsercmd[] = {"librewolf", NULL};
+ static const char *keepassxccmd[] = {"keepassxc", NULL};
+ static const char *emacscmd[] = {"emacs", NULL};
+ static const char *termcmd[] = {"xterm", NULL };
+
+ /* last cmd must be NULL! */
+ Autostarttag autostarttaglist[] = {
+ {.cmd = browsercmd, .tags = 1 << 0 },
+ {.cmd = keepassxccmd, .tags = 1 << 4 },
+ {.cmd = emacscmd, .tags = 1 << 7 },
+ {.cmd = termcmd, .tags = 1 << 8 },
+ {.cmd = NULL, .tags = 0 },
+ };
+
+Download
+--------
+* [dwm-autostarttags-6.4.diff](dwm-autostarttags-6.4.diff)
+
+Author
+------
+* Christian Wills <cwills.dev+suckless_AT_gmail.com>
Received on Mon Dec 04 2023 - 07:39:46 CET
This archive was generated by hypermail 2.3.0
: Mon Dec 04 2023 - 07:48:46 CET