improved selection policy
c3c94c0e
1 file(s) · +24 −20
| 3 | 3 | * See LICENSE file for license details. |
|
| 4 | 4 | */ |
|
| 5 | 5 | #include "dwm.h" |
|
| 6 | + | #include <stdio.h> |
|
| 6 | 7 | ||
| 7 | 8 | /* static */ |
|
| 8 | 9 | ||
| 10 | + | static Client * |
|
| 11 | + | minclient() |
|
| 12 | + | { |
|
| 13 | + | Client *c, *min; |
|
| 14 | + | ||
| 15 | + | for(min = c = clients; c; c = c->next) |
|
| 16 | + | if(c->weight < min->weight) |
|
| 17 | + | min = c; |
|
| 18 | + | return min; |
|
| 19 | + | } |
|
| 20 | + | ||
| 21 | + | ||
| 9 | 22 | static void |
|
| 10 | 23 | reorder() |
|
| 11 | 24 | { |
|
| 12 | - | Client *c, *orig, *p; |
|
| 25 | + | Client *c, *newclients, *tail; |
|
| 13 | 26 | ||
| 14 | - | orig = clients; |
|
| 15 | - | clients = NULL; |
|
| 16 | - | ||
| 17 | - | while((c = orig)) { |
|
| 18 | - | orig = orig->next; |
|
| 27 | + | newclients = tail = NULL; |
|
| 28 | + | while((c = minclient())) { |
|
| 19 | 29 | detach(c); |
|
| 20 | - | ||
| 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; |
|
| 30 | + | if(tail) { |
|
| 31 | + | c->prev = tail; |
|
| 32 | + | tail->next = c; |
|
| 33 | + | tail = c; |
|
| 27 | 34 | } |
|
| 28 | 35 | else |
|
| 29 | - | clients = c; |
|
| 36 | + | tail = newclients = c; |
|
| 30 | 37 | } |
|
| 38 | + | clients = newclients; |
|
| 31 | 39 | } |
|
| 32 | 40 | ||
| 33 | 41 | /* extern */ |
|
| 59 | 67 | else |
|
| 60 | 68 | ban(c); |
|
| 61 | 69 | } |
|
| 62 | - | if(!sel || !isvisible(sel)) |
|
| 63 | - | sel = getnext(clients); |
|
| 64 | - | if(sel) |
|
| 70 | + | if((sel = getnext(clients))) |
|
| 65 | 71 | focus(sel); |
|
| 66 | 72 | else |
|
| 67 | 73 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); |
|
| 124 | 130 | else |
|
| 125 | 131 | ban(c); |
|
| 126 | 132 | } |
|
| 127 | - | if(!sel || !isvisible(sel)) |
|
| 128 | - | sel = getnext(clients); |
|
| 129 | - | if(sel) |
|
| 133 | + | if((sel = getnext(clients))) |
|
| 130 | 134 | focus(sel); |
|
| 131 | 135 | else |
|
| 132 | 136 | XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime); |
|