summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@suckless.org>2007-02-20 10:49:53 +0100
committerAnselm R. Garbe <arg@suckless.org>2007-02-20 10:49:53 +0100
commit8012fcf3334148d2b39646fd372a7514cc74c250 (patch)
tree157855dd25044e50f7696eb57655c88c6069ac2e
parentusing eprint instead of fputs (diff)
downloaddwm-8012fcf3334148d2b39646fd372a7514cc74c250.tar.gz
dwm-8012fcf3334148d2b39646fd372a7514cc74c250.zip
split screen.c into layout.c and tag.c (because the view is an implicit mixture of both)
-rw-r--r--Makefile2
-rw-r--r--dwm.h18
-rw-r--r--layout.c (renamed from screen.c)143
-rw-r--r--tag.c149
4 files changed, 160 insertions, 152 deletions
diff --git a/Makefile b/Makefile
index 221efa4..4af6a3d 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
3 3
4include config.mk 4include config.mk
5 5
6SRC = client.c event.c main.c screen.c util.c 6SRC = client.c event.c layout.c main.c tag.c util.c
7OBJ = ${SRC:.c=.o} 7OBJ = ${SRC:.c=.o}
8 8
9all: options dwm 9all: options dwm
diff --git a/dwm.h b/dwm.h
index d4cc1fa..822f959 100644
--- a/dwm.h
+++ b/dwm.h
@@ -120,6 +120,15 @@ extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is
120/* event.c */ 120/* event.c */
121extern void grabkeys(void); /* grab all keys defined in config.h */ 121extern void grabkeys(void); /* grab all keys defined in config.h */
122 122
123/* layout.c */
124extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */
125extern void initlayouts(void); /* initialize layout array */
126extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */
127extern void restack(void); /* restores z layers of all clients */
128extern void setlayout(Arg *arg); /* sets layout, -1 toggles */
129extern void toggleversatile(Arg *arg); /* toggles focusesd client between versatile/and non-versatile state */
130extern void versatile(void); /* arranges all windows versatile */
131
123/* main.c */ 132/* main.c */
124extern void drawstatus(void); /* draw the bar */ 133extern void drawstatus(void); /* draw the bar */
125extern unsigned int textw(const char *text); /* return the width of text in px*/ 134extern unsigned int textw(const char *text); /* return the width of text in px*/
@@ -127,20 +136,13 @@ extern void quit(Arg *arg); /* quit dwm nicely */
127extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ 136extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */
128extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ 137extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */
129 138
130/* screen.c */ 139/* tag.c */
131extern void compileregs(void); /* initialize regexps of rules defined in config.h */ 140extern void compileregs(void); /* initialize regexps of rules defined in config.h */
132extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */
133extern void initlayouts(void); /* initialize layout array */
134extern Bool isvisible(Client *c); /* returns True if client is visible */ 141extern Bool isvisible(Client *c); /* returns True if client is visible */
135extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */
136extern void restack(void); /* restores z layers of all clients */
137extern void setlayout(Arg *arg); /* sets layout, -1 toggles */
138extern void settags(Client *c, Client *trans); /* sets tags of c */ 142extern void settags(Client *c, Client *trans); /* sets tags of c */
139extern void tag(Arg *arg); /* tags c with arg's index */ 143extern void tag(Arg *arg); /* tags c with arg's index */
140extern void toggleversatile(Arg *arg); /* toggles focusesd client between versatile/and non-versatile state */
141extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ 144extern void toggletag(Arg *arg); /* toggles c tags with arg's index */
142extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */ 145extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */
143extern void versatile(void); /* arranges all windows versatile */
144extern void view(Arg *arg); /* views the tag with arg's index */ 146extern void view(Arg *arg); /* views the tag with arg's index */
145 147
146/* util.c */ 148/* util.c */
diff --git a/screen.c b/layout.c
index 8abe3d7..d754afb 100644
--- a/screen.c
+++ b/layout.c
@@ -2,12 +2,6 @@
2 * See LICENSE file for license details. 2 * See LICENSE file for license details.
3 */ 3 */
4#include "dwm.h" 4#include "dwm.h"
5#include <regex.h>
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <sys/types.h>
10#include <X11/Xutil.h>
11 5
12unsigned int master = MASTER; 6unsigned int master = MASTER;
13unsigned int nmaster = NMASTER; 7unsigned int nmaster = NMASTER;
@@ -16,22 +10,6 @@ Layout *lt = NULL;
16 10
17/* static */ 11/* static */
18 12
19typedef struct {
20 const char *prop;
21 const char *tags;
22 Bool isversatile;
23} Rule;
24
25typedef struct {
26 regex_t *propregex;
27 regex_t *tagregex;
28} Regs;
29
30TAGS
31RULES
32
33static Regs *regs = NULL;
34static unsigned int nrules = 0;
35static unsigned int nlayouts = 0; 13static unsigned int nlayouts = 0;
36 14
37static void 15static void
@@ -91,33 +69,6 @@ LAYOUTS
91/* extern */ 69/* extern */
92 70
93void 71void
94compileregs(void) {
95 unsigned int i;
96 regex_t *reg;
97
98 if(regs)
99 return;
100 nrules = sizeof rule / sizeof rule[0];
101 regs = emallocz(nrules * sizeof(Regs));
102 for(i = 0; i < nrules; i++) {
103 if(rule[i].prop) {
104 reg = emallocz(sizeof(regex_t));
105 if(regcomp(reg, rule[i].prop, REG_EXTENDED))
106 free(reg);
107 else
108 regs[i].propregex = reg;
109 }
110 if(rule[i].tags) {
111 reg = emallocz(sizeof(regex_t));
112 if(regcomp(reg, rule[i].tags, REG_EXTENDED))
113 free(reg);
114 else
115 regs[i].tagregex = reg;
116 }
117 }
118}
119
120void
121incnmaster(Arg *arg) { 72incnmaster(Arg *arg) {
122 if((lt->arrange != tile) || (nmaster + arg->i < 1) 73 if((lt->arrange != tile) || (nmaster + arg->i < 1)
123 || (wah / (nmaster + arg->i) <= 2 * BORDERPX)) 74 || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
@@ -142,16 +93,6 @@ initlayouts(void) {
142 } 93 }
143} 94}
144 95
145Bool
146isvisible(Client *c) {
147 unsigned int i;
148
149 for(i = 0; i < ntags; i++)
150 if(c->tags[i] && seltag[i])
151 return True;
152 return False;
153}
154
155void 96void
156resizemaster(Arg *arg) { 97resizemaster(Arg *arg) {
157 if(lt->arrange != tile) 98 if(lt->arrange != tile)
@@ -213,68 +154,6 @@ setlayout(Arg *arg) {
213} 154}
214 155
215void 156void
216settags(Client *c, Client *trans) {
217 char prop[512];
218 unsigned int i, j;
219 regmatch_t tmp;
220 Bool matched = trans != NULL;
221 XClassHint ch = { 0 };
222
223 if(matched)
224 for(i = 0; i < ntags; i++)
225 c->tags[i] = trans->tags[i];
226 else {
227 XGetClassHint(dpy, c->win, &ch);
228 snprintf(prop, sizeof prop, "%s:%s:%s",
229 ch.res_class ? ch.res_class : "",
230 ch.res_name ? ch.res_name : "", c->name);
231 for(i = 0; i < nrules; i++)
232 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
233 c->isversatile = rule[i].isversatile;
234 for(j = 0; regs[i].tagregex && j < ntags; j++) {
235 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
236 matched = True;
237 c->tags[j] = True;
238 }
239 }
240 }
241 if(ch.res_class)
242 XFree(ch.res_class);
243 if(ch.res_name)
244 XFree(ch.res_name);
245 }
246 if(!matched)
247 for(i = 0; i < ntags; i++)
248 c->tags[i] = seltag[i];
249}
250
251void
252tag(Arg *arg) {
253 unsigned int i;
254
255 if(!sel)
256 return;
257 for(i = 0; i < ntags; i++)
258 sel->tags[i] = (arg->i == -1) ? True : False;
259 if(arg->i >= 0 && arg->i < ntags)
260 sel->tags[arg->i] = True;
261 lt->arrange();
262}
263
264void
265toggletag(Arg *arg) {
266 unsigned int i;
267
268 if(!sel)
269 return;
270 sel->tags[arg->i] = !sel->tags[arg->i];
271 for(i = 0; i < ntags && !sel->tags[i]; i++);
272 if(i == ntags)
273 sel->tags[arg->i] = True;
274 lt->arrange();
275}
276
277void
278toggleversatile(Arg *arg) { 157toggleversatile(Arg *arg) {
279 if(!sel || lt->arrange == versatile) 158 if(!sel || lt->arrange == versatile)
280 return; 159 return;
@@ -283,17 +162,6 @@ toggleversatile(Arg *arg) {
283} 162}
284 163
285void 164void
286toggleview(Arg *arg) {
287 unsigned int i;
288
289 seltag[arg->i] = !seltag[arg->i];
290 for(i = 0; i < ntags && !seltag[i]; i++);
291 if(i == ntags)
292 seltag[arg->i] = True; /* cannot toggle last view */
293 lt->arrange();
294}
295
296void
297versatile(void) { 165versatile(void) {
298 Client *c; 166 Client *c;
299 167
@@ -315,14 +183,3 @@ versatile(void) {
315 } 183 }
316 restack(); 184 restack();
317} 185}
318
319void
320view(Arg *arg) {
321 unsigned int i;
322
323 for(i = 0; i < ntags; i++)
324 seltag[i] = (arg->i == -1) ? True : False;
325 if(arg->i >= 0 && arg->i < ntags)
326 seltag[arg->i] = True;
327 lt->arrange();
328}
diff --git a/tag.c b/tag.c
new file mode 100644
index 0000000..f54ac3f
--- /dev/null
+++ b/tag.c
@@ -0,0 +1,149 @@
1/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
2 * See LICENSE file for license details.
3 */
4#include "dwm.h"
5#include <regex.h>
6#include <stdio.h>
7#include <X11/Xutil.h>
8
9/* static */
10
11typedef struct {
12 const char *prop;
13 const char *tags;
14 Bool isversatile;
15} Rule;
16
17typedef struct {
18 regex_t *propregex;
19 regex_t *tagregex;
20} Regs;
21
22TAGS
23RULES
24
25static Regs *regs = NULL;
26static unsigned int nrules = 0;
27
28/* extern */
29
30void
31compileregs(void) {
32 unsigned int i;
33 regex_t *reg;
34
35 if(regs)
36 return;
37 nrules = sizeof rule / sizeof rule[0];
38 regs = emallocz(nrules * sizeof(Regs));
39 for(i = 0; i < nrules; i++) {
40 if(rule[i].prop) {
41 reg = emallocz(sizeof(regex_t));
42 if(regcomp(reg, rule[i].prop, REG_EXTENDED))
43 free(reg);
44 else
45 regs[i].propregex = reg;
46 }
47 if(rule[i].tags) {
48 reg = emallocz(sizeof(regex_t));
49 if(regcomp(reg, rule[i].tags, REG_EXTENDED))
50 free(reg);
51 else
52 regs[i].tagregex = reg;
53 }
54 }
55}
56
57Bool
58isvisible(Client *c) {
59 unsigned int i;
60
61 for(i = 0; i < ntags; i++)
62 if(c->tags[i] && seltag[i])
63 return True;
64 return False;
65}
66
67void
68settags(Client *c, Client *trans) {
69 char prop[512];
70 unsigned int i, j;
71 regmatch_t tmp;
72 Bool matched = trans != NULL;
73 XClassHint ch = { 0 };
74
75 if(matched)
76 for(i = 0; i < ntags; i++)
77 c->tags[i] = trans->tags[i];
78 else {
79 XGetClassHint(dpy, c->win, &ch);
80 snprintf(prop, sizeof prop, "%s:%s:%s",
81 ch.res_class ? ch.res_class : "",
82 ch.res_name ? ch.res_name : "", c->name);
83 for(i = 0; i < nrules; i++)
84 if(regs[i].propregex && !regexec(regs[i].propregex, prop, 1, &tmp, 0)) {
85 c->isversatile = rule[i].isversatile;
86 for(j = 0; regs[i].tagregex && j < ntags; j++) {
87 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
88 matched = True;
89 c->tags[j] = True;
90 }
91 }
92 }
93 if(ch.res_class)
94 XFree(ch.res_class);
95 if(ch.res_name)
96 XFree(ch.res_name);
97 }
98 if(!matched)
99 for(i = 0; i < ntags; i++)
100 c->tags[i] = seltag[i];
101}
102
103void
104tag(Arg *arg) {
105 unsigned int i;
106
107 if(!sel)
108 return;
109 for(i = 0; i < ntags; i++)
110 sel->tags[i] = (arg->i == -1) ? True : False;
111 if(arg->i >= 0 && arg->i < ntags)
112 sel->tags[arg->i] = True;
113 lt->arrange();
114}
115
116void
117toggletag(Arg *arg) {
118 unsigned int i;
119
120 if(!sel)
121 return;
122 sel->tags[arg->i] = !sel->tags[arg->i];
123 for(i = 0; i < ntags && !sel->tags[i]; i++);
124 if(i == ntags)
125 sel->tags[arg->i] = True;
126 lt->arrange();
127}
128
129void
130toggleview(Arg *arg) {
131 unsigned int i;
132
133 seltag[arg->i] = !seltag[arg->i];
134 for(i = 0; i < ntags && !seltag[i]; i++);
135 if(i == ntags)
136 seltag[arg->i] = True; /* cannot toggle last view */
137 lt->arrange();
138}
139
140void
141view(Arg *arg) {
142 unsigned int i;
143
144 for(i = 0; i < ntags; i++)
145 seltag[i] = (arg->i == -1) ? True : False;
146 if(arg->i >= 0 && arg->i < ntags)
147 seltag[arg->i] = True;
148 lt->arrange();
149}