X-Git-Url: https://git.xinqibao.xyz/dwm.git/blobdiff_plain/46d5f9d1bfd8caaabaabfb7c7e5eac269aff4987..653826572d5dfe36fc567b2fdce7ef5d9ad0bfbc:/view.c

diff --git a/view.c b/view.c
index 21e7bbd..06aed3e 100644
--- a/view.c
+++ b/view.c
@@ -1,7 +1,8 @@
-/* (C)opyright MMVI 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,13 +70,16 @@ dofloat(void) {
 
 void
 dotile(void) {
-	unsigned int i, n, mpx, stackw, th;
+	unsigned int i, n, mw, mh, tw, th;
 	Client *c;
 
 	for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
 		n++;
-	mpx = (waw * master) / 1000;
-	stackw = waw - mpx;
+	/* window geoms */
+	mw = (n > nmaster) ? (waw * master) / 1000 : waw;
+	mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
+	tw = waw - mw;
+	th = (n > nmaster) ? wah / (n - nmaster) : 0;
 
 	for(i = 0, c = clients; c; c = c->next)
 		if(isvisible(c)) {
@@ -86,20 +90,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 = waw - stackw - 2 * BORDERPX;
-				c->h = wah - 2 * BORDERPX;
-				th = wah / (n - 1);
+			if(i < nmaster) {
+				c->y += i * mh;
+				c->w = mw - 2 * BORDERPX;
+				c->h = mh - 2 * BORDERPX;
 			}
 			else {  /* tile window */
-				c->x += mpx;
-				c->w = stackw - 2 * BORDERPX;
+				c->x += mw;
+				c->w = tw - 2 * BORDERPX;
 				if(th > bh) {
-					c->y = way + (i - 1) * th;
+					c->y += (i - nmaster) * th;
 					c->h = th - 2 * BORDERPX;
 				}
 				else /* fallback if th < bh */
@@ -148,6 +148,18 @@ focusprev(Arg *arg) {
 	}
 }
 
+void
+incnmaster(Arg *arg) {
+	if((arrange == dofloat) || (nmaster + arg->i < 1) || (wah / (nmaster + arg->i) < bh))
+		return;
+	nmaster += arg->i;
+	updatemodetext();
+	if(sel)
+		arrange();
+	else
+		drawstatus();
+}
+
 Bool
 isvisible(Client *c) {
 	unsigned int i;
@@ -202,7 +214,7 @@ restack(void) {
 
 void
 togglefloat(Arg *arg) {
-	if (!sel)
+	if (!sel || arrange == dofloat)
 		return;
 	sel->isfloat = !sel->isfloat;
 	arrange();
@@ -211,6 +223,7 @@ togglefloat(Arg *arg) {
 void
 togglemode(Arg *arg) {
 	arrange = (arrange == dofloat) ? dotile : dofloat;
+	updatemodetext();
 	if(sel)
 		arrange();
 	else
@@ -229,21 +242,19 @@ toggleview(Arg *arg) {
 }
 
 void
-view(Arg *arg) {
-	unsigned int i;
-
-	for(i = 0; i < ntags; i++)
-		seltag[i] = False;
-	seltag[arg->i] = True;
-	arrange();
+updatemodetext() {
+	snprintf(mtext, sizeof mtext, arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, nmaster);
+	bmw = textw(mtext);
 }
 
 void
-viewall(Arg *arg) {
+view(Arg *arg) {
 	unsigned int i;
 
 	for(i = 0; i < ntags; i++)
-		seltag[i] = True;
+		seltag[i] = (arg->i == -1) ? True : False;
+	if(arg->i >= 0 && arg->i < ntags)
+		seltag[arg->i] = True;
 	arrange();
 }
 
@@ -258,11 +269,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;