about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--dwm.c52
1 files changed, 15 insertions, 37 deletions
diff --git a/dwm.c b/dwm.c
index 0e4703e..2fe70e4 100644
--- a/dwm.c
+++ b/dwm.c
@@ -170,7 +170,6 @@ void spawn(const void *arg);
 void tag(const void *arg);
 uint textnw(const char *text, uint len);
 void tile(void);
-void tileresize(Client *c, int x, int y, int w, int h);
 void togglebar(const void *arg);
 void togglefloating(const void *arg);
 void togglelayout(const void *arg);
@@ -1123,6 +1122,10 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
 		x = sx;
 	if(y + h + 2 * c->bw < sy)
 		y = sy;
+	if(h < bh)
+		h = bh;
+	if(w < bh)
+		w = bh;
 	if(c->x != x || c->y != y || c->w != w || c->h != h || c->isbanned || c->ismax) {
 		c->isbanned = c->ismax = False;
 		c->x = wc.x = x;
@@ -1435,7 +1438,7 @@ textnw(const char *text, uint len) {
 
 void
 tile(void) {
-	int x, y, h, w, mx, my, mw, mh, tx, ty, tw, th;
+	int x, y, h, w, mw;
 	uint i, n;
 	Client *c;
 
@@ -1443,56 +1446,31 @@ tile(void) {
 	if(n == 0)
 		return;
 
-	/* master area geometry */
-	mx = wx;
-	my = wy;
-	mw = mfact * ww;
-	mh = wh;
-
-	/* tile area geometry */
-	tx = mx + mw;
-	ty = wy;
-	tw = ww - mw;
-	th = wh;
-
 	/* master */
 	c = nexttiled(clients);
-
-	if(n == 1)
-		tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw);
-	else
-		tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw);
+	mw = mfact * ww;
+	resize(c, wx, wy, ((n == 1) ? ww : mw) - 2 * c->bw, wh - 2 * c->bw, resizehints);
 
 	if(--n == 0)
 		return;
 
 	/* tile stack */
-	x = (tx > c->x + c->w) ? c->x + c->w + 2 * c->bw : tw;
-	y = ty;
-	w = (tx > c->x + c->w) ? wx + ww - x : tw;
-	h = th / n;
+	x = (wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : ww - mw;
+	y = wy;
+	w = (wx + mw > c->x + c->w) ? wx + ww - x : ww - mw;
+	h = wh / n;
 	if(h < bh)
-		h = th;
+		h = wh;
 
 	for(i = 0, c = nexttiled(c->next); c; c = nexttiled(c->next), i++) {
-		if(i + 1 == n) /* remainder */
-			tileresize(c, x, y, w - 2 * c->bw, (ty + th) - y - 2 * c->bw);
-		else
-			tileresize(c, x, y, w - 2 * c->bw, h - 2 * c->bw);
-		if(h != th)
+		resize(c, x, y, w - 2 * c->bw, /* remainder */ ((i + 1 == n)
+		       ? (wy + wh) - y : h) - 2 * c->bw, resizehints);
+		if(h != wh)
 			y = c->y + c->h + 2 * c->bw;
 	}
 }
 
 void
-tileresize(Client *c, int x, int y, int w, int h) {
-	resize(c, x, y, w, h, resizehints);
-	if(resizehints && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
-		/* client doesn't accept size constraints */
-		resize(c, x, y, w, h, False);
-}
-
-void
 togglebar(const void *arg) {
 	showbar = !showbar;
 	updategeom();
d2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
/* See LICENSE file for copyright and license details. */
int bx, by, bw, bh, blw, mx, my, mw, mh, tx, ty, tw, th, wx, wy, ww, wh;

void setmfact(const char *arg);
void tile(void);
void tileresize(Client *c, int x, int y, int w, int h);
void updatetilegeom(void);

void
setmfact(const char *arg) {
	double d;

	if(!arg || lt->arrange != tile)
		return;
	else {
		d = strtod(arg, NULL);
		if(arg[0] == '-' || arg[0] == '+')
			d += mfact;
		if(d < 0.1 || d > 0.9)
			return;
		mfact = d;
	}
	updatetilegeom();
	arrange();
}

void
tile(void) {
	int x, y, h, w;
	unsigned int i, n;
	Client *c;

	for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++);
	if(n == 0)
		return;

	/* master */
	c = nextunfloating(clients);

	if(n == 1)
		tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw);
	else
		tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw);

	if(--n == 0)
		return;

	/* tile stack */
	x = (tx > c->x + c->w) ? c->x + c->w + 2 * c->bw : tw;
	y = ty;
	w = (tx > c->x + c->w) ? wx + ww - x : tw;
	h = th / n;
	if(h < bh)
		h = th;

	for(i = 0, c = nextunfloating(c->next); c; c = nextunfloating(c->next), i++) {
		if(i + 1 == n) /* remainder */
			tileresize(c, x, y, w - 2 * c->bw, (ty + th) - y - 2 * c->bw);
		else
			tileresize(c, x, y, w - 2 * c->bw, h - 2 * c->bw);
		if(h != th)
			y = c->y + c->h + 2 * c->bw;
	}
}

void
tileresize(Client *c, int x, int y, int w, int h) {
	resize(c, x, y, w, h, resizehints);
	if(resizehints && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
		/* client doesn't accept size constraints */
		resize(c, x, y, w, h, False);
}

void
zoom(const char *arg) {
	Client *c = sel;

	if(c == nextunfloating(clients))
		if(!c || !(c = nextunfloating(c->next)))
			return;
	if(lt->arrange == tile && !sel->isfloating) {
		detach(c);
		attach(c);
		focus(c);
	}
	arrange();
}

void
updatetilegeom(void) {
	/* master area geometry */
	mx = wx;
	my = wy;
	mw = mfact * ww;
	mh = wh;

	/* tile area geometry */
	tx = mx + mw;
	ty = wy;
	tw = ww - mw;
	th = wh;
}