layouts/fibonacci.c
branchstil
changeset 1534 ff21639cb978
equal deleted inserted replaced
1533:e2e1cbb46541 1534:ff21639cb978
       
     1 void
       
     2 fibonacci(Monitor *mon, int s) {
       
     3 	unsigned int i, n, nx, ny, nw, nh;
       
     4 	Client *c;
       
     5 
       
     6 	for(n = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next), n++);
       
     7 	if(n == 0)
       
     8 		return;
       
     9 	
       
    10 	nx = mon->wx;
       
    11 	ny = 0;
       
    12 	nw = mon->ww;
       
    13 	nh = mon->wh;
       
    14 	
       
    15 	for(i = 0, c = nexttiled(mon->clients); c; c = nexttiled(c->next)) {
       
    16 		if((i % 2 && nh / 2 > 2 * c->bw)
       
    17 		   || (!(i % 2) && nw / 2 > 2 * c->bw)) {
       
    18 			if(i < n - 1) {
       
    19 				if(i % 2)
       
    20 					nh /= 2;
       
    21 				else
       
    22 					nw /= 2;
       
    23 				if((i % 4) == 2 && !s)
       
    24 					nx += nw;
       
    25 				else if((i % 4) == 3 && !s)
       
    26 					ny += nh;
       
    27 			}
       
    28 			if((i % 4) == 0) {
       
    29 				if(s)
       
    30 					ny += nh;
       
    31 				else
       
    32 					ny -= nh;
       
    33 			}
       
    34 			else if((i % 4) == 1)
       
    35 				nx += nw;
       
    36 			else if((i % 4) == 2)
       
    37 				ny += nh;
       
    38 			else if((i % 4) == 3) {
       
    39 				if(s)
       
    40 					nx += nw;
       
    41 				else
       
    42 					nx -= nw;
       
    43 			}
       
    44 			if(i == 0)
       
    45 			{
       
    46 				if(n != 1)
       
    47 					nw = mon->ww * selmon->mfacts[selmon->curtag];
       
    48 				ny = mon->wy;
       
    49 			}
       
    50 			else if(i == 1)
       
    51 				nw = mon->ww - nw;
       
    52 			i++;
       
    53 		}
       
    54 		resize(c, nx, ny, nw - 2 * c->bw, nh - 2 * c->bw, False);
       
    55 	}
       
    56 }
       
    57 
       
    58 void
       
    59 dwindle(Monitor *mon) {
       
    60 	fibonacci(mon, 1);
       
    61 }
       
    62 
       
    63 void
       
    64 spiral(Monitor *mon) {
       
    65 	fibonacci(mon, 0);
       
    66 }