aewl

changeset 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
files client.c dwm.h tag.c view.c
diffstat 4 files changed, 32 insertions(+), 55 deletions(-) [+]
line diff
     1.1 --- a/client.c	Tue Aug 29 09:57:57 2006 +0200
     1.2 +++ b/client.c	Tue Aug 29 13:40:09 2006 +0200
     1.3 @@ -241,7 +241,10 @@
     1.4  			|| (c->maxw && c->minw &&
     1.5  				c->maxw == c->minw && c->maxh == c->minh);
     1.6  
     1.7 -	attach(c);
     1.8 +	if(clients)
     1.9 +		clients->prev = c;
    1.10 +	c->next = clients;
    1.11 +	clients = c;
    1.12  
    1.13  	settitle(c);
    1.14  	if(isvisible(c))
     2.1 --- a/dwm.h	Tue Aug 29 09:57:57 2006 +0200
     2.2 +++ b/dwm.h	Tue Aug 29 13:40:09 2006 +0200
     2.3 @@ -56,7 +56,7 @@
     2.4  	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
     2.5  	int grav;
     2.6  	long flags; 
     2.7 -	unsigned int border;
     2.8 +	unsigned int border, weight;
     2.9  	Bool isfloat;
    2.10  	Bool ismax;
    2.11  	Bool *tags;
    2.12 @@ -127,7 +127,6 @@
    2.13  extern void spawn(Arg *arg);
    2.14  
    2.15  /* view.c */
    2.16 -extern void attach(Client *c);
    2.17  extern void detach(Client *c);
    2.18  extern void dofloat(Arg *arg);
    2.19  extern void dotile(Arg *arg);
     3.1 --- a/tag.c	Tue Aug 29 09:57:57 2006 +0200
     3.2 +++ b/tag.c	Tue Aug 29 13:40:09 2006 +0200
     3.3 @@ -106,6 +106,8 @@
     3.4  	if(!matched)
     3.5  		for(i = 0; i < ntags; i++)
     3.6  			c->tags[i] = seltag[i];
     3.7 +	for(i = 0; i < ntags && !c->tags[i]; i++);
     3.8 +	c->weight = i;
     3.9  }
    3.10  
    3.11  void
    3.12 @@ -120,8 +122,6 @@
    3.13  		sel->tags[i] = False;
    3.14  	sel->tags[arg->i] = True;
    3.15  	settitle(sel);
    3.16 -	detach(sel);
    3.17 -	attach(sel);
    3.18  	if(!isvisible(sel))
    3.19  		arrange(NULL);
    3.20  	else
    3.21 @@ -141,8 +141,6 @@
    3.22  	if(i == ntags)
    3.23  		sel->tags[arg->i] = True;
    3.24  	settitle(sel);
    3.25 -	detach(sel);
    3.26 -	attach(sel);
    3.27  	if(!isvisible(sel))
    3.28  		arrange(NULL);
    3.29  	else
     4.1 --- a/view.c	Tue Aug 29 09:57:57 2006 +0200
     4.2 +++ b/view.c	Tue Aug 29 13:40:09 2006 +0200
     4.3 @@ -6,27 +6,28 @@
     4.4  
     4.5  /* static */
     4.6  
     4.7 -static Client *
     4.8 -getslot(Client *c)
     4.9 +static void
    4.10 +reorder()
    4.11  {
    4.12 -	unsigned int i, tic;
    4.13 -	Client *p;
    4.14 +	Client *c, *orig, *p;
    4.15  
    4.16 -	for(tic = 0; tic < ntags && !c->tags[tic]; tic++);
    4.17 -	for(p = clients; p; p = p->next) {
    4.18 -		for(i = 0; i < ntags && !p->tags[i]; i++);
    4.19 -		if(tic < i)
    4.20 -			return p;
    4.21 +	orig = clients;
    4.22 +	clients = NULL;
    4.23 +
    4.24 +	while((c = orig)) {
    4.25 +		orig = orig->next;
    4.26 +		detach(c);
    4.27 +
    4.28 +		for(p = clients; p && p->next && p->weight <= c->weight; p = p->next);
    4.29 +		c->prev = p;
    4.30 +		if(p) {
    4.31 +			if((c->next = p->next))
    4.32 +				c->next->prev = c;
    4.33 +			p->next = c;
    4.34 +		}
    4.35 +		else
    4.36 +			clients = c;
    4.37  	}
    4.38 -	return p;
    4.39 -}
    4.40 -
    4.41 -static Client *
    4.42 -tail()
    4.43 -{
    4.44 -	Client *c;
    4.45 -	for(c = clients; c && c->next; c = c->next);
    4.46 -	return c;
    4.47  }
    4.48  
    4.49  /* extern */
    4.50 @@ -34,35 +35,6 @@
    4.51  void (*arrange)(Arg *) = DEFMODE;
    4.52  
    4.53  void
    4.54 -attach(Client *c)
    4.55 -{
    4.56 -	Client *p;
    4.57 -
    4.58 -	if(!clients) {
    4.59 -		clients = c;
    4.60 -		return;
    4.61 -	}
    4.62 -	if(!(p = getnext(clients)) && !(p = getslot(c))) {
    4.63 -		p = tail();
    4.64 -		c->prev = p;
    4.65 -		p->next = c;
    4.66 -		return;
    4.67 -	}
    4.68 -
    4.69 -	if(p == clients) {
    4.70 -		c->next = clients;
    4.71 -		clients->prev = c;
    4.72 -		clients = c;
    4.73 -	}
    4.74 -	else {
    4.75 -		p->prev->next = c;
    4.76 -		c->prev = p->prev;
    4.77 -		p->prev = c;
    4.78 -		c->next = p;
    4.79 -	}
    4.80 -}
    4.81 -
    4.82 -void
    4.83  detach(Client *c)
    4.84  {
    4.85  	if(c->prev)
    4.86 @@ -277,6 +249,7 @@
    4.87  	for(i = 0; i < ntags && !seltag[i]; i++);
    4.88  	if(i == ntags)
    4.89  		seltag[arg->i] = True; /* cannot toggle last view */
    4.90 +	reorder();
    4.91  	arrange(NULL);
    4.92  }
    4.93  
    4.94 @@ -284,10 +257,12 @@
    4.95  view(Arg *arg)
    4.96  {
    4.97  	unsigned int i;
    4.98 +	Client *c;
    4.99  
   4.100  	for(i = 0; i < ntags; i++)
   4.101  		seltag[i] = False;
   4.102  	seltag[arg->i] = True;
   4.103 +	reorder();
   4.104  	arrange(NULL);
   4.105  }
   4.106  
   4.107 @@ -303,7 +278,9 @@
   4.108  		if(!(c = getnext(c->next)))
   4.109  			return;
   4.110  	detach(c);
   4.111 -	attach(c);
   4.112 +	c->next = clients;
   4.113 +	clients->prev = c;
   4.114 +	clients = c;
   4.115  	focus(c);
   4.116  	arrange(NULL);
   4.117  }