summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarg@suckless.org <unknown>2007-10-24 16:07:43 +0200
committerarg@suckless.org <unknown>2007-10-24 16:07:43 +0200
commit29f2b15ddc3a1462780340a10738a98a5e9280eb (patch)
tree5507a634cd0d06f54213fcf499a895193a94580b
parentparenthized use of ISTILE macro in dwm.c (diff)
downloaddwm-29f2b15ddc3a1462780340a10738a98a5e9280eb.tar.gz
dwm-29f2b15ddc3a1462780340a10738a98a5e9280eb.zip
some cleanup, removed ntags variable, defined NTAGS macro, simplified tag(), view() and idxoftag(), fixed some NULL comparisions
Diffstat (limited to '')
-rw-r--r--dwm.c47
1 files changed, 20 insertions, 27 deletions
diff --git a/dwm.c b/dwm.c
index 67fa0a7..b8fc56a 100644
--- a/dwm.c
+++ b/dwm.c
@@ -232,10 +232,9 @@ Regs *regs = NULL;
232/* configuration, allows nested code to access above variables */ 232/* configuration, allows nested code to access above variables */
233#include "config.h" 233#include "config.h"
234 234
235/* statically define the number of tags. */ 235#define NTAGS (sizeof tags / sizeof tags[0])
236unsigned int ntags = sizeof tags / sizeof tags[0]; 236Bool seltags[NTAGS] = {[0] = True};
237Bool seltags[sizeof tags / sizeof tags[0]] = {[0] = True}; 237Bool prevtags[NTAGS] = {[0] = True};
238Bool prevtags[sizeof tags / sizeof tags[0]] = {[0] = True};
239 238
240/* function implementations */ 239/* function implementations */
241void 240void
@@ -254,7 +253,7 @@ applyrules(Client *c) {
254 for(i = 0; i < nrules; i++) 253 for(i = 0; i < nrules; i++)
255 if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) { 254 if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) {
256 c->isfloating = rules[i].isfloating; 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 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) { 257 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
259 matched = True; 258 matched = True;
260 c->tags[j] = True; 259 c->tags[j] = True;
@@ -313,7 +312,7 @@ buttonpress(XEvent *e) {
313 312
314 if(barwin == ev->window) { 313 if(barwin == ev->window) {
315 x = 0; 314 x = 0;
316 for(i = 0; i < ntags; i++) { 315 for(i = 0; i < NTAGS; i++) {
317 x += textw(tags[i]); 316 x += textw(tags[i]);
318 if(ev->x < x) { 317 if(ev->x < x) {
319 if(ev->button == Button1) { 318 if(ev->button == Button1) {
@@ -537,7 +536,7 @@ drawbar(void) {
537 int i, x; 536 int i, x;
538 537
539 dc.x = dc.y = 0; 538 dc.x = dc.y = 0;
540 for(i = 0; i < ntags; i++) { 539 for(i = 0; i < NTAGS; i++) {
541 dc.w = textw(tags[i]); 540 dc.w = textw(tags[i]);
542 if(seltags[i]) { 541 if(seltags[i]) {
543 drawtext(tags[i], dc.sel); 542 drawtext(tags[i], dc.sel);
@@ -847,10 +846,8 @@ unsigned int
847idxoftag(const char *tag) { 846idxoftag(const char *tag) {
848 unsigned int i; 847 unsigned int i;
849 848
850 for(i = 0; i < ntags; i++) 849 for(i = 0; (i < NTAGS) && (tags[i] != tag); i++);
851 if(tags[i] == tag) 850 return (i < NTAGS) ? i : 0;
852 return i;
853 return 0;
854} 851}
855 852
856void 853void
@@ -930,7 +927,7 @@ Bool
930isvisible(Client *c) { 927isvisible(Client *c) {
931 unsigned int i; 928 unsigned int i;
932 929
933 for(i = 0; i < ntags; i++) 930 for(i = 0; i < NTAGS; i++)
934 if(c->tags[i] && seltags[i]) 931 if(c->tags[i] && seltags[i])
935 return True; 932 return True;
936 return False; 933 return False;
@@ -1140,7 +1137,7 @@ propertynotify(XEvent *e) {
1140 default: break; 1137 default: break;
1141 case XA_WM_TRANSIENT_FOR: 1138 case XA_WM_TRANSIENT_FOR:
1142 XGetTransientForHint(dpy, c->win, &trans); 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 arrange(); 1141 arrange();
1145 break; 1142 break;
1146 case XA_WM_NORMAL_HINTS: 1143 case XA_WM_NORMAL_HINTS:
@@ -1542,11 +1539,9 @@ tag(const char *arg) {
1542 1539
1543 if(!sel) 1540 if(!sel)
1544 return; 1541 return;
1545 for(i = 0; i < ntags; i++) 1542 for(i = 0; i < NTAGS; i++)
1546 sel->tags[i] = arg == NULL; 1543 sel->tags[i] = (NULL == arg);
1547 i = idxoftag(arg); 1544 sel->tags[idxoftag(arg)] = True;
1548 if(i >= 0 && i < ntags)
1549 sel->tags[i] = True;
1550 arrange(); 1545 arrange();
1551} 1546}
1552 1547
@@ -1662,9 +1657,9 @@ toggletag(const char *arg) {
1662 return; 1657 return;
1663 i = idxoftag(arg); 1658 i = idxoftag(arg);
1664 sel->tags[i] = !sel->tags[i]; 1659 sel->tags[i] = !sel->tags[i];
1665 for(j = 0; j < ntags && !sel->tags[j]; j++); 1660 for(j = 0; j < NTAGS && !sel->tags[j]; j++);
1666 if(j == ntags) 1661 if(j == NTAGS)
1667 sel->tags[i] = True; 1662 sel->tags[i] = True; /* at least one tag must be enabled */
1668 arrange(); 1663 arrange();
1669} 1664}
1670 1665
@@ -1674,8 +1669,8 @@ toggleview(const char *arg) {
1674 1669
1675 i = idxoftag(arg); 1670 i = idxoftag(arg);
1676 seltags[i] = !seltags[i]; 1671 seltags[i] = !seltags[i];
1677 for(j = 0; j < ntags && !seltags[j]; j++); 1672 for(j = 0; j < NTAGS && !seltags[j]; j++);
1678 if(j == ntags) 1673 if(j == NTAGS)
1679 seltags[i] = True; /* at least one tag must be viewed */ 1674 seltags[i] = True; /* at least one tag must be viewed */
1680 arrange(); 1675 arrange();
1681} 1676}
@@ -1841,11 +1836,9 @@ view(const char *arg) {
1841 unsigned int i; 1836 unsigned int i;
1842 1837
1843 memcpy(prevtags, seltags, sizeof seltags); 1838 memcpy(prevtags, seltags, sizeof seltags);
1844 for(i = 0; i < ntags; i++) 1839 for(i = 0; i < NTAGS; i++)
1845 seltags[i] = arg == NULL; 1840 seltags[i] = arg == NULL;
1846 i = idxoftag(arg); 1841 seltags[idxoftag(arg)] = True;
1847 if(i >= 0 && i < ntags)
1848 seltags[i] = True;
1849 arrange(); 1842 arrange();
1850} 1843}
1851 1844