screen.c
changeset 73 c2ddb9dbbd10
child 74 5370ef170cc9
equal deleted inserted replaced
72:d0eb0bb63c40 73:c2ddb9dbbd10
       
     1 /*
       
     2  * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
       
     3  * See LICENSE file for license details.
       
     4  */
       
     5 
       
     6 #include "dwm.h"
       
     7 
       
     8 void (*arrange)(Arg *) = tiling;
       
     9 
       
    10 void
       
    11 view(Arg *arg)
       
    12 {
       
    13 	Client *c;
       
    14 
       
    15 	tsel = arg->i;
       
    16 	arrange(NULL);
       
    17 
       
    18 	for(c = clients; c; c = next(c->next))
       
    19 		draw_client(c);
       
    20 	draw_bar();
       
    21 }
       
    22 
       
    23 void
       
    24 floating(Arg *arg)
       
    25 {
       
    26 	Client *c;
       
    27 
       
    28 	arrange = floating;
       
    29 	for(c = clients; c; c = c->next) {
       
    30 		if(c->tags[tsel])
       
    31 			resize(c, True);
       
    32 		else
       
    33 			ban_client(c);
       
    34 	}
       
    35 	if(sel && !sel->tags[tsel]) {
       
    36 		if((sel = next(clients))) {
       
    37 			craise(sel);
       
    38 			focus(sel);
       
    39 		}
       
    40 	}
       
    41 	draw_bar();
       
    42 }
       
    43 
       
    44 void
       
    45 tiling(Arg *arg)
       
    46 {
       
    47 	Client *c;
       
    48 	int n, i, w, h;
       
    49 
       
    50 	w = sw - mw;
       
    51 	arrange = tiling;
       
    52 	for(n = 0, c = clients; c; c = c->next)
       
    53 		if(c->tags[tsel] && !c->floating)
       
    54 			n++;
       
    55 
       
    56 	if(n > 1)
       
    57 		h = (sh - bh) / (n - 1);
       
    58 	else
       
    59 		h = sh - bh;
       
    60 
       
    61 	for(i = 0, c = clients; c; c = c->next) {
       
    62 		if(c->tags[tsel]) {
       
    63 			if(c->floating) {
       
    64 				craise(c);
       
    65 				resize(c, True);
       
    66 				continue;
       
    67 			}
       
    68 			if(n == 1) {
       
    69 				c->x = sx;
       
    70 				c->y = sy + bh;
       
    71 				c->w = sw - 2 * c->border;
       
    72 				c->h = sh - 2 * c->border - bh;
       
    73 			}
       
    74 			else if(i == 0) {
       
    75 				c->x = sx;
       
    76 				c->y = sy + bh;
       
    77 				c->w = mw - 2 * c->border;
       
    78 				c->h = sh - 2 * c->border - bh;
       
    79 			}
       
    80 			else {
       
    81 				c->x = sx + mw;
       
    82 				c->y = sy + (i - 1) * h + bh;
       
    83 				c->w = w - 2 * c->border;
       
    84 				c->h = h - 2 * c->border;
       
    85 			}
       
    86 			resize(c, False);
       
    87 			i++;
       
    88 		}
       
    89 		else
       
    90 			ban_client(c);
       
    91 	}
       
    92 	if(!sel || (sel && !sel->tags[tsel])) {
       
    93 		if((sel = next(clients))) {
       
    94 			craise(sel);
       
    95 			focus(sel);
       
    96 		}
       
    97 	}
       
    98 	draw_bar();
       
    99 }
       
   100