diff options
| author | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-13 19:55:07 +0200 |
|---|---|---|
| committer | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-13 19:55:07 +0200 |
| commit | 3aad92202d58208c4197857d3f17c535ba0bd56a (patch) | |
| tree | 9a1b23fcf9a4f8c0810d6893b217f265ebebfda6 | |
| parent | several other additions/fixes, dwm is quite usable already (diff) | |
| download | dwm-3aad92202d58208c4197857d3f17c535ba0bd56a.tar.gz dwm-3aad92202d58208c4197857d3f17c535ba0bd56a.zip | |
new stuff
Diffstat (limited to '')
| -rw-r--r-- | client.c | 122 | ||||
| -rw-r--r-- | config.mk | 2 | ||||
| -rw-r--r-- | dev.c | 12 | ||||
| -rw-r--r-- | dwm.h | 24 | ||||
| -rw-r--r-- | main.c | 4 |
5 files changed, 103 insertions, 61 deletions
| @@ -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 | ||
| 14 | static void (*arrange)(Arg *) = floating; | 14 | static void (*arrange)(Arg *) = tiling; |
| 15 | 15 | ||
| 16 | static void | 16 | static Rule rule[] = { |
| 17 | center(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 | ||
| 22 | static Client * | 20 | static Client * |
| 23 | next(Client *c) | 21 | next(Client *c) |
| @@ -29,18 +27,18 @@ next(Client *c) | |||
| 29 | void | 27 | void |
| 30 | zoom(Arg *arg) | 28 | zoom(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 | |||
| 119 | tiling(Arg *arg) | 117 | tiling(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 | ||
| 321 | static void | ||
| 322 | init_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 | |||
| 326 | void | 358 | void |
| 327 | manage(Window w, XWindowAttributes *wa) | 359 | manage(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 | ||
| 375 | void | 409 | void |
| @@ -11,7 +11,7 @@ X11LIB = /usr/X11R6/lib | |||
| 11 | VERSION = 0.0 | 11 | VERSION = 0.0 |
| 12 | 12 | ||
| 13 | # includes and libs | 13 | # includes and libs |
| 14 | LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11 | 14 | LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11 |
| 15 | 15 | ||
| 16 | # Linux/BSD | 16 | # Linux/BSD |
| 17 | CFLAGS = -g -Wall -O2 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ | 17 | CFLAGS = -g -Wall -O2 -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ |
| @@ -20,8 +20,7 @@ const char *browse[] = { "firefox", NULL }; | |||
| 20 | const char *xlock[] = { "xlock", NULL }; | 20 | const char *xlock[] = { "xlock", NULL }; |
| 21 | 21 | ||
| 22 | static Key key[] = { | 22 | static 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[] = { | |||
| 48 | void | 48 | void |
| 49 | update_keys(void) | 49 | update_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 | |||
| 63 | keypress(XEvent *e) | 63 | keypress(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) |
| @@ -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 */ |
| 17 | enum { Tscratch, Tdev, Tirc, Twww, Twork, TLast }; | 18 | enum { Tscratch, Tdev, Tirc, Twww, Twork, TLast }; |
| 18 | 19 | ||
| 19 | /********** CUSTOMIZE **********/ | 20 | /********** CUSTOMIZE **********/ |
| 20 | 21 | ||
| 22 | typedef union Arg Arg; | ||
| 21 | typedef struct DC DC; | 23 | typedef struct DC DC; |
| 22 | typedef struct Client Client; | 24 | typedef struct Client Client; |
| 23 | typedef struct Fnt Fnt; | 25 | typedef struct Fnt Fnt; |
| 24 | typedef struct Key Key; | 26 | typedef struct Key Key; |
| 25 | typedef union Arg Arg; | 27 | typedef struct Rule Rule; |
| 26 | 28 | ||
| 27 | union Arg { | 29 | union 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 | ||
| 76 | struct Rule { | ||
| 77 | const char *class; | ||
| 78 | const char *instance; | ||
| 79 | char *tags[TLast]; | ||
| 80 | }; | ||
| 81 | |||
| 74 | struct Key { | 82 | struct Key { |
| 75 | unsigned long mod; | 83 | unsigned long mod; |
| 76 | KeySym keysym; | 84 | KeySym keysym; |
| @@ -85,8 +93,8 @@ extern Cursor cursor[CurLast]; | |||
| 85 | extern Bool running, issel; | 93 | extern Bool running, issel; |
| 86 | extern void (*handler[LASTEvent]) (XEvent *); | 94 | extern void (*handler[LASTEvent]) (XEvent *); |
| 87 | 95 | ||
| 88 | extern int tsel, screen, sx, sy, sw, sh, th; | 96 | extern int tsel, screen, sx, sy, sw, sh, mw, th; |
| 89 | extern char stext[1024], *tags[TLast]; | 97 | extern char *tags[TLast]; |
| 90 | 98 | ||
| 91 | extern DC dc; | 99 | extern DC dc; |
| 92 | extern Client *clients, *sel; | 100 | extern Client *clients, *sel; |
| @@ -33,9 +33,8 @@ Cursor cursor[CurLast]; | |||
| 33 | Bool running = True; | 33 | Bool running = True; |
| 34 | Bool issel; | 34 | Bool issel; |
| 35 | 35 | ||
| 36 | char stext[1024]; | ||
| 37 | int tsel = Tdev; /* default tag */ | 36 | int tsel = Tdev; /* default tag */ |
| 38 | int screen, sx, sy, sw, sh, th; | 37 | int screen, sx, sy, sw, sh, mw, th; |
| 39 | 38 | ||
| 40 | DC dc = {0}; | 39 | DC dc = {0}; |
| 41 | Client *clients = NULL; | 40 | Client *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); |
