this algorithm seems to keep order for any scenario

new_dwm
Anselm R. Garbe 19 years ago
parent 5056bb952d
commit 016c54196e

@ -4,6 +4,31 @@
*/ */
#include "dwm.h" #include "dwm.h"
/* static */
static Client *
getslot(Client *c)
{
unsigned int i, tic;
Client *p;
for(tic = 0; tic < ntags && !c->tags[tic]; tic++);
for(p = clients; p; p = p->next) {
for(i = 0; i < ntags && !p->tags[i]; i++);
if(tic < i)
return p;
}
return p;
}
static Client *
tail()
{
Client *c;
for(c = clients; c && c->next; c = c->next);
return c;
}
/* extern */ /* extern */
void (*arrange)(Arg *) = DEFMODE; void (*arrange)(Arg *) = DEFMODE;
@ -11,27 +36,29 @@ void (*arrange)(Arg *) = DEFMODE;
void void
attach(Client *c) attach(Client *c)
{ {
Client *first = getnext(clients); Client *p;
if(!first) { if(!clients) {
if(clients) { clients = c;
for(first = clients; first->next; first = first->next); return;
first->next = c; }
c->prev = first; if(!(p = getnext(clients)) && !(p = getslot(c))) {
} p = tail();
else c->prev = p;
clients = c; p->next = c;
return;
} }
else if(first == clients) {
if(p == clients) {
c->next = clients; c->next = clients;
clients->prev = c; clients->prev = c;
clients = c; clients = c;
} }
else { else {
first->prev->next = c; p->prev->next = c;
c->prev = first->prev; c->prev = p->prev;
first->prev = c; p->prev = c;
c->next = first; c->next = p;
} }
} }

Loading…
Cancel
Save