summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--client.c8
-rw-r--r--config.mk4
-rw-r--r--dwm.h35
-rw-r--r--main.c2
-rw-r--r--screen.c (renamed from layout.c)218
-rw-r--r--tag.c174
7 files changed, 215 insertions, 228 deletions
diff --git a/Makefile b/Makefile
index b1378b8..691e44c 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
3 3
4include config.mk 4include config.mk
5 5
6SRC += client.c draw.c event.c layout.c main.c tag.c util.c 6SRC += client.c draw.c event.c main.c screen.c util.c
7OBJ = ${SRC:.c=.o} 7OBJ = ${SRC:.c=.o}
8 8
9all: options dwm 9all: options dwm
diff --git a/client.c b/client.c
index d94c0ed..9f46a0e 100644
--- a/client.c
+++ b/client.c
@@ -182,7 +182,7 @@ killclient(const char *arg) {
182} 182}
183 183
184Bool 184Bool
185loadprops(Client *c) { 185getprops(Client *c) {
186 unsigned int i; 186 unsigned int i;
187 Bool result = False; 187 Bool result = False;
188 188
@@ -242,11 +242,11 @@ manage(Window w, XWindowAttributes *wa) {
242 if(t) 242 if(t)
243 for(i = 0; i < ntags; i++) 243 for(i = 0; i < ntags; i++)
244 c->tags[i] = t->tags[i]; 244 c->tags[i] = t->tags[i];
245 if(!loadprops(c)) 245 if(!getprops(c))
246 applyrules(c); 246 applyrules(c);
247 if(!c->isfloating) 247 if(!c->isfloating)
248 c->isfloating = (rettrans == Success) || c->isfixed; 248 c->isfloating = (rettrans == Success) || c->isfixed;
249 saveprops(c); 249 setprops(c);
250 attach(c); 250 attach(c);
251 attachstack(c); 251 attachstack(c);
252 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */ 252 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
@@ -318,7 +318,7 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
318} 318}
319 319
320void 320void
321saveprops(Client *c) { 321setprops(Client *c) {
322 unsigned int i; 322 unsigned int i;
323 323
324 for(i = 0; i < ntags && i < sizeof prop - 1; i++) 324 for(i = 0; i < ntags && i < sizeof prop - 1; i++)
diff --git a/config.mk b/config.mk
index 682bb41..320aea1 100644
--- a/config.mk
+++ b/config.mk
@@ -20,8 +20,8 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
20# flags 20# flags
21CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" 21CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
22LDFLAGS = -s ${LIBS} 22LDFLAGS = -s ${LIBS}
23CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" 23#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
24LDFLAGS = -g ${LIBS} 24#LDFLAGS = -g ${LIBS}
25 25
26# Solaris 26# Solaris
27#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\" 27#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
diff --git a/dwm.h b/dwm.h
index 36a0266..105912f 100644
--- a/dwm.h
+++ b/dwm.h
@@ -96,11 +96,11 @@ void configure(Client *c); /* send synthetic configure event */
96void detach(Client *c); /* detaches c from global client list */ 96void detach(Client *c); /* detaches c from global client list */
97void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */ 97void focus(Client *c); /* focus c if visible && !NULL, or focus top visible */
98void killclient(const char *arg); /* kill sel nicely */ 98void killclient(const char *arg); /* kill sel nicely */
99Bool loadprops(Client *c); /* loads client properties */ 99Bool getprops(Client *c); /* gets client properties */
100void manage(Window w, XWindowAttributes *wa); /* manage new client */ 100void manage(Window w, XWindowAttributes *wa); /* manage new client */
101void resize(Client *c, int x, int y, 101void resize(Client *c, int x, int y,
102 int w, int h, Bool sizehints); /* resize with given coordinates c*/ 102 int w, int h, Bool sizehints); /* resize with given coordinates c*/
103void saveprops(Client *c); /* saves client properties */ 103void setprops(Client *c); /* sets client properties */
104void unban(Client *c); /* unbans c */ 104void unban(Client *c); /* unbans c */
105void unmanage(Client *c, long state); /* unmanage c */ 105void unmanage(Client *c, long state); /* unmanage c */
106void updatesizehints(Client *c); /* update the size hint variables of c */ 106void updatesizehints(Client *c); /* update the size hint variables of c */
@@ -114,22 +114,6 @@ unsigned int textw(const char *text); /* return the width of text in px*/
114/* event.c */ 114/* event.c */
115void grabkeys(void); /* grab all keys defined in config.h */ 115void grabkeys(void); /* grab all keys defined in config.h */
116 116
117/* layout.c */
118void arrange(void); /* arranges all windows depending on the layout in use */
119void focusnext(const char *arg); /* focuses next visible client */
120void focusprev(const char *arg); /* focuses prev visible client */
121const char *getsymbol(void); /* returns symbol of enabled layout */
122Bool isfloating(void); /* returns True if floating layout is enabled */
123Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */
124void initlayouts(void); /* initialize layout array */
125void loaddwmprops(void); /* loads dwm properties */
126Client *nexttiled(Client *c); /* returns tiled successor of c */
127void restack(void); /* restores z layers of all clients */
128void savedwmprops(void); /* saves dwm properties */
129void setlayout(const char *arg); /* sets layout, NULL means next layout */
130void togglebar(const char *arg); /* shows/hides the bar */
131void togglemax(const char *arg); /* toggles maximization of floating client */
132
133/* main.c */ 117/* main.c */
134Bool gettextprop(Window w, Atom atom, 118Bool gettextprop(Window w, Atom atom,
135 char *text, unsigned int size); /* return text property, UTF-8 compliant */ 119 char *text, unsigned int size); /* return text property, UTF-8 compliant */
@@ -137,12 +121,25 @@ void updatebarpos(void); /* updates the bar position */
137void quit(const char *arg); /* quit dwm nicely */ 121void quit(const char *arg); /* quit dwm nicely */
138int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ 122int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */
139 123
140/* tag.c */ 124/* screen.c */
141void applyrules(Client *c); /* applies rules to c */ 125void applyrules(Client *c); /* applies rules to c */
126void arrange(void); /* arranges all windows depending on the layout in use */
142void compileregs(void); /* initialize regexps of rules defined in config.h */ 127void compileregs(void); /* initialize regexps of rules defined in config.h */
128void focusnext(const char *arg); /* focuses next visible client */
129void focusprev(const char *arg); /* focuses prev visible client */
130const char *getsymbol(void); /* returns symbol of enabled layout */
131void initlayouts(void); /* initialize layout array */
132Bool isarrange(void (*func)()); /* returns True if func is the layout function in use */
133Bool isfloating(void); /* returns True if floating layout is enabled */
143Bool isvisible(Client *c); /* returns True if client is visible */ 134Bool isvisible(Client *c); /* returns True if client is visible */
135void getdwmprops(void); /* gets dwm properties */
136Client *nexttiled(Client *c); /* returns tiled successor of c */
137void restack(void); /* restores z layers of all clients */
138void setlayout(const char *arg); /* sets layout, NULL means next layout */
144void tag(const char *arg); /* tags sel with arg's index */ 139void tag(const char *arg); /* tags sel with arg's index */
140void togglebar(const char *arg); /* shows/hides the bar */
145void togglefloating(const char *arg); /* toggles sel between floating/tiled state */ 141void togglefloating(const char *arg); /* toggles sel between floating/tiled state */
142void togglemax(const char *arg); /* toggles maximization of floating client */
146void toggletag(const char *arg); /* toggles sel tags with arg's index */ 143void toggletag(const char *arg); /* toggles sel tags with arg's index */
147void toggleview(const char *arg); /* toggles the tag with arg's index (in)visible */ 144void toggleview(const char *arg); /* toggles the tag with arg's index (in)visible */
148void view(const char *arg); /* views the tag with arg's index */ 145void view(const char *arg); /* views the tag with arg's index */
diff --git a/main.c b/main.c
index 9127d16..35a3a78 100644
--- a/main.c
+++ b/main.c
@@ -206,7 +206,7 @@ setup(void) {
206 XSetFont(dpy, dc.gc, dc.font.xfont->fid); 206 XSetFont(dpy, dc.gc, dc.font.xfont->fid);
207 /* multihead support */ 207 /* multihead support */
208 selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 208 selscreen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
209 loaddwmprops(); 209 getdwmprops();
210} 210}
211 211
212/* 212/*
diff --git a/layout.c b/screen.c
index 2763d2c..03387eb 100644
--- a/layout.c
+++ b/screen.c
@@ -1,5 +1,7 @@
1/* See LICENSE file for copyright and license details. */ 1/* See LICENSE file for copyright and license details. */
2#include "dwm.h" 2#include "dwm.h"
3#include <regex.h>
4#include <stdio.h>
3#include <stdlib.h> 5#include <stdlib.h>
4#include <string.h> 6#include <string.h>
5#include <X11/Xatom.h> 7#include <X11/Xatom.h>
@@ -12,9 +14,35 @@ typedef struct {
12 void (*arrange)(void); 14 void (*arrange)(void);
13} Layout; 15} Layout;
14 16
15unsigned int blw = 0; 17typedef struct {
16static char prop[128]; 18 const char *prop;
19 const char *tags;
20 Bool isfloating;
21} Rule;
22
23typedef struct {
24 regex_t *propregex;
25 regex_t *tagregex;
26} Regs;
27
28TAGS
29RULES
30
31static char prop[512];
32static unsigned int nrules = 0;
33static unsigned int nlayouts = 0;
17static unsigned int ltidx = 0; /* default */ 34static unsigned int ltidx = 0; /* default */
35static Regs *regs = NULL;
36
37static unsigned int
38idxoftag(const char *tag) {
39 unsigned int i;
40
41 for(i = 0; i < ntags; i++)
42 if(tags[i] == tag)
43 return i;
44 return 0;
45}
18 46
19static void 47static void
20floating(void) { /* default floating layout */ 48floating(void) { /* default floating layout */
@@ -25,12 +53,56 @@ floating(void) { /* default floating layout */
25 resize(c, c->x, c->y, c->w, c->h, True); 53 resize(c, c->x, c->y, c->w, c->h, True);
26} 54}
27 55
28static unsigned int nlayouts = 0; 56static void
57setdwmprops(void) {
58 unsigned int i;
59
60 for(i = 0; i < ntags && i < sizeof prop - 1; i++)
61 prop[i] = seltags[i] ? '1' : '0';
62 if(i < sizeof prop - 1)
63 prop[i++] = (char)ltidx;
64 prop[i] = '\0';
65 XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
66 PropModeReplace, (unsigned char *)prop, i);
67}
29 68
30LAYOUTS 69LAYOUTS
31 70
32/* extern */ 71/* extern */
33 72
73unsigned int blw = 0;
74
75void
76applyrules(Client *c) {
77 unsigned int i, j;
78 regmatch_t tmp;
79 Bool matched = False;
80 XClassHint ch = { 0 };
81
82 /* rule matching */
83 XGetClassHint(dpy, c->win, &ch);
84 snprintf(prop, sizeof prop, "%s:%s:%s",
85 ch.res_class ? ch.res_class : "",
86 ch.res_name ? ch.res_name : "", c->name);
87 for(i = 0; i < nrules; i++)
88 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
89 c->isfloating = rules[i].isfloating;
90 for(j = 0; regs[i].tagregex && j < ntags; j++) {
91 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
92 matched = True;
93 c->tags[j] = True;
94 }
95 }
96 }
97 if(ch.res_class)
98 XFree(ch.res_class);
99 if(ch.res_name)
100 XFree(ch.res_name);
101 if(!matched)
102 for(i = 0; i < ntags; i++)
103 c->tags[i] = seltags[i];
104}
105
34void 106void
35arrange(void) { 107arrange(void) {
36 Client *c; 108 Client *c;
@@ -46,6 +118,33 @@ arrange(void) {
46} 118}
47 119
48void 120void
121compileregs(void) {
122 unsigned int i;
123 regex_t *reg;
124
125 if(regs)
126 return;
127 nrules = sizeof rules / sizeof rules[0];
128 regs = emallocz(nrules * sizeof(Regs));
129 for(i = 0; i < nrules; i++) {
130 if(rules[i].prop) {
131 reg = emallocz(sizeof(regex_t));
132 if(regcomp(reg, rules[i].prop, REG_EXTENDED))
133 free(reg);
134 else
135 regs[i].propregex = reg;
136 }
137 if(rules[i].tags) {
138 reg = emallocz(sizeof(regex_t));
139 if(regcomp(reg, rules[i].tags, REG_EXTENDED))
140 free(reg);
141 else
142 regs[i].tagregex = reg;
143 }
144 }
145}
146
147void
49focusnext(const char *arg) { 148focusnext(const char *arg) {
50 Client *c; 149 Client *c;
51 150
@@ -83,6 +182,18 @@ getsymbol(void)
83 return layouts[ltidx].symbol; 182 return layouts[ltidx].symbol;
84} 183}
85 184
185void
186initlayouts(void) {
187 unsigned int i, w;
188
189 nlayouts = sizeof layouts / sizeof layouts[0];
190 for(blw = i = 0; i < nlayouts; i++) {
191 w = textw(layouts[i].symbol);
192 if(w > blw)
193 blw = w;
194 }
195}
196
86Bool 197Bool
87isfloating(void) { 198isfloating(void) {
88 return layouts[ltidx].arrange == floating; 199 return layouts[ltidx].arrange == floating;
@@ -94,20 +205,18 @@ isarrange(void (*func)())
94 return func == layouts[ltidx].arrange; 205 return func == layouts[ltidx].arrange;
95} 206}
96 207
97void 208Bool
98initlayouts(void) { 209isvisible(Client *c) {
99 unsigned int i, w; 210 unsigned int i;
100 211
101 nlayouts = sizeof layouts / sizeof layouts[0]; 212 for(i = 0; i < ntags; i++)
102 for(blw = i = 0; i < nlayouts; i++) { 213 if(c->tags[i] && seltags[i])
103 w = textw(layouts[i].symbol); 214 return True;
104 if(w > blw) 215 return False;
105 blw = w;
106 }
107} 216}
108 217
109void 218void
110loaddwmprops(void) { 219getdwmprops(void) {
111 unsigned int i; 220 unsigned int i;
112 221
113 if(gettextprop(root, dwmprops, prop, sizeof prop)) { 222 if(gettextprop(root, dwmprops, prop, sizeof prop)) {
@@ -156,19 +265,6 @@ restack(void) {
156} 265}
157 266
158void 267void
159savedwmprops(void) {
160 unsigned int i;
161
162 for(i = 0; i < ntags && i < sizeof prop - 1; i++)
163 prop[i] = seltags[i] ? '1' : '0';
164 if(i < sizeof prop - 1)
165 prop[i++] = (char)ltidx;
166 prop[i] = '\0';
167 XChangeProperty(dpy, root, dwmprops, XA_STRING, 8,
168 PropModeReplace, (unsigned char *)prop, i);
169}
170
171void
172setlayout(const char *arg) { 268setlayout(const char *arg) {
173 int i; 269 int i;
174 270
@@ -186,7 +282,22 @@ setlayout(const char *arg) {
186 arrange(); 282 arrange();
187 else 283 else
188 drawstatus(); 284 drawstatus();
189 savedwmprops(); 285 setdwmprops();
286}
287
288void
289tag(const char *arg) {
290 unsigned int i;
291
292 if(!sel)
293 return;
294 for(i = 0; i < ntags; i++)
295 sel->tags[i] = arg == NULL;
296 i = idxoftag(arg);
297 if(i >= 0 && i < ntags)
298 sel->tags[i] = True;
299 setprops(sel);
300 arrange();
190} 301}
191 302
192void 303void
@@ -200,6 +311,18 @@ togglebar(const char *arg) {
200} 311}
201 312
202void 313void
314togglefloating(const char *arg) {
315 if(!sel || isfloating())
316 return;
317 sel->isfloating = !sel->isfloating;
318 if(sel->isfloating) {
319 resize(sel, sel->x, sel->y, sel->w, sel->h, True);
320 setprops(sel);
321 }
322 arrange();
323}
324
325void
203togglemax(const char *arg) { 326togglemax(const char *arg) {
204 XEvent ev; 327 XEvent ev;
205 328
@@ -217,3 +340,44 @@ togglemax(const char *arg) {
217 drawstatus(); 340 drawstatus();
218 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev)); 341 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
219} 342}
343
344void
345toggletag(const char *arg) {
346 unsigned int i, j;
347
348 if(!sel)
349 return;
350 i = idxoftag(arg);
351 sel->tags[i] = !sel->tags[i];
352 for(j = 0; j < ntags && !sel->tags[j]; j++);
353 if(j == ntags)
354 sel->tags[i] = True;
355 setprops(sel);
356 arrange();
357}
358
359void
360toggleview(const char *arg) {
361 unsigned int i, j;
362
363 i = idxoftag(arg);
364 seltags[i] = !seltags[i];
365 for(j = 0; j < ntags && !seltags[j]; j++);
366 if(j == ntags)
367 seltags[i] = True; /* cannot toggle last view */
368 setdwmprops();
369 arrange();
370}
371
372void
373view(const char *arg) {
374 unsigned int i;
375
376 for(i = 0; i < ntags; i++)
377 seltags[i] = arg == NULL;
378 i = idxoftag(arg);
379 if(i >= 0 && i < ntags)
380 seltags[i] = True;
381 setdwmprops();
382 arrange();
383}
diff --git a/tag.c b/tag.c
deleted file mode 100644
index 685308a..0000000
--- a/tag.c
+++ /dev/null
@@ -1,174 +0,0 @@
1/* See LICENSE file for copyright and license details. */
2#include "dwm.h"
3#include <regex.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <X11/Xutil.h>
7
8/* static */
9
10typedef struct {
11 const char *prop;
12 const char *tags;
13 Bool isfloating;
14} Rule;
15
16typedef struct {
17 regex_t *propregex;
18 regex_t *tagregex;
19} Regs;
20
21TAGS
22RULES
23
24static Regs *regs = NULL;
25static unsigned int nrules = 0;
26static char prop[512];
27
28static unsigned int
29idxoftag(const char *tag) {
30 unsigned int i;
31
32 for(i = 0; i < ntags; i++)
33 if(tags[i] == tag)
34 return i;
35 return 0;
36}
37
38/* extern */
39
40void
41applyrules(Client *c) {
42 unsigned int i, j;
43 regmatch_t tmp;
44 Bool matched = False;
45 XClassHint ch = { 0 };
46
47 /* rule matching */
48 XGetClassHint(dpy, c->win, &ch);
49 snprintf(prop, sizeof prop, "%s:%s:%s",
50 ch.res_class ? ch.res_class : "",
51 ch.res_name ? ch.res_name : "", c->name);
52 for(i = 0; i < nrules; i++)
53 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
54 c->isfloating = rules[i].isfloating;
55 for(j = 0; regs[i].tagregex && j < ntags; j++) {
56 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
57 matched = True;
58 c->tags[j] = True;
59 }
60 }
61 }
62 if(ch.res_class)
63 XFree(ch.res_class);
64 if(ch.res_name)
65 XFree(ch.res_name);
66 if(!matched)
67 for(i = 0; i < ntags; i++)
68 c->tags[i] = seltags[i];
69}
70
71void
72compileregs(void) {
73 unsigned int i;
74 regex_t *reg;
75
76 if(regs)
77 return;
78 nrules = sizeof rules / sizeof rules[0];
79 regs = emallocz(nrules * sizeof(Regs));
80 for(i = 0; i < nrules; i++) {
81 if(rules[i].prop) {
82 reg = emallocz(sizeof(regex_t));
83 if(regcomp(reg, rules[i].prop, REG_EXTENDED))
84 free(reg);
85 else
86 regs[i].propregex = reg;
87 }
88 if(rules[i].tags) {
89 reg = emallocz(sizeof(regex_t));
90 if(regcomp(reg, rules[i].tags, REG_EXTENDED))
91 free(reg);
92 else
93 regs[i].tagregex = reg;
94 }
95 }
96}
97
98Bool
99isvisible(Client *c) {
100 unsigned int i;
101
102 for(i = 0; i < ntags; i++)
103 if(c->tags[i] && seltags[i])
104 return True;
105 return False;
106}
107
108void
109tag(const char *arg) {
110 unsigned int i;
111
112 if(!sel)
113 return;
114 for(i = 0; i < ntags; i++)
115 sel->tags[i] = arg == NULL;
116 i = idxoftag(arg);
117 if(i >= 0 && i < ntags)
118 sel->tags[i] = True;
119 saveprops(sel);
120 arrange();
121}
122
123void
124togglefloating(const char *arg) {
125 if(!sel || isfloating())
126 return;
127 sel->isfloating = !sel->isfloating;
128 if(sel->isfloating) {
129 resize(sel, sel->x, sel->y, sel->w, sel->h, True);
130 saveprops(sel);
131 }
132 arrange();
133}
134
135void
136toggletag(const char *arg) {
137 unsigned int i, j;
138
139 if(!sel)
140 return;
141 i = idxoftag(arg);
142 sel->tags[i] = !sel->tags[i];
143 for(j = 0; j < ntags && !sel->tags[j]; j++);
144 if(j == ntags)
145 sel->tags[i] = True;
146 saveprops(sel);
147 arrange();
148}
149
150void
151toggleview(const char *arg) {
152 unsigned int i, j;
153
154 i = idxoftag(arg);
155 seltags[i] = !seltags[i];
156 for(j = 0; j < ntags && !seltags[j]; j++);
157 if(j == ntags)
158 seltags[i] = True; /* cannot toggle last view */
159 savedwmprops();
160 arrange();
161}
162
163void
164view(const char *arg) {
165 unsigned int i;
166
167 for(i = 0; i < ntags; i++)
168 seltags[i] = arg == NULL;
169 i = idxoftag(arg);
170 if(i >= 0 && i < ntags)
171 seltags[i] = True;
172 savedwmprops();
173 arrange();
174}