still something wrong with reorder()
9d739090
4 file(s) · +32 −55
| 241 | 241 | || (c->maxw && c->minw && |
|
| 242 | 242 | c->maxw == c->minw && c->maxh == c->minh); |
|
| 243 | 243 | ||
| 244 | - | attach(c); |
|
| 244 | + | if(clients) |
|
| 245 | + | clients->prev = c; |
|
| 246 | + | c->next = clients; |
|
| 247 | + | clients = c; |
|
| 245 | 248 | ||
| 246 | 249 | settitle(c); |
|
| 247 | 250 | if(isvisible(c)) |
| 56 | 56 | int basew, baseh, incw, inch, maxw, maxh, minw, minh; |
|
| 57 | 57 | int grav; |
|
| 58 | 58 | long flags; |
|
| 59 | - | unsigned int border; |
|
| 59 | + | unsigned int border, weight; |
|
| 60 | 60 | Bool isfloat; |
|
| 61 | 61 | Bool ismax; |
|
| 62 | 62 | Bool *tags; |
|
| 127 | 127 | extern void spawn(Arg *arg); |
|
| 128 | 128 | ||
| 129 | 129 | /* view.c */ |
|
| 130 | - | extern void attach(Client *c); |
|
| 131 | 130 | extern void detach(Client *c); |
|
| 132 | 131 | extern void dofloat(Arg *arg); |
|
| 133 | 132 | extern void dotile(Arg *arg); |
|
| 106 | 106 | if(!matched) |
|
| 107 | 107 | for(i = 0; i < ntags; i++) |
|
| 108 | 108 | c->tags[i] = seltag[i]; |
|
| 109 | + | for(i = 0; i < ntags && !c->tags[i]; i++); |
|
| 110 | + | c->weight = i; |
|
| 109 | 111 | } |
|
| 110 | 112 | ||
| 111 | 113 | void |
|
| 120 | 122 | sel->tags[i] = False; |
|
| 121 | 123 | sel->tags[arg->i] = True; |
|
| 122 | 124 | settitle(sel); |
|
| 123 | - | detach(sel); |
|
| 124 | - | attach(sel); |
|
| 125 | 125 | if(!isvisible(sel)) |
|
| 126 | 126 | arrange(NULL); |
|
| 127 | 127 | else |
|
| 141 | 141 | if(i == ntags) |
|
| 142 | 142 | sel->tags[arg->i] = True; |
|
| 143 | 143 | settitle(sel); |
|
| 144 | - | detach(sel); |
|
| 145 | - | attach(sel); |
|
| 146 | 144 | if(!isvisible(sel)) |
|
| 147 | 145 | arrange(NULL); |
|
| 148 | 146 | else |
|
| 6 | 6 | ||
| 7 | 7 | /* static */ |
|
| 8 | 8 | ||
| 9 | - | static Client * |
|
| 10 | - | getslot(Client *c) |
|
| 9 | + | static void |
|
| 10 | + | reorder() |
|
| 11 | 11 | { |
|
| 12 | - | unsigned int i, tic; |
|
| 13 | - | Client *p; |
|
| 12 | + | Client *c, *orig, *p; |
|
| 13 | + | ||
| 14 | + | orig = clients; |
|
| 15 | + | clients = NULL; |
|
| 14 | 16 | ||
| 15 | - | for(tic = 0; tic < ntags && !c->tags[tic]; tic++); |
|
| 16 | - | for(p = clients; p; p = p->next) { |
|
| 17 | - | for(i = 0; i < ntags && !p->tags[i]; i++); |
|
| 18 | - | if(tic < i) |
|
| 19 | - | return p; |
|
| 20 | - | } |
|
| 21 | - | return p; |
|
| 22 | - | } |
|
| 17 | + | while((c = orig)) { |
|
| 18 | + | orig = orig->next; |
|
| 19 | + | detach(c); |
|
| 23 | 20 | ||
| 24 | - | static Client * |
|
| 25 | - | tail() |
|
| 26 | - | { |
|
| 27 | - | Client *c; |
|
| 28 | - | for(c = clients; c && c->next; c = c->next); |
|
| 29 | - | return c; |
|
| 21 | + | for(p = clients; p && p->next && p->weight <= c->weight; p = p->next); |
|
| 22 | + | c->prev = p; |
|
| 23 | + | if(p) { |
|
| 24 | + | if((c->next = p->next)) |
|
| 25 | + | c->next->prev = c; |
|
| 26 | + | p->next = c; |
|
| 27 | + | } |
|
| 28 | + | else |
|
| 29 | + | clients = c; |
|
| 30 | + | } |
|
| 30 | 31 | } |
|
| 31 | 32 | ||
| 32 | 33 | /* extern */ |
|
| 33 | 34 | ||
| 34 | 35 | void (*arrange)(Arg *) = DEFMODE; |
|
| 35 | - | ||
| 36 | - | void |
|
| 37 | - | attach(Client *c) |
|
| 38 | - | { |
|
| 39 | - | Client *p; |
|
| 40 | - | ||
| 41 | - | if(!clients) { |
|
| 42 | - | clients = c; |
|
| 43 | - | return; |
|
| 44 | - | } |
|
| 45 | - | if(!(p = getnext(clients)) && !(p = getslot(c))) { |
|
| 46 | - | p = tail(); |
|
| 47 | - | c->prev = p; |
|
| 48 | - | p->next = c; |
|
| 49 | - | return; |
|
| 50 | - | } |
|
| 51 | - | ||
| 52 | - | if(p == clients) { |
|
| 53 | - | c->next = clients; |
|
| 54 | - | clients->prev = c; |
|
| 55 | - | clients = c; |
|
| 56 | - | } |
|
| 57 | - | else { |
|
| 58 | - | p->prev->next = c; |
|
| 59 | - | c->prev = p->prev; |
|
| 60 | - | p->prev = c; |
|
| 61 | - | c->next = p; |
|
| 62 | - | } |
|
| 63 | - | } |
|
| 64 | 36 | ||
| 65 | 37 | void |
|
| 66 | 38 | detach(Client *c) |
|
| 277 | 249 | for(i = 0; i < ntags && !seltag[i]; i++); |
|
| 278 | 250 | if(i == ntags) |
|
| 279 | 251 | seltag[arg->i] = True; /* cannot toggle last view */ |
|
| 252 | + | reorder(); |
|
| 280 | 253 | arrange(NULL); |
|
| 281 | 254 | } |
|
| 282 | 255 | ||
| 284 | 257 | view(Arg *arg) |
|
| 285 | 258 | { |
|
| 286 | 259 | unsigned int i; |
|
| 260 | + | Client *c; |
|
| 287 | 261 | ||
| 288 | 262 | for(i = 0; i < ntags; i++) |
|
| 289 | 263 | seltag[i] = False; |
|
| 290 | 264 | seltag[arg->i] = True; |
|
| 265 | + | reorder(); |
|
| 291 | 266 | arrange(NULL); |
|
| 292 | 267 | } |
|
| 293 | 268 | ||
| 303 | 278 | if(!(c = getnext(c->next))) |
|
| 304 | 279 | return; |
|
| 305 | 280 | detach(c); |
|
| 306 | - | attach(c); |
|
| 281 | + | c->next = clients; |
|
| 282 | + | clients->prev = c; |
|
| 283 | + | clients = c; |
|
| 307 | 284 | focus(c); |
|
| 308 | 285 | arrange(NULL); |
|
| 309 | 286 | } |
|