applied Ph's MIN/MAX patch, nice work! 874837f6
anselm@anselm1 · 2008-04-20 18:28 1 file(s) · +22 −31
dwm.c +22 −31
41 41
#include <X11/Xutil.h>
42 42
43 43
/* macros */
44 +
#define MAX(a, b) ((a)>(b)?(a):(b))
45 +
#define MIN(a, b) ((a)<(b)?(a):(b))
44 46
#define BUTTONMASK		(ButtonPressMask|ButtonReleaseMask)
45 47
#define CLEANMASK(mask)		(mask & ~(numlockmask|LockMask))
46 48
#define LENGTH(x)		(sizeof x / sizeof x[0])
601 603
	if(!text)
602 604
		return;
603 605
	w = 0;
604 -
	olen = len = strlen(text);
605 -
	if(len >= sizeof buf)
606 -
		len = sizeof buf - 1;
606 +
	olen = strlen(text);
607 +
	len = MIN(olen, sizeof buf - 1);
607 608
	memcpy(buf, text, len);
608 609
	buf[len] = 0;
609 610
	h = dc.font.ascent + dc.font.descent;
880 881
		font_extents = XExtentsOfFontSet(dc.font.set);
881 882
		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
882 883
		for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
883 -
			if(dc.font.ascent < (*xfonts)->ascent)
884 -
				dc.font.ascent = (*xfonts)->ascent;
885 -
			if(dc.font.descent < (*xfonts)->descent)
886 -
				dc.font.descent = (*xfonts)->descent;
884 +
			dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
885 +
			dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
887 886
			xfonts++;
888 887
		}
889 888
	}
1008 1007
			c->x = wx + ww - c->w - 2 * c->bw;
1009 1008
		if(c->y + c->h + 2 * c->bw > wy + wh)
1010 1009
			c->y = wy + wh - c->h - 2 * c->bw;
1011 -
		if(c->x < wx)
1012 -
			c->x = wx;
1013 -
		if(c->y < wy)
1014 -
			c->y = wy;
1010 +
		c->x = MAX(c->x, wx);
1011 +
		c->y = MAX(c->y, wy);
1015 1012
		c->bw = BORDERPX;
1016 1013
	}
1017 1014
1177 1174
1178 1175
	if(sizehints) {
1179 1176
		/* set minimum possible */
1180 -
		if(w < 1)
1181 -
			w = 1;
1182 -
		if(h < 1)
1183 -
			h = 1;
1177 +
		w = MAX(1, w);
1178 +
		h = MAX(1, h);
1184 1179
1185 1180
		/* temporarily remove base dimensions */
1186 1181
		w -= c->basew;
1206 1201
		w += c->basew;
1207 1202
		h += c->baseh;
1208 1203
1209 -
		if(c->minw > 0 && w < c->minw)
1210 -
			w = c->minw;
1211 -
		if(c->minh > 0 && h < c->minh)
1212 -
			h = c->minh;
1213 -
		if(c->maxw > 0 && w > c->maxw)
1214 -
			w = c->maxw;
1215 -
		if(c->maxh > 0 && h > c->maxh)
1216 -
			h = c->maxh;
1204 +
		w = MAX(w, c->minw);
1205 +
		h = MAX(h, c->minh);
1206 +
		
1207 +
		if (c->maxw)
1208 +
			w = MIN(w, c->maxw);
1209 +
1210 +
		if (c->maxh)
1211 +
			h = MIN(h, c->maxh);
1217 1212
	}
1218 1213
	if(w <= 0 || h <= 0)
1219 1214
		return;
1266 1261
			break;
1267 1262
		case MotionNotify:
1268 1263
			XSync(dpy, False);
1269 -
			if((nw = ev.xmotion.x - ocx - 2 * c->bw + 1) <= 0)
1270 -
				nw = 1;
1271 -
			if((nh = ev.xmotion.y - ocy - 2 * c->bw + 1) <= 0)
1272 -
				nh = 1;
1264 +
			nw = MAX(ev.xmotion.x - ocx - 2 * c->bw + 1, 1);
1265 +
			nh = MAX(ev.xmotion.y - ocy - 2 * c->bw + 1, 1);
1273 1266
			if(!c->isfloating && !lt->isfloating && (abs(nw - c->w) > SNAP || abs(nh - c->h) > SNAP))
1274 1267
				togglefloating(NULL);
1275 1268
			if((lt->isfloating) || c->isfloating)
1520 1513
	/* init bar */
1521 1514
	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
1522 1515
		w = textw(layouts[i].symbol);
1523 -
		if(w > blw)
1524 -
			blw = w;
1516 +
		blw = MAX(blw, w);
1525 1517
	}
1526 1518
	for(bgw = i = 0; LENGTH(geoms) > 1 && i < LENGTH(geoms); i++) {
1527 1519
		w = textw(geoms[i].symbol);
1528 -
		if(w > bgw)
1529 -
			bgw = w;
1520 +
		bgw = MAX(bgw, w);
1530 1521
	}
1531 1522
1532 1523
	wa.override_redirect = 1;