dwm-meillo

diff view.c @ 381:b00cc483d13b

still something wrong with reorder()
author Anselm R. Garbe <arg@10kloc.org>
date Tue, 29 Aug 2006 13:40:09 +0200
parents 4bf79305d675
children 76b62c0c8c11
line diff
     1.1 --- a/view.c	Tue Aug 29 09:57:57 2006 +0200
     1.2 +++ b/view.c	Tue Aug 29 13:40:09 2006 +0200
     1.3 @@ -6,27 +6,28 @@
     1.4  
     1.5  /* static */
     1.6  
     1.7 -static Client *
     1.8 -getslot(Client *c)
     1.9 +static void
    1.10 +reorder()
    1.11  {
    1.12 -	unsigned int i, tic;
    1.13 -	Client *p;
    1.14 +	Client *c, *orig, *p;
    1.15  
    1.16 -	for(tic = 0; tic < ntags && !c->tags[tic]; tic++);
    1.17 -	for(p = clients; p; p = p->next) {
    1.18 -		for(i = 0; i < ntags && !p->tags[i]; i++);
    1.19 -		if(tic < i)
    1.20 -			return p;
    1.21 +	orig = clients;
    1.22 +	clients = NULL;
    1.23 +
    1.24 +	while((c = orig)) {
    1.25 +		orig = orig->next;
    1.26 +		detach(c);
    1.27 +
    1.28 +		for(p = clients; p && p->next && p->weight <= c->weight; p = p->next);
    1.29 +		c->prev = p;
    1.30 +		if(p) {
    1.31 +			if((c->next = p->next))
    1.32 +				c->next->prev = c;
    1.33 +			p->next = c;
    1.34 +		}
    1.35 +		else
    1.36 +			clients = c;
    1.37  	}
    1.38 -	return p;
    1.39 -}
    1.40 -
    1.41 -static Client *
    1.42 -tail()
    1.43 -{
    1.44 -	Client *c;
    1.45 -	for(c = clients; c && c->next; c = c->next);
    1.46 -	return c;
    1.47  }
    1.48  
    1.49  /* extern */
    1.50 @@ -34,35 +35,6 @@
    1.51  void (*arrange)(Arg *) = DEFMODE;
    1.52  
    1.53  void
    1.54 -attach(Client *c)
    1.55 -{
    1.56 -	Client *p;
    1.57 -
    1.58 -	if(!clients) {
    1.59 -		clients = c;
    1.60 -		return;
    1.61 -	}
    1.62 -	if(!(p = getnext(clients)) && !(p = getslot(c))) {
    1.63 -		p = tail();
    1.64 -		c->prev = p;
    1.65 -		p->next = c;
    1.66 -		return;
    1.67 -	}
    1.68 -
    1.69 -	if(p == clients) {
    1.70 -		c->next = clients;
    1.71 -		clients->prev = c;
    1.72 -		clients = c;
    1.73 -	}
    1.74 -	else {
    1.75 -		p->prev->next = c;
    1.76 -		c->prev = p->prev;
    1.77 -		p->prev = c;
    1.78 -		c->next = p;
    1.79 -	}
    1.80 -}
    1.81 -
    1.82 -void
    1.83  detach(Client *c)
    1.84  {
    1.85  	if(c->prev)
    1.86 @@ -277,6 +249,7 @@
    1.87  	for(i = 0; i < ntags && !seltag[i]; i++);
    1.88  	if(i == ntags)
    1.89  		seltag[arg->i] = True; /* cannot toggle last view */
    1.90 +	reorder();
    1.91  	arrange(NULL);
    1.92  }
    1.93  
    1.94 @@ -284,10 +257,12 @@
    1.95  view(Arg *arg)
    1.96  {
    1.97  	unsigned int i;
    1.98 +	Client *c;
    1.99  
   1.100  	for(i = 0; i < ntags; i++)
   1.101  		seltag[i] = False;
   1.102  	seltag[arg->i] = True;
   1.103 +	reorder();
   1.104  	arrange(NULL);
   1.105  }
   1.106  
   1.107 @@ -303,7 +278,9 @@
   1.108  		if(!(c = getnext(c->next)))
   1.109  			return;
   1.110  	detach(c);
   1.111 -	attach(c);
   1.112 +	c->next = clients;
   1.113 +	clients->prev = c;
   1.114 +	clients = c;
   1.115  	focus(c);
   1.116  	arrange(NULL);
   1.117  }