dwm-pertag-perseltag-6.2.diff (6466B)
1 diff -up a/dwm.c b/dwm.c 2 --- a/dwm.c 2020-05-23 00:20:34.877944603 +0200 3 +++ b/dwm.c 2020-06-22 12:49:55.298859682 +0200 4 @@ -111,6 +111,7 @@ typedef struct { 5 void (*arrange)(Monitor *); 6 } Layout; 7 8 +typedef struct Pertag Pertag; 9 struct Monitor { 10 char ltsymbol[16]; 11 float mfact; 12 @@ -130,6 +131,7 @@ struct Monitor { 13 Monitor *next; 14 Window barwin; 15 const Layout *lt[2]; 16 + Pertag *pertag; 17 }; 18 19 typedef struct { 20 @@ -271,6 +273,15 @@ static Window root, wmcheckwin; 21 /* configuration, allows nested code to access above variables */ 22 #include "config.h" 23 24 +struct Pertag { 25 + unsigned int curtag, prevtag; /* current and previous tag */ 26 + int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */ 27 + float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */ 28 + unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */ 29 + const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes */ 30 + int showbars[LENGTH(tags) + 1]; /* display bar for the current tag */ 31 +}; 32 + 33 /* compile-time check if all tags fit into an unsigned int bit array. */ 34 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; 35 36 @@ -631,6 +642,7 @@ Monitor * 37 createmon(void) 38 { 39 Monitor *m; 40 + unsigned int i; 41 42 m = ecalloc(1, sizeof(Monitor)); 43 m->tagset[0] = m->tagset[1] = 1; 44 @@ -641,6 +653,20 @@ createmon(void) 45 m->lt[0] = &layouts[0]; 46 m->lt[1] = &layouts[1 % LENGTH(layouts)]; 47 strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); 48 + m->pertag = ecalloc(1, sizeof(Pertag)); 49 + m->pertag->curtag = m->pertag->prevtag = 1; 50 + 51 + for (i = 0; i <= LENGTH(tags); i++) { 52 + m->pertag->nmasters[i] = m->nmaster; 53 + m->pertag->mfacts[i] = m->mfact; 54 + 55 + m->pertag->ltidxs[i][0] = m->lt[0]; 56 + m->pertag->ltidxs[i][1] = m->lt[1]; 57 + m->pertag->sellts[i] = m->sellt; 58 + 59 + m->pertag->showbars[i] = m->showbar; 60 + } 61 + 62 return m; 63 } 64 65 @@ -966,7 +992,16 @@ grabkeys(void) 66 void 67 incnmaster(const Arg *arg) 68 { 69 + unsigned int i; 70 selmon->nmaster = MAX(selmon->nmaster + arg->i, 0); 71 + for(i=0; i<LENGTH(tags); ++i) 72 + if(selmon->tagset[selmon->seltags] & 1<<i) 73 + selmon->pertag->nmasters[i+1] = selmon->nmaster; 74 + 75 + if(selmon->pertag->curtag == 0) 76 + { 77 + selmon->pertag->nmasters[0] = selmon->nmaster; 78 + } 79 arrange(selmon); 80 } 81 82 @@ -1500,11 +1535,26 @@ setfullscreen(Client *c, int fullscreen) 83 void 84 setlayout(const Arg *arg) 85 { 86 + unsigned int i; 87 if (!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) 88 selmon->sellt ^= 1; 89 if (arg && arg->v) 90 selmon->lt[selmon->sellt] = (Layout *)arg->v; 91 strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); 92 + 93 + for(i=0; i<LENGTH(tags); ++i) 94 + if(selmon->tagset[selmon->seltags] & 1<<i) 95 + { 96 + selmon->pertag->ltidxs[i+1][selmon->sellt] = selmon->lt[selmon->sellt]; 97 + selmon->pertag->sellts[i+1] = selmon->sellt; 98 + } 99 + 100 + if(selmon->pertag->curtag == 0) 101 + { 102 + selmon->pertag->ltidxs[0][selmon->sellt] = selmon->lt[selmon->sellt]; 103 + selmon->pertag->sellts[0] = selmon->sellt; 104 + } 105 + 106 if (selmon->sel) 107 arrange(selmon); 108 else 109 @@ -1516,13 +1566,24 @@ void 110 setmfact(const Arg *arg) 111 { 112 float f; 113 + unsigned int i; 114 115 if (!arg || !selmon->lt[selmon->sellt]->arrange) 116 return; 117 f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; 118 - if (f < 0.1 || f > 0.9) 119 + if (arg->f == 0.0) 120 + f = mfact; 121 + if (f < 0.05 || f > 0.95) 122 return; 123 selmon->mfact = f; 124 + for(i=0; i<LENGTH(tags); ++i) 125 + if(selmon->tagset[selmon->seltags] & 1<<i) 126 + selmon->pertag->mfacts[i+1] = f; 127 + 128 + if(selmon->pertag->curtag == 0) 129 + { 130 + selmon->pertag->mfacts[0] = f; 131 + } 132 arrange(selmon); 133 } 134 135 @@ -1699,7 +1760,16 @@ tile(Monitor *m) 136 void 137 togglebar(const Arg *arg) 138 { 139 + unsigned int i; 140 selmon->showbar = !selmon->showbar; 141 + for(i=0; i<LENGTH(tags); ++i) 142 + if(selmon->tagset[selmon->seltags] & 1<<i) 143 + selmon->pertag->showbars[i+1] = selmon->showbar; 144 + 145 + if(selmon->pertag->curtag == 0) 146 + { 147 + selmon->pertag->showbars[0] = selmon->showbar; 148 + } 149 updatebarpos(selmon); 150 XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); 151 arrange(selmon); 152 @@ -1738,9 +1808,33 @@ void 153 toggleview(const Arg *arg) 154 { 155 unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); 156 + int i; 157 158 if (newtagset) { 159 selmon->tagset[selmon->seltags] = newtagset; 160 + 161 + if (newtagset == ~0) { 162 + selmon->pertag->prevtag = selmon->pertag->curtag; 163 + selmon->pertag->curtag = 0; 164 + } 165 + 166 + /* test if the user did not select the same tag */ 167 + if (!(newtagset & 1 << (selmon->pertag->curtag - 1))) { 168 + selmon->pertag->prevtag = selmon->pertag->curtag; 169 + for (i = 0; !(newtagset & 1 << i); i++) ; 170 + selmon->pertag->curtag = i + 1; 171 + } 172 + 173 + /* apply settings for this view */ 174 + selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag]; 175 + selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag]; 176 + selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag]; 177 + selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]; 178 + selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1]; 179 + 180 + if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag]) 181 + togglebar(NULL); 182 + 183 focus(NULL); 184 arrange(selmon); 185 } 186 @@ -2035,11 +2129,37 @@ updatewmhints(Client *c) 187 void 188 view(const Arg *arg) 189 { 190 + int i; 191 + unsigned int tmptag; 192 + 193 if ((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) 194 return; 195 selmon->seltags ^= 1; /* toggle sel tagset */ 196 - if (arg->ui & TAGMASK) 197 + if (arg->ui & TAGMASK) { 198 selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; 199 + selmon->pertag->prevtag = selmon->pertag->curtag; 200 + 201 + if (arg->ui == ~0) 202 + selmon->pertag->curtag = 0; 203 + else { 204 + for (i = 0; !(arg->ui & 1 << i); i++) ; 205 + selmon->pertag->curtag = i + 1; 206 + } 207 + } else { 208 + tmptag = selmon->pertag->prevtag; 209 + selmon->pertag->prevtag = selmon->pertag->curtag; 210 + selmon->pertag->curtag = tmptag; 211 + } 212 + 213 + selmon->nmaster = selmon->pertag->nmasters[selmon->pertag->curtag]; 214 + selmon->mfact = selmon->pertag->mfacts[selmon->pertag->curtag]; 215 + selmon->sellt = selmon->pertag->sellts[selmon->pertag->curtag]; 216 + selmon->lt[selmon->sellt] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt]; 217 + selmon->lt[selmon->sellt^1] = selmon->pertag->ltidxs[selmon->pertag->curtag][selmon->sellt^1]; 218 + 219 + if (selmon->showbar != selmon->pertag->showbars[selmon->pertag->curtag]) 220 + togglebar(NULL); 221 + 222 focus(NULL); 223 arrange(selmon); 224 }