summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarg@10ksloc.org <unknown>2006-08-03 12:12:26 +0200
committerarg@10ksloc.org <unknown>2006-08-03 12:12:26 +0200
commitb35575574be53a1b3be42d7037d2f432a19a3890 (patch)
tree6be2344c68ec6590fa816bbd578e0f36fe21c0b8
parenthotfix of settags (diff)
downloaddwm-b35575574be53a1b3be42d7037d2f432a19a3890.tar.gz
dwm-b35575574be53a1b3be42d7037d2f432a19a3890.zip
removed TLast tag enum, now tags is simple defined as char *[] array, the rest is calculated correctly, rules take an int array for the tags
-rw-r--r--client.c4
-rw-r--r--config.arg.h52
-rw-r--r--config.default.h48
-rw-r--r--draw.c4
-rw-r--r--dwm.h5
-rw-r--r--event.c2
-rw-r--r--main.c3
-rw-r--r--tag.c19
8 files changed, 66 insertions, 71 deletions
diff --git a/client.c b/client.c
index f4ed1a0..91d031e 100644
--- a/client.c
+++ b/client.c
@@ -16,7 +16,7 @@ resizetitle(Client *c)
16 int i; 16 int i;
17 17
18 c->tw = 0; 18 c->tw = 0;
19 for(i = 0; i < TLast; i++) 19 for(i = 0; i < ntags; i++)
20 if(c->tags[i]) 20 if(c->tags[i])
21 c->tw += textw(tags[i]); 21 c->tw += textw(tags[i]);
22 c->tw += textw(c->name); 22 c->tw += textw(c->name);
@@ -211,6 +211,7 @@ manage(Window w, XWindowAttributes *wa)
211 XSetWindowAttributes twa; 211 XSetWindowAttributes twa;
212 212
213 c = emallocz(sizeof(Client)); 213 c = emallocz(sizeof(Client));
214 c->tags = emallocz(ntags * sizeof(Bool));
214 c->win = w; 215 c->win = w;
215 c->x = c->tx = wa->x; 216 c->x = c->tx = wa->x;
216 c->y = c->ty = wa->y; 217 c->y = c->ty = wa->y;
@@ -429,6 +430,7 @@ unmanage(Client *c)
429 if(!sel) 430 if(!sel)
430 sel = clients; 431 sel = clients;
431 } 432 }
433 free(c->tags);
432 free(c); 434 free(c);
433 435
434 XSync(dpy, False); 436 XSync(dpy, False);
diff --git a/config.arg.h b/config.arg.h
index a3d312c..00a1d13 100644
--- a/config.arg.h
+++ b/config.arg.h
@@ -3,18 +3,11 @@
3 * See LICENSE file for license details. 3 * See LICENSE file for license details.
4 */ 4 */
5 5
6enum { Tfnord, Tdev, Tnet, Twork, Tmisc, TLast };
7#define TAGS \ 6#define TAGS \
8const char *tags[TLast] = { \ 7const char *tags[] = { "fnord", "dev", "net", "work", "misc", NULL };
9 [Tfnord] = "fnord", \
10 [Tdev] = "dev", \
11 [Tnet] = "net", \
12 [Twork] = "work", \
13 [Tmisc] = "misc", \
14};
15 8
16#define DEFMODE dotile /* dofloat */ 9#define DEFMODE dotile /* dofloat */
17#define DEFTAG Tdev 10#define DEFTAG 1 /* index */
18#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*" 11#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
19#define BGCOLOR "#0a2c2d" 12#define BGCOLOR "#0a2c2d"
20#define FGCOLOR "#ddeeee" 13#define FGCOLOR "#ddeeee"
@@ -33,11 +26,11 @@ const char *tags[TLast] = { \
33 const char *xlock[] = { "xlock", NULL }; \ 26 const char *xlock[] = { "xlock", NULL }; \
34static Key key[] = { \ 27static Key key[] = { \
35 /* modifier key function arguments */ \ 28 /* modifier key function arguments */ \
36 { MODKEY, XK_0, view, { .i = Tfnord } }, \ 29 { MODKEY, XK_0, view, { .i = 0 } }, \
37 { MODKEY, XK_1, view, { .i = Tdev } }, \ 30 { MODKEY, XK_1, view, { .i = 1 } }, \
38 { MODKEY, XK_2, view, { .i = Tnet } }, \ 31 { MODKEY, XK_2, view, { .i = 2 } }, \
39 { MODKEY, XK_3, view, { .i = Twork } }, \ 32 { MODKEY, XK_3, view, { .i = 3 } }, \
40 { MODKEY, XK_4, view, { .i = Tmisc} }, \ 33 { MODKEY, XK_4, view, { .i = 4 } }, \
41 { MODKEY, XK_h, viewprev, { 0 } }, \ 34 { MODKEY, XK_h, viewprev, { 0 } }, \
42 { MODKEY, XK_j, focusnext, { 0 } }, \ 35 { MODKEY, XK_j, focusnext, { 0 } }, \
43 { MODKEY, XK_k, focusprev, { 0 } }, \ 36 { MODKEY, XK_k, focusprev, { 0 } }, \
@@ -45,16 +38,16 @@ static Key key[] = { \
45 { MODKEY, XK_m, togglemax, { 0 } }, \ 38 { MODKEY, XK_m, togglemax, { 0 } }, \
46 { MODKEY, XK_space, togglemode, { 0 } }, \ 39 { MODKEY, XK_space, togglemode, { 0 } }, \
47 { MODKEY, XK_Return, zoom, { 0 } }, \ 40 { MODKEY, XK_Return, zoom, { 0 } }, \
48 { MODKEY|ControlMask, XK_0, appendtag, { .i = Tfnord } }, \ 41 { MODKEY|ControlMask, XK_0, appendtag, { .i = 0 } }, \
49 { MODKEY|ControlMask, XK_1, appendtag, { .i = Tdev } }, \ 42 { MODKEY|ControlMask, XK_1, appendtag, { .i = 1 } }, \
50 { MODKEY|ControlMask, XK_2, appendtag, { .i = Tnet } }, \ 43 { MODKEY|ControlMask, XK_2, appendtag, { .i = 2 } }, \
51 { MODKEY|ControlMask, XK_3, appendtag, { .i = Twork } }, \ 44 { MODKEY|ControlMask, XK_3, appendtag, { .i = 3 } }, \
52 { MODKEY|ControlMask, XK_4, appendtag, { .i = Tmisc } }, \ 45 { MODKEY|ControlMask, XK_4, appendtag, { .i = 4 } }, \
53 { MODKEY|ShiftMask, XK_0, replacetag, { .i = Tfnord } }, \ 46 { MODKEY|ShiftMask, XK_0, replacetag, { .i = 0 } }, \
54 { MODKEY|ShiftMask, XK_1, replacetag, { .i = Tdev } }, \ 47 { MODKEY|ShiftMask, XK_1, replacetag, { .i = 1 } }, \
55 { MODKEY|ShiftMask, XK_2, replacetag, { .i = Tnet } }, \ 48 { MODKEY|ShiftMask, XK_2, replacetag, { .i = 2 } }, \
56 { MODKEY|ShiftMask, XK_3, replacetag, { .i = Twork } }, \ 49 { MODKEY|ShiftMask, XK_3, replacetag, { .i = 3 } }, \
57 { MODKEY|ShiftMask, XK_4, replacetag, { .i = Tmisc } }, \ 50 { MODKEY|ShiftMask, XK_4, replacetag, { .i = 5 } }, \
58 { MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \ 51 { MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \
59 { MODKEY|ShiftMask, XK_q, quit, { 0 } }, \ 52 { MODKEY|ShiftMask, XK_q, quit, { 0 } }, \
60 { MODKEY|ShiftMask, XK_Return, spawn, { .argv = term } }, \ 53 { MODKEY|ShiftMask, XK_Return, spawn, { .argv = term } }, \
@@ -64,10 +57,11 @@ static Key key[] = { \
64}; 57};
65 58
66#define RULES \ 59#define RULES \
60 const unsigned int firefox[] = { 2 }; \
67static Rule rule[] = { \ 61static Rule rule[] = { \
68 /* class:instance tags isfloat */ \ 62 /* class:instance tags isfloat */ \
69 { "Firefox.*", { [Tnet] = True }, False }, \ 63 { "Firefox.*", firefox, False }, \
70 { "Gimp.*", { 0 }, True}, \ 64 { "Gimp.*", NULL, True}, \
71 { "MPlayer.*", { 0 }, True}, \ 65 { "MPlayer.*", NULL, True}, \
72 { "Acroread.*", { 0 }, True}, \ 66 { "Acroread.*", NULL, True}, \
73}; 67};
diff --git a/config.default.h b/config.default.h
index ec1804f..ce3773e 100644
--- a/config.default.h
+++ b/config.default.h
@@ -3,18 +3,11 @@
3 * See LICENSE file for license details. 3 * See LICENSE file for license details.
4 */ 4 */
5 5
6enum { Tfnord, Tdev, Tnet, Twork, Tmisc, TLast };
7#define TAGS \ 6#define TAGS \
8const char *tags[TLast] = { \ 7const char *tags[] = { "0", "1", "2", "3", "4", NULL };
9 [Tfnord] = "fnord", \
10 [Tdev] = "dev", \
11 [Tnet] = "net", \
12 [Twork] = "work", \
13 [Tmisc] = "misc", \
14};
15 8
16#define DEFMODE dotile /* dofloat */ 9#define DEFMODE dotile /* dofloat */
17#define DEFTAG Tdev 10#define DEFTAG 1 /* index */
18#define FONT "fixed" 11#define FONT "fixed"
19#define BGCOLOR "#666699" 12#define BGCOLOR "#666699"
20#define FGCOLOR "#eeeeee" 13#define FGCOLOR "#eeeeee"
@@ -27,11 +20,11 @@ const char *tags[TLast] = { \
27 const char *term[] = { "xterm", NULL }; \ 20 const char *term[] = { "xterm", NULL }; \
28static Key key[] = { \ 21static Key key[] = { \
29 /* modifier key function arguments */ \ 22 /* modifier key function arguments */ \
30 { MODKEY, XK_0, view, { .i = Tfnord } }, \ 23 { MODKEY, XK_0, view, { .i = 0 } }, \
31 { MODKEY, XK_1, view, { .i = Tdev } }, \ 24 { MODKEY, XK_1, view, { .i = 1 } }, \
32 { MODKEY, XK_2, view, { .i = Tnet } }, \ 25 { MODKEY, XK_2, view, { .i = 2 } }, \
33 { MODKEY, XK_3, view, { .i = Twork } }, \ 26 { MODKEY, XK_3, view, { .i = 3 } }, \
34 { MODKEY, XK_4, view, { .i = Tmisc} }, \ 27 { MODKEY, XK_4, view, { .i = 4 } }, \
35 { MODKEY, XK_h, viewprev, { 0 } }, \ 28 { MODKEY, XK_h, viewprev, { 0 } }, \
36 { MODKEY, XK_j, focusnext, { 0 } }, \ 29 { MODKEY, XK_j, focusnext, { 0 } }, \
37 { MODKEY, XK_k, focusprev, { 0 } }, \ 30 { MODKEY, XK_k, focusprev, { 0 } }, \
@@ -39,24 +32,25 @@ static Key key[] = { \
39 { MODKEY, XK_m, togglemax, { 0 } }, \ 32 { MODKEY, XK_m, togglemax, { 0 } }, \
40 { MODKEY, XK_space, togglemode, { 0 } }, \ 33 { MODKEY, XK_space, togglemode, { 0 } }, \
41 { MODKEY, XK_Return, zoom, { 0 } }, \ 34 { MODKEY, XK_Return, zoom, { 0 } }, \
42 { MODKEY|ControlMask, XK_0, appendtag, { .i = Tfnord } }, \ 35 { MODKEY|ControlMask, XK_0, appendtag, { .i = 0 } }, \
43 { MODKEY|ControlMask, XK_1, appendtag, { .i = Tdev } }, \ 36 { MODKEY|ControlMask, XK_1, appendtag, { .i = 1 } }, \
44 { MODKEY|ControlMask, XK_2, appendtag, { .i = Tnet } }, \ 37 { MODKEY|ControlMask, XK_2, appendtag, { .i = 2 } }, \
45 { MODKEY|ControlMask, XK_3, appendtag, { .i = Twork } }, \ 38 { MODKEY|ControlMask, XK_3, appendtag, { .i = 3 } }, \
46 { MODKEY|ControlMask, XK_4, appendtag, { .i = Tmisc } }, \ 39 { MODKEY|ControlMask, XK_4, appendtag, { .i = 4 } }, \
47 { MODKEY|ShiftMask, XK_0, replacetag, { .i = Tfnord } }, \ 40 { MODKEY|ShiftMask, XK_0, replacetag, { .i = 0 } }, \
48 { MODKEY|ShiftMask, XK_1, replacetag, { .i = Tdev } }, \ 41 { MODKEY|ShiftMask, XK_1, replacetag, { .i = 1 } }, \
49 { MODKEY|ShiftMask, XK_2, replacetag, { .i = Tnet } }, \ 42 { MODKEY|ShiftMask, XK_2, replacetag, { .i = 2 } }, \
50 { MODKEY|ShiftMask, XK_3, replacetag, { .i = Twork } }, \ 43 { MODKEY|ShiftMask, XK_3, replacetag, { .i = 3 } }, \
51 { MODKEY|ShiftMask, XK_4, replacetag, { .i = Tmisc } }, \ 44 { MODKEY|ShiftMask, XK_4, replacetag, { .i = 4 } }, \
52 { MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \ 45 { MODKEY|ShiftMask, XK_c, killclient, { 0 } }, \
53 { MODKEY|ShiftMask, XK_q, quit, { 0 } }, \ 46 { MODKEY|ShiftMask, XK_q, quit, { 0 } }, \
54 { MODKEY|ShiftMask, XK_Return, spawn, { .argv = term } }, \ 47 { MODKEY|ShiftMask, XK_Return, spawn, { .argv = term } }, \
55}; 48};
56 49
57#define RULES \ 50#define RULES \
51 const unsigned int firefox[] = { 2 }; \
58static Rule rule[] = { \ 52static Rule rule[] = { \
59 /* class:instance tags isfloat */ \ 53 /* class:instance tags isfloat */ \
60 { "Firefox.*", { [Tnet] = True }, False }, \ 54 { "Firefox.*", firefox, False }, \
61 { "Gimp.*", { 0 }, True}, \ 55 { "Gimp.*", NULL, True}, \
62}; 56};
diff --git a/draw.c b/draw.c
index 506a862..dffb490 100644
--- a/draw.c
+++ b/draw.c
@@ -114,7 +114,7 @@ drawstatus()
114 drawtext(NULL, !istile, False); 114 drawtext(NULL, !istile, False);
115 115
116 dc.w = 0; 116 dc.w = 0;
117 for(i = 0; i < TLast; i++) { 117 for(i = 0; i < ntags; i++) {
118 dc.x += dc.w; 118 dc.x += dc.w;
119 dc.w = textw(tags[i]); 119 dc.w = textw(tags[i]);
120 if(istile) 120 if(istile)
@@ -153,7 +153,7 @@ drawtitle(Client *c)
153 dc.x = dc.y = 0; 153 dc.x = dc.y = 0;
154 154
155 dc.w = 0; 155 dc.w = 0;
156 for(i = 0; i < TLast; i++) { 156 for(i = 0; i < ntags; i++) {
157 if(c->tags[i]) { 157 if(c->tags[i]) {
158 dc.x += dc.w; 158 dc.x += dc.w;
159 dc.w = textw(tags[i]); 159 dc.w = textw(tags[i]);
diff --git a/dwm.h b/dwm.h
index c44da29..25971ac 100644
--- a/dwm.h
+++ b/dwm.h
@@ -60,16 +60,17 @@ struct Client {
60 unsigned int border; 60 unsigned int border;
61 Bool isfloat; 61 Bool isfloat;
62 Bool ismax; 62 Bool ismax;
63 Bool tags[TLast]; 63 Bool *tags;
64 Client *next; 64 Client *next;
65 Client *prev; 65 Client *prev;
66 Window win; 66 Window win;
67 Window title; 67 Window title;
68}; 68};
69 69
70extern const char *tags[TLast]; 70extern const char *tags[];
71extern char stext[1024]; 71extern char stext[1024];
72extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw; 72extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
73extern unsigned int ntags;
73extern void (*handler[LASTEvent])(XEvent *); 74extern void (*handler[LASTEvent])(XEvent *);
74extern void (*arrange)(Arg *); 75extern void (*arrange)(Arg *);
75extern Atom wmatom[WMLast], netatom[NetLast]; 76extern Atom wmatom[WMLast], netatom[NetLast];
diff --git a/event.c b/event.c
index 0c159c7..88e1b10 100644
--- a/event.c
+++ b/event.c
@@ -105,7 +105,7 @@ buttonpress(XEvent *e)
105 switch(ev->button) { 105 switch(ev->button) {
106 default: 106 default:
107 x = 0; 107 x = 0;
108 for(a.i = 0; a.i < TLast; a.i++) { 108 for(a.i = 0; a.i < ntags; a.i++) {
109 x += textw(tags[a.i]); 109 x += textw(tags[a.i]);
110 if(ev->x < x) { 110 if(ev->x < x) {
111 view(&a); 111 view(&a);
diff --git a/main.c b/main.c
index 33a2a9a..9ea09bf 100644
--- a/main.c
+++ b/main.c
@@ -85,6 +85,7 @@ xerrorstart(Display *dsply, XErrorEvent *ee)
85char stext[1024]; 85char stext[1024];
86int tsel = DEFTAG; 86int tsel = DEFTAG;
87int screen, sx, sy, sw, sh, bx, by, bw, bh, mw; 87int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
88unsigned int ntags;
88Atom wmatom[WMLast], netatom[NetLast]; 89Atom wmatom[WMLast], netatom[NetLast];
89Bool running = True; 90Bool running = True;
90Bool issel = True; 91Bool issel = True;
@@ -210,6 +211,8 @@ main(int argc, char *argv[])
210 211
211 grabkeys(); 212 grabkeys();
212 213
214 for(ntags = 0; tags[ntags]; ntags++);
215
213 /* style */ 216 /* style */
214 dc.bg = getcolor(BGCOLOR); 217 dc.bg = getcolor(BGCOLOR);
215 dc.fg = getcolor(FGCOLOR); 218 dc.fg = getcolor(FGCOLOR);
diff --git a/tag.c b/tag.c
index 9022371..b20e71e 100644
--- a/tag.c
+++ b/tag.c
@@ -13,7 +13,7 @@
13 13
14typedef struct { 14typedef struct {
15 const char *pattern; 15 const char *pattern;
16 Bool tags[TLast]; 16 const unsigned int *tags;
17 Bool isfloat; 17 Bool isfloat;
18} Rule; 18} Rule;
19 19
@@ -145,7 +145,7 @@ replacetag(Arg *arg)
145 if(!sel) 145 if(!sel)
146 return; 146 return;
147 147
148 for(i = 0; i < TLast; i++) 148 for(i = 0; i < ntags; i++)
149 sel->tags[i] = False; 149 sel->tags[i] = False;
150 appendtag(arg); 150 appendtag(arg);
151} 151}
@@ -155,7 +155,7 @@ settags(Client *c)
155{ 155{
156 char classinst[256]; 156 char classinst[256];
157 static unsigned int len = sizeof(rule) / sizeof(rule[0]); 157 static unsigned int len = sizeof(rule) / sizeof(rule[0]);
158 unsigned int i, j; 158 unsigned int i, j, n;
159 regex_t regex; 159 regex_t regex;
160 regmatch_t tmp; 160 regmatch_t tmp;
161 Bool matched = False; 161 Bool matched = False;
@@ -168,10 +168,11 @@ settags(Client *c)
168 for(i = 0; !matched && i < len; i++) { 168 for(i = 0; !matched && i < len; i++) {
169 if(!regcomp(&regex, rule[i].pattern, 0)) { 169 if(!regcomp(&regex, rule[i].pattern, 0)) {
170 if(!regexec(&regex, classinst, 1, &tmp, 0)) { 170 if(!regexec(&regex, classinst, 1, &tmp, 0)) {
171 for(j = 0; j < TLast; j++) { 171 n = rule[i].tags ?
172 if((c->tags[j] = rule[i].tags[j])) 172 sizeof(rule[i].tags) / sizeof(rule[i].tags[0]) : 0;
173 matched = True; 173 matched = n != 0;
174 } 174 for(j = 0; j < n; j++)
175 c->tags[rule[i].tags[j]] = True;
175 c->isfloat = rule[i].isfloat; 176 c->isfloat = rule[i].isfloat;
176 } 177 }
177 regfree(&regex); 178 regfree(&regex);
@@ -204,13 +205,13 @@ view(Arg *arg)
204void 205void
205viewnext(Arg *arg) 206viewnext(Arg *arg)
206{ 207{
207 arg->i = (tsel < TLast-1) ? tsel+1 : 0; 208 arg->i = (tsel < ntags-1) ? tsel+1 : 0;
208 view(arg); 209 view(arg);
209} 210}
210 211
211void 212void
212viewprev(Arg *arg) 213viewprev(Arg *arg)
213{ 214{
214 arg->i = (tsel > 0) ? tsel-1 : TLast-1; 215 arg->i = (tsel > 0) ? tsel-1 : ntags-1;
215 view(arg); 216 view(arg);
216} 217}