URI: 
       dwm-pertag-6.0.diff - sites - public wiki contents of suckless.org
  HTML git clone git://git.suckless.org/sites
   DIR Log
   DIR Files
   DIR Refs
       ---
       dwm-pertag-6.0.diff (5955B)
       ---
            1 Author: Jan Christoph Ebersbach <jceb@e-jc.de>
            2 URL: http://dwm.suckless.org/patches/pertag
            3 This patch keeps layout, mwfact, barpos and nmaster per tag.
            4 
            5 diff -r ec4baab78314 dwm.c
            6 --- a/dwm.c        Mon Dec 19 15:38:30 2011 +0100
            7 +++ b/dwm.c        Fri Apr 06 08:23:29 2012 +0200
            8 @@ -124,6 +124,7 @@
            9          void (*arrange)(Monitor *);
           10  } Layout;
           11  
           12 +typedef struct Pertag Pertag;
           13  struct Monitor {
           14          char ltsymbol[16];
           15          float mfact;
           16 @@ -143,6 +144,7 @@
           17          Monitor *next;
           18          Window barwin;
           19          const Layout *lt[2];
           20 +        Pertag *pertag;
           21  };
           22  
           23  typedef struct {
           24 @@ -287,6 +289,15 @@
           25  /* configuration, allows nested code to access above variables */
           26  #include "config.h"
           27  
           28 +struct Pertag {
           29 +        unsigned int curtag, prevtag; /* current and previous tag */
           30 +        int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
           31 +        float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
           32 +        unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
           33 +        const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes  */
           34 +        Bool showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
           35 +};
           36 +
           37  /* compile-time check if all tags fit into an unsigned int bit array. */
           38  struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
           39  
           40 @@ -646,6 +657,7 @@
           41  Monitor *
           42  createmon(void) {
           43          Monitor *m;
           44 +        int i;
           45  
           46          if(!(m = (Monitor *)calloc(1, sizeof(Monitor))))
           47                  die("fatal: could not malloc() %u bytes\n", sizeof(Monitor));
           48 @@ -657,6 +669,24 @@
           49          m->lt[0] = &layouts[0];
           50          m->lt[1] = &layouts[1 % LENGTH(layouts)];
           51          strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol);
           52 +        if(!(m->pertag = (Pertag *)calloc(1, sizeof(Pertag))))
           53 +                die("fatal: could not malloc() %u bytes\n", sizeof(Pertag));
           54 +        m->pertag->curtag = m->pertag->prevtag = 1;
           55 +        for(i=0; i <= LENGTH(tags); i++) {
           56 +                /* init nmaster */
           57 +                m->pertag->nmasters[i] = m->nmaster;
           58 +
           59 +                /* init mfacts */
           60 +                m->pertag->mfacts[i] = m->mfact;
           61 +
           62 +                /* init layouts */
           63 +                m->pertag->ltidxs[i][0] = m->lt[0];
           64 +                m->pertag->ltidxs[i][1] = m->lt[1];
           65 +                m->pertag->sellts[i] = m->sellt;
           66 +
           67 +                /* init showbar */
           68 +                m->pertag->showbars[i] = m->showbar;
           69 +        }
           70          return m;
           71  }
           72  
           73 @@ -1028,7 +1058,7 @@
           74  
           75  void
           76  incnmaster(const Arg *arg) {
           77 -        selmon->nmaster = MAX(selmon->nmaster + arg->i, 0);
           78 +        selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag] = MAX(selmon->nmaster + arg->i, 0);
           79          arrange(selmon);
           80  }
           81  
           82 @@ -1555,10 +1585,13 @@
           83  
           84  void
           85  setlayout(const Arg *arg) {
           86 -        if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt])
           87 -                selmon->sellt ^= 1;
           88 +        if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) {
           89 +                selmon->pertag->sellts[selmon->pertag->curtag] ^= 1;
           90 +                selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
           91 +        }
           92          if(arg && arg->v)
           93 -                selmon->lt[selmon->sellt] = (Layout *)arg->v;
           94 +                selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt] = (Layout *)arg->v;
           95 +        selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
           96          strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol);
           97          if(selmon->sel)
           98                  arrange(selmon);
           99 @@ -1576,7 +1609,7 @@
          100          f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
          101          if(f < 0.1 || f > 0.9)
          102                  return;
          103 -        selmon->mfact = f;
          104 +        selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag] = f;
          105          arrange(selmon);
          106  }
          107  
          108 @@ -1729,7 +1762,7 @@
          109  
          110  void
          111  togglebar(const Arg *arg) {
          112 -        selmon->showbar = !selmon->showbar;
          113 +        selmon->showbar = selmon->pertag->showbars[selmon->pertag->curtag] = !selmon->showbar;
          114          updatebarpos(selmon);
          115          XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh);
          116          arrange(selmon);
          117 @@ -1763,9 +1796,29 @@
          118  void
          119  toggleview(const Arg *arg) {
          120          unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK);
          121 +        int i;
          122  
          123          if(newtagset) {
          124 +                if(newtagset == ~0) {
          125 +                        selmon->pertag->prevtag = selmon->pertag->curtag;
          126 +                        selmon->pertag->curtag = 0;
          127 +                }
          128 +                /* test if the user did not select the same tag */
          129 +                if(!(newtagset & 1 << (selmon->pertag->curtag - 1))) {
          130 +                        selmon->pertag->prevtag = selmon->pertag->curtag;
          131 +                        for (i=0; !(newtagset & 1 << i); i++) ;
          132 +                        selmon->pertag->curtag = i + 1;
          133 +                }
          134                  selmon->tagset[selmon->seltags] = newtagset;
          135 +
          136 +                /* apply settings for this view */
          137 +                selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
          138 +                selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
          139 +                selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
          140 +                selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
          141 +                selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
          142 +                if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
          143 +                        togglebar(NULL);
          144                  focus(NULL);
          145                  arrange(selmon);
          146          }
          147 @@ -2043,11 +2096,33 @@
          148  
          149  void
          150  view(const Arg *arg) {
          151 +        int i;
          152 +        unsigned int tmptag;
          153 +
          154          if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags])
          155                  return;
          156          selmon->seltags ^= 1; /* toggle sel tagset */
          157 -        if(arg->ui & TAGMASK)
          158 +        if(arg->ui & TAGMASK) {
          159 +                selmon->pertag->prevtag = selmon->pertag->curtag;
          160                  selmon->tagset[selmon->seltags] = arg->ui & TAGMASK;
          161 +                if(arg->ui == ~0)
          162 +                        selmon->pertag->curtag = 0;
          163 +                else {
          164 +                        for (i=0; !(arg->ui & 1 << i); i++) ;
          165 +                        selmon->pertag->curtag = i + 1;
          166 +                }
          167 +        } else {
          168 +                tmptag = selmon->pertag->prevtag;
          169 +                selmon->pertag->prevtag = selmon->pertag->curtag;
          170 +                selmon->pertag->curtag = tmptag;
          171 +        }
          172 +        selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag];
          173 +        selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag];
          174 +        selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag];
          175 +        selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt];
          176 +        selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1];
          177 +        if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag])
          178 +                togglebar(NULL);
          179          focus(NULL);
          180          arrange(selmon);
          181  }