dwm-namedscratchpads-6.2.diff - sites - public wiki contents of suckless.org
 (HTM) git clone git://git.suckless.org/sites
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
       dwm-namedscratchpads-6.2.diff (4568B)
       ---
            1 diff '--color=auto' -up dwm-6.2/config.def.h dwm-6.2-new/config.def.h
            2 --- dwm-6.2/config.def.h        2019-02-02 12:55:28.000000000 +0000
            3 +++ dwm-6.2-new/config.def.h        2020-04-26 13:51:06.713332746 +0100
            4 @@ -26,9 +26,10 @@ static const Rule rules[] = {
            5           *        WM_CLASS(STRING) = instance, class
            6           *        WM_NAME(STRING) = title
            7           */
            8 -        /* class      instance    title       tags mask     isfloating   monitor */
            9 -        { "Gimp",     NULL,       NULL,       0,            1,           -1 },
           10 -        { "Firefox",  NULL,       NULL,       1 << 8,       0,           -1 },
           11 +        /* class      instance    title       tags mask     isfloating   monitor    scratch key */
           12 +        { "Gimp",     NULL,       NULL,       0,            1,           -1,        0  },
           13 +        { "firefox",  NULL,       NULL,       1 << 8,       0,           -1,        0  },
           14 +        { NULL,       NULL,   "scratchpad",   0,            1,           -1,       's' },
           15  };
           16  
           17  /* layout(s) */
           18 @@ -59,10 +60,14 @@ static char dmenumon[2] = "0"; /* compon
           19  static const char *dmenucmd[] = { "dmenu_run", "-m", dmenumon, "-fn", dmenufont, "-nb", col_gray1, "-nf", col_gray3, "-sb", col_cyan, "-sf", col_gray4, NULL };
           20  static const char *termcmd[]  = { "st", NULL };
           21  
           22 +/*First arg only serves to match against key in rules*/
           23 +static const char *scratchpadcmd[] = {"s", "st", "-t", "scratchpad", NULL}; 
           24 +
           25  static Key keys[] = {
           26          /* modifier                     key        function        argument */
           27          { MODKEY,                       XK_p,      spawn,          {.v = dmenucmd } },
           28          { MODKEY|ShiftMask,             XK_Return, spawn,          {.v = termcmd } },
           29 +        { MODKEY,                       XK_grave,  togglescratch,  {.v = scratchpadcmd } },
           30          { MODKEY,                       XK_b,      togglebar,      {0} },
           31          { MODKEY,                       XK_j,      focusstack,     {.i = +1 } },
           32          { MODKEY,                       XK_k,      focusstack,     {.i = -1 } },
           33 diff '--color=auto' -up dwm-6.2/dwm.c dwm-6.2-new/dwm.c
           34 --- dwm-6.2/dwm.c        2019-02-02 12:55:28.000000000 +0000
           35 +++ dwm-6.2-new/dwm.c        2020-04-26 13:55:56.820584361 +0100
           36 @@ -93,6 +93,7 @@ struct Client {
           37          int bw, oldbw;
           38          unsigned int tags;
           39          int isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
           40 +        char scratchkey;
           41          Client *next;
           42          Client *snext;
           43          Monitor *mon;
           44 @@ -139,6 +140,7 @@ typedef struct {
           45          unsigned int tags;
           46          int isfloating;
           47          int monitor;
           48 +        const char scratchkey;
           49  } Rule;
           50  
           51  /* function declarations */
           52 @@ -206,11 +208,13 @@ static void seturgent(Client *c, int urg
           53  static void showhide(Client *c);
           54  static void sigchld(int unused);
           55  static void spawn(const Arg *arg);
           56 +static void spawnscratch(const Arg *arg);
           57  static void tag(const Arg *arg);
           58  static void tagmon(const Arg *arg);
           59  static void tile(Monitor *);
           60  static void togglebar(const Arg *arg);
           61  static void togglefloating(const Arg *arg);
           62 +static void togglescratch(const Arg *arg);
           63  static void toggletag(const Arg *arg);
           64  static void toggleview(const Arg *arg);
           65  static void unfocus(Client *c, int setfocus);
           66 @@ -287,6 +291,7 @@ applyrules(Client *c)
           67          /* rule matching */
           68          c->isfloating = 0;
           69          c->tags = 0;
           70 +        c->scratchkey = 0;
           71          XGetClassHint(dpy, c->win, &ch);
           72          class    = ch.res_class ? ch.res_class : broken;
           73          instance = ch.res_name  ? ch.res_name  : broken;
           74 @@ -299,6 +304,7 @@ applyrules(Client *c)
           75                  {
           76                          c->isfloating = r->isfloating;
           77                          c->tags |= r->tags;
           78 +                        c->scratchkey = r->scratchkey;
           79                          for (m = mons; m && m->num != r->monitor; m = m->next);
           80                          if (m)
           81                                  c->mon = m;
           82 @@ -308,6 +314,7 @@ applyrules(Client *c)
           83                  XFree(ch.res_class);
           84          if (ch.res_name)
           85                  XFree(ch.res_name);
           86 +
           87          c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
           88  }
           89  
           90 @@ -1652,6 +1659,19 @@ spawn(const Arg *arg)
           91          }
           92  }
           93  
           94 +void spawnscratch(const Arg *arg)
           95 +{
           96 +        if (fork() == 0) {
           97 +                if (dpy)
           98 +                        close(ConnectionNumber(dpy));
           99 +                setsid();
          100 +                execvp(((char **)arg->v)[1], ((char **)arg->v)+1);
          101 +                fprintf(stderr, "dwm: execvp %s", ((char **)arg->v)[1]);
          102 +                perror(" failed");
          103 +                exit(EXIT_SUCCESS);
          104 +        }
          105 +}
          106 +
          107  void
          108  tag(const Arg *arg)
          109  {
          110 @@ -1720,6 +1740,28 @@ togglefloating(const Arg *arg)
          111  }
          112  
          113  void
          114 +togglescratch(const Arg *arg)
          115 +{
          116 +        Client *c;
          117 +        unsigned int found = 0;
          118 +
          119 +        for (c = selmon->clients; c && !(found = c->scratchkey == ((char**)arg->v)[0][0]); c = c->next);
          120 +        if (found) {
          121 +                c->tags = ISVISIBLE(c) ? 0 : selmon->tagset[selmon->seltags];
          122 +                focus(NULL);
          123 +                arrange(selmon);
          124 +
          125 +                if (ISVISIBLE(c)) {
          126 +                        focus(c);
          127 +                        restack(selmon);
          128 +                }
          129 +
          130 +        } else{
          131 +                spawnscratch(arg);
          132 +        }
          133 +}
          134 +
          135 +void
          136  toggletag(const Arg *arg)
          137  {
          138          unsigned int newtags;