summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@suckless.org>2007-02-19 13:00:29 +0100
committerAnselm R. Garbe <arg@suckless.org>2007-02-19 13:00:29 +0100
commit5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63 (patch)
tree2025c7842831bd512df4816717e5e47160f99f7c
parentsimplified configurerequest to a bare minimum, removed wrong ban() calls (diff)
downloaddwm-5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63.tar.gz
dwm-5cc27f1b3c61df4f048cdac9e0feb31a2dd80c63.zip
introduced tile.c, some refactoring of functions
Diffstat (limited to '')
-rw-r--r--Makefile2
-rw-r--r--config.arg.h2
-rw-r--r--config.default.h2
-rw-r--r--dwm.h13
-rw-r--r--main.c2
-rw-r--r--tag.c2
-rw-r--r--tile.c132
-rw-r--r--view.c136
8 files changed, 150 insertions, 141 deletions
diff --git a/Makefile b/Makefile
index e337ec2..18626a7 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 main.c tag.c util.c view.c 6SRC = client.c draw.c event.c main.c tile.c tag.c util.c view.c
7OBJ = ${SRC:.c=.o} 7OBJ = ${SRC:.c=.o}
8 8
9all: options dwm 9all: options dwm
diff --git a/config.arg.h b/config.arg.h
index 2b94fd6..fae30d0 100644
--- a/config.arg.h
+++ b/config.arg.h
@@ -5,11 +5,11 @@
5#define TAGS \ 5#define TAGS \
6const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; 6const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
7 7
8#define BORDERPX 1
9#define DEFMODE dotile /* dofloat */ 8#define DEFMODE dotile /* dofloat */
10#define FLOATSYMBOL "><>" 9#define FLOATSYMBOL "><>"
11#define TILESYMBOL "[]=" 10#define TILESYMBOL "[]="
12 11
12#define BORDERPX 1
13#define FONT "-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*" 13#define FONT "-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
14#define NORMBORDERCOLOR "#333" 14#define NORMBORDERCOLOR "#333"
15#define NORMBGCOLOR "#222" 15#define NORMBGCOLOR "#222"
diff --git a/config.default.h b/config.default.h
index b8654bd..c1274a1 100644
--- a/config.default.h
+++ b/config.default.h
@@ -5,11 +5,11 @@
5#define TAGS \ 5#define TAGS \
6const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL }; 6const char *tags[] = { "1", "2", "3", "4", "5", "6", "7", "8", "9", NULL };
7 7
8#define BORDERPX 1
9#define DEFMODE dotile /* dofloat */ 8#define DEFMODE dotile /* dofloat */
10#define FLOATSYMBOL "><>" 9#define FLOATSYMBOL "><>"
11#define TILESYMBOL "[]=" 10#define TILESYMBOL "[]="
12 11
12#define BORDERPX 1
13#define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*" 13#define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*"
14#define NORMBORDERCOLOR "#dddddd" 14#define NORMBORDERCOLOR "#dddddd"
15#define NORMBGCOLOR "#eeeeee" 15#define NORMBGCOLOR "#eeeeee"
diff --git a/dwm.h b/dwm.h
index 43b3730..c07229a 100644
--- a/dwm.h
+++ b/dwm.h
@@ -127,11 +127,17 @@ extern void sendevent(Window w, Atom a, long value); /* send synthetic event to
127extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ 127extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */
128 128
129/* tag.c */ 129/* tag.c */
130extern void initrregs(void); /* initialize regexps of rules defined in config.h */ 130extern void compileregexps(void); /* initialize regexps of rules defined in config.h */
131extern void settags(Client *c, Client *trans); /* sets tags of c */ 131extern void settags(Client *c, Client *trans); /* sets tags of c */
132extern void tag(Arg *arg); /* tags c with arg's index */ 132extern void tag(Arg *arg); /* tags c with arg's index */
133extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ 133extern void toggletag(Arg *arg); /* toggles c tags with arg's index */
134 134
135/* tile.c */
136extern void dotile(void); /* arranges all windows tiled */
137extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */
138extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */
139extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */
140
135/* util.c */ 141/* util.c */
136extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ 142extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */
137extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ 143extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
@@ -140,15 +146,12 @@ extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */
140/* view.c */ 146/* view.c */
141extern void detach(Client *c); /* detaches c from global client list */ 147extern void detach(Client *c); /* detaches c from global client list */
142extern void dofloat(void); /* arranges all windows floating */ 148extern void dofloat(void); /* arranges all windows floating */
143extern void dotile(void); /* arranges all windows tiled */
144extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ 149extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */
145extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ 150extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */
146extern void incnmaster(Arg *arg); /* increments nmaster with arg's index value */
147extern Bool isvisible(Client *c); /* returns True if client is visible */ 151extern Bool isvisible(Client *c); /* returns True if client is visible */
148extern void resizemaster(Arg *arg); /* resizes the master percent with arg's index value */ 152extern Client *nextmanaged(Client *c); /* returns managed successor of c */
149extern void restack(void); /* restores z layers of all clients */ 153extern void restack(void); /* restores z layers of all clients */
150extern void togglefloat(Arg *arg); /* toggles focusesd client between floating/non-floating state */ 154extern void togglefloat(Arg *arg); /* toggles focusesd client between floating/non-floating state */
151extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */ 155extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/dofloat) */
152extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */ 156extern void toggleview(Arg *arg); /* toggles the tag with arg's index (in)visible */
153extern void view(Arg *arg); /* views the tag with arg's index */ 157extern void view(Arg *arg); /* views the tag with arg's index */
154extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */
diff --git a/main.c b/main.c
index 5ed8981..bd19e49 100644
--- a/main.c
+++ b/main.c
@@ -117,7 +117,7 @@ setup(void) {
117 wa.cursor = cursor[CurNormal]; 117 wa.cursor = cursor[CurNormal];
118 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); 118 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
119 grabkeys(); 119 grabkeys();
120 initrregs(); 120 compileregexps();
121 for(ntags = 0; tags[ntags]; ntags++); 121 for(ntags = 0; tags[ntags]; ntags++);
122 seltag = emallocz(sizeof(Bool) * ntags); 122 seltag = emallocz(sizeof(Bool) * ntags);
123 seltag[0] = True; 123 seltag[0] = True;
diff --git a/tag.c b/tag.c
index a6db1d5..d3065d5 100644
--- a/tag.c
+++ b/tag.c
@@ -32,7 +32,7 @@ static unsigned int len = 0;
32/* extern */ 32/* extern */
33 33
34void 34void
35initrregs(void) { 35compileregexps(void) {
36 unsigned int i; 36 unsigned int i;
37 regex_t *reg; 37 regex_t *reg;
38 38
diff --git a/tile.c b/tile.c
new file mode 100644
index 0000000..a9bc0f5
--- /dev/null
+++ b/tile.c
@@ -0,0 +1,132 @@
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
6/* static */
7
8static void
9togglemax(Client *c) {
10 XEvent ev;
11
12 if(c->isfixed)
13 return;
14
15 if((c->ismax = !c->ismax)) {
16 c->rx = c->x;
17 c->ry = c->y;
18 c->rw = c->w;
19 c->rh = c->h;
20 resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
21 }
22 else
23 resize(c, c->rx, c->ry, c->rw, c->rh, True);
24 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
25}
26
27/* extern */
28
29void
30dotile(void) {
31 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
32 Client *c;
33
34 for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
35 n++;
36 /* window geoms */
37 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
38 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
39 th = (n > nmaster) ? wah / (n - nmaster) : 0;
40 tw = waw - mw;
41
42 for(i = 0, c = clients; c; c = c->next)
43 if(isvisible(c)) {
44 if(c->isbanned)
45 XMoveWindow(dpy, c->win, c->x, c->y);
46 c->isbanned = False;
47 if(c->isfloat)
48 continue;
49 c->ismax = False;
50 nx = wax;
51 ny = way;
52 if(i < nmaster) {
53 ny += i * mh;
54 nw = mw - 2 * BORDERPX;
55 nh = mh - 2 * BORDERPX;
56 }
57 else { /* tile window */
58 nx += mw;
59 nw = tw - 2 * BORDERPX;
60 if(th > 2 * BORDERPX) {
61 ny += (i - nmaster) * th;
62 nh = th - 2 * BORDERPX;
63 }
64 else /* fallback if th <= 2 * BORDERPX */
65 nh = wah - 2 * BORDERPX;
66 }
67 resize(c, nx, ny, nw, nh, False);
68 i++;
69 }
70 else {
71 c->isbanned = True;
72 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
73 }
74 if(!sel || !isvisible(sel)) {
75 for(c = stack; c && !isvisible(c); c = c->snext);
76 focus(c);
77 }
78 restack();
79}
80
81void
82incnmaster(Arg *arg) {
83 if((arrange == dofloat) || (nmaster + arg->i < 1)
84 || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
85 return;
86 nmaster += arg->i;
87 if(sel)
88 arrange();
89 else
90 drawstatus();
91}
92
93void
94resizemaster(Arg *arg) {
95 if(arrange != dotile)
96 return;
97 if(arg->i == 0)
98 master = MASTER;
99 else {
100 if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
101 || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
102 return;
103 master += arg->i;
104 }
105 arrange();
106}
107
108void
109zoom(Arg *arg) {
110 unsigned int n;
111 Client *c;
112
113 if(!sel)
114 return;
115 if(sel->isfloat || (arrange == dofloat)) {
116 togglemax(sel);
117 return;
118 }
119 for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
120 n++;
121
122 if((c = sel) == nextmanaged(clients))
123 if(!(c = nextmanaged(c->next)))
124 return;
125 detach(c);
126 if(clients)
127 clients->prev = c;
128 c->next = clients;
129 clients = c;
130 focus(c);
131 arrange();
132}
diff --git a/view.c b/view.c
index 66f550c..72aa04e 100644
--- a/view.c
+++ b/view.c
@@ -2,34 +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 <stdio.h>
6
7/* static */
8
9static Client *
10nexttiled(Client *c) {
11 for(; c && (c->isfloat || !isvisible(c)); c = c->next);
12 return c;
13}
14
15static void
16togglemax(Client *c) {
17 XEvent ev;
18
19 if(c->isfixed)
20 return;
21
22 if((c->ismax = !c->ismax)) {
23 c->rx = c->x;
24 c->ry = c->y;
25 c->rw = c->w;
26 c->rh = c->h;
27 resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
28 }
29 else
30 resize(c, c->rx, c->ry, c->rw, c->rh, True);
31 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
32}
33 5
34/* extern */ 6/* extern */
35 7
@@ -70,58 +42,6 @@ dofloat(void) {
70} 42}
71 43
72void 44void
73dotile(void) {
74 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
75 Client *c;
76
77 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
78 n++;
79 /* window geoms */
80 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
81 mw = (n > nmaster) ? (waw * master) / 1000 : waw;
82 th = (n > nmaster) ? wah / (n - nmaster) : 0;
83 tw = waw - mw;
84
85 for(i = 0, c = clients; c; c = c->next)
86 if(isvisible(c)) {
87 if(c->isbanned)
88 XMoveWindow(dpy, c->win, c->x, c->y);
89 c->isbanned = False;
90 if(c->isfloat)
91 continue;
92 c->ismax = False;
93 nx = wax;
94 ny = way;
95 if(i < nmaster) {
96 ny += i * mh;
97 nw = mw - 2 * BORDERPX;
98 nh = mh - 2 * BORDERPX;
99 }
100 else { /* tile window */
101 nx += mw;
102 nw = tw - 2 * BORDERPX;
103 if(th > 2 * BORDERPX) {
104 ny += (i - nmaster) * th;
105 nh = th - 2 * BORDERPX;
106 }
107 else /* fallback if th <= 2 * BORDERPX */
108 nh = wah - 2 * BORDERPX;
109 }
110 resize(c, nx, ny, nw, nh, False);
111 i++;
112 }
113 else {
114 c->isbanned = True;
115 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
116 }
117 if(!sel || !isvisible(sel)) {
118 for(c = stack; c && !isvisible(c); c = c->snext);
119 focus(c);
120 }
121 restack();
122}
123
124void
125focusnext(Arg *arg) { 45focusnext(Arg *arg) {
126 Client *c; 46 Client *c;
127 47
@@ -153,18 +73,6 @@ focusprev(Arg *arg) {
153 } 73 }
154} 74}
155 75
156void
157incnmaster(Arg *arg) {
158 if((arrange == dofloat) || (nmaster + arg->i < 1)
159 || (wah / (nmaster + arg->i) <= 2 * BORDERPX))
160 return;
161 nmaster += arg->i;
162 if(sel)
163 arrange();
164 else
165 drawstatus();
166}
167
168Bool 76Bool
169isvisible(Client *c) { 77isvisible(Client *c) {
170 unsigned int i; 78 unsigned int i;
@@ -175,19 +83,10 @@ isvisible(Client *c) {
175 return False; 83 return False;
176} 84}
177 85
178void 86Client *
179resizemaster(Arg *arg) { 87nextmanaged(Client *c) {
180 if(arrange != dotile) 88 for(; c && (c->isfloat || !isvisible(c)); c = c->next);
181 return; 89 return c;
182 if(arg->i == 0)
183 master = MASTER;
184 else {
185 if(waw * (master + arg->i) / 1000 >= waw - 2 * BORDERPX
186 || waw * (master + arg->i) / 1000 <= 2 * BORDERPX)
187 return;
188 master += arg->i;
189 }
190 arrange();
191} 90}
192 91
193void 92void
@@ -203,7 +102,7 @@ restack(void) {
203 if(arrange != dofloat) { 102 if(arrange != dofloat) {
204 if(!sel->isfloat) 103 if(!sel->isfloat)
205 XLowerWindow(dpy, sel->win); 104 XLowerWindow(dpy, sel->win);
206 for(c = nexttiled(clients); c; c = nexttiled(c->next)) { 105 for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) {
207 if(c == sel) 106 if(c == sel)
208 continue; 107 continue;
209 XLowerWindow(dpy, c->win); 108 XLowerWindow(dpy, c->win);
@@ -252,28 +151,3 @@ view(Arg *arg) {
252 arrange(); 151 arrange();
253} 152}
254 153
255void
256zoom(Arg *arg) {
257 unsigned int n;
258 Client *c;
259
260 if(!sel)
261 return;
262 if(sel->isfloat || (arrange == dofloat)) {
263 togglemax(sel);
264 return;
265 }
266 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
267 n++;
268
269 if((c = sel) == nexttiled(clients))
270 if(!(c = nexttiled(c->next)))
271 return;
272 detach(c);
273 if(clients)
274 clients->prev = c;
275 c->next = clients;
276 clients = c;
277 focus(c);
278 arrange();
279}