summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config.def.h87
-rw-r--r--config.mk8
-rw-r--r--dwm.c211
3 files changed, 138 insertions, 168 deletions
diff --git a/config.def.h b/config.def.h
index 63c8c06..9e92c28 100644
--- a/config.def.h
+++ b/config.def.h
@@ -18,7 +18,8 @@ const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };
18 18
19Rule rules[] = { 19Rule rules[] = {
20 /* class instance title tags ref isfloating */ 20 /* class instance title tags ref isfloating */
21 { "Gimp", NULL, NULL, NULL, True }, 21 { "Gimp", NULL, NULL, 0, True },
22 { "Firefox", NULL, NULL, 1 << 8, True },
22}; 23};
23 24
24/* layout(s) */ 25/* layout(s) */
@@ -35,55 +36,55 @@ Layout layouts[] = {
35#define MODKEY Mod1Mask 36#define MODKEY Mod1Mask
36Key keys[] = { 37Key keys[] = {
37 /* modifier key function argument */ 38 /* modifier key function argument */
38 { MODKEY, XK_p, spawn, "exec dmenu_run -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGCOLOR"' -sb '"SELBGCOLOR"' -sf '"SELFGCOLOR"'" }, 39 { MODKEY, XK_p, spawn, (char *)"exec dmenu_run -fn '"FONT"' -nb '"NORMBGCOLOR"' -nf '"NORMFGCOLOR"' -sb '"SELBGCOLOR"' -sf '"SELFGCOLOR"'" },
39 { MODKEY|ShiftMask, XK_Return, spawn, "exec uxterm" }, 40 { MODKEY|ShiftMask, XK_Return, spawn, (char *)"exec uxterm" },
40 { MODKEY, XK_b, togglebar, NULL }, 41 { MODKEY, XK_b, togglebar, NULL },
41 { MODKEY, XK_j, focusnext, NULL }, 42 { MODKEY, XK_j, focusnext, NULL },
42 { MODKEY, XK_k, focusprev, NULL }, 43 { MODKEY, XK_k, focusprev, NULL },
43 { MODKEY, XK_h, setmfact, "-0.05" }, 44 { MODKEY, XK_h, setmfact, (double[]){+0.05} },
44 { MODKEY, XK_l, setmfact, "+0.05" }, 45 { MODKEY, XK_l, setmfact, (double[]){-0.05} },
45 { MODKEY, XK_Return, zoom, NULL }, 46 { MODKEY, XK_Return, zoom, NULL },
46 { MODKEY, XK_Tab, viewprevtag, NULL }, 47 { MODKEY, XK_Tab, viewprevtag, NULL },
47 { MODKEY|ShiftMask, XK_c, killclient, NULL }, 48 { MODKEY|ShiftMask, XK_c, killclient, NULL },
48 { MODKEY, XK_space, togglelayout, NULL }, 49 { MODKEY, XK_space, togglelayout, NULL },
49 { MODKEY|ShiftMask, XK_space, togglefloating, NULL }, 50 { MODKEY|ShiftMask, XK_space, togglefloating, NULL },
50 { MODKEY, XK_0, view, NULL }, 51 { MODKEY, XK_0, view, (int[]){ ~0 } },
51 { MODKEY, XK_1, view, tags[0] }, 52 { MODKEY, XK_1, view, (int[]){ 1 << 0 } },
52 { MODKEY, XK_2, view, tags[1] }, 53 { MODKEY, XK_2, view, (int[]){ 1 << 1 } },
53 { MODKEY, XK_3, view, tags[2] }, 54 { MODKEY, XK_3, view, (int[]){ 1 << 2 } },
54 { MODKEY, XK_4, view, tags[3] }, 55 { MODKEY, XK_4, view, (int[]){ 1 << 3 } },
55 { MODKEY, XK_5, view, tags[4] }, 56 { MODKEY, XK_5, view, (int[]){ 1 << 4 } },
56 { MODKEY, XK_6, view, tags[5] }, 57 { MODKEY, XK_6, view, (int[]){ 1 << 5 } },
57 { MODKEY, XK_7, view, tags[6] }, 58 { MODKEY, XK_7, view, (int[]){ 1 << 6 } },
58 { MODKEY, XK_8, view, tags[7] }, 59 { MODKEY, XK_8, view, (int[]){ 1 << 7 } },
59 { MODKEY, XK_9, view, tags[8] }, 60 { MODKEY, XK_9, view, (int[]){ 1 << 8 } },
60 { MODKEY|ControlMask, XK_1, toggleview, tags[0] }, 61 { MODKEY|ControlMask, XK_1, toggleview, (int[]){ 1 << 0 } },
61 { MODKEY|ControlMask, XK_2, toggleview, tags[1] }, 62 { MODKEY|ControlMask, XK_2, toggleview, (int[]){ 1 << 1 } },
62 { MODKEY|ControlMask, XK_3, toggleview, tags[2] }, 63 { MODKEY|ControlMask, XK_3, toggleview, (int[]){ 1 << 2 } },
63 { MODKEY|ControlMask, XK_4, toggleview, tags[3] }, 64 { MODKEY|ControlMask, XK_4, toggleview, (int[]){ 1 << 3 } },
64 { MODKEY|ControlMask, XK_5, toggleview, tags[4] }, 65 { MODKEY|ControlMask, XK_5, toggleview, (int[]){ 1 << 4 } },
65 { MODKEY|ControlMask, XK_6, toggleview, tags[5] }, 66 { MODKEY|ControlMask, XK_6, toggleview, (int[]){ 1 << 5 } },
66 { MODKEY|ControlMask, XK_7, toggleview, tags[6] }, 67 { MODKEY|ControlMask, XK_7, toggleview, (int[]){ 1 << 6 } },
67 { MODKEY|ControlMask, XK_8, toggleview, tags[7] }, 68 { MODKEY|ControlMask, XK_8, toggleview, (int[]){ 1 << 7 } },
68 { MODKEY|ControlMask, XK_9, toggleview, tags[8] }, 69 { MODKEY|ControlMask, XK_9, toggleview, (int[]){ 1 << 8 } },
69 { MODKEY|ShiftMask, XK_0, tag, NULL }, 70 { MODKEY|ShiftMask, XK_0, tag, (int[]){ ~0 } },
70 { MODKEY|ShiftMask, XK_1, tag, tags[0] }, 71 { MODKEY|ShiftMask, XK_1, tag, (int[]){ 1 << 0 } },
71 { MODKEY|ShiftMask, XK_2, tag, tags[1] }, 72 { MODKEY|ShiftMask, XK_2, tag, (int[]){ 1 << 1 } },
72 { MODKEY|ShiftMask, XK_3, tag, tags[2] }, 73 { MODKEY|ShiftMask, XK_3, tag, (int[]){ 1 << 2 } },
73 { MODKEY|ShiftMask, XK_4, tag, tags[3] }, 74 { MODKEY|ShiftMask, XK_4, tag, (int[]){ 1 << 3 } },
74 { MODKEY|ShiftMask, XK_5, tag, tags[4] }, 75 { MODKEY|ShiftMask, XK_5, tag, (int[]){ 1 << 4 } },
75 { MODKEY|ShiftMask, XK_6, tag, tags[5] }, 76 { MODKEY|ShiftMask, XK_6, tag, (int[]){ 1 << 5 } },
76 { MODKEY|ShiftMask, XK_7, tag, tags[6] }, 77 { MODKEY|ShiftMask, XK_7, tag, (int[]){ 1 << 6 } },
77 { MODKEY|ShiftMask, XK_8, tag, tags[7] }, 78 { MODKEY|ShiftMask, XK_8, tag, (int[]){ 1 << 7 } },
78 { MODKEY|ShiftMask, XK_9, tag, tags[8] }, 79 { MODKEY|ShiftMask, XK_9, tag, (int[]){ 1 << 8 } },
79 { MODKEY|ControlMask|ShiftMask, XK_1, toggletag, tags[0] }, 80 { MODKEY|ControlMask|ShiftMask, XK_1, toggletag, (int[]){ 1 << 0 } },
80 { MODKEY|ControlMask|ShiftMask, XK_2, toggletag, tags[1] }, 81 { MODKEY|ControlMask|ShiftMask, XK_2, toggletag, (int[]){ 1 << 1 } },
81 { MODKEY|ControlMask|ShiftMask, XK_3, toggletag, tags[2] }, 82 { MODKEY|ControlMask|ShiftMask, XK_3, toggletag, (int[]){ 1 << 2 } },
82 { MODKEY|ControlMask|ShiftMask, XK_4, toggletag, tags[3] }, 83 { MODKEY|ControlMask|ShiftMask, XK_4, toggletag, (int[]){ 1 << 3 } },
83 { MODKEY|ControlMask|ShiftMask, XK_5, toggletag, tags[4] }, 84 { MODKEY|ControlMask|ShiftMask, XK_5, toggletag, (int[]){ 1 << 4 } },
84 { MODKEY|ControlMask|ShiftMask, XK_6, toggletag, tags[5] }, 85 { MODKEY|ControlMask|ShiftMask, XK_6, toggletag, (int[]){ 1 << 5 } },
85 { MODKEY|ControlMask|ShiftMask, XK_7, toggletag, tags[6] }, 86 { MODKEY|ControlMask|ShiftMask, XK_7, toggletag, (int[]){ 1 << 6 } },
86 { MODKEY|ControlMask|ShiftMask, XK_8, toggletag, tags[7] }, 87 { MODKEY|ControlMask|ShiftMask, XK_8, toggletag, (int[]){ 1 << 7 } },
87 { MODKEY|ControlMask|ShiftMask, XK_9, toggletag, tags[8] }, 88 { MODKEY|ControlMask|ShiftMask, XK_9, toggletag, (int[]){ 1 << 8 } },
88 { MODKEY|ShiftMask, XK_q, quit, NULL }, 89 { MODKEY|ShiftMask, XK_q, quit, NULL },
89}; 90};
diff --git a/config.mk b/config.mk
index d8411df..ede70af 100644
--- a/config.mk
+++ b/config.mk
@@ -20,10 +20,10 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 ${XINERAMALIBS}
20 20
21# flags 21# flags
22CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS} 22CPPFLAGS = -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
23CFLAGS = -Os ${INCS} ${CPPFLAGS} 23#CFLAGS = -Os ${INCS} ${CPPFLAGS}
24LDFLAGS = -s ${LIBS} 24#LDFLAGS = -s ${LIBS}
25#CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} ${CPPFLAGS} 25CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} ${CPPFLAGS}
26#LDFLAGS = -g ${LIBS} 26LDFLAGS = -g ${LIBS}
27 27
28# Solaris 28# Solaris
29#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" 29#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
diff --git a/dwm.c b/dwm.c
index 2f1dbf8..66a2cb4 100644
--- a/dwm.c
+++ b/dwm.c
@@ -51,6 +51,7 @@
51#define LENGTH(x) (sizeof x / sizeof x[0]) 51#define LENGTH(x) (sizeof x / sizeof x[0])
52#define MAXTAGLEN 16 52#define MAXTAGLEN 16
53#define MOUSEMASK (BUTTONMASK|PointerMotionMask) 53#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
54#define TAGMASK ((int)((1LL << LENGTH(tags)) - 1))
54 55
55/* enums */ 56/* enums */
56enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */ 57enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
@@ -68,7 +69,7 @@ struct Client {
68 long flags; 69 long flags;
69 unsigned int bw, oldbw; 70 unsigned int bw, oldbw;
70 Bool isbanned, isfixed, isfloating, isurgent; 71 Bool isbanned, isfixed, isfloating, isurgent;
71 Bool *tags; 72 unsigned int tags;
72 Client *next; 73 Client *next;
73 Client *prev; 74 Client *prev;
74 Client *snext; 75 Client *snext;
@@ -93,8 +94,8 @@ typedef struct {
93typedef struct { 94typedef struct {
94 unsigned long mod; 95 unsigned long mod;
95 KeySym keysym; 96 KeySym keysym;
96 void (*func)(const char *arg); 97 void (*func)(void *arg);
97 const char *arg; 98 void *arg;
98} Key; 99} Key;
99 100
100typedef struct { 101typedef struct {
@@ -107,7 +108,7 @@ typedef struct {
107 const char *class; 108 const char *class;
108 const char *instance; 109 const char *instance;
109 const char *title; 110 const char *title;
110 const char *tag; 111 unsigned int tags;
111 Bool isfloating; 112 Bool isfloating;
112} Rule; 113} Rule;
113 114
@@ -135,48 +136,47 @@ void eprint(const char *errstr, ...);
135void expose(XEvent *e); 136void expose(XEvent *e);
136void focus(Client *c); 137void focus(Client *c);
137void focusin(XEvent *e); 138void focusin(XEvent *e);
138void focusnext(const char *arg); 139void focusnext(void *arg);
139void focusprev(const char *arg); 140void focusprev(void *arg);
140Client *getclient(Window w); 141Client *getclient(Window w);
141unsigned long getcolor(const char *colstr); 142unsigned long getcolor(const char *colstr);
142long getstate(Window w); 143long getstate(Window w);
143Bool gettextprop(Window w, Atom atom, char *text, unsigned int size); 144Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
144void grabbuttons(Client *c, Bool focused); 145void grabbuttons(Client *c, Bool focused);
145void grabkeys(void); 146void grabkeys(void);
146unsigned int idxoftag(const char *t);
147void initfont(const char *fontstr); 147void initfont(const char *fontstr);
148Bool isoccupied(unsigned int t); 148Bool isoccupied(unsigned int t);
149Bool isprotodel(Client *c); 149Bool isprotodel(Client *c);
150Bool isurgent(unsigned int t); 150Bool isurgent(unsigned int t);
151Bool isvisible(Client *c); 151Bool isvisible(Client *c);
152void keypress(XEvent *e); 152void keypress(XEvent *e);
153void killclient(const char *arg); 153void killclient(void *arg);
154void manage(Window w, XWindowAttributes *wa); 154void manage(Window w, XWindowAttributes *wa);
155void mappingnotify(XEvent *e); 155void mappingnotify(XEvent *e);
156void maprequest(XEvent *e); 156void maprequest(XEvent *e);
157void movemouse(Client *c); 157void movemouse(Client *c);
158Client *nextunfloating(Client *c); 158Client *nextunfloating(Client *c);
159void propertynotify(XEvent *e); 159void propertynotify(XEvent *e);
160void quit(const char *arg); 160void quit(void *arg);
161void resize(Client *c, int x, int y, int w, int h, Bool sizehints); 161void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
162void resizemouse(Client *c); 162void resizemouse(Client *c);
163void restack(void); 163void restack(void);
164void run(void); 164void run(void);
165void scan(void); 165void scan(void);
166void setclientstate(Client *c, long state); 166void setclientstate(Client *c, long state);
167void setmfact(const char *arg); 167void setmfact(void *arg);
168void setup(void); 168void setup(void);
169void spawn(const char *arg); 169void spawn(void *arg);
170void tag(const char *arg); 170void tag(void *arg);
171unsigned int textnw(const char *text, unsigned int len); 171unsigned int textnw(const char *text, unsigned int len);
172unsigned int textw(const char *text); 172unsigned int textw(const char *text);
173void tile(void); 173void tile(void);
174void tileresize(Client *c, int x, int y, int w, int h); 174void tileresize(Client *c, int x, int y, int w, int h);
175void togglebar(const char *arg); 175void togglebar(void *arg);
176void togglefloating(const char *arg); 176void togglefloating(void *arg);
177void togglelayout(const char *arg); 177void togglelayout(void *arg);
178void toggletag(const char *arg); 178void toggletag(void *arg);
179void toggleview(const char *arg); 179void toggleview(void *arg);
180void unban(Client *c); 180void unban(Client *c);
181void unmanage(Client *c); 181void unmanage(Client *c);
182void unmapnotify(XEvent *e); 182void unmapnotify(XEvent *e);
@@ -186,19 +186,19 @@ void updatesizehints(Client *c);
186void updatetilegeom(void); 186void updatetilegeom(void);
187void updatetitle(Client *c); 187void updatetitle(Client *c);
188void updatewmhints(Client *c); 188void updatewmhints(Client *c);
189void view(const char *arg); 189void view(void *arg);
190void viewprevtag(const char *arg); 190void viewprevtag(void *arg);
191int xerror(Display *dpy, XErrorEvent *ee); 191int xerror(Display *dpy, XErrorEvent *ee);
192int xerrordummy(Display *dpy, XErrorEvent *ee); 192int xerrordummy(Display *dpy, XErrorEvent *ee);
193int xerrorstart(Display *dpy, XErrorEvent *ee); 193int xerrorstart(Display *dpy, XErrorEvent *ee);
194void zoom(const char *arg); 194void zoom(void *arg);
195 195
196/* variables */ 196/* variables */
197char stext[256]; 197char stext[256];
198int screen, sx, sy, sw, sh; 198int screen, sx, sy, sw, sh;
199int bx, by, bw, bh, blw, wx, wy, ww, wh; 199int bx, by, bw, bh, blw, wx, wy, ww, wh;
200int mx, my, mw, mh, tx, ty, tw, th; 200int mx, my, mw, mh, tx, ty, tw, th;
201int seltags = 0; 201unsigned int seltags = 0;
202int (*xerrorxlib)(Display *, XErrorEvent *); 202int (*xerrorxlib)(Display *, XErrorEvent *);
203unsigned int numlockmask = 0; 203unsigned int numlockmask = 0;
204void (*handler[LASTEvent]) (XEvent *) = { 204void (*handler[LASTEvent]) (XEvent *) = {
@@ -218,7 +218,7 @@ void (*handler[LASTEvent]) (XEvent *) = {
218Atom wmatom[WMLast], netatom[NetLast]; 218Atom wmatom[WMLast], netatom[NetLast];
219Bool otherwm, readin; 219Bool otherwm, readin;
220Bool running = True; 220Bool running = True;
221Bool *tagset[2]; 221unsigned int tagset[] = {1, 1}; /* after start, first tag is selected */
222Client *clients = NULL; 222Client *clients = NULL;
223Client *sel = NULL; 223Client *sel = NULL;
224Client *stack = NULL; 224Client *stack = NULL;
@@ -231,14 +231,15 @@ Window root, barwin;
231 231
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#define TAGSZ (LENGTH(tags) * sizeof(Bool)) 234
235/* check if all tags will fit into a unsigned int bitarray. */
236static char tags_is_a_sign_that_your_IQ[sizeof(int) * 8 < LENGTH(tags) ? -1 : 1];
235 237
236/* function implementations */ 238/* function implementations */
237 239
238void 240void
239applyrules(Client *c) { 241applyrules(Client *c) {
240 unsigned int i; 242 unsigned int i;
241 Bool matched = False;
242 Rule *r; 243 Rule *r;
243 XClassHint ch = { 0 }; 244 XClassHint ch = { 0 };
244 245
@@ -250,18 +251,15 @@ applyrules(Client *c) {
250 && (!r->class || (ch.res_class && strstr(ch.res_class, r->class))) 251 && (!r->class || (ch.res_class && strstr(ch.res_class, r->class)))
251 && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) { 252 && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) {
252 c->isfloating = r->isfloating; 253 c->isfloating = r->isfloating;
253 if(r->tag) { 254 c->tags |= r->tags & TAGMASK;
254 c->tags[idxoftag(r->tag)] = True;
255 matched = True;
256 }
257 } 255 }
258 } 256 }
259 if(ch.res_class) 257 if(ch.res_class)
260 XFree(ch.res_class); 258 XFree(ch.res_class);
261 if(ch.res_name) 259 if(ch.res_name)
262 XFree(ch.res_name); 260 XFree(ch.res_name);
263 if(!matched) 261 if(!c->tags)
264 memcpy(c->tags, tagset[seltags], TAGSZ); 262 c->tags = tagset[seltags];
265} 263}
266 264
267void 265void
@@ -307,7 +305,7 @@ ban(Client *c) {
307 305
308void 306void
309buttonpress(XEvent *e) { 307buttonpress(XEvent *e) {
310 unsigned int i, x; 308 unsigned int i, x, mask;
311 Client *c; 309 Client *c;
312 XButtonPressedEvent *ev = &e->xbutton; 310 XButtonPressedEvent *ev = &e->xbutton;
313 311
@@ -316,17 +314,18 @@ buttonpress(XEvent *e) {
316 for(i = 0; i < LENGTH(tags); i++) { 314 for(i = 0; i < LENGTH(tags); i++) {
317 x += textw(tags[i]); 315 x += textw(tags[i]);
318 if(ev->x < x) { 316 if(ev->x < x) {
317 mask = 1 << i;
319 if(ev->button == Button1) { 318 if(ev->button == Button1) {
320 if(ev->state & MODKEY) 319 if(ev->state & MODKEY)
321 tag(tags[i]); 320 tag(&mask);
322 else 321 else
323 view(tags[i]); 322 view(&mask);
324 } 323 }
325 else if(ev->button == Button3) { 324 else if(ev->button == Button3) {
326 if(ev->state & MODKEY) 325 if(ev->state & MODKEY)
327 toggletag(tags[i]); 326 toggletag(&mask);
328 else 327 else
329 toggleview(tags[i]); 328 toggleview(&mask);
330 } 329 }
331 return; 330 return;
332 } 331 }
@@ -501,13 +500,13 @@ drawbar(void) {
501 for(c = stack; c && !isvisible(c); c = c->snext); 500 for(c = stack; c && !isvisible(c); c = c->snext);
502 for(i = 0; i < LENGTH(tags); i++) { 501 for(i = 0; i < LENGTH(tags); i++) {
503 dc.w = textw(tags[i]); 502 dc.w = textw(tags[i]);
504 if(tagset[seltags][i]) { 503 if(tagset[seltags] & 1 << i) {
505 drawtext(tags[i], dc.sel, isurgent(i)); 504 drawtext(tags[i], dc.sel, isurgent(i));
506 drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), dc.sel); 505 drawsquare(c && c->tags & 1 << i, isoccupied(i), isurgent(i), dc.sel);
507 } 506 }
508 else { 507 else {
509 drawtext(tags[i], dc.norm, isurgent(i)); 508 drawtext(tags[i], dc.norm, isurgent(i));
510 drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), dc.norm); 509 drawsquare(c && c->tags & 1 << i, isoccupied(i), isurgent(i), dc.norm);
511 } 510 }
512 dc.x += dc.w; 511 dc.x += dc.w;
513 } 512 }
@@ -668,7 +667,7 @@ focusin(XEvent *e) { /* there are some broken focus acquiring clients */
668} 667}
669 668
670void 669void
671focusnext(const char *arg) { 670focusnext(void *arg) {
672 Client *c; 671 Client *c;
673 672
674 if(!sel) 673 if(!sel)
@@ -683,7 +682,7 @@ focusnext(const char *arg) {
683} 682}
684 683
685void 684void
686focusprev(const char *arg) { 685focusprev(void *arg) {
687 Client *c; 686 Client *c;
688 687
689 if(!sel) 688 if(!sel)
@@ -808,14 +807,6 @@ grabkeys(void) {
808 } 807 }
809} 808}
810 809
811unsigned int
812idxoftag(const char *t) {
813 unsigned int i;
814
815 for(i = 0; (i < LENGTH(tags)) && t && strcmp(tags[i], t); i++);
816 return (i < LENGTH(tags)) ? i : 0;
817}
818
819void 810void
820initfont(const char *fontstr) { 811initfont(const char *fontstr) {
821 char *def, **missing; 812 char *def, **missing;
@@ -861,7 +852,7 @@ isoccupied(unsigned int t) {
861 Client *c; 852 Client *c;
862 853
863 for(c = clients; c; c = c->next) 854 for(c = clients; c; c = c->next)
864 if(c->tags[t]) 855 if(c->tags & 1 << t)
865 return True; 856 return True;
866 return False; 857 return False;
867} 858}
@@ -886,19 +877,14 @@ isurgent(unsigned int t) {
886 Client *c; 877 Client *c;
887 878
888 for(c = clients; c; c = c->next) 879 for(c = clients; c; c = c->next)
889 if(c->isurgent && c->tags[t]) 880 if(c->isurgent && c->tags & 1 << t)
890 return True; 881 return True;
891 return False; 882 return False;
892} 883}
893 884
894Bool 885Bool
895isvisible(Client *c) { 886isvisible(Client *c) {
896 unsigned int i; 887 return c->tags & tagset[seltags];
897
898 for(i = 0; i < LENGTH(tags); i++)
899 if(c->tags[i] && tagset[seltags][i])
900 return True;
901 return False;
902} 888}
903 889
904void 890void
@@ -919,7 +905,7 @@ keypress(XEvent *e) {
919} 905}
920 906
921void 907void
922killclient(const char *arg) { 908killclient(void *arg) {
923 XEvent ev; 909 XEvent ev;
924 910
925 if(!sel) 911 if(!sel)
@@ -945,7 +931,6 @@ manage(Window w, XWindowAttributes *wa) {
945 XWindowChanges wc; 931 XWindowChanges wc;
946 932
947 c = emallocz(sizeof(Client)); 933 c = emallocz(sizeof(Client));
948 c->tags = emallocz(TAGSZ);
949 c->win = w; 934 c->win = w;
950 935
951 /* geometry */ 936 /* geometry */
@@ -980,7 +965,7 @@ manage(Window w, XWindowAttributes *wa) {
980 if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success)) 965 if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
981 for(t = clients; t && t->win != trans; t = t->next); 966 for(t = clients; t && t->win != trans; t = t->next);
982 if(t) 967 if(t)
983 memcpy(c->tags, t->tags, TAGSZ); 968 c->tags = t->tags;
984 else 969 else
985 applyrules(c); 970 applyrules(c);
986 if(!c->isfloating) 971 if(!c->isfloating)
@@ -1103,7 +1088,7 @@ propertynotify(XEvent *e) {
1103} 1088}
1104 1089
1105void 1090void
1106quit(const char *arg) { 1091quit(void *arg) {
1107 readin = running = False; 1092 readin = running = False;
1108} 1093}
1109 1094
@@ -1334,20 +1319,17 @@ setclientstate(Client *c, long state) {
1334 PropModeReplace, (unsigned char *)data, 2); 1319 PropModeReplace, (unsigned char *)data, 2);
1335} 1320}
1336 1321
1322/* arg > 1.0 will set mfact absolutly */
1337void 1323void
1338setmfact(const char *arg) { 1324setmfact(void *arg) {
1339 double d; 1325 double d = *((double*) arg);
1340 1326
1341 if(!arg || lt->arrange != tile) 1327 if(!d || lt->arrange != tile)
1342 return; 1328 return;
1343 else { 1329 d = d < 1.0 ? d + mfact : d - 1.0;
1344 d = strtod(arg, NULL); 1330 if(d < 0.1 || d > 0.9)
1345 if(arg[0] == '-' || arg[0] == '+') 1331 return;
1346 d += mfact; 1332 mfact = d;
1347 if(d < 0.1 || d > 0.9)
1348 return;
1349 mfact = d;
1350 }
1351 updatetilegeom(); 1333 updatetilegeom();
1352 arrange(); 1334 arrange();
1353} 1335}
@@ -1396,11 +1378,6 @@ setup(void) {
1396 if(!dc.font.set) 1378 if(!dc.font.set)
1397 XSetFont(dpy, dc.gc, dc.font.xfont->fid); 1379 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
1398 1380
1399 /* init tags */
1400 tagset[0] = emallocz(TAGSZ);
1401 tagset[1] = emallocz(TAGSZ);
1402 tagset[0][0] = tagset[1][0] = True;
1403
1404 /* init bar */ 1381 /* init bar */
1405 for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) { 1382 for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
1406 w = textw(layouts[i].symbol); 1383 w = textw(layouts[i].symbol);
@@ -1435,13 +1412,11 @@ setup(void) {
1435} 1412}
1436 1413
1437void 1414void
1438spawn(const char *arg) { 1415spawn(void *arg) {
1439 static char *shell = NULL; 1416 static char *shell = NULL;
1440 1417
1441 if(!shell && !(shell = getenv("SHELL"))) 1418 if(!shell && !(shell = getenv("SHELL")))
1442 shell = "/bin/sh"; 1419 shell = "/bin/sh";
1443 if(!arg)
1444 return;
1445 /* The double-fork construct avoids zombie processes and keeps the code 1420 /* The double-fork construct avoids zombie processes and keeps the code
1446 * clean from stupid signal handlers. */ 1421 * clean from stupid signal handlers. */
1447 if(fork() == 0) { 1422 if(fork() == 0) {
@@ -1449,8 +1424,8 @@ spawn(const char *arg) {
1449 if(dpy) 1424 if(dpy)
1450 close(ConnectionNumber(dpy)); 1425 close(ConnectionNumber(dpy));
1451 setsid(); 1426 setsid();
1452 execl(shell, shell, "-c", arg, (char *)NULL); 1427 execl(shell, shell, "-c", (char *)arg, (char *)NULL);
1453 fprintf(stderr, "dwm: execl '%s -c %s'", shell, arg); 1428 fprintf(stderr, "dwm: execl '%s -c %s'", shell, (char *)arg);
1454 perror(" failed"); 1429 perror(" failed");
1455 } 1430 }
1456 exit(0); 1431 exit(0);
@@ -1459,15 +1434,11 @@ spawn(const char *arg) {
1459} 1434}
1460 1435
1461void 1436void
1462tag(const char *arg) { 1437tag(void *arg) {
1463 unsigned int i; 1438 if(sel && *(int *)arg & TAGMASK) {
1464 1439 sel->tags = *(int *)arg & TAGMASK;
1465 if(!sel) 1440 arrange();
1466 return; 1441 }
1467 for(i = 0; i < LENGTH(tags); i++)
1468 sel->tags[i] = (arg == NULL);
1469 sel->tags[idxoftag(arg)] = True;
1470 arrange();
1471} 1442}
1472 1443
1473unsigned int 1444unsigned int
@@ -1534,7 +1505,7 @@ tileresize(Client *c, int x, int y, int w, int h) {
1534} 1505}
1535 1506
1536void 1507void
1537togglebar(const char *arg) { 1508togglebar(void *arg) {
1538 showbar = !showbar; 1509 showbar = !showbar;
1539 updategeom(); 1510 updategeom();
1540 updatebar(); 1511 updatebar();
@@ -1542,7 +1513,7 @@ togglebar(const char *arg) {
1542} 1513}
1543 1514
1544void 1515void
1545togglefloating(const char *arg) { 1516togglefloating(void *arg) {
1546 if(!sel) 1517 if(!sel)
1547 return; 1518 return;
1548 sel->isfloating = !sel->isfloating; 1519 sel->isfloating = !sel->isfloating;
@@ -1552,7 +1523,7 @@ togglefloating(const char *arg) {
1552} 1523}
1553 1524
1554void 1525void
1555togglelayout(const char *arg) { 1526togglelayout(void *arg) {
1556 unsigned int i; 1527 unsigned int i;
1557 1528
1558 if(!arg) { 1529 if(!arg) {
@@ -1561,7 +1532,7 @@ togglelayout(const char *arg) {
1561 } 1532 }
1562 else { 1533 else {
1563 for(i = 0; i < LENGTH(layouts); i++) 1534 for(i = 0; i < LENGTH(layouts); i++)
1564 if(!strcmp(arg, layouts[i].symbol)) 1535 if(!strcmp((char *)arg, layouts[i].symbol))
1565 break; 1536 break;
1566 if(i == LENGTH(layouts)) 1537 if(i == LENGTH(layouts))
1567 return; 1538 return;
@@ -1574,29 +1545,27 @@ togglelayout(const char *arg) {
1574} 1545}
1575 1546
1576void 1547void
1577toggletag(const char *arg) { 1548toggletag(void *arg) {
1578 unsigned int i, j; 1549 int i, m = *(int *)arg;
1550 for(i = 0; i < sizeof(int) * 8; i++)
1551 fputc(m & 1 << i ? '1' : '0', stdout);
1552 puts("");
1553 for(i = 0; i < sizeof(int) * 8; i++)
1554 fputc(TAGMASK & 1 << i ? '1' : '0', stdout);
1555 puts("aaa");
1579 1556
1580 if(!sel) 1557 if(sel && (sel->tags ^ ((*(int *)arg) & TAGMASK))) {
1581 return; 1558 sel->tags ^= (*(int *)arg) & TAGMASK;
1582 i = idxoftag(arg); 1559 arrange();
1583 sel->tags[i] = !sel->tags[i]; 1560 }
1584 for(j = 0; j < LENGTH(tags) && !sel->tags[j]; j++);
1585 if(j == LENGTH(tags))
1586 sel->tags[i] = True; /* at least one tag must be enabled */
1587 arrange();
1588} 1561}
1589 1562
1590void 1563void
1591toggleview(const char *arg) { 1564toggleview(void *arg) {
1592 unsigned int i, j; 1565 if((tagset[seltags] ^ ((*(int *)arg) & TAGMASK))) {
1593 1566 tagset[seltags] ^= (*(int *)arg) & TAGMASK;
1594 i = idxoftag(arg); 1567 arrange();
1595 tagset[seltags][i] = !tagset[seltags][i]; 1568 }
1596 for(j = 0; j < LENGTH(tags) && !tagset[seltags][j]; j++);
1597 if(j == LENGTH(tags))
1598 tagset[seltags][i] = True; /* at least one tag must be viewed */
1599 arrange();
1600} 1569}
1601 1570
1602void 1571void
@@ -1622,7 +1591,6 @@ unmanage(Client *c) {
1622 focus(NULL); 1591 focus(NULL);
1623 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); 1592 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
1624 setclientstate(c, WithdrawnState); 1593 setclientstate(c, WithdrawnState);
1625 free(c->tags);
1626 free(c); 1594 free(c);
1627 XSync(dpy, False); 1595 XSync(dpy, False);
1628 XSetErrorHandler(xerror); 1596 XSetErrorHandler(xerror);
@@ -1769,15 +1737,16 @@ updatewmhints(Client *c) {
1769} 1737}
1770 1738
1771void 1739void
1772view(const char *arg) { 1740view(void *arg) {
1773 seltags ^= 1; /* toggle sel tagset */ 1741 if(*(int *)arg & TAGMASK) {
1774 memset(tagset[seltags], (NULL == arg), TAGSZ); 1742 seltags ^= 1; /* toggle sel tagset */
1775 tagset[seltags][idxoftag(arg)] = True; 1743 tagset[seltags] = *(int *)arg & TAGMASK;
1776 arrange(); 1744 arrange();
1745 }
1777} 1746}
1778 1747
1779void 1748void
1780viewprevtag(const char *arg) { 1749viewprevtag(void *arg) {
1781 seltags ^= 1; /* toggle sel tagset */ 1750 seltags ^= 1; /* toggle sel tagset */
1782 arrange(); 1751 arrange();
1783} 1752}
@@ -1816,7 +1785,7 @@ xerrorstart(Display *dpy, XErrorEvent *ee) {
1816} 1785}
1817 1786
1818void 1787void
1819zoom(const char *arg) { 1788zoom(void *arg) {
1820 Client *c = sel; 1789 Client *c = sel;
1821 1790
1822 if(c == nextunfloating(clients)) 1791 if(c == nextunfloating(clients))