summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--bar.c54
-rw-r--r--client.c230
-rw-r--r--draw.c67
-rw-r--r--dwm.h31
-rw-r--r--event.c96
-rw-r--r--key.c (renamed from dev.c)169
-rw-r--r--main.c2
-rw-r--r--screen.c100
9 files changed, 374 insertions, 377 deletions
diff --git a/Makefile b/Makefile
index 536960b..e2caadd 100644
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@
3 3
4include config.mk 4include config.mk
5 5
6SRC = bar.c client.c dev.c draw.c event.c main.c util.c 6SRC = client.c draw.c event.c key.c main.c screen.c util.c
7OBJ = ${SRC:.c=.o} 7OBJ = ${SRC:.c=.o}
8MAN1 = dwm.1 8MAN1 = dwm.1
9BIN = dwm 9BIN = dwm
diff --git a/bar.c b/bar.c
deleted file mode 100644
index 3027bc2..0000000
--- a/bar.c
+++ /dev/null
@@ -1,54 +0,0 @@
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#include "dwm.h"
7
8void
9barclick(XButtonPressedEvent *e)
10{
11 int x = 0;
12 Arg a;
13 for(a.i = 0; a.i < TLast; a.i++) {
14 x += textw(tags[a.i]) + dc.font.height;
15 if(e->x < x) {
16 view(&a);
17 return;
18 }
19 }
20}
21
22void
23draw_bar()
24{
25 int i, modw;
26 char *mode = arrange == tiling ? "#" : "~";
27
28 dc.x = dc.y = 0;
29 dc.w = bw;
30 drawtext(NULL, False, False);
31
32 modw = textw(mode) + dc.font.height;
33 dc.w = 0;
34 for(i = 0; i < TLast; i++) {
35 dc.x += dc.w;
36 dc.w = textw(tags[i]) + dc.font.height;
37 drawtext(tags[i], i == tsel, True);
38 }
39 if(sel) {
40 dc.x += dc.w;
41 dc.w = textw(sel->name) + dc.font.height;
42 drawtext(sel->name, True, True);
43 }
44 dc.w = textw(stext) + dc.font.height;
45 dc.x = bx + bw - dc.w - modw;
46 drawtext(stext, False, False);
47
48 dc.x = bx + bw - modw;
49 dc.w = modw;
50 drawtext(mode, True, True);
51
52 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
53 XFlush(dpy);
54}
diff --git a/client.c b/client.c
index 5b666c9..63fb1e5 100644
--- a/client.c
+++ b/client.c
@@ -11,14 +11,12 @@
11 11
12#include "dwm.h" 12#include "dwm.h"
13 13
14void (*arrange)(Arg *) = tiling;
15
16static Rule rule[] = { 14static Rule rule[] = {
17 /* class instance tags floating */ 15 /* class instance tags floating */
18 { "Firefox-bin", "Gecko", { [Twww] = "www" }, False }, 16 { "Firefox-bin", "Gecko", { [Twww] = "www" }, False },
19}; 17};
20 18
21static Client * 19Client *
22next(Client *c) 20next(Client *c)
23{ 21{
24 for(; c && !c->tags[tsel]; c = c->next); 22 for(; c && !c->tags[tsel]; c = c->next);
@@ -26,202 +24,12 @@ next(Client *c)
26} 24}
27 25
28void 26void
29zoom(Arg *arg)
30{
31 Client **l, *c;
32
33 if(!sel)
34 return;
35
36 if(sel == next(clients) && sel->next) {
37 if((c = next(sel->next)))
38 sel = c;
39 }
40
41 for(l = &clients; *l && *l != sel; l = &(*l)->next);
42 *l = sel->next;
43
44 sel->next = clients; /* pop */
45 clients = sel;
46 arrange(NULL);
47 focus(sel);
48}
49
50void
51max(Arg *arg)
52{
53 if(!sel)
54 return;
55 sel->x = sx;
56 sel->y = sy + bh;
57 sel->w = sw - 2 * sel->border;
58 sel->h = sh - 2 * sel->border - bh;
59 craise(sel);
60 resize(sel, False);
61}
62
63void
64view(Arg *arg)
65{
66 Client *c;
67
68 tsel = arg->i;
69 arrange(NULL);
70
71 for(c = clients; c; c = next(c->next))
72 draw_client(c);
73 draw_bar();
74}
75
76void
77tappend(Arg *arg)
78{
79 if(!sel)
80 return;
81
82 sel->tags[arg->i] = tags[arg->i];
83 arrange(NULL);
84}
85
86void
87ttrunc(Arg *arg)
88{
89 int i;
90 if(!sel)
91 return;
92
93 for(i = 0; i < TLast; i++)
94 sel->tags[i] = NULL;
95 tappend(arg);
96}
97
98static void
99ban_client(Client *c) 27ban_client(Client *c)
100{ 28{
101 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); 29 XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
102 XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty); 30 XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
103} 31}
104 32
105void
106floating(Arg *arg)
107{
108 Client *c;
109
110 arrange = floating;
111 for(c = clients; c; c = c->next) {
112 if(c->tags[tsel])
113 resize(c, True);
114 else
115 ban_client(c);
116 }
117 if(sel && !sel->tags[tsel]) {
118 if((sel = next(clients))) {
119 craise(sel);
120 focus(sel);
121 }
122 }
123 draw_bar();
124}
125
126void
127tiling(Arg *arg)
128{
129 Client *c;
130 int n, i, w, h;
131
132 w = sw - mw;
133 arrange = tiling;
134 for(n = 0, c = clients; c; c = c->next)
135 if(c->tags[tsel] && !c->floating)
136 n++;
137
138 if(n > 1)
139 h = (sh - bh) / (n - 1);
140 else
141 h = sh - bh;
142
143 for(i = 0, c = clients; c; c = c->next) {
144 if(c->tags[tsel]) {
145 if(c->floating) {
146 craise(c);
147 resize(c, True);
148 continue;
149 }
150 if(n == 1) {
151 c->x = sx;
152 c->y = sy + bh;
153 c->w = sw - 2 * c->border;
154 c->h = sh - 2 * c->border - bh;
155 }
156 else if(i == 0) {
157 c->x = sx;
158 c->y = sy + bh;
159 c->w = mw - 2 * c->border;
160 c->h = sh - 2 * c->border - bh;
161 }
162 else {
163 c->x = sx + mw;
164 c->y = sy + (i - 1) * h + bh;
165 c->w = w - 2 * c->border;
166 c->h = h - 2 * c->border;
167 }
168 resize(c, False);
169 i++;
170 }
171 else
172 ban_client(c);
173 }
174 if(!sel || (sel && !sel->tags[tsel])) {
175 if((sel = next(clients))) {
176 craise(sel);
177 focus(sel);
178 }
179 }
180 draw_bar();
181}
182
183void
184prevc(Arg *arg)
185{
186 Client *c;
187
188 if(!sel)
189 return;
190
191 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
192 craise(c);
193 focus(c);
194 }
195}
196
197void
198nextc(Arg *arg)
199{
200 Client *c;
201
202 if(!sel)
203 return;
204
205 if(!(c = next(sel->next)))
206 c = next(clients);
207 if(c) {
208 craise(c);
209 c->revert = sel;
210 focus(c);
211 }
212}
213
214void
215ckill(Arg *arg)
216{
217 if(!sel)
218 return;
219 if(sel->proto & WM_PROTOCOL_DELWIN)
220 send_message(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
221 else
222 XKillClient(dpy, sel->win);
223}
224
225static void 33static void
226resize_title(Client *c) 34resize_title(Client *c)
227{ 35{
@@ -230,8 +38,8 @@ resize_title(Client *c)
230 c->tw = 0; 38 c->tw = 0;
231 for(i = 0; i < TLast; i++) 39 for(i = 0; i < TLast; i++)
232 if(c->tags[i]) 40 if(c->tags[i])
233 c->tw += textw(c->tags[i]) + dc.font.height; 41 c->tw += textw(c->tags[i]);
234 c->tw += textw(c->name) + dc.font.height; 42 c->tw += textw(c->name);
235 if(c->tw > c->w) 43 if(c->tw > c->w)
236 c->tw = c->w + 2; 44 c->tw = c->w + 2;
237 c->tx = c->x + c->w - c->tw + 2; 45 c->tx = c->x + c->w - c->tw + 2;
@@ -584,35 +392,3 @@ getclient(Window w)
584 return c; 392 return c;
585 return NULL; 393 return NULL;
586} 394}
587
588void
589draw_client(Client *c)
590{
591 int i;
592 if(c == sel) {
593 draw_bar();
594 XUnmapWindow(dpy, c->title);
595 XSetWindowBorder(dpy, c->win, dc.fg);
596 return;
597 }
598
599 XSetWindowBorder(dpy, c->win, dc.bg);
600 XMapWindow(dpy, c->title);
601
602 dc.x = dc.y = 0;
603
604 dc.w = 0;
605 for(i = 0; i < TLast; i++) {
606 if(c->tags[i]) {
607 dc.x += dc.w;
608 dc.w = textw(c->tags[i]) + dc.font.height;
609 drawtext(c->tags[i], False, True);
610 }
611 }
612 dc.x += dc.w;
613 dc.w = textw(c->name) + dc.font.height;
614 drawtext(c->name, False, True);
615 XCopyArea(dpy, dc.drawable, c->title, dc.gc,
616 0, 0, c->tw, c->th, 0, 0);
617 XFlush(dpy);
618}
diff --git a/draw.c b/draw.c
index 3fbc85c..5bb6fc2 100644
--- a/draw.c
+++ b/draw.c
@@ -10,6 +10,71 @@
10 10
11#include "dwm.h" 11#include "dwm.h"
12 12
13void
14draw_bar()
15{
16 int i;
17
18 dc.x = dc.y = 0;
19 dc.w = bw;
20 drawtext(NULL, False, False);
21
22 if(arrange == floating) {
23 dc.w = textw("~");
24 drawtext("~", False, False);
25 }
26 else
27 dc.w = 0;
28 for(i = 0; i < TLast; i++) {
29 dc.x += dc.w;
30 dc.w = textw(tags[i]);
31 drawtext(tags[i], i == tsel, True);
32 }
33 if(sel) {
34 dc.x += dc.w;
35 dc.w = textw(sel->name);
36 drawtext(sel->name, True, True);
37 }
38 dc.w = textw(stext);
39 dc.x = bx + bw - dc.w;
40 drawtext(stext, False, False);
41
42 XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
43 XFlush(dpy);
44}
45
46void
47draw_client(Client *c)
48{
49 int i;
50 if(c == sel) {
51 draw_bar();
52 XUnmapWindow(dpy, c->title);
53 XSetWindowBorder(dpy, c->win, dc.fg);
54 return;
55 }
56
57 XSetWindowBorder(dpy, c->win, dc.bg);
58 XMapWindow(dpy, c->title);
59
60 dc.x = dc.y = 0;
61
62 dc.w = 0;
63 for(i = 0; i < TLast; i++) {
64 if(c->tags[i]) {
65 dc.x += dc.w;
66 dc.w = textw(c->tags[i]);
67 drawtext(c->tags[i], False, True);
68 }
69 }
70 dc.x += dc.w;
71 dc.w = textw(c->name);
72 drawtext(c->name, False, True);
73 XCopyArea(dpy, dc.drawable, c->title, dc.gc,
74 0, 0, c->tw, c->th, 0, 0);
75 XFlush(dpy);
76}
77
13static void 78static void
14drawborder(void) 79drawborder(void)
15{ 80{
@@ -103,7 +168,7 @@ textnw(char *text, unsigned int len)
103unsigned int 168unsigned int
104textw(char *text) 169textw(char *text)
105{ 170{
106 return textnw(text, strlen(text)); 171 return textnw(text, strlen(text)) + dc.font.height;
107} 172}
108 173
109void 174void
diff --git a/dwm.h b/dwm.h
index 6843870..ba12527 100644
--- a/dwm.h
+++ b/dwm.h
@@ -94,6 +94,7 @@ extern Cursor cursor[CurLast];
94extern Bool running, issel; 94extern Bool running, issel;
95extern void (*handler[LASTEvent])(XEvent *); 95extern void (*handler[LASTEvent])(XEvent *);
96extern void (*arrange)(Arg *); 96extern void (*arrange)(Arg *);
97extern Key key[];
97 98
98extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw; 99extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
99extern char *tags[TLast], stext[1024]; 100extern char *tags[TLast], stext[1024];
@@ -101,35 +102,24 @@ extern char *tags[TLast], stext[1024];
101extern DC dc; 102extern DC dc;
102extern Client *clients, *sel; 103extern Client *clients, *sel;
103 104
104/* bar.c */
105extern void draw_bar();
106extern void barclick(XButtonPressedEvent *e);
107
108/* client.c */ 105/* client.c */
109extern void manage(Window w, XWindowAttributes *wa); 106extern void manage(Window w, XWindowAttributes *wa);
110extern void unmanage(Client *c); 107extern void unmanage(Client *c);
111extern Client *getclient(Window w); 108extern Client *getclient(Window w);
112extern void focus(Client *c); 109extern void focus(Client *c);
113extern void update_name(Client *c); 110extern void update_name(Client *c);
114extern void draw_client(Client *c);
115extern void resize(Client *c, Bool inc); 111extern void resize(Client *c, Bool inc);
116extern void update_size(Client *c); 112extern void update_size(Client *c);
117extern Client *gettitle(Window w); 113extern Client *gettitle(Window w);
118extern void craise(Client *c); 114extern void craise(Client *c);
119extern void lower(Client *c); 115extern void lower(Client *c);
120extern void ckill(Arg *arg);
121extern void nextc(Arg *arg);
122extern void prevc(Arg *arg);
123extern void max(Arg *arg);
124extern void floating(Arg *arg);
125extern void tiling(Arg *arg);
126extern void ttrunc(Arg *arg);
127extern void tappend(Arg *arg);
128extern void view(Arg *arg);
129extern void zoom(Arg *arg);
130extern void gravitate(Client *c, Bool invert); 116extern void gravitate(Client *c, Bool invert);
117extern void ban_client(Client *c);
118extern Client *next(Client *c);
131 119
132/* draw.c */ 120/* draw.c */
121extern void draw_bar();
122extern void draw_client(Client *c);
133extern void drawtext(const char *text, Bool invert, Bool border); 123extern void drawtext(const char *text, Bool invert, Bool border);
134extern unsigned long initcolor(const char *colstr); 124extern unsigned long initcolor(const char *colstr);
135extern void initfont(const char *fontstr); 125extern void initfont(const char *fontstr);
@@ -137,11 +127,9 @@ extern unsigned int textnw(char *text, unsigned int len);
137extern unsigned int textw(char *text); 127extern unsigned int textw(char *text);
138extern unsigned int texth(void); 128extern unsigned int texth(void);
139 129
140/* dev.c */ 130/* key.c */
141extern void update_keys(void); 131extern void grabkeys();
142extern void keypress(XEvent *e); 132extern void keypress(XEvent *e);
143extern void mresize(Client *c);
144extern void mmove(Client *c);
145 133
146/* main.c */ 134/* main.c */
147extern int error_handler(Display *dsply, XErrorEvent *e); 135extern int error_handler(Display *dsply, XErrorEvent *e);
@@ -149,6 +137,11 @@ extern void send_message(Window w, Atom a, long value);
149extern int win_proto(Window w); 137extern int win_proto(Window w);
150extern void quit(Arg *arg); 138extern void quit(Arg *arg);
151 139
140/* screen.c */
141extern void floating(Arg *arg);
142extern void tiling(Arg *arg);
143extern void view(Arg *arg);
144
152/* util.c */ 145/* util.c */
153extern void error(const char *errstr, ...); 146extern void error(const char *errstr, ...);
154extern void *emallocz(unsigned int size); 147extern void *emallocz(unsigned int size);
diff --git a/event.c b/event.c
index 61dcec5..b369ede 100644
--- a/event.c
+++ b/event.c
@@ -7,11 +7,15 @@
7#include <stdio.h> 7#include <stdio.h>
8#include <stdlib.h> 8#include <stdlib.h>
9#include <string.h> 9#include <string.h>
10#include <unistd.h>
10#include <X11/keysym.h> 11#include <X11/keysym.h>
11#include <X11/Xatom.h> 12#include <X11/Xatom.h>
12 13
13#include "dwm.h" 14#include "dwm.h"
14 15
16#define ButtonMask (ButtonPressMask | ButtonReleaseMask)
17#define MouseMask (ButtonMask | PointerMotionMask)
18
15/* local functions */ 19/* local functions */
16static void buttonpress(XEvent *e); 20static void buttonpress(XEvent *e);
17static void configurerequest(XEvent *e); 21static void configurerequest(XEvent *e);
@@ -19,7 +23,6 @@ static void destroynotify(XEvent *e);
19static void enternotify(XEvent *e); 23static void enternotify(XEvent *e);
20static void leavenotify(XEvent *e); 24static void leavenotify(XEvent *e);
21static void expose(XEvent *e); 25static void expose(XEvent *e);
22static void keymapnotify(XEvent *e);
23static void maprequest(XEvent *e); 26static void maprequest(XEvent *e);
24static void propertynotify(XEvent *e); 27static void propertynotify(XEvent *e);
25static void unmapnotify(XEvent *e); 28static void unmapnotify(XEvent *e);
@@ -32,21 +35,100 @@ void (*handler[LASTEvent]) (XEvent *) = {
32 [LeaveNotify] = leavenotify, 35 [LeaveNotify] = leavenotify,
33 [Expose] = expose, 36 [Expose] = expose,
34 [KeyPress] = keypress, 37 [KeyPress] = keypress,
35 [KeymapNotify] = keymapnotify,
36 [MapRequest] = maprequest, 38 [MapRequest] = maprequest,
37 [PropertyNotify] = propertynotify, 39 [PropertyNotify] = propertynotify,
38 [UnmapNotify] = unmapnotify 40 [UnmapNotify] = unmapnotify
39}; 41};
40 42
41static void 43static void
44mresize(Client *c)
45{
46 XEvent ev;
47 int ocx, ocy;
48
49 ocx = c->x;
50 ocy = c->y;
51 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
52 None, cursor[CurResize], CurrentTime) != GrabSuccess)
53 return;
54 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);
55 for(;;) {
56 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
57 switch(ev.type) {
58 default: break;
59 case Expose:
60 handler[Expose](&ev);
61 break;
62 case MotionNotify:
63 XFlush(dpy);
64 c->w = abs(ocx - ev.xmotion.x);
65 c->h = abs(ocy - ev.xmotion.y);
66 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w;
67 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h;
68 resize(c, True);
69 break;
70 case ButtonRelease:
71 XUngrabPointer(dpy, CurrentTime);
72 return;
73 }
74 }
75}
76
77static void
78mmove(Client *c)
79{
80 XEvent ev;
81 int x1, y1, ocx, ocy, di;
82 unsigned int dui;
83 Window dummy;
84
85 ocx = c->x;
86 ocy = c->y;
87 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
88 None, cursor[CurMove], CurrentTime) != GrabSuccess)
89 return;
90 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
91 for(;;) {
92 XMaskEvent(dpy, MouseMask | ExposureMask, &ev);
93 switch (ev.type) {
94 default: break;
95 case Expose:
96 handler[Expose](&ev);
97 break;
98 case MotionNotify:
99 XFlush(dpy);
100 c->x = ocx + (ev.xmotion.x - x1);
101 c->y = ocy + (ev.xmotion.y - y1);
102 resize(c, False);
103 break;
104 case ButtonRelease:
105 XUngrabPointer(dpy, CurrentTime);
106 return;
107 }
108 }
109}
110
111static void
42buttonpress(XEvent *e) 112buttonpress(XEvent *e)
43{ 113{
114 int x;
115 Arg a;
44 XButtonPressedEvent *ev = &e->xbutton; 116 XButtonPressedEvent *ev = &e->xbutton;
45 Client *c; 117 Client *c;
46 118
47 if(barwin == ev->window) 119 if(barwin == ev->window) {
48 barclick(ev); 120 x = (arrange == floating) ? textw("~") : 0;
121 for(a.i = 0; a.i < TLast; a.i++) {
122 x += textw(tags[a.i]);
123 if(ev->x < x) {
124 view(&a);
125 break;
126 }
127 }
128 }
49 else if((c = getclient(ev->window))) { 129 else if((c = getclient(ev->window))) {
130 if(arrange == tiling && !c->floating)
131 return;
50 craise(c); 132 craise(c);
51 switch(ev->button) { 133 switch(ev->button) {
52 default: 134 default:
@@ -150,12 +232,6 @@ expose(XEvent *e)
150} 232}
151 233
152static void 234static void
153keymapnotify(XEvent *e)
154{
155 update_keys();
156}
157
158static void
159maprequest(XEvent *e) 235maprequest(XEvent *e)
160{ 236{
161 XMapRequestEvent *ev = &e->xmaprequest; 237 XMapRequestEvent *ev = &e->xmaprequest;
diff --git a/dev.c b/key.c
index 7f500d9..8fb1c34 100644
--- a/dev.c
+++ b/key.c
@@ -3,12 +3,23 @@
3 * See LICENSE file for license details. 3 * See LICENSE file for license details.
4 */ 4 */
5 5
6#include "dwm.h" 6#include <fcntl.h>
7 7#include <stdio.h>
8#include <stdlib.h> 8#include <stdlib.h>
9#include <string.h> 9#include <string.h>
10#include <unistd.h> 10#include <unistd.h>
11#include <X11/keysym.h> 11#include <X11/keysym.h>
12#include <X11/Xatom.h>
13
14#include "dwm.h"
15
16static void ckill(Arg *arg);
17static void nextc(Arg *arg);
18static void prevc(Arg *arg);
19static void max(Arg *arg);
20static void ttrunc(Arg *arg);
21static void tappend(Arg *arg);
22static void zoom(Arg *arg);
12 23
13/********** CUSTOMIZE **********/ 24/********** CUSTOMIZE **********/
14 25
@@ -19,7 +30,7 @@ const char *term[] = {
19const char *browse[] = { "firefox", NULL }; 30const char *browse[] = { "firefox", NULL };
20const char *xlock[] = { "xlock", NULL }; 31const char *xlock[] = { "xlock", NULL };
21 32
22static Key key[] = { 33Key key[] = {
23 /* modifier key function arguments */ 34 /* modifier key function arguments */
24 { Mod1Mask, XK_Return, zoom, { 0 } }, 35 { Mod1Mask, XK_Return, zoom, { 0 } },
25 { Mod1Mask, XK_k, prevc, { 0 } }, 36 { Mod1Mask, XK_k, prevc, { 0 } },
@@ -49,7 +60,7 @@ static Key key[] = {
49/********** CUSTOMIZE **********/ 60/********** CUSTOMIZE **********/
50 61
51void 62void
52update_keys(void) 63grabkeys()
53{ 64{
54 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; 65 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
55 unsigned int i; 66 unsigned int i;
@@ -58,7 +69,8 @@ update_keys(void)
58 for(i = 0; i < len; i++) { 69 for(i = 0; i < len; i++) {
59 code = XKeysymToKeycode(dpy, key[i].keysym); 70 code = XKeysymToKeycode(dpy, key[i].keysym);
60 XUngrabKey(dpy, code, key[i].mod, root); 71 XUngrabKey(dpy, code, key[i].mod, root);
61 XGrabKey(dpy, code, key[i].mod, root, True, GrabModeAsync, GrabModeAsync); 72 XGrabKey(dpy, code, key[i].mod, root, True,
73 GrabModeAsync, GrabModeAsync);
62 } 74 }
63} 75}
64 76
@@ -79,73 +91,102 @@ keypress(XEvent *e)
79 } 91 }
80} 92}
81 93
82#define ButtonMask (ButtonPressMask | ButtonReleaseMask) 94static void
83#define MouseMask (ButtonMask | PointerMotionMask) 95zoom(Arg *arg)
96{
97 Client **l, *c;
84 98
85void 99 if(!sel)
86mresize(Client *c) 100 return;
101
102 if(sel == next(clients) && sel->next) {
103 if((c = next(sel->next)))
104 sel = c;
105 }
106
107 for(l = &clients; *l && *l != sel; l = &(*l)->next);
108 *l = sel->next;
109
110 sel->next = clients; /* pop */
111 clients = sel;
112 arrange(NULL);
113 focus(sel);
114}
115
116static void
117max(Arg *arg)
87{ 118{
88 XEvent ev; 119 if(!sel)
89 int ocx, ocy; 120 return;
121 sel->x = sx;
122 sel->y = sy + bh;
123 sel->w = sw - 2 * sel->border;
124 sel->h = sh - 2 * sel->border - bh;
125 craise(sel);
126 resize(sel, False);
127}
90 128
91 ocx = c->x; 129static void
92 ocy = c->y; 130tappend(Arg *arg)
93 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync, 131{
94 None, cursor[CurResize], CurrentTime) != GrabSuccess) 132 if(!sel)
95 return; 133 return;
96 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h); 134
97 for(;;) { 135 sel->tags[arg->i] = tags[arg->i];
98 XMaskEvent(dpy, MouseMask | ExposureMask, &ev); 136 arrange(NULL);
99 switch(ev.type) { 137}
100 default: break; 138
101 case Expose: 139static void
102 handler[Expose](&ev); 140ttrunc(Arg *arg)
103 break; 141{
104 case MotionNotify: 142 int i;
105 XFlush(dpy); 143 if(!sel)
106 c->w = abs(ocx - ev.xmotion.x); 144 return;
107 c->h = abs(ocy - ev.xmotion.y); 145
108 c->x = (ocx <= ev.xmotion.x) ? ocx : ocx - c->w; 146 for(i = 0; i < TLast; i++)
109 c->y = (ocy <= ev.xmotion.y) ? ocy : ocy - c->h; 147 sel->tags[i] = NULL;
110 resize(c, True); 148 tappend(arg);
111 break; 149}
112 case ButtonRelease: 150
113 XUngrabPointer(dpy, CurrentTime); 151static void
114 return; 152prevc(Arg *arg)
115 } 153{
154 Client *c;
155
156 if(!sel)
157 return;
158
159 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
160 craise(c);
161 focus(c);
116 } 162 }
117} 163}
118 164
119void 165static void
120mmove(Client *c) 166nextc(Arg *arg)
121{ 167{
122 XEvent ev; 168 Client *c;
123 int x1, y1, ocx, ocy, di; 169
124 unsigned int dui; 170 if(!sel)
125 Window dummy;
126
127 ocx = c->x;
128 ocy = c->y;
129 if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
130 None, cursor[CurMove], CurrentTime) != GrabSuccess)
131 return; 171 return;
132 XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui); 172
133 for(;;) { 173 if(!(c = next(sel->next)))
134 XMaskEvent(dpy, MouseMask | ExposureMask, &ev); 174 c = next(clients);
135 switch (ev.type) { 175 if(c) {
136 default: break; 176 craise(c);
137 case Expose: 177 c->revert = sel;
138 handler[Expose](&ev); 178 focus(c);
139 break;
140 case MotionNotify:
141 XFlush(dpy);
142 c->x = ocx + (ev.xmotion.x - x1);
143 c->y = ocy + (ev.xmotion.y - y1);
144 resize(c, False);
145 break;
146 case ButtonRelease:
147 XUngrabPointer(dpy, CurrentTime);
148 return;
149 }
150 } 179 }
151} 180}
181
182static void
183ckill(Arg *arg)
184{
185 if(!sel)
186 return;
187 if(sel->proto & WM_PROTOCOL_DELWIN)
188 send_message(sel->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
189 else
190 XKillClient(dpy, sel->win);
191}
192
diff --git a/main.c b/main.c
index b59ff96..5c0ef0d 100644
--- a/main.c
+++ b/main.c
@@ -239,7 +239,7 @@ main(int argc, char *argv[])
239 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); 239 cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing);
240 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); 240 cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
241 241
242 update_keys(); 242 grabkeys();
243 243
244 /* style */ 244 /* style */
245 dc.bg = initcolor(BGCOLOR); 245 dc.bg = initcolor(BGCOLOR);
diff --git a/screen.c b/screen.c
new file mode 100644
index 0000000..f2891cf
--- /dev/null
+++ b/screen.c
@@ -0,0 +1,100 @@
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#include "dwm.h"
7
8void (*arrange)(Arg *) = tiling;
9
10void
11view(Arg *arg)
12{
13 Client *c;
14
15 tsel = arg->i;
16 arrange(NULL);
17
18 for(c = clients; c; c = next(c->next))
19 draw_client(c);
20 draw_bar();
21}
22
23void
24floating(Arg *arg)
25{
26 Client *c;
27
28 arrange = floating;
29 for(c = clients; c; c = c->next) {
30 if(c->tags[tsel])
31 resize(c, True);
32 else
33 ban_client(c);
34 }
35 if(sel && !sel->tags[tsel]) {
36 if((sel = next(clients))) {
37 craise(sel);
38 focus(sel);
39 }
40 }
41 draw_bar();
42}
43
44void
45tiling(Arg *arg)
46{
47 Client *c;
48 int n, i, w, h;
49
50 w = sw - mw;
51 arrange = tiling;
52 for(n = 0, c = clients; c; c = c->next)
53 if(c->tags[tsel] && !c->floating)
54 n++;
55
56 if(n > 1)
57 h = (sh - bh) / (n - 1);
58 else
59 h = sh - bh;
60
61 for(i = 0, c = clients; c; c = c->next) {
62 if(c->tags[tsel]) {
63 if(c->floating) {
64 craise(c);
65 resize(c, True);
66 continue;
67 }
68 if(n == 1) {
69 c->x = sx;
70 c->y = sy + bh;
71 c->w = sw - 2 * c->border;
72 c->h = sh - 2 * c->border - bh;
73 }
74 else if(i == 0) {
75 c->x = sx;
76 c->y = sy + bh;
77 c->w = mw - 2 * c->border;
78 c->h = sh - 2 * c->border - bh;
79 }
80 else {
81 c->x = sx + mw;
82 c->y = sy + (i - 1) * h + bh;
83 c->w = w - 2 * c->border;
84 c->h = h - 2 * c->border;
85 }
86 resize(c, False);
87 i++;
88 }
89 else
90 ban_client(c);
91 }
92 if(!sel || (sel && !sel->tags[tsel])) {
93 if((sel = next(clients))) {
94 craise(sel);
95 focus(sel);
96 }
97 }
98 draw_bar();
99}
100