summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile2
-rw-r--r--client.c73
-rw-r--r--dwm.h10
-rw-r--r--screen.c (renamed from view.c)51
4 files changed, 67 insertions, 69 deletions
diff --git a/Makefile b/Makefile
index 31ae1c1..a9f129d 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 manage.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 45f2d19..eaf4a10 100644
--- a/client.c
+++ b/client.c
@@ -10,6 +10,19 @@
10/* static */ 10/* static */
11 11
12static void 12static void
13attachstack(Client *c) {
14 c->snext = stack;
15 stack = c;
16}
17
18static void
19detachstack(Client *c) {
20 Client **tc;
21 for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
22 *tc = c->snext;
23}
24
25static void
13grabbuttons(Client *c, Bool focused) { 26grabbuttons(Client *c, Bool focused) {
14 XUngrabButton(dpy, AnyButton, AnyModifier, c->win); 27 XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
15 28
@@ -68,6 +81,24 @@ setclientstate(Client *c, long state) {
68 PropModeReplace, (unsigned char *)data, 2); 81 PropModeReplace, (unsigned char *)data, 2);
69} 82}
70 83
84static void
85togglemax(Client *c) {
86 XEvent ev;
87
88 if(c->isfixed)
89 return;
90 if((c->ismax = !c->ismax)) {
91 c->rx = c->x;
92 c->ry = c->y;
93 c->rw = c->w;
94 c->rh = c->h;
95 resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
96 }
97 else
98 resize(c, c->rx, c->ry, c->rw, c->rh, True);
99 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
100}
101
71static int 102static int
72xerrordummy(Display *dsply, XErrorEvent *ee) { 103xerrordummy(Display *dsply, XErrorEvent *ee) {
73 return 0; 104 return 0;
@@ -84,12 +115,6 @@ attach(Client *c) {
84} 115}
85 116
86void 117void
87attachstack(Client *c) {
88 c->snext = stack;
89 stack = c;
90}
91
92void
93configure(Client *c) { 118configure(Client *c) {
94 XConfigureEvent ce; 119 XConfigureEvent ce;
95 120
@@ -119,13 +144,6 @@ detach(Client *c) {
119} 144}
120 145
121void 146void
122detachstack(Client *c) {
123 Client **tc;
124 for(tc=&stack; *tc && *tc != c; tc=&(*tc)->snext);
125 *tc = c->snext;
126}
127
128void
129focus(Client *c) { 147focus(Client *c) {
130 if(c && !isvisible(c)) 148 if(c && !isvisible(c))
131 return; 149 return;
@@ -256,6 +274,12 @@ manage(Window w, XWindowAttributes *wa) {
256 arrange(); 274 arrange();
257} 275}
258 276
277Client *
278nexttiled(Client *c) {
279 for(; c && (c->isfloat || !isvisible(c)); c = c->next);
280 return c;
281}
282
259void 283void
260resize(Client *c, int x, int y, int w, int h, Bool sizehints) { 284resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
261 float actual, dx, dy, max, min; 285 float actual, dx, dy, max, min;
@@ -416,3 +440,26 @@ unmanage(Client *c) {
416 XUngrabServer(dpy); 440 XUngrabServer(dpy);
417 arrange(); 441 arrange();
418} 442}
443
444void
445zoom(Arg *arg) {
446 unsigned int n;
447 Client *c;
448
449 if(!sel)
450 return;
451 if(sel->isfloat || (arrange == dofloat)) {
452 togglemax(sel);
453 return;
454 }
455 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
456 n++;
457
458 if((c = sel) == nexttiled(clients))
459 if(!(c = nexttiled(c->next)))
460 return;
461 detach(c);
462 attach(c);
463 focus(c);
464 arrange();
465}
diff --git a/dwm.h b/dwm.h
index cca9984..57fab91 100644
--- a/dwm.h
+++ b/dwm.h
@@ -99,22 +99,20 @@ extern Display *dpy;
99extern Window root, barwin; 99extern Window root, barwin;
100 100
101/* client.c */ 101/* client.c */
102extern void attach(Client *c); /* attaches c to global client list */
103extern void attachstack(Client *c); /* attaches client to stack */
104extern void configure(Client *c); /* send synthetic configure event */ 102extern void configure(Client *c); /* send synthetic configure event */
105extern void detach(Client *c); /* detaches c from global client list */
106extern void detachstack(Client *c); /* detaches client from stack */
107extern void focus(Client *c); /* focus c, c may be NULL */ 103extern void focus(Client *c); /* focus c, c may be NULL */
108extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */ 104extern void focusnext(Arg *arg); /* focuses next visible client, arg is ignored */
109extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */ 105extern void focusprev(Arg *arg); /* focuses previous visible client, arg is ignored */
110extern Client *getclient(Window w); /* return client of w */ 106extern Client *getclient(Window w); /* return client of w */
111extern void killclient(Arg *arg); /* kill c nicely */ 107extern void killclient(Arg *arg); /* kill c nicely */
112extern void manage(Window w, XWindowAttributes *wa); /* manage new client */ 108extern void manage(Window w, XWindowAttributes *wa); /* manage new client */
109Client *nexttiled(Client *c); /* returns tiled successor of c */
113extern void resize(Client *c, int x, int y, 110extern void resize(Client *c, int x, int y,
114 int w, int h, Bool sizehints); /* resize c*/ 111 int w, int h, Bool sizehints); /* resize c*/
115extern void updatesizehints(Client *c); /* update the size hint variables of c */ 112extern void updatesizehints(Client *c); /* update the size hint variables of c */
116extern void updatetitle(Client *c); /* update the name of c */ 113extern void updatetitle(Client *c); /* update the name of c */
117extern void unmanage(Client *c); /* destroy c */ 114extern void unmanage(Client *c); /* destroy c */
115extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */
118 116
119/* draw.c */ 117/* draw.c */
120extern void drawstatus(void); /* draw the bar */ 118extern void drawstatus(void); /* draw the bar */
@@ -131,7 +129,7 @@ extern void quit(Arg *arg); /* quit dwm nicely */
131extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */ 129extern void sendevent(Window w, Atom a, long value); /* send synthetic event to w */
132extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */ 130extern int xerror(Display *dsply, XErrorEvent *ee); /* dwm's X error handler */
133 131
134/* manage.c */ 132/* screen.c */
135extern void compileregexps(void); /* initialize regexps of rules defined in config.h */ 133extern void compileregexps(void); /* initialize regexps of rules defined in config.h */
136extern void dofloat(void); /* arranges all windows floating */ 134extern void dofloat(void); /* arranges all windows floating */
137extern void dotile(void); /* arranges all windows tiled */ 135extern void dotile(void); /* arranges all windows tiled */
@@ -146,9 +144,9 @@ extern void togglemode(Arg *arg); /* toggles global arrange function (dotile/do
146extern void toggletag(Arg *arg); /* toggles c tags with arg's index */ 144extern void toggletag(Arg *arg); /* toggles c tags with arg's index */
147extern 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 */
148extern void view(Arg *arg); /* views the tag with arg's index */ 146extern void view(Arg *arg); /* views the tag with arg's index */
149extern void zoom(Arg *arg); /* zooms the focused client to master area, arg is ignored */
150 147
151/* util.c */ 148/* util.c */
152extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */ 149extern void *emallocz(unsigned int size); /* allocates zero-initialized memory, exits on error */
153extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */ 150extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
154extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */ 151extern void spawn(Arg *arg); /* forks a new subprocess with to arg's cmd */
152
diff --git a/view.c b/screen.c
index 34aae58..041cac7 100644
--- a/view.c
+++ b/screen.c
@@ -32,30 +32,6 @@ RULES
32static Regexps *regexps = NULL; 32static Regexps *regexps = NULL;
33static unsigned int len = 0; 33static unsigned int len = 0;
34 34
35static Client *
36nextmanaged(Client *c) {
37 for(; c && (c->isfloat || !isvisible(c)); c = c->next);
38 return c;
39}
40
41static void
42togglemax(Client *c) {
43 XEvent ev;
44
45 if(c->isfixed)
46 return;
47 if((c->ismax = !c->ismax)) {
48 c->rx = c->x;
49 c->ry = c->y;
50 c->rw = c->w;
51 c->rh = c->h;
52 resize(c, wax, way, waw - 2 * BORDERPX, wah - 2 * BORDERPX, True);
53 }
54 else
55 resize(c, c->rx, c->ry, c->rw, c->rh, True);
56 while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
57}
58
59/* extern */ 35/* extern */
60 36
61void 37void
@@ -112,7 +88,7 @@ dotile(void) {
112 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th; 88 unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
113 Client *c; 89 Client *c;
114 90
115 for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next)) 91 for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
116 n++; 92 n++;
117 /* window geoms */ 93 /* window geoms */
118 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1); 94 mh = (n > nmaster) ? wah / nmaster : wah / (n > 0 ? n : 1);
@@ -209,7 +185,7 @@ restack(void) {
209 if(arrange != dofloat) { 185 if(arrange != dofloat) {
210 if(!sel->isfloat) 186 if(!sel->isfloat)
211 XLowerWindow(dpy, sel->win); 187 XLowerWindow(dpy, sel->win);
212 for(c = nextmanaged(clients); c; c = nextmanaged(c->next)) { 188 for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
213 if(c == sel) 189 if(c == sel)
214 continue; 190 continue;
215 XLowerWindow(dpy, c->win); 191 XLowerWindow(dpy, c->win);
@@ -319,26 +295,3 @@ view(Arg *arg) {
319 seltag[arg->i] = True; 295 seltag[arg->i] = True;
320 arrange(); 296 arrange();
321} 297}
322
323void
324zoom(Arg *arg) {
325 unsigned int n;
326 Client *c;
327
328 if(!sel)
329 return;
330 if(sel->isfloat || (arrange == dofloat)) {
331 togglemax(sel);
332 return;
333 }
334 for(n = 0, c = nextmanaged(clients); c; c = nextmanaged(c->next))
335 n++;
336
337 if((c = sel) == nextmanaged(clients))
338 if(!(c = nextmanaged(c->next)))
339 return;
340 detach(c);
341 attach(c);
342 focus(c);
343 arrange();
344}