X-Git-Url: https://git.xinqibao.xyz/dwm.git/blobdiff_plain/cb4aa5bc35cf16a06bb2b4e880648e390fa2cc55..d108cfa7fc47000af49e70a49e865b9eb236c57d:/view.c

diff --git a/view.c b/view.c
index b3b412d..4513a45 100644
--- a/view.c
+++ b/view.c
@@ -1,7 +1,8 @@
-/* (C)opyright MMVII Anselm R. Garbe <garbeam at gmail dot com>
+/* (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 */
 
@@ -69,12 +70,21 @@ dofloat(void) {
 
 void
 dotile(void) {
-	unsigned int i, n, mpw, th;
+	unsigned int i, n, mw, mh, tw, th;
 	Client *c;
 
 	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
 		n++;
-	mpw = (waw * master) / 1000;
+
+	/* window geoms */
+	if(nmaster > 0) {
+		mh = (n > nmaster) ?  wah / nmaster : wah / (n > 0 ? n : 1);
+		mw = (n > nmaster) ? (waw * master) / 1000 : waw;
+	}
+	else
+		mh = mw = 0;
+	th = (n > nmaster) ? wah / (n - nmaster) : 0;
+	tw = waw - mw;
 
 	for(i = 0, c = clients; c; c = c->next)
 		if(isvisible(c)) {
@@ -85,20 +95,16 @@ dotile(void) {
 			c->ismax = False;
 			c->x = wax;
 			c->y = way;
-			if(n == 1) { /* only 1 window */
-				c->w = waw - 2 * BORDERPX;
-				c->h = wah - 2 * BORDERPX;
-			}
-			else if(i == 0) { /* master window */
-				c->w = mpw - 2 * BORDERPX;
-				c->h = wah - 2 * BORDERPX;
-				th = wah / (n - 1);
+			if((nmaster > 0) && (i < nmaster)) {
+				c->y += i * mh;
+				c->w = mw - 2 * BORDERPX;
+				c->h = mh - 2 * BORDERPX;
 			}
 			else {  /* tile window */
-				c->x += mpw;
-				c->w = (waw - mpw) - 2 * BORDERPX;
+				c->x += mw;
+				c->w = tw - 2 * BORDERPX;
 				if(th > bh) {
-					c->y += (i - 1) * th;
+					c->y += (i - nmaster) * th;
 					c->h = th - 2 * BORDERPX;
 				}
 				else /* fallback if th < bh */
@@ -147,6 +153,20 @@ focusprev(Arg *arg) {
 	}
 }
 
+void
+incnmaster(Arg *arg) {
+	if((arrange == dofloat)
+	|| ((int)nmaster + arg->i < 0)
+	|| (((int)nmaster + arg->i > 0) && (wah / (nmaster + arg->i) < bh)))
+		return;
+	nmaster += arg->i;
+	updatemodetext();
+	if(sel)
+		arrange();
+	else
+		drawstatus();
+}
+
 Bool
 isvisible(Client *c) {
 	unsigned int i;
@@ -210,6 +230,7 @@ togglefloat(Arg *arg) {
 void
 togglemode(Arg *arg) {
 	arrange = (arrange == dofloat) ? dotile : dofloat;
+	updatemodetext();
 	if(sel)
 		arrange();
 	else
@@ -227,6 +248,12 @@ toggleview(Arg *arg) {
 	arrange();
 }
 
+void
+updatemodetext() {
+	snprintf(mtext, sizeof mtext, arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, nmaster);
+	bmw = textw(mtext);
+}
+
 void
 view(Arg *arg) {
 	unsigned int i;
@@ -249,11 +276,9 @@ zoom(Arg *arg) {
 		togglemax(sel);
 		return;
 	}
-	for(n = 0, c = clients; c; c = c->next)
-		if(isvisible(c) && !c->isfloat)
-			n++;
-	if(n < 2 || (arrange == dofloat))
-		return;
+	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
+		n++;
+
 	if((c = sel) == nexttiled(clients))
 		if(!(c = nexttiled(c->next)))
 			return;