some cleanup, removed ntags variable, defined NTAGS macro, simplified tag(), view() and idxoftag(), fixed some NULL comparisions 29f2b15d
arg@suckless.org · 2007-10-24 16:07 1 file(s) · +20 −27
dwm.c +20 −27
232 232
/* configuration, allows nested code to access above variables */
233 233
#include "config.h"
234 234
235 -
/* statically define the number of tags. */
236 -
unsigned int ntags = sizeof tags / sizeof tags[0];
237 -
Bool seltags[sizeof tags / sizeof tags[0]] = {[0] = True};
238 -
Bool prevtags[sizeof tags / sizeof tags[0]] = {[0] = True};
235 +
#define NTAGS (sizeof tags / sizeof tags[0])
236 +
Bool seltags[NTAGS] = {[0] = True};
237 +
Bool prevtags[NTAGS] = {[0] = True};
239 238
240 239
/* function implementations */
241 240
void
254 253
	for(i = 0; i < nrules; i++)
255 254
		if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) {
256 255
			c->isfloating = rules[i].isfloating;
257 -
			for(j = 0; regs[i].tagregex && j < ntags; j++) {
256 +
			for(j = 0; regs[i].tagregex && j < NTAGS; j++) {
258 257
				if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
259 258
					matched = True;
260 259
					c->tags[j] = True;
313 312
314 313
	if(barwin == ev->window) {
315 314
		x = 0;
316 -
		for(i = 0; i < ntags; i++) {
315 +
		for(i = 0; i < NTAGS; i++) {
317 316
			x += textw(tags[i]);
318 317
			if(ev->x < x) {
319 318
				if(ev->button == Button1) {
537 536
	int i, x;
538 537
539 538
	dc.x = dc.y = 0;
540 -
	for(i = 0; i < ntags; i++) {
539 +
	for(i = 0; i < NTAGS; i++) {
541 540
		dc.w = textw(tags[i]);
542 541
		if(seltags[i]) {
543 542
			drawtext(tags[i], dc.sel);
847 846
idxoftag(const char *tag) {
848 847
	unsigned int i;
849 848
850 -
	for(i = 0; i < ntags; i++)
851 -
		if(tags[i] == tag)
852 -
			return i;
853 -
	return 0;
849 +
	for(i = 0; (i < NTAGS) && (tags[i] != tag); i++);
850 +
	return (i < NTAGS) ? i : 0;
854 851
}
855 852
856 853
void
930 927
isvisible(Client *c) {
931 928
	unsigned int i;
932 929
933 -
	for(i = 0; i < ntags; i++)
930 +
	for(i = 0; i < NTAGS; i++)
934 931
		if(c->tags[i] && seltags[i])
935 932
			return True;
936 933
	return False;
1140 1137
			default: break;
1141 1138
			case XA_WM_TRANSIENT_FOR:
1142 1139
				XGetTransientForHint(dpy, c->win, &trans);
1143 -
				if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
1140 +
				if(!c->isfloating && (c->isfloating = (NULL != getclient(trans))))
1144 1141
					arrange();
1145 1142
				break;
1146 1143
			case XA_WM_NORMAL_HINTS:
1542 1539
1543 1540
	if(!sel)
1544 1541
		return;
1545 -
	for(i = 0; i < ntags; i++)
1546 -
		sel->tags[i] = arg == NULL;
1547 -
	i = idxoftag(arg);
1548 -
	if(i >= 0 && i < ntags)
1549 -
		sel->tags[i] = True;
1542 +
	for(i = 0; i < NTAGS; i++)
1543 +
		sel->tags[i] = (NULL == arg);
1544 +
	sel->tags[idxoftag(arg)] = True;
1550 1545
	arrange();
1551 1546
}
1552 1547
1662 1657
		return;
1663 1658
	i = idxoftag(arg);
1664 1659
	sel->tags[i] = !sel->tags[i];
1665 -
	for(j = 0; j < ntags && !sel->tags[j]; j++);
1666 -
	if(j == ntags)
1667 -
		sel->tags[i] = True;
1660 +
	for(j = 0; j < NTAGS && !sel->tags[j]; j++);
1661 +
	if(j == NTAGS)
1662 +
		sel->tags[i] = True; /* at least one tag must be enabled */
1668 1663
	arrange();
1669 1664
}
1670 1665
1674 1669
1675 1670
	i = idxoftag(arg);
1676 1671
	seltags[i] = !seltags[i];
1677 -
	for(j = 0; j < ntags && !seltags[j]; j++);
1678 -
	if(j == ntags)
1672 +
	for(j = 0; j < NTAGS && !seltags[j]; j++);
1673 +
	if(j == NTAGS)
1679 1674
		seltags[i] = True; /* at least one tag must be viewed */
1680 1675
	arrange();
1681 1676
}
1841 1836
	unsigned int i;
1842 1837
1843 1838
	memcpy(prevtags, seltags, sizeof seltags);
1844 -
	for(i = 0; i < ntags; i++)
1839 +
	for(i = 0; i < NTAGS; i++)
1845 1840
		seltags[i] = arg == NULL;
1846 -
	i = idxoftag(arg);
1847 -
	if(i >= 0 && i < ntags)
1848 -
		seltags[i] = True;
1841 +
	seltags[idxoftag(arg)] = True;
1849 1842
	arrange();
1850 1843
}
1851 1844