aewl

diff client.c @ 127:1480e19f6377

using double-linked list in order to get correct prev focus handling
author arg@10ksloc.org
date Thu, 20 Jul 2006 16:54:20 +0200
parents 75576e44c1d8
children 0a407fbb8092
line diff
     1.1 --- a/client.c	Thu Jul 20 15:40:41 2006 +0200
     1.2 +++ b/client.c	Thu Jul 20 16:54:20 2006 +0200
     1.3 @@ -77,7 +77,6 @@
     1.4  		c = getnext(clients, tsel);
     1.5  	if(c) {
     1.6  		higher(c);
     1.7 -		c->revert = sel;
     1.8  		focus(c);
     1.9  	}
    1.10  }
    1.11 @@ -93,7 +92,11 @@
    1.12  	if(sel->ismax)
    1.13  		togglemax(NULL);
    1.14  
    1.15 -	if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
    1.16 +	if(!(c = getprev(sel->prev))) {
    1.17 +		for(c = clients; c && c->next; c = c->next);
    1.18 +		c = getprev(c);
    1.19 +	}
    1.20 +	if(c) {
    1.21  		higher(c);
    1.22  		focus(c);
    1.23  	}
    1.24 @@ -127,6 +130,8 @@
    1.25  	int dx = 0, dy = 0;
    1.26  
    1.27  	switch(c->grav) {
    1.28 +	default:
    1.29 +		break;
    1.30  	case StaticGravity:
    1.31  	case NorthWestGravity:
    1.32  	case NorthGravity:
    1.33 @@ -143,11 +148,11 @@
    1.34  	case SouthWestGravity:
    1.35  		dy = -(c->h);
    1.36  		break;
    1.37 -	default:
    1.38 -		break;
    1.39  	}
    1.40  
    1.41  	switch (c->grav) {
    1.42 +	default:
    1.43 +		break;
    1.44  	case StaticGravity:
    1.45  	case NorthWestGravity:
    1.46  	case WestGravity:
    1.47 @@ -164,8 +169,6 @@
    1.48  	case SouthEastGravity:
    1.49  		dx = -(c->w + c->border);
    1.50  		break;
    1.51 -	default:
    1.52 -		break;
    1.53  	}
    1.54  
    1.55  	if(invert) {
    1.56 @@ -204,7 +207,6 @@
    1.57  void
    1.58  manage(Window w, XWindowAttributes *wa)
    1.59  {
    1.60 -	int diff;
    1.61  	Client *c;
    1.62  	Window trans;
    1.63  	XSetWindowAttributes twa;
    1.64 @@ -224,7 +226,7 @@
    1.65  	c->proto = getproto(c->win);
    1.66  	setsize(c);
    1.67  	XSelectInput(dpy, c->win,
    1.68 -			StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
    1.69 +		StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
    1.70  	XGetTransientForHint(dpy, c->win, &trans);
    1.71  	twa.override_redirect = 1;
    1.72  	twa.background_pixmap = ParentRelative;
    1.73 @@ -237,6 +239,8 @@
    1.74  
    1.75  	settags(c);
    1.76  
    1.77 +	if(clients)
    1.78 +		clients->prev = c;
    1.79  	c->next = clients;
    1.80  	clients = c;
    1.81  
    1.82 @@ -264,6 +268,7 @@
    1.83  	else {
    1.84  		XMapRaised(dpy, c->win);
    1.85  		XMapRaised(dpy, c->title);
    1.86 +
    1.87  	}
    1.88  }
    1.89  
    1.90 @@ -273,9 +278,15 @@
    1.91  	Client **l;
    1.92  
    1.93  	for(l = &clients; *l && *l != c; l = &(*l)->next);
    1.94 +	if(c->prev)
    1.95 +		c->prev->next = c->next;
    1.96 +	if(c->next)
    1.97 +		c->next->prev = c->prev;
    1.98  	*l = c->next;
    1.99  
   1.100 -	c->next = clients; /* pop */
   1.101 +	if(clients)
   1.102 +		clients->prev = c;
   1.103 +	c->next = clients;
   1.104  	clients = c;
   1.105  	arrange(NULL);
   1.106  }
   1.107 @@ -439,13 +450,18 @@
   1.108  	XDestroyWindow(dpy, c->title);
   1.109  
   1.110  	for(l = &clients; *l && *l != c; l = &(*l)->next);
   1.111 +	if(c->prev)
   1.112 +		c->prev->next = c->next;
   1.113 +	if(c->next)
   1.114 +		c->next->prev = c->prev;
   1.115  	*l = c->next;
   1.116 -	for(l = &clients; *l; l = &(*l)->next)
   1.117 -		if((*l)->revert == c)
   1.118 -			(*l)->revert = NULL;
   1.119 -	if(sel == c)
   1.120 -		sel = sel->revert ? sel->revert : clients;
   1.121 -
   1.122 +	if(sel == c) {
   1.123 +		sel = getnext(c->next, tsel);
   1.124 +		if(!sel)
   1.125 +			sel = getprev(c->prev);
   1.126 +		if(!sel)
   1.127 +			sel = clients;
   1.128 +	}
   1.129  	free(c);
   1.130  
   1.131  	XSync(dpy, False);