about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authoranselm@anselm1 <unknown>2008-04-20 18:28:21 +0100
committeranselm@anselm1 <unknown>2008-04-20 18:28:21 +0100
commit874837f653433315bd2733823a0a1efe6f76b373 (patch)
treee36c41a1222e1e4c8d0b32106486c26df6fc984e
parent5fa559dbfc6238a911c210ae4124586c6886df23 (diff)
downloaddwm-874837f653433315bd2733823a0a1efe6f76b373.tar.gz
applied Ph's MIN/MAX patch, nice work!
-rw-r--r--dwm.c53
1 files changed, 22 insertions, 31 deletions
diff --git a/dwm.c b/dwm.c
index c174994..7f2a638 100644
--- a/dwm.c
+++ b/dwm.c
@@ -41,6 +41,8 @@
 #include <X11/Xutil.h>
 
 /* macros */
+#define MAX(a, b) ((a)>(b)?(a):(b))
+#define MIN(a, b) ((a)<(b)?(a):(b))
 #define BUTTONMASK		(ButtonPressMask|ButtonReleaseMask)
 #define CLEANMASK(mask)		(mask & ~(numlockmask|LockMask))
 #define LENGTH(x)		(sizeof x / sizeof x[0])
@@ -601,9 +603,8 @@ drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
 	if(!text)
 		return;
 	w = 0;
-	olen = len = strlen(text);
-	if(len >= sizeof buf)
-		len = sizeof buf - 1;
+	olen = strlen(text);
+	len = MIN(olen, sizeof buf - 1);
 	memcpy(buf, text, len);
 	buf[len] = 0;
 	h = dc.font.ascent + dc.font.descent;
@@ -880,10 +881,8 @@ initfont(const char *fontstr) {
 		font_extents = XExtentsOfFontSet(dc.font.set);
 		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
 		for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
-			if(dc.font.ascent < (*xfonts)->ascent)
-				dc.font.ascent = (*xfonts)->ascent;
-			if(dc.font.descent < (*xfonts)->descent)
-				dc.font.descent = (*xfonts)->descent;
+			dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
+			dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
 			xfonts++;
 		}
 	}
@@ -1008,10 +1007,8 @@ manage(Window w, XWindowAttributes *wa) {
 			c->x = wx + ww - c->w - 2 * c->bw;
 		if(c->y + c->h + 2 * c->bw > wy + wh)
 			c->y = wy + wh - c->h - 2 * c->bw;
-		if(c->x < wx)
-			c->x = wx;
-		if(c->y < wy)
-			c->y = wy;
+		c->x = MAX(c->x, wx);
+		c->y = MAX(c->y, wy);
 		c->bw = BORDERPX;
 	}
 
@@ -1177,10 +1174,8 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
 
 	if(sizehints) {
 		/* set minimum possible */
-		if(w < 1)
-			w = 1;
-		if(h < 1)
-			h = 1;
+		w = MAX(1, w);
+		h = MAX(1, h);
 
 		/* temporarily remove base dimensions */
 		w -= c->basew;
@@ -1206,14 +1201,14 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
 		w += c->basew;
 		h += c->baseh;
 
-		if(c->minw > 0 && w < c->minw)
-			w = c->minw;
-		if(c->minh > 0 && h < c->minh)
-			h = c->minh;
-		if(c->maxw > 0 && w > c->maxw)
-			w = c->maxw;
-		if(c->maxh > 0 && h > c->maxh)
-			h = c->maxh;
+		w = MAX(w, c->minw);
+		h = MAX(h, c->minh);
+		
+		if (c->maxw)
+			w = MIN(w, c->maxw);
+
+		if (c->maxh)
+			h = MIN(h, c->maxh);
 	}
 	if(w <= 0 || h <= 0)
 		return;
@@ -1266,10 +1261,8 @@ resizemouse(Client *c) {
 			break;
 		case MotionNotify:
 			XSync(dpy, False);
-			if((nw = ev.xmotion.x - ocx - 2 * c->bw + 1) <= 0)
-				nw = 1;
-			if((nh = ev.xmotion.y - ocy - 2 * c->bw + 1) <= 0)
-				nh = 1;
+			nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
+			nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
 			if(!c->isfloating && !lt->isfloating && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP))
 				togglefloating(NULL);
 			if((lt->isfloating) || c->isfloating)
@@ -1520,13 +1513,11 @@ setup(void) {
 	/* init bar */
 	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
 		w = textw(layouts[i].symbol);
-		if(w > blw)
-			blw = w;
+		blw = MAX(blw, w);
 	}
 	for(bgw = i = 0; LENGTH(geoms) > 1 && i < LENGTH(geoms); i++) {
 		w = textw(geoms[i].symbol);
-		if(w > bgw)
-			bgw = w;
+		bgw = MAX(bgw, w);
 	}
 
 	wa.override_redirect = 1;
Anselm R.Garbe <arg@10ksloc.org> 2006-08-11 19:26:12 +0200 implemented viewextend and added M-S-C-n shortcuts for extending the current view... updated man page (works great!) nice feature' href='/acidbong/suckless/dwm/commit/config.default.h?h=master&id=292ccc4c43d9529cb6db0973fcab6e24c73607a5'>292ccc4 ^
df74b26 ^


292ccc4 ^
10885d3 ^

8b4bc82 ^



39ffc18 ^
8b4bc82 ^



39ffc18 ^
df74b26 ^

bab575c ^
8b4bc82 ^



39ffc18 ^
8b4bc82 ^



39ffc18 ^
df74b26 ^
b515765 ^

d6a6eca ^
2dd5212 ^
b515765 ^

d6a6eca ^
e21d93b ^

b515765 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65