URI: 
       dwm-autostarttags-6.4.diff - sites - public wiki contents of suckless.org
  HTML git clone git://git.suckless.org/sites
   DIR Log
   DIR Files
   DIR Refs
       ---
       dwm-autostarttags-6.4.diff (3605B)
       ---
            1 From c5a1d2e5f899a0d12833eef20f540d0869db462d Mon Sep 17 00:00:00 2001
            2 From: cwills <cwills.dev@gmail.com>
            3 Date: Sun, 3 Dec 2023 21:41:29 -0500
            4 Subject: [PATCH] spawn cmds on specific tags at startup
            5 
            6 ---
            7  config.def.h | 13 +++++++++++++
            8  dwm.c        | 48 ++++++++++++++++++++++++++++++++++++++++++++++--
            9  2 files changed, 59 insertions(+), 2 deletions(-)
           10 
           11 diff --git a/config.def.h b/config.def.h
           12 index 9efa774..4aac448 100644
           13 --- a/config.def.h
           14 +++ b/config.def.h
           15 @@ -60,6 +60,19 @@ static char dmenumon[2] = "0"; /* component of dmenucmd, manipulated in spawn()
           16  static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
           17  static const char *termcmd[]  = { "st", NULL };
           18  
           19 +static const char *termcmd2[] = { "xterm", NULL };
           20 +static const char *browsercmd[] = {"librewolf", NULL};
           21 +static const char *keepassxccmd[] = {"keepassxc", NULL};
           22 +static const char *emacscmd[] = {"emacs", NULL};
           23 +
           24 +Autostarttag autostarttaglist[] = {
           25 +        {.cmd = browsercmd, .tags = 1 << 0 },
           26 +        {.cmd = keepassxccmd, .tags = 1 << 4 },
           27 +        {.cmd = emacscmd, .tags = 1 << 7 },
           28 +        {.cmd = termcmd2, .tags = 1 << 8 },
           29 +        {.cmd = NULL, .tags = 0 },
           30 +};
           31 +
           32  static const Key keys[] = {
           33          /* modifier                     key        function        argument */
           34          { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
           35 diff --git a/dwm.c b/dwm.c
           36 index f1d86b2..000ff46 100644
           37 --- a/dwm.c
           38 +++ b/dwm.c
           39 @@ -141,6 +141,11 @@ typedef struct {
           40          int monitor;
           41  } Rule;
           42  
           43 +typedef struct {
           44 +        const char **cmd;
           45 +        unsigned int tags;
           46 +} Autostarttag;
           47 +
           48  /* function declarations */
           49  static void applyrules(Client *c);
           50  static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
           51 @@ -206,6 +211,8 @@ static void setup(void);
           52  static void seturgent(Client *c, int urg);
           53  static void showhide(Client *c);
           54  static void spawn(const Arg *arg);
           55 +static void autostarttagsspawner(void);
           56 +static void applyautostarttags(Client *c);
           57  static void tag(const Arg *arg);
           58  static void tagmon(const Arg *arg);
           59  static void tile(Monitor *m);
           60 @@ -267,6 +274,9 @@ static Display *dpy;
           61  static Drw *drw;
           62  static Monitor *mons, *selmon;
           63  static Window root, wmcheckwin;
           64 +static unsigned int autostarttags = 0;
           65 +static int autostartcomplete = 0;
           66 +static int autostartcmdscomplete = 0;
           67  
           68  /* configuration, allows nested code to access above variables */
           69  #include "config.h"
           70 @@ -1050,7 +1060,11 @@ manage(Window w, XWindowAttributes *wa)
           71                  c->tags = t->tags;
           72          } else {
           73                  c->mon = selmon;
           74 -                applyrules(c);
           75 +                if (autostarttags) {
           76 +                        applyautostarttags(c);
           77 +                } else {
           78 +                        applyrules(c);
           79 +                }
           80          }
           81  
           82          if (c->x + WIDTH(c) > c->mon->wx + c->mon->ww)
           83 @@ -1385,9 +1399,12 @@ run(void)
           84          XEvent ev;
           85          /* main event loop */
           86          XSync(dpy, False);
           87 -        while (running && !XNextEvent(dpy, &ev))
           88 +        while (running && !XNextEvent(dpy, &ev)){
           89 +                if (!(autostartcomplete || autostarttags))
           90 +                        autostarttagsspawner();
           91                  if (handler[ev.type])
           92                          handler[ev.type](&ev); /* call handler */
           93 +        }
           94  }
           95  
           96  void
           97 @@ -1676,6 +1693,33 @@ tag(const Arg *arg)
           98          }
           99  }
          100  
          101 +void
          102 +autostarttagsspawner(void)
          103 +{
          104 +        int i;
          105 +        Arg arg;
          106 +
          107 +        for (i = autostartcmdscomplete; i < LENGTH(autostarttaglist) ; i++){
          108 +                autostartcmdscomplete += 1;
          109 +                autostarttags = autostarttaglist[i].tags;
          110 +                arg.v = autostarttaglist[i].cmd ;
          111 +                spawn(&arg);
          112 +                return;
          113 +        }
          114 +        autostartcomplete = 1;
          115 +        return;
          116 +}
          117 +
          118 +void
          119 +applyautostarttags(Client *c)
          120 +{
          121 +        if (!c)
          122 +                return;
          123 +        c->tags = autostarttags;
          124 +        autostarttags = 0;
          125 +        return;
          126 +}
          127 +
          128  void
          129  tagmon(const Arg *arg)
          130  {
          131 -- 
          132 2.30.2
          133