summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-13 19:55:07 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-13 19:55:07 +0200
commit3aad92202d58208c4197857d3f17c535ba0bd56a (patch)
tree9a1b23fcf9a4f8c0810d6893b217f265ebebfda6
parentseveral other additions/fixes, dwm is quite usable already (diff)
downloaddwm-3aad92202d58208c4197857d3f17c535ba0bd56a.tar.gz
dwm-3aad92202d58208c4197857d3f17c535ba0bd56a.zip
new stuff
-rw-r--r--client.c122
-rw-r--r--config.mk2
-rw-r--r--dev.c12
-rw-r--r--dwm.h24
-rw-r--r--main.c4
5 files changed, 103 insertions, 61 deletions
diff --git a/client.c b/client.c
index 2ff1994..3c8825d 100644
--- a/client.c
+++ b/client.c
@@ -3,21 +3,19 @@
3 * See LICENSE file for license details. 3 * See LICENSE file for license details.
4 */ 4 */
5 5
6#include <math.h>
7#include <stdlib.h> 6#include <stdlib.h>
7#include <stdio.h>
8#include <string.h> 8#include <string.h>
9#include <X11/Xatom.h> 9#include <X11/Xatom.h>
10#include <X11/Xutil.h> 10#include <X11/Xutil.h>
11 11
12#include "dwm.h" 12#include "dwm.h"
13 13
14static void (*arrange)(Arg *) = floating; 14static void (*arrange)(Arg *) = tiling;
15 15
16static void 16static Rule rule[] = {
17center(Client *c) 17 { "Firefox-bin", "Gecko", { [Twww] = "www" } },
18{ 18};
19 XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
20}
21 19
22static Client * 20static Client *
23next(Client *c) 21next(Client *c)
@@ -29,18 +27,18 @@ next(Client *c)
29void 27void
30zoom(Arg *arg) 28zoom(Arg *arg)
31{ 29{
32 Client **l; 30 Client **l, *old;
33 31
34 if(!sel) 32 if(!(old = sel))
35 return; 33 return;
36 34
37 for(l = &clients; *l && *l != sel; l = &(*l)->next); 35 for(l = &clients; *l && *l != sel; l = &(*l)->next);
38 *l = sel->next; 36 *l = sel->next;
39 37
40 sel->next = clients; /* pop */ 38 old->next = clients; /* pop */
41 clients = sel; 39 clients = old;
40 sel = old;
42 arrange(NULL); 41 arrange(NULL);
43 center(sel);
44 focus(sel); 42 focus(sel);
45} 43}
46 44
@@ -119,39 +117,38 @@ void
119tiling(Arg *arg) 117tiling(Arg *arg)
120{ 118{
121 Client *c; 119 Client *c;
122 int n, cols, rows, gw, gh, i, j; 120 int n, i, w, h;
123 float rt, fd;
124 121
122 w = sw - mw;
125 arrange = tiling; 123 arrange = tiling;
126 for(n = 0, c = clients; c; c = next(c->next), n++); 124 for(n = 0, c = clients; c; c = c->next)
127 if(n) { 125 if(c->tags[tsel])
128 rt = sqrt(n); 126 n++;
129 if(modff(rt, &fd) < 0.5)
130 rows = floor(rt);
131 else
132 rows = ceil(rt);
133 if(rows * rows < n)
134 cols = rows + 1;
135 else
136 cols = rows;
137 127
138 gw = (sw - 2) / cols; 128 h = (n > 2) ? sh / (n - 2) : sh;
139 gh = (sh - 2) / rows;
140 }
141 else
142 cols = rows = gw = gh = 0;
143 129
144 for(i = j = 0, c = clients; c; c = c->next) { 130 for(i = 0, c = clients; c; c = c->next) {
145 if(c->tags[tsel]) { 131 if(c->tags[tsel]) {
146 c->x = i * gw; 132 if(n == 1) {
147 c->y = j * gh; 133 c->x = sx;
148 c->w = gw; 134 c->y = sy;
149 c->h = gh; 135 c->w = sw;
150 resize(c); 136 c->h = sh;
151 if(++i == cols) {
152 j++;
153 i = 0;
154 } 137 }
138 else if(i == 1) {
139 c->x = sx;
140 c->y = sy;
141 c->w = mw;
142 c->h = sh;
143 }
144 else {
145 c->x = sx + mw;
146 c->y = sy + (i - 2) * h;
147 c->w = w;
148 c->h = h;
149 }
150 resize(c);
151 i++;
155 } 152 }
156 else 153 else
157 ban_client(c); 154 ban_client(c);
@@ -175,7 +172,6 @@ prevc(Arg *arg)
175 172
176 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) { 173 if((c = sel->revert && sel->revert->tags[tsel] ? sel->revert : NULL)) {
177 craise(c); 174 craise(c);
178 center(c);
179 focus(c); 175 focus(c);
180 } 176 }
181} 177}
@@ -192,7 +188,6 @@ nextc(Arg *arg)
192 c = next(clients); 188 c = next(clients);
193 if(c) { 189 if(c) {
194 craise(c); 190 craise(c);
195 center(c);
196 c->revert = sel; 191 c->revert = sel;
197 focus(c); 192 focus(c);
198 } 193 }
@@ -323,6 +318,43 @@ focus(Client *c)
323 discard_events(EnterWindowMask); 318 discard_events(EnterWindowMask);
324} 319}
325 320
321static void
322init_tags(Client *c)
323{
324 XClassHint ch;
325 static unsigned int len = rule ? sizeof(rule) / sizeof(rule[0]) : 0;
326 unsigned int i, j;
327 Bool matched = False;
328
329 if(!len) {
330 c->tags[tsel] = tags[tsel];
331 return;
332 }
333
334 if(XGetClassHint(dpy, c->win, &ch)) {
335 if(ch.res_class && ch.res_name) {
336 fprintf(stderr, "%s:%s\n", ch.res_class, ch.res_name);
337 for(i = 0; i < len; i++)
338 if(!strncmp(rule[i].class, ch.res_class, sizeof(rule[i].class))
339 && !strncmp(rule[i].instance, ch.res_name, sizeof(rule[i].instance)))
340 {
341 fprintf(stderr, "->>>%s:%s\n", ch.res_class, ch.res_name);
342 for(j = 0; j < TLast; j++)
343 c->tags[j] = rule[i].tags[j];
344 matched = True;
345 break;
346 }
347 }
348 if(ch.res_class)
349 XFree(ch.res_class);
350 if(ch.res_name)
351 XFree(ch.res_name);
352 }
353
354 if(!matched)
355 c->tags[tsel] = tags[tsel];
356}
357
326void 358void
327manage(Window w, XWindowAttributes *wa) 359manage(Window w, XWindowAttributes *wa)
328{ 360{
@@ -346,13 +378,13 @@ manage(Window w, XWindowAttributes *wa)
346 twa.background_pixmap = ParentRelative; 378 twa.background_pixmap = ParentRelative;
347 twa.event_mask = ExposureMask; 379 twa.event_mask = ExposureMask;
348 380
349 c->tags[tsel] = tags[tsel];
350 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th, 381 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
351 0, DefaultDepth(dpy, screen), CopyFromParent, 382 0, DefaultDepth(dpy, screen), CopyFromParent,
352 DefaultVisual(dpy, screen), 383 DefaultVisual(dpy, screen),
353 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); 384 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
354 385
355 update_name(c); 386 update_name(c);
387 init_tags(c);
356 388
357 for(l = &clients; *l; l = &(*l)->next); 389 for(l = &clients; *l; l = &(*l)->next);
358 c->next = *l; /* *l == nil */ 390 c->next = *l; /* *l == nil */
@@ -368,8 +400,10 @@ manage(Window w, XWindowAttributes *wa)
368 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask, 400 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
369 GrabModeAsync, GrabModeSync, None, None); 401 GrabModeAsync, GrabModeSync, None, None);
370 arrange(NULL); 402 arrange(NULL);
371 center(c); 403 if(c->tags[tsel])
372 focus(c); 404 focus(c);
405 else
406 ban_client(c);
373} 407}
374 408
375void 409void
diff --git a/config.mk b/config.mk
index 33edcd7..39533c2 100644
--- a/config.mk
+++ b/config.mk
@@ -11,7 +11,7 @@ X11LIB = /usr/X11R6/lib
11VERSION = 0.0 11VERSION = 0.0
12 12
13# includes and libs 13# includes and libs
14LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11 14LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11
15 15
16# Linux/BSD 16# Linux/BSD
17CFLAGS = -g -Wall -O2 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ 17CFLAGS = -g -Wall -O2 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
diff --git a/dev.c b/dev.c
index d788320..c77ef58 100644
--- a/dev.c
+++ b/dev.c
@@ -20,8 +20,7 @@ const char *browse[] = { "firefox", NULL };
20const char *xlock[] = { "xlock", NULL }; 20const char *xlock[] = { "xlock", NULL };
21 21
22static Key key[] = { 22static Key key[] = {
23 { Mod1Mask, XK_Return, zoom, { 0 } }, 23 { Mod1Mask, XK_Return, spawn, { .argv = term } },
24 { Mod1Mask, XK_t, spawn, { .argv = term } },
25 { Mod1Mask, XK_w, spawn, { .argv = browse } }, 24 { Mod1Mask, XK_w, spawn, { .argv = browse } },
26 { Mod1Mask, XK_l, spawn, { .argv = xlock } }, 25 { Mod1Mask, XK_l, spawn, { .argv = xlock } },
27 { Mod1Mask, XK_k, prevc, { 0 } }, 26 { Mod1Mask, XK_k, prevc, { 0 } },
@@ -33,6 +32,7 @@ static Key key[] = {
33 { Mod1Mask, XK_3, view, { .i = Twww } }, 32 { Mod1Mask, XK_3, view, { .i = Twww } },
34 { Mod1Mask, XK_4, view, { .i = Twork } }, 33 { Mod1Mask, XK_4, view, { .i = Twork } },
35 { Mod1Mask, XK_space, tiling, { 0 } }, 34 { Mod1Mask, XK_space, tiling, { 0 } },
35 { Mod1Mask | ShiftMask, XK_Return, zoom, { 0 } },
36 { Mod1Mask | ShiftMask, XK_space, floating, { 0 } }, 36 { Mod1Mask | ShiftMask, XK_space, floating, { 0 } },
37 { Mod1Mask | ShiftMask, XK_0, tag, { .i = Tscratch } }, 37 { Mod1Mask | ShiftMask, XK_0, tag, { .i = Tscratch } },
38 { Mod1Mask | ShiftMask, XK_1, tag, { .i = Tdev } }, 38 { Mod1Mask | ShiftMask, XK_1, tag, { .i = Tdev } },
@@ -48,10 +48,10 @@ static Key key[] = {
48void 48void
49update_keys(void) 49update_keys(void)
50{ 50{
51 unsigned int i, len; 51 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
52 unsigned int i;
52 KeyCode code; 53 KeyCode code;
53 54
54 len = sizeof(key) / sizeof(key[0]);
55 for(i = 0; i < len; i++) { 55 for(i = 0; i < len; i++) {
56 code = XKeysymToKeycode(dpy, key[i].keysym); 56 code = XKeysymToKeycode(dpy, key[i].keysym);
57 XUngrabKey(dpy, code, key[i].mod, root); 57 XUngrabKey(dpy, code, key[i].mod, root);
@@ -63,11 +63,11 @@ void
63keypress(XEvent *e) 63keypress(XEvent *e)
64{ 64{
65 XKeyEvent *ev = &e->xkey; 65 XKeyEvent *ev = &e->xkey;
66 unsigned int i, len; 66 static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
67 unsigned int i;
67 KeySym keysym; 68 KeySym keysym;
68 69
69 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); 70 keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
70 len = sizeof(key) / sizeof(key[0]);
71 for(i = 0; i < len; i++) 71 for(i = 0; i < len; i++)
72 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { 72 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
73 if(key[i].func) 73 if(key[i].func)
diff --git a/dwm.h b/dwm.h
index 49aa126..118ac24 100644
--- a/dwm.h
+++ b/dwm.h
@@ -7,22 +7,24 @@
7 7
8/********** CUSTOMIZE **********/ 8/********** CUSTOMIZE **********/
9 9
10#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*" 10#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
11#define BGCOLOR "DarkSlateGrey" 11#define BGCOLOR "#666699"
12#define FGCOLOR "LightSteelBlue" 12#define FGCOLOR "#ffffff"
13#define BORDERCOLOR "SlateGray" 13#define BORDERCOLOR "#9999CC"
14#define WM_PROTOCOL_DELWIN 1 14#define MASTERW 52 /* percent */
15#define WM_PROTOCOL_DELWIN 1
15 16
16/* tags */ 17/* tags */
17enum { Tscratch, Tdev, Tirc, Twww, Twork, TLast }; 18enum { Tscratch, Tdev, Tirc, Twww, Twork, TLast };
18 19
19/********** CUSTOMIZE **********/ 20/********** CUSTOMIZE **********/
20 21
22typedef union Arg Arg;
21typedef struct DC DC; 23typedef struct DC DC;
22typedef struct Client Client; 24typedef struct Client Client;
23typedef struct Fnt Fnt; 25typedef struct Fnt Fnt;
24typedef struct Key Key; 26typedef struct Key Key;
25typedef union Arg Arg; 27typedef struct Rule Rule;
26 28
27union Arg { 29union Arg {
28 const char **argv; 30 const char **argv;
@@ -71,6 +73,12 @@ struct Client {
71 Client *revert; 73 Client *revert;
72}; 74};
73 75
76struct Rule {
77 const char *class;
78 const char *instance;
79 char *tags[TLast];
80};
81
74struct Key { 82struct Key {
75 unsigned long mod; 83 unsigned long mod;
76 KeySym keysym; 84 KeySym keysym;
@@ -85,8 +93,8 @@ extern Cursor cursor[CurLast];
85extern Bool running, issel; 93extern Bool running, issel;
86extern void (*handler[LASTEvent]) (XEvent *); 94extern void (*handler[LASTEvent]) (XEvent *);
87 95
88extern int tsel, screen, sx, sy, sw, sh, th; 96extern int tsel, screen, sx, sy, sw, sh, mw, th;
89extern char stext[1024], *tags[TLast]; 97extern char *tags[TLast];
90 98
91extern DC dc; 99extern DC dc;
92extern Client *clients, *sel; 100extern Client *clients, *sel;
diff --git a/main.c b/main.c
index 07e12aa..eff5ce9 100644
--- a/main.c
+++ b/main.c
@@ -33,9 +33,8 @@ Cursor cursor[CurLast];
33Bool running = True; 33Bool running = True;
34Bool issel; 34Bool issel;
35 35
36char stext[1024];
37int tsel = Tdev; /* default tag */ 36int tsel = Tdev; /* default tag */
38int screen, sx, sy, sw, sh, th; 37int screen, sx, sy, sw, sh, mw, th;
39 38
40DC dc = {0}; 39DC dc = {0};
41Client *clients = NULL; 40Client *clients = NULL;
@@ -223,6 +222,7 @@ main(int argc, char *argv[])
223 sx = sy = 0; 222 sx = sy = 0;
224 sw = DisplayWidth(dpy, screen); 223 sw = DisplayWidth(dpy, screen);
225 sh = DisplayHeight(dpy, screen); 224 sh = DisplayHeight(dpy, screen);
225 mw = (sw * MASTERW) / 100;
226 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 226 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
227 227
228 XSetErrorHandler(0); 228 XSetErrorHandler(0);