summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--client.c6
-rw-r--r--config.arg.h13
-rw-r--r--config.default.h13
-rw-r--r--dwm.122
-rw-r--r--dwm.h7
-rw-r--r--event.c4
-rw-r--r--layout.c214
-rw-r--r--tag.c8
8 files changed, 90 insertions, 197 deletions
diff --git a/client.c b/client.c
index d4dfe6e..08fe1bd 100644
--- a/client.c
+++ b/client.c
@@ -230,7 +230,7 @@ manage(Window w, XWindowAttributes *wa) {
230 setclientstate(c, IconicState); 230 setclientstate(c, IconicState);
231 c->isbanned = True; 231 c->isbanned = True;
232 focus(c); 232 focus(c);
233 lt->arrange(); 233 lt->arrange(NULL);
234} 234}
235 235
236void 236void
@@ -305,7 +305,7 @@ togglefloating(const char *arg) {
305 sel->isfloating = !sel->isfloating; 305 sel->isfloating = !sel->isfloating;
306 if(sel->isfloating) 306 if(sel->isfloating)
307 resize(sel, sel->x, sel->y, sel->w, sel->h, True); 307 resize(sel, sel->x, sel->y, sel->w, sel->h, True);
308 lt->arrange(); 308 lt->arrange(NULL);
309} 309}
310 310
311void 311void
@@ -337,7 +337,7 @@ unmanage(Client *c) {
337 XSync(dpy, False); 337 XSync(dpy, False);
338 XSetErrorHandler(xerror); 338 XSetErrorHandler(xerror);
339 XUngrabServer(dpy); 339 XUngrabServer(dpy);
340 lt->arrange(); 340 lt->arrange(NULL);
341} 341}
342 342
343void 343void
diff --git a/config.arg.h b/config.arg.h
index d5994b2..4d441f8 100644
--- a/config.arg.h
+++ b/config.arg.h
@@ -24,15 +24,14 @@ static Rule rule[] = { \
24}; 24};
25 25
26/* layout(s) */ 26/* layout(s) */
27void tile(const char *arg); /* arranges all windows tiled */
27#define LAYOUTS \ 28#define LAYOUTS \
28static Layout layout[] = { \ 29static Layout layout[] = { \
29 /* symbol function */ \ 30 /* symbol function */ \
30 { "[]=", tile }, /* first entry is default */ \ 31 { "[]=", tile }, /* first entry is default */ \
31 { "><>", floating }, \ 32 { "><>", floating }, \
32}; 33};
33#define NMASTER 1 /* clients in master area */ 34#define MASTER 0.6 /* 0.1 .. 0.9 */
34#define HRATIO .8 /* horizontal ratio of tile */
35#define VRATIO .9 /* vertical ratio of tile */
36#define SNAP 32 /* snap pixel */ 35#define SNAP 32 /* snap pixel */
37 36
38/* key definitions */ 37/* key definitions */
@@ -47,14 +46,10 @@ static Key key[] = { \
47 "exec urxvtcd -tr -bg '#111' -fg '#eee' -cr '#eee' +sb -fn '"FONT"'" }, \ 46 "exec urxvtcd -tr -bg '#111' -fg '#eee' -cr '#eee' +sb -fn '"FONT"'" }, \
48 { MODKEY, XK_space, setlayout, NULL }, \ 47 { MODKEY, XK_space, setlayout, NULL }, \
49 { MODKEY, XK_b, togglebar, NULL }, \ 48 { MODKEY, XK_b, togglebar, NULL }, \
50 { MODKEY, XK_h, incnmaster, "1" }, \ 49 { MODKEY, XK_h, tile, "-0.05" }, \
51 { MODKEY, XK_l, incnmaster, "-1" }, \
52 { MODKEY, XK_j, focusclient, "1" }, \ 50 { MODKEY, XK_j, focusclient, "1" }, \
53 { MODKEY, XK_k, focusclient, "-1" }, \ 51 { MODKEY, XK_k, focusclient, "-1" }, \
54 { MODKEY|ShiftMask, XK_h, inchratio, ".1" }, \ 52 { MODKEY, XK_l, tile, "0.05" }, \
55 { MODKEY|ShiftMask, XK_l, inchratio, "-.1" }, \
56 { MODKEY|ShiftMask, XK_j, incvratio, "-.1" }, \
57 { MODKEY|ShiftMask, XK_k, incvratio, ".1" }, \
58 { MODKEY, XK_m, togglemax, NULL }, \ 53 { MODKEY, XK_m, togglemax, NULL }, \
59 { MODKEY, XK_Return, zoom, NULL }, \ 54 { MODKEY, XK_Return, zoom, NULL }, \
60 { MODKEY|ShiftMask, XK_space, togglefloating, NULL }, \ 55 { MODKEY|ShiftMask, XK_space, togglefloating, NULL }, \
diff --git a/config.default.h b/config.default.h
index eaba9fb..ec32e9d 100644
--- a/config.default.h
+++ b/config.default.h
@@ -25,15 +25,14 @@ static Rule rule[] = { \
25}; 25};
26 26
27/* layout(s) */ 27/* layout(s) */
28void tile(const char *arg); /* arranges all windows tiled */
28#define LAYOUTS \ 29#define LAYOUTS \
29static Layout layout[] = { \ 30static Layout layout[] = { \
30 /* symbol function */ \ 31 /* symbol function */ \
31 { "[]=", tile }, /* first entry is default */ \ 32 { "[]=", tile }, /* first entry is default */ \
32 { "><>", floating }, \ 33 { "><>", floating }, \
33}; 34};
34#define NMASTER 1 /* clients in master area */ 35#define MASTER 0.6 /* 0.1 .. 0.9 */
35#define HRATIO .8 /* horizontal ratio of tile */
36#define VRATIO 1 /* vertical ratio of tile */
37#define SNAP 32 /* snap pixel */ 36#define SNAP 32 /* snap pixel */
38 37
39/* key definitions */ 38/* key definitions */
@@ -45,14 +44,10 @@ static Key key[] = { \
45 { MODKEY, XK_p, spawn, "exe=`dmenu_path | dmenu` && exec $exe" }, \ 44 { MODKEY, XK_p, spawn, "exe=`dmenu_path | dmenu` && exec $exe" }, \
46 { MODKEY, XK_space, setlayout, NULL }, \ 45 { MODKEY, XK_space, setlayout, NULL }, \
47 { MODKEY, XK_b, togglebar, NULL }, \ 46 { MODKEY, XK_b, togglebar, NULL }, \
48 { MODKEY, XK_h, incnmaster, "1" }, \ 47 { MODKEY, XK_h, tile, "-0.05" }, \
49 { MODKEY, XK_l, incnmaster, "-1" }, \
50 { MODKEY, XK_j, focusclient, "1" }, \ 48 { MODKEY, XK_j, focusclient, "1" }, \
51 { MODKEY, XK_k, focusclient, "-1" }, \ 49 { MODKEY, XK_k, focusclient, "-1" }, \
52 { MODKEY|ShiftMask, XK_h, inchratio, ".1" }, \ 50 { MODKEY, XK_l, tile, "0.05" }, \
53 { MODKEY|ShiftMask, XK_l, inchratio, "-.1" }, \
54 { MODKEY|ShiftMask, XK_j, incvratio, "-.1" }, \
55 { MODKEY|ShiftMask, XK_k, incvratio, ".1" }, \
56 { MODKEY, XK_m, togglemax, NULL }, \ 51 { MODKEY, XK_m, togglemax, NULL }, \
57 { MODKEY, XK_Return, zoom, NULL }, \ 52 { MODKEY, XK_Return, zoom, NULL }, \
58 { MODKEY|ShiftMask, XK_space, togglefloating, NULL }, \ 53 { MODKEY|ShiftMask, XK_space, togglefloating, NULL }, \
diff --git a/dwm.1 b/dwm.1
index 47b8880..885405a 100644
--- a/dwm.1
+++ b/dwm.1
@@ -10,7 +10,7 @@ floating layouts. Either layout can be applied dynamically, optimizing the
10environment for the application in use and the task performed. 10environment for the application in use and the task performed.
11.P 11.P
12In tiled layout windows are managed in a master and stacking area. The master 12In tiled layout windows are managed in a master and stacking area. The master
13area contains the windows which currently need most attention, whereas the 13area contains the window which currently needs most attention, whereas the
14stacking area contains all other windows. In floating layout windows can be 14stacking area contains all other windows. In floating layout windows can be
15resized and moved freely. Dialog windows are always managed floating, 15resized and moved freely. Dialog windows are always managed floating,
16regardless of the layout applied. 16regardless of the layout applied.
@@ -62,29 +62,17 @@ Zooms/cycles current window to/from master area (tiled layout only).
62.B Mod1\-b 62.B Mod1\-b
63Shows/hides the status bar. 63Shows/hides the status bar.
64.TP 64.TP
65.B Mod1\-h
66Decreases the master area width about 5% (tiled layout only).
67.TP
65.B Mod1\-j 68.B Mod1\-j
66Focus next window. 69Focus next window.
67.TP 70.TP
68.B Mod1\-k 71.B Mod1\-k
69Focus previous window. 72Focus previous window.
70.TP 73.TP
71.B Mod1\-h
72Increase the number of windows in the master area (tiled layout only).
73.TP
74.B Mod1\-l 74.B Mod1\-l
75Decrease the number of windows in the master area (tiled layout only). 75Increases the master area width about 5% (tiled layout only).
76.TP
77.B Mod1\-Shift\-k
78Increase vertical tile ratio, effects tile heights (tiled layout only).
79.TP
80.B Mod1\-Shift\-j
81Decrease vertical tile ratio, effects tile heights (tiled layout only).
82.TP
83.B Mod1\-Shift\-h
84Increase horizontal tile ratio, effects master area width (tiled layout only).
85.TP
86.B Mod1\-Shift\-l
87Decrease horizontal tile ratio, effects master area width (tiled layout only).
88.TP 76.TP
89.B Mod1\-m 77.B Mod1\-m
90Toggles maximization of current window (floating layout only). 78Toggles maximization of current window (floating layout only).
diff --git a/dwm.h b/dwm.h
index 7f7d422..d20cf32 100644
--- a/dwm.h
+++ b/dwm.h
@@ -76,7 +76,7 @@ typedef struct {
76 76
77typedef struct { 77typedef struct {
78 const char *symbol; 78 const char *symbol;
79 void (*arrange)(void); 79 void (*arrange)(const char *);
80} Layout; 80} Layout;
81 81
82extern const char *tags[]; /* all tags */ 82extern const char *tags[]; /* all tags */
@@ -120,11 +120,8 @@ unsigned int textw(const char *text); /* return the width of text in px*/
120void grabkeys(void); /* grab all keys defined in config.h */ 120void grabkeys(void); /* grab all keys defined in config.h */
121 121
122/* layout.c */ 122/* layout.c */
123void floating(void); /* arranges all windows floating */ 123void floating(const char *arg); /* arranges all windows floating */
124void focusclient(const char *arg); /* focuses next(1)/previous(-1) visible client */ 124void focusclient(const char *arg); /* focuses next(1)/previous(-1) visible client */
125void inchratio(const char *arg); /* increments the horizontal tile ratio with arg's value */
126void incvratio(const char *arg); /* increments the vertical tile ratio with arg's value */
127void incnmaster(const char *arg); /* increments nmaster with arg's index value */
128void initlayouts(void); /* initialize layout array */ 125void initlayouts(void); /* initialize layout array */
129Client *nexttiled(Client *c); /* returns tiled successor of c */ 126Client *nexttiled(Client *c); /* returns tiled successor of c */
130void restack(void); /* restores z layers of all clients */ 127void restack(void); /* restores z layers of all clients */
diff --git a/event.c b/event.c
index d0716fa..0fa1081 100644
--- a/event.c
+++ b/event.c
@@ -216,7 +216,7 @@ configurenotify(XEvent *e) {
216 dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); 216 dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
217 XResizeWindow(dpy, barwin, sw, bh); 217 XResizeWindow(dpy, barwin, sw, bh);
218 updatebarpos(); 218 updatebarpos();
219 lt->arrange(); 219 lt->arrange(NULL);
220 } 220 }
221} 221}
222 222
@@ -317,7 +317,7 @@ propertynotify(XEvent *e) {
317 case XA_WM_TRANSIENT_FOR: 317 case XA_WM_TRANSIENT_FOR:
318 XGetTransientForHint(dpy, c->win, &trans); 318 XGetTransientForHint(dpy, c->win, &trans);
319 if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL))) 319 if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
320 lt->arrange(); 320 lt->arrange(NULL);
321 break; 321 break;
322 case XA_WM_NORMAL_HINTS: 322 case XA_WM_NORMAL_HINTS:
323 updatesizehints(c); 323 updatesizehints(c);
diff --git a/layout.c b/layout.c
index 7a7abae..0002397 100644
--- a/layout.c
+++ b/layout.c
@@ -8,131 +8,19 @@ Layout *lt = NULL;
8 8
9/* static */ 9/* static */
10 10
11static double hratio = HRATIO;
12static double vratio = VRATIO;
13static unsigned int nlayouts = 0; 11static unsigned int nlayouts = 0;
14static unsigned int nmaster = NMASTER;
15
16static double /* simple pow() */
17spow(double x, double y)
18{
19 if(y == 0)
20 return 1;
21 while(--y)
22 x *= x;
23 return x;
24}
25
26static void
27tile(void) {
28 Bool mmaxtile = False, smaxtile = False; /* fallback tiling */
29 double mscale = 0, sscale = 0, sum = 0;
30 unsigned int i, n, nx, ny, nw, nh, mw, tw;
31 Client *c;
32
33 /* preparation */
34 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
35 n++;
36 nx = wax;
37 ny = way;
38 mw = (n <= nmaster) ? waw : waw / (1 + hratio);
39 tw = waw - mw;
40 if(n > 0) {
41 if(n <= nmaster) {
42 for(i = 0; i < n; i++)
43 sum += spow(vratio, i);
44 mscale = wah / sum;
45 if(vratio >= 1)
46 mmaxtile = bh > mscale;
47 else
48 mmaxtile = bh > (mscale * spow(vratio, n - 1));
49 }
50 else {
51 for(i = 0; i < nmaster; i++)
52 sum += spow(vratio, i);
53 mscale = wah / sum;
54 for(sum = 0, i = 0; i < (n - nmaster); i++)
55 sum += spow(vratio, i);
56 sscale = wah / sum;
57 if(vratio >= 1) {
58 mmaxtile = bh > mscale;
59 smaxtile = bh > sscale;
60 }
61 else {
62 mmaxtile = bh > (mscale * spow(vratio, nmaster - 1));
63 smaxtile = bh > (sscale * spow(vratio, n - nmaster - 1));
64 }
65 }
66 }
67 /* tiling */
68 for(i = 0, c = clients; c; c = c->next)
69 if(isvisible(c)) {
70 unban(c);
71 if(c->isfloating)
72 continue;
73 c->ismax = False;
74 if(i < nmaster) { /* master window */
75 nw = mw - 2 * c->border;
76 if(mmaxtile) {
77 ny = way;
78 nh = wah - 2 * c->border;
79 }
80 else if(i + 1 == (n < nmaster ? n : nmaster))
81 nh = (way + wah) - ny - 2 * c->border;
82 else
83 nh = (mscale * spow(vratio, i)) - 2 * c->border;
84 }
85 else { /* tile window */
86 nw = tw - 2 * c->border;
87 if(i == nmaster) {
88 ny = way;
89 nx = wax + mw;
90 }
91 if(smaxtile) {
92 ny = way;
93 nh = wah - 2 * c->border;
94 }
95 else if(i + 1 == n)
96 nh = (way + wah) - ny - 2 * c->border;
97 else
98 nh = (sscale * spow(vratio, i - nmaster)) - 2 * c->border;
99 }
100 resize(c, nx, ny, nw, nh, False);
101 ny += nh;
102 i++;
103 }
104 else
105 ban(c);
106 focus(NULL);
107 restack();
108}
109 12
110LAYOUTS 13LAYOUTS
111 14
112static void
113incratio(const char *arg, double *ratio, double def) {
114 double delta;
115
116 if(lt->arrange != tile)
117 return;
118 if(!arg)
119 *ratio = def;
120 else {
121 if(1 == sscanf(arg, "%lf", &delta)) {
122 if(delta + (*ratio) < .1 || delta + (*ratio) > 1.9)
123 return;
124 *ratio += delta;
125 }
126 }
127 lt->arrange();
128}
129
130/* extern */ 15/* extern */
131 16
132void 17void
133floating(void) { 18floating(const char *arg) {
134 Client *c; 19 Client *c;
135 20
21 if(lt->arrange != floating)
22 return;
23
136 for(c = clients; c; c = c->next) 24 for(c = clients; c; c = c->next)
137 if(isvisible(c)) { 25 if(isvisible(c)) {
138 unban(c); 26 unban(c);
@@ -169,35 +57,6 @@ focusclient(const char *arg) {
169} 57}
170 58
171void 59void
172inchratio(const char *arg) {
173 incratio(arg, &hratio, HRATIO);
174}
175
176void
177incvratio(const char *arg) {
178 incratio(arg, &vratio, VRATIO);
179}
180
181void
182incnmaster(const char *arg) {
183 int i;
184
185 if(!arg)
186 nmaster = NMASTER;
187 else {
188 i = atoi(arg);
189 if((lt->arrange != tile) || (nmaster + i < 1)
190 || (wah / (nmaster + i) <= 2 * BORDERPX))
191 return;
192 nmaster += i;
193 }
194 if(sel)
195 lt->arrange();
196 else
197 drawstatus();
198}
199
200void
201initlayouts(void) { 60initlayouts(void) {
202 unsigned int i, w; 61 unsigned int i, w;
203 62
@@ -261,19 +120,78 @@ setlayout(const char *arg) {
261 lt = &layout[i]; 120 lt = &layout[i];
262 } 121 }
263 if(sel) 122 if(sel)
264 lt->arrange(); 123 lt->arrange(NULL);
265 else 124 else
266 drawstatus(); 125 drawstatus();
267} 126}
268 127
269void 128void
129tile(const char *arg) {
130 static double master = MASTER;
131 double delta;
132 unsigned int i, n, nx, ny, nw, nh, mw, th;
133 Client *c;
134
135 if(lt->arrange != tile)
136 return;
137
138 /* arg handling, manipulate master */
139 if(arg && (1 == sscanf(arg, "%lf", &delta))) {
140 if(delta + master > 0.1 && delta + master < 0.9)
141 master += delta;
142 }
143
144 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
145 n++;
146
147 /* window geoms */
148 mw = (n == 1) ? waw : master * waw;
149 th = (n > 1) ? wah / (n - 1) : 0;
150 if(n > 1 && th < bh)
151 th = wah;
152
153 nx = wax;
154 ny = way;
155 for(i = 0, c = clients; c; c = c->next)
156 if(isvisible(c)) {
157 unban(c);
158 if(c->isfloating)
159 continue;
160 c->ismax = False;
161 if(i == 0) { /* master */
162 nw = mw - 2 * c->border;
163 nh = wah - 2 * c->border;
164 }
165 else { /* tile window */
166 if(i == 1) {
167 ny = way;
168 nx += mw;
169 }
170 nw = waw - mw - 2 * c->border;
171 if(i + 1 == n) /* remainder */
172 nh = (way + wah) - ny - 2 * c->border;
173 else
174 nh = th - 2 * c->border;
175 }
176 resize(c, nx, ny, nw, nh, False);
177 if(n > 1 && th != wah)
178 ny += nh;
179 i++;
180 }
181 else
182 ban(c);
183 focus(NULL);
184 restack();
185}
186
187void
270togglebar(const char *arg) { 188togglebar(const char *arg) {
271 if(bpos == BarOff) 189 if(bpos == BarOff)
272 bpos = (BARPOS == BarOff) ? BarTop : BARPOS; 190 bpos = (BARPOS == BarOff) ? BarTop : BARPOS;
273 else 191 else
274 bpos = BarOff; 192 bpos = BarOff;
275 updatebarpos(); 193 updatebarpos();
276 lt->arrange(); 194 lt->arrange(NULL);
277} 195}
278 196
279void 197void
@@ -307,5 +225,5 @@ zoom(const char *arg) {
307 detach(c); 225 detach(c);
308 attach(c); 226 attach(c);
309 focus(c); 227 focus(c);
310 lt->arrange(); 228 lt->arrange(NULL);
311} 229}
diff --git a/tag.c b/tag.c
index c44954b..e9d6445 100644
--- a/tag.c
+++ b/tag.c
@@ -110,7 +110,7 @@ tag(const char *arg) {
110 i = arg ? atoi(arg) : 0; 110 i = arg ? atoi(arg) : 0;
111 if(i >= 0 && i < ntags) 111 if(i >= 0 && i < ntags)
112 sel->tags[i] = True; 112 sel->tags[i] = True;
113 lt->arrange(); 113 lt->arrange(NULL);
114} 114}
115 115
116void 116void
@@ -124,7 +124,7 @@ toggletag(const char *arg) {
124 for(j = 0; j < ntags && !sel->tags[j]; j++); 124 for(j = 0; j < ntags && !sel->tags[j]; j++);
125 if(j == ntags) 125 if(j == ntags)
126 sel->tags[i] = True; 126 sel->tags[i] = True;
127 lt->arrange(); 127 lt->arrange(NULL);
128} 128}
129 129
130void 130void
@@ -136,7 +136,7 @@ toggleview(const char *arg) {
136 for(j = 0; j < ntags && !seltag[j]; j++); 136 for(j = 0; j < ntags && !seltag[j]; j++);
137 if(j == ntags) 137 if(j == ntags)
138 seltag[i] = True; /* cannot toggle last view */ 138 seltag[i] = True; /* cannot toggle last view */
139 lt->arrange(); 139 lt->arrange(NULL);
140} 140}
141 141
142void 142void
@@ -148,5 +148,5 @@ view(const char *arg) {
148 i = arg ? atoi(arg) : 0; 148 i = arg ? atoi(arg) : 0;
149 if(i >= 0 && i < ntags) 149 if(i >= 0 && i < ntags)
150 seltag[i] = True; 150 seltag[i] = True;
151 lt->arrange(); 151 lt->arrange(NULL);
152} 152}