| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277 | /* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */#include "dwm.h"#include <stdio.h>/* static */static Client *nexttiled(Client *c) {	for(; c && (c->isfloat || !isvisible(c)); c = c->next);	return c;}static voidtogglemax(Client *c) {	XEvent ev;			if(c->isfixed)		return;	if((c->ismax = !c->ismax)) {		c->rx = c->x;		c->ry = c->y;		c->rw = c->w;		c->rh = c->h;		resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);	}	else		resize(c, c->rx, c->ry, c->rw, c->rh, True);	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));}/* extern */void (*arrange)(void) = DEFMODE;voiddetach(Client *c) {	if(c->prev)		c->prev->next = c->next;	if(c->next)		c->next->prev = c->prev;	if(c == clients)		clients = c->next;	c->next = c->prev = NULL;}voiddofloat(void) {	Client *c;	for(c = clients; c; c = c->next) {		if(isvisible(c)) {			if(c->isbanned)				XMoveWindow(dpy, c->win, c->x, c->y);			c->isbanned = False;			resize(c, c->x, c->y, c->w, c->h, True);		}		else {			c->isbanned = True;			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);		}	}	if(!sel || !isvisible(sel)) {		for(c = stack; c && !isvisible(c); c = c->snext);		focus(c);	}	restack();}voiddotile(void) {	unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;	Client *c;	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))		n++;	/* window geoms */	mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);	mw = (n > nmaster) ? (waw * master) / 1000 : waw;	th = (n > nmaster) ? wah / (n - nmaster) : 0;	tw = waw - mw;	for(i = 0, c = clients; c; c = c->next)		if(isvisible(c)) {			if(c->isbanned)				XMoveWindow(dpy, c->win, c->x, c->y);			c->isbanned = False;			if(c->isfloat)				continue;			c->ismax = False;			nx = wax;			ny = way;			if(i < nmaster) {				ny += i * mh;				nw = mw - 2 * BORDERPX;				nh = mh - 2 * BORDERPX;			}			else {  /* tile window */				nx += mw;				nw = tw - 2 * BORDERPX;				if(th > 2 * BORDERPX) {					ny += (i - nmaster) * th;					nh = th - 2 * BORDERPX;				}				else /* fallback if th <= 2 * BORDERPX */					nh = wah - 2 * BORDERPX;			}			resize(c, nx, ny, nw, nh, False);			i++;		}		else {			c->isbanned = True;			XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);		}	if(!sel || !isvisible(sel)) {		for(c = stack; c && !isvisible(c); c = c->snext);		focus(c);	}	restack();}voidfocusnext(Arg *arg) {	Client *c;   	if(!sel)		return;	for(c = sel->next; c && !isvisible(c); c = c->next);	if(!c)		for(c = clients; c && !isvisible(c); c = c->next);	if(c) {		focus(c);		restack();	}}voidfocusprev(Arg *arg) {	Client *c;	if(!sel)		return;	for(c = sel->prev; c && !isvisible(c); c = c->prev);	if(!c) {		for(c = clients; c && c->next; c = c->next);		for(; c && !isvisible(c); c = c->prev);	}	if(c) {		focus(c);		restack();	}}voidincnmaster(Arg *arg) {	if((arrange == dofloat) || (nmaster + arg->i < 1)	|| (wah / (nmaster + arg->i) <= 2 * BORDERPX))		return;	nmaster += arg->i;	if(sel)		arrange();	else		drawstatus();}Boolisvisible(Client *c) {	unsigned int i;	for(i = 0; i < ntags; i++)		if(c->tags[i] && seltag[i])			return True;	return False;}voidresizemaster(Arg *arg) {	if(arg->i == 0)		master = MASTER;	else {		if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX		|| waw * (master + arg->i) / 1000 <= 2 * BORDERPX)			return;		master += arg->i;	}	arrange();}voidrestack(void) {	Client *c;	XEvent ev;	drawstatus();	if(!sel)		return;	if(sel->isfloat || arrange == dofloat)		XRaiseWindow(dpy, sel->win);	if(arrange != dofloat) {		if(!sel->isfloat)			XLowerWindow(dpy, sel->win);		for(c = nexttiled(clients); c; c = nexttiled(c->next)) {			if(c == sel)				continue;			XLowerWindow(dpy, c->win);		}	}	XSync(dpy, False);	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));}voidtogglefloat(Arg *arg) {	if(!sel || arrange == dofloat)		return;	sel->isfloat = !sel->isfloat;	arrange();}voidtogglemode(Arg *arg) {	arrange = (arrange == dofloat) ? dotile : dofloat;	if(sel)		arrange();	else		drawstatus();}voidtoggleview(Arg *arg) {	unsigned int i;	seltag[arg->i] = !seltag[arg->i];	for(i = 0; i < ntags && !seltag[i]; i++);	if(i == ntags)		seltag[arg->i] = True; /* cannot toggle last view */	arrange();}voidview(Arg *arg) {	unsigned int i;	for(i = 0; i < ntags; i++)		seltag[i] = (arg->i == -1) ? True : False;	if(arg->i >= 0 && arg->i < ntags)		seltag[arg->i] = True;	arrange();}voidzoom(Arg *arg) {	unsigned int n;	Client *c;	if(!sel)		return;	if(sel->isfloat || (arrange == dofloat)) {		togglemax(sel);		return;	}	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))		n++;	if((c = sel) == nexttiled(clients))		if(!(c = nexttiled(c->next)))			return;	detach(c);	if(clients)		clients->prev = c;	c->next = clients;	clients = c;	focus(c);	arrange();}
 |