X-Git-Url: https://git.xinqibao.xyz/dwm.git/blobdiff_plain/5d9146ff372ae0c5196e290fb2c1f828d4137e20..9e56e1ded6889335035c8ffbe2763d3d83978673:/tile.c?ds=sidebyside

diff --git a/tile.c b/tile.c
index fe25943..e1c68f8 100644
--- a/tile.c
+++ b/tile.c
@@ -1,134 +1,79 @@
-/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
- * See LICENSE file for license details.
- */
+/* See LICENSE file for copyright and license details. */
 #include "dwm.h"
-
-unsigned int master = MASTER;
-unsigned int nmaster = NMASTER;
+#include <stdio.h>
 
 /* static */
 
-static void
-togglemax(Client *c) {
-	XEvent ev;
+static double mwfact = MWFACT;
+
+/* extern */
 
-	if(c->isfixed)
+void
+addtomwfact(const char *arg) {
+	double delta;
+
+	if(!isarrange(tile))
 		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);
+
+	/* arg handling, manipulate mwfact */
+	if(arg && (1 == sscanf(arg, "%lf", &delta))) {
+		if(delta + mwfact > 0.1 && delta + mwfact < 0.9)
+			mwfact += delta;
 	}
-	else
-		resize(c, c->rx, c->ry, c->rw, c->rh, True);
-	while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
+	arrange();
 }
 
-/* extern */
-
 void
-dotile(void) {
-	unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
+tile(void) {
+	unsigned int i, n, nx, ny, nw, nh, mw, th;
 	Client *c;
 
-	for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
+	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;
+	mw = (n == 1) ? waw : mwfact * waw;
+	th = (n > 1) ? wah / (n - 1) : 0;
+	if(n > 1 && th < bh)
+		th = wah;
 
-	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 = wax;
+	ny = way;
+	for(i = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) {
+		c->ismax = False;
+		if(i == 0) { /* master */
+			nw = mw - 2 * c->border;
+			nh = wah - 2 * c->border;
+		}
+		else {  /* tile window */
+			if(i == 1) {
+				ny = way;
 				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);
+			nw = waw - mw - 2 * c->border;
+			if(i + 1 == n) /* remainder */
+				nh = (way + wah) - ny - 2 * c->border;
+			else
+				nh = th - 2 * c->border;
 		}
-	if(!sel || !isvisible(sel)) {
-		for(c = stack; c && !isvisible(c); c = c->snext);
-		focus(c);
-	}
-	restack();
-}
-
-void
-incnmaster(Arg *arg) {
-	if((arrange == dofloat) || (nmaster + arg->i < 1)
-	|| (wah / (nmaster + arg->i) <= 2 * BORDERPX))
-		return;
-	nmaster += arg->i;
-	if(sel)
-		arrange();
-	else
-		drawstatus();
-}
-
-void
-resizemaster(Arg *arg) {
-	if(arrange != dotile)
-		return;
-	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;
+		resize(c, nx, ny, nw, nh, False);
+		if(n > 1 && th != wah)
+			ny += nh + 2 * c->border;
+		i++;
 	}
-	arrange();
 }
 
 void
-zoom(Arg *arg) {
-	unsigned int n;
+zoom(const char *arg) {
 	Client *c;
 
-	if(!sel)
-		return;
-	if(sel->isfloat || (arrange == dofloat)) {
-		togglemax(sel);
+	if(!sel || !isarrange(tile) || sel->isfloating)
 		return;
-	}
-	for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
-		n++;
-
-	if((c = sel) == nextmanaged(clients))
-		if(!(c = nextmanaged(c->next)))
+	if((c = sel) == nexttiled(clients))
+		if(!(c = nexttiled(c->next)))
 			return;
 	detach(c);
-	if(clients)
-		clients->prev = c;
-	c->next = clients;
-	clients = c;
+	attach(c);
 	focus(c);
 	arrange();
 }