dwm-r1578-pertag.diff (4963B)
1 diff --git a/dwm.c b/dwm.c 2 --- a/dwm.c 3 +++ b/dwm.c 4 @@ -122,27 +122,6 @@ 5 void (*arrange)(Monitor *); 6 } Layout; 7 8 -struct Monitor { 9 - char ltsymbol[16]; 10 - float mfact; 11 - int nmaster; 12 - int num; 13 - int by; /* bar geometry */ 14 - int mx, my, mw, mh; /* screen size */ 15 - int wx, wy, ww, wh; /* window area */ 16 - unsigned int seltags; 17 - unsigned int sellt; 18 - unsigned int tagset[2]; 19 - Bool showbar; 20 - Bool topbar; 21 - Client *clients; 22 - Client *sel; 23 - Client *stack; 24 - Monitor *next; 25 - Window barwin; 26 - const Layout *lt[2]; 27 -}; 28 - 29 typedef struct { 30 const char *class; 31 const char *instance; 32 @@ -281,6 +260,33 @@ 33 /* configuration, allows nested code to access above variables */ 34 #include "config.h" 35 36 +struct Monitor { 37 + char ltsymbol[16]; 38 + float mfact; 39 + int nmaster; 40 + int num; 41 + int by; /* bar geometry */ 42 + int mx, my, mw, mh; /* screen size */ 43 + int wx, wy, ww, wh; /* window area */ 44 + unsigned int seltags; 45 + unsigned int sellt; 46 + unsigned int tagset[2]; 47 + Bool showbar; 48 + Bool topbar; 49 + Client *clients; 50 + Client *sel; 51 + Client *stack; 52 + Monitor *next; 53 + Window barwin; 54 + const Layout *lt[2]; 55 + int curtag; 56 + int prevtag; 57 + const Layout *lts[LENGTH(tags) + 1]; 58 + float mfacts[LENGTH(tags) + 1]; 59 + int nmasters[LENGTH(tags) + 1]; 60 + Bool showbars[LENGTH(tags) + 1]; 61 +}; 62 + 63 /* compile-time check if all tags fit into an unsigned int bit array. */ 64 struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; }; 65 66 @@ -661,6 +667,7 @@ 67 Monitor * 68 createmon(void) { 69 Monitor *m; 70 + unsigned int i; 71 72 if(!(m = (Monitor *)calloc(1, sizeof(Monitor)))) 73 die("fatal: could not malloc() %u bytes\n", sizeof(Monitor)); 74 @@ -672,6 +679,16 @@ 75 m->lt[0] = &layouts[0]; 76 m->lt[1] = &layouts[1 % LENGTH(layouts)]; 77 strncpy(m->ltsymbol, layouts[0].symbol, sizeof m->ltsymbol); 78 + 79 + /* pertag init */ 80 + m->curtag = m->prevtag = 1; 81 + for(i=0; i < LENGTH(tags) + 1 ; i++) { 82 + m->mfacts[i] = mfact; 83 + m->nmasters[i] = nmaster; 84 + m->lts[i] = &layouts[0]; 85 + m->showbars[i] = m->showbar; 86 + } 87 + 88 return m; 89 } 90 91 @@ -1028,7 +1045,8 @@ 92 93 void 94 incnmaster(const Arg *arg) { 95 - selmon->nmaster = MAX(selmon->nmaster + arg->i, 1); 96 + selmon->nmasters[selmon->curtag] = MAX(selmon->nmaster + arg->i, 1); 97 + selmon->nmaster = selmon->nmasters[selmon->curtag]; 98 arrange(selmon); 99 } 100 101 @@ -1515,7 +1533,7 @@ 102 if(!arg || !arg->v || arg->v != selmon->lt[selmon->sellt]) 103 selmon->sellt ^= 1; 104 if(arg && arg->v) 105 - selmon->lt[selmon->sellt] = (Layout *)arg->v; 106 + selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag] = (Layout *)arg->v; 107 strncpy(selmon->ltsymbol, selmon->lt[selmon->sellt]->symbol, sizeof selmon->ltsymbol); 108 if(selmon->sel) 109 arrange(selmon); 110 @@ -1533,7 +1551,7 @@ 111 f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0; 112 if(f < 0.1 || f > 0.9) 113 return; 114 - selmon->mfact = f; 115 + selmon->mfact = selmon->mfacts[selmon->curtag] = f; 116 arrange(selmon); 117 } 118 119 @@ -1680,7 +1698,7 @@ 120 121 void 122 togglebar(const Arg *arg) { 123 - selmon->showbar = !selmon->showbar; 124 + selmon->showbar = selmon->showbars[selmon->curtag] = !selmon->showbar; 125 updatebarpos(selmon); 126 XMoveResizeWindow(dpy, selmon->barwin, selmon->wx, selmon->by, selmon->ww, bh); 127 arrange(selmon); 128 @@ -1699,13 +1717,28 @@ 129 130 void 131 toggletag(const Arg *arg) { 132 - unsigned int newtags; 133 + unsigned int i, newtags; 134 135 if(!selmon->sel) 136 return; 137 newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); 138 if(newtags) { 139 selmon->sel->tags = newtags; 140 + if(newtags == ~0) { 141 + selmon->prevtag = selmon->curtag; 142 + selmon->curtag = 0; 143 + } 144 + if(!(newtags & 1 << (selmon->curtag - 1))) { 145 + selmon->prevtag = selmon->curtag; 146 + for (i=0; !(newtags & 1 << i); i++); 147 + selmon->curtag = i + 1; 148 + } 149 + selmon->sel->tags = newtags; 150 + selmon->lt[selmon->sellt] = selmon->lts[selmon->curtag]; 151 + selmon->mfact = selmon->mfacts[selmon->curtag]; 152 + selmon->nmaster = selmon->nmasters[selmon->curtag]; 153 + if (selmon->showbar != selmon->showbars[selmon->curtag]) 154 + togglebar(NULL); 155 focus(NULL); 156 arrange(selmon); 157 } 158 @@ -1982,11 +2015,30 @@ 159 160 void 161 view(const Arg *arg) { 162 + unsigned int i; 163 + 164 if((arg->ui & TAGMASK) == selmon->tagset[selmon->seltags]) 165 return; 166 selmon->seltags ^= 1; /* toggle sel tagset */ 167 - if(arg->ui & TAGMASK) 168 + if(arg->ui & TAGMASK) { 169 selmon->tagset[selmon->seltags] = arg->ui & TAGMASK; 170 + selmon->prevtag = selmon->curtag; 171 + if(arg->ui == ~0) 172 + selmon->curtag = 0; 173 + else { 174 + for (i=0; !(arg->ui & 1 << i); i++); 175 + selmon->curtag = i + 1; 176 + } 177 + } else { 178 + selmon->prevtag= selmon->curtag ^ selmon->prevtag; 179 + selmon->curtag^= selmon->prevtag; 180 + selmon->prevtag= selmon->curtag ^ selmon->prevtag; 181 + } 182 + selmon->lt[selmon->sellt]= selmon->lts[selmon->curtag]; 183 + selmon->mfact = selmon->mfacts[selmon->curtag]; 184 + selmon->nmaster = selmon->nmasters[selmon->curtag]; 185 + if(selmon->showbar != selmon->showbars[selmon->curtag]) 186 + togglebar(NULL); 187 focus(NULL); 188 arrange(selmon); 189 }