view.c
changeset 382 76b62c0c8c11
parent 381 b00cc483d13b
child 388 aba385c61b3b
equal deleted inserted replaced
381:b00cc483d13b 382:76b62c0c8c11
     1 /*
     1 /*
     2  * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
     2  * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
     3  * See LICENSE file for license details.
     3  * See LICENSE file for license details.
     4  */
     4  */
     5 #include "dwm.h"
     5 #include "dwm.h"
       
     6 #include <stdio.h>
     6 
     7 
     7 /* static */
     8 /* static */
       
     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 
     8 
    21 
     9 static void
    22 static void
    10 reorder()
    23 reorder()
    11 {
    24 {
    12 	Client *c, *orig, *p;
    25 	Client *c, *newclients, *tail;
    13 
    26 
    14 	orig = clients;
    27 	newclients = tail = NULL;
    15 	clients = NULL;
    28 	while((c = minclient())) {
    16 
       
    17 	while((c = orig)) {
       
    18 		orig = orig->next;
       
    19 		detach(c);
    29 		detach(c);
    20 
    30 		if(tail) {
    21 		for(p = clients; p && p->next && p->weight <= c->weight; p = p->next);
    31 			c->prev = tail;
    22 		c->prev = p;
    32 			tail->next = c;
    23 		if(p) {
    33 			tail = c;
    24 			if((c->next = p->next))
       
    25 				c->next->prev = c;
       
    26 			p->next = c;
       
    27 		}
    34 		}
    28 		else
    35 		else
    29 			clients = c;
    36 			tail = newclients = c;
    30 	}
    37 	}
       
    38 	clients = newclients;
    31 }
    39 }
    32 
    40 
    33 /* extern */
    41 /* extern */
    34 
    42 
    35 void (*arrange)(Arg *) = DEFMODE;
    43 void (*arrange)(Arg *) = DEFMODE;
    57 			resize(c, True, TopLeft);
    65 			resize(c, True, TopLeft);
    58 		}
    66 		}
    59 		else
    67 		else
    60 			ban(c);
    68 			ban(c);
    61 	}
    69 	}
    62 	if(!sel || !isvisible(sel))
    70 	if((sel = getnext(clients)))
    63 		sel = getnext(clients);
       
    64 	if(sel)
       
    65 		focus(sel);
    71 		focus(sel);
    66 	else
    72 	else
    67 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
    73 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
    68 	restack();
    74 	restack();
    69 }
    75 }
   122 			i++;
   128 			i++;
   123 		}
   129 		}
   124 		else
   130 		else
   125 			ban(c);
   131 			ban(c);
   126 	}
   132 	}
   127 	if(!sel || !isvisible(sel))
   133 	if((sel = getnext(clients)))
   128 		sel = getnext(clients);
       
   129 	if(sel)
       
   130 		focus(sel);
   134 		focus(sel);
   131 	else
   135 	else
   132 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
   136 		XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
   133 	restack();
   137 	restack();
   134 }
   138 }