diff options
| author | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-13 01:04:38 +0200 |
|---|---|---|
| committer | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-13 01:04:38 +0200 |
| commit | da2bbd371c522d63d737d43a127601a3fdbcb9d8 (patch) | |
| tree | fe7f5874dc09c446d3da38f15930c5f6ae523c13 | |
| parent | new stuff, fixed several issues (diff) | |
| download | dwm-da2bbd371c522d63d737d43a127601a3fdbcb9d8.tar.gz dwm-da2bbd371c522d63d737d43a127601a3fdbcb9d8.zip | |
before leaning things up
| -rw-r--r-- | bar.c | 22 | ||||
| -rw-r--r-- | client.c | 61 | ||||
| -rw-r--r-- | config.h | 5 | ||||
| -rw-r--r-- | event.c | 4 | ||||
| -rw-r--r-- | kb.c | 17 | ||||
| -rw-r--r-- | menu.c | 57 | ||||
| -rw-r--r-- | mouse.c | 32 | ||||
| -rw-r--r-- | wm.c | 51 | ||||
| -rw-r--r-- | wm.h | 13 |
9 files changed, 150 insertions, 112 deletions
| @@ -8,22 +8,34 @@ | |||
| 8 | void | 8 | void |
| 9 | draw_bar() | 9 | draw_bar() |
| 10 | { | 10 | { |
| 11 | int i; | ||
| 11 | brush.x = brush.y = 0; | 12 | brush.x = brush.y = 0; |
| 12 | brush.w = bw; | 13 | brush.w = bw; |
| 13 | brush.h = bh; | 14 | brush.h = bh; |
| 14 | draw(dpy, &brush, False, NULL); | 15 | draw(dpy, &brush, False, NULL); |
| 15 | 16 | ||
| 17 | brush.w = 0; | ||
| 18 | for(i = 0; i < TLast; i++) { | ||
| 19 | brush.x += brush.w; | ||
| 20 | brush.w = textw(&brush.font, tags[i]) + bh; | ||
| 21 | if(i == tsel) { | ||
| 22 | swap((void **)&brush.fg, (void **)&brush.bg); | ||
| 23 | draw(dpy, &brush, True, tags[i]); | ||
| 24 | swap((void **)&brush.fg, (void **)&brush.bg); | ||
| 25 | } | ||
| 26 | else | ||
| 27 | draw(dpy, &brush, True, tags[i]); | ||
| 28 | } | ||
| 16 | if(stack) { | 29 | if(stack) { |
| 17 | brush.w = textw(&brush.font, stack->name) + bh; | ||
| 18 | swap((void **)&brush.fg, (void **)&brush.bg); | 30 | swap((void **)&brush.fg, (void **)&brush.bg); |
| 31 | brush.x += brush.w; | ||
| 32 | brush.w = textw(&brush.font, stack->name) + bh; | ||
| 19 | draw(dpy, &brush, True, stack->name); | 33 | draw(dpy, &brush, True, stack->name); |
| 20 | swap((void **)&brush.fg, (void **)&brush.bg); | 34 | swap((void **)&brush.fg, (void **)&brush.bg); |
| 21 | brush.x += brush.w; | ||
| 22 | } | 35 | } |
| 23 | 36 | brush.w = textw(&brush.font, stext) + bh; | |
| 24 | brush.w = textw(&brush.font, statustext) + bh; | ||
| 25 | brush.x = bx + bw - brush.w; | 37 | brush.x = bx + bw - brush.w; |
| 26 | draw(dpy, &brush, False, statustext); | 38 | draw(dpy, &brush, False, stext); |
| 27 | XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, bw, bh, 0, 0); | 39 | XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, bw, bh, 0, 0); |
| 28 | XFlush(dpy); | 40 | XFlush(dpy); |
| 29 | } | 41 | } |
| @@ -11,6 +11,8 @@ | |||
| 11 | #include "util.h" | 11 | #include "util.h" |
| 12 | #include "wm.h" | 12 | #include "wm.h" |
| 13 | 13 | ||
| 14 | void (*arrange)(void *aux); | ||
| 15 | |||
| 14 | void | 16 | void |
| 15 | max(void *aux) | 17 | max(void *aux) |
| 16 | { | 18 | { |
| @@ -25,12 +27,24 @@ max(void *aux) | |||
| 25 | } | 27 | } |
| 26 | 28 | ||
| 27 | void | 29 | void |
| 28 | arrange(void *aux) | 30 | floating(void *aux) |
| 31 | { | ||
| 32 | Client *c; | ||
| 33 | |||
| 34 | arrange = floating; | ||
| 35 | for(c = stack; c; c = c->snext) | ||
| 36 | resize(c); | ||
| 37 | discard_events(EnterWindowMask); | ||
| 38 | } | ||
| 39 | |||
| 40 | void | ||
| 41 | grid(void *aux) | ||
| 29 | { | 42 | { |
| 30 | Client *c; | 43 | Client *c; |
| 31 | int n, cols, rows, gw, gh, i, j; | 44 | int n, cols, rows, gw, gh, i, j; |
| 32 | float rt, fd; | 45 | float rt, fd; |
| 33 | 46 | ||
| 47 | arrange = grid; | ||
| 34 | if(!clients) | 48 | if(!clients) |
| 35 | return; | 49 | return; |
| 36 | for(n = 0, c = clients; c; c = c->next, n++); | 50 | for(n = 0, c = clients; c; c = c->next, n++); |
| @@ -95,7 +109,13 @@ kill(void *aux) | |||
| 95 | static void | 109 | static void |
| 96 | resize_title(Client *c) | 110 | resize_title(Client *c) |
| 97 | { | 111 | { |
| 98 | c->tw = textw(&brush.font, c->name) + bh; | 112 | int i; |
| 113 | |||
| 114 | c->tw = 0; | ||
| 115 | for(i = 0; i < TLast; i++) | ||
| 116 | if(c->tags[i]) | ||
| 117 | c->tw += textw(&brush.font, c->tags[i]) + bh; | ||
| 118 | c->tw += textw(&brush.font, c->name) + bh; | ||
| 99 | if(c->tw > c->w) | 119 | if(c->tw > c->w) |
| 100 | c->tw = c->w + 2; | 120 | c->tw = c->w + 2; |
| 101 | c->tx = c->x + c->w - c->tw + 2; | 121 | c->tx = c->x + c->w - c->tw + 2; |
| @@ -190,8 +210,8 @@ focus(Client *c) | |||
| 190 | 210 | ||
| 191 | old = stack; | 211 | old = stack; |
| 192 | for(l = &stack; *l && *l != c; l = &(*l)->snext); | 212 | for(l = &stack; *l && *l != c; l = &(*l)->snext); |
| 193 | eassert(*l == c); | 213 | if(*l) |
| 194 | *l = c->snext; | 214 | *l = c->snext; |
| 195 | c->snext = stack; | 215 | c->snext = stack; |
| 196 | stack = c; | 216 | stack = c; |
| 197 | if(old && old != c) { | 217 | if(old && old != c) { |
| @@ -230,17 +250,16 @@ manage(Window w, XWindowAttributes *wa) | |||
| 230 | twa.background_pixmap = ParentRelative; | 250 | twa.background_pixmap = ParentRelative; |
| 231 | twa.event_mask = ExposureMask; | 251 | twa.event_mask = ExposureMask; |
| 232 | 252 | ||
| 253 | c->tags[tsel] = tags[tsel]; | ||
| 233 | c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th, | 254 | c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th, |
| 234 | 0, DefaultDepth(dpy, screen), CopyFromParent, | 255 | 0, DefaultDepth(dpy, screen), CopyFromParent, |
| 235 | DefaultVisual(dpy, screen), | 256 | DefaultVisual(dpy, screen), |
| 236 | CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); | 257 | CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); |
| 237 | update_name(c); | ||
| 238 | 258 | ||
| 259 | update_name(c); | ||
| 239 | for(l=&clients; *l; l=&(*l)->next); | 260 | for(l=&clients; *l; l=&(*l)->next); |
| 240 | c->next = *l; /* *l == nil */ | 261 | c->next = *l; /* *l == nil */ |
| 241 | *l = c; | 262 | *l = c; |
| 242 | c->snext = stack; | ||
| 243 | stack = c; | ||
| 244 | XMapRaised(dpy, c->win); | 263 | XMapRaised(dpy, c->win); |
| 245 | XMapRaised(dpy, c->title); | 264 | XMapRaised(dpy, c->title); |
| 246 | XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask, | 265 | XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask, |
| @@ -249,7 +268,7 @@ manage(Window w, XWindowAttributes *wa) | |||
| 249 | GrabModeAsync, GrabModeSync, None, None); | 268 | GrabModeAsync, GrabModeSync, None, None); |
| 250 | XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask, | 269 | XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask, |
| 251 | GrabModeAsync, GrabModeSync, None, None); | 270 | GrabModeAsync, GrabModeSync, None, None); |
| 252 | resize(c); | 271 | arrange(NULL); |
| 253 | focus(c); | 272 | focus(c); |
| 254 | } | 273 | } |
| 255 | 274 | ||
| @@ -308,11 +327,24 @@ gravitate(Client *c, Bool invert) | |||
| 308 | c->y += dy; | 327 | c->y += dy; |
| 309 | } | 328 | } |
| 310 | 329 | ||
| 330 | |||
| 311 | void | 331 | void |
| 312 | resize(Client *c) | 332 | resize(Client *c) |
| 313 | { | 333 | { |
| 314 | XConfigureEvent e; | 334 | XConfigureEvent e; |
| 315 | 335 | ||
| 336 | if(c->incw) | ||
| 337 | c->w -= (c->w - c->basew) % c->incw; | ||
| 338 | if(c->inch) | ||
| 339 | c->h -= (c->h - c->baseh) % c->inch; | ||
| 340 | if(c->minw && c->w < c->minw) | ||
| 341 | c->w = c->minw; | ||
| 342 | if(c->minh && c->h < c->minh) | ||
| 343 | c->h = c->minh; | ||
| 344 | if(c->maxw && c->w > c->maxw) | ||
| 345 | c->w = c->maxw; | ||
| 346 | if(c->maxh && c->h > c->maxh) | ||
| 347 | c->h = c->maxh; | ||
| 316 | resize_title(c); | 348 | resize_title(c); |
| 317 | XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); | 349 | XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); |
| 318 | e.type = ConfigureNotify; | 350 | e.type = ConfigureNotify; |
| @@ -357,6 +389,7 @@ unmanage(Client *c) | |||
| 357 | XFlush(dpy); | 389 | XFlush(dpy); |
| 358 | XSetErrorHandler(error_handler); | 390 | XSetErrorHandler(error_handler); |
| 359 | XUngrabServer(dpy); | 391 | XUngrabServer(dpy); |
| 392 | arrange(NULL); | ||
| 360 | if(stack) | 393 | if(stack) |
| 361 | focus(stack); | 394 | focus(stack); |
| 362 | } | 395 | } |
| @@ -384,15 +417,25 @@ getclient(Window w) | |||
| 384 | void | 417 | void |
| 385 | draw_client(Client *c) | 418 | draw_client(Client *c) |
| 386 | { | 419 | { |
| 420 | int i; | ||
| 387 | if(c == stack) { | 421 | if(c == stack) { |
| 388 | draw_bar(); | 422 | draw_bar(); |
| 389 | return; | 423 | return; |
| 390 | } | 424 | } |
| 391 | 425 | ||
| 392 | brush.x = brush.y = 0; | 426 | brush.x = brush.y = 0; |
| 393 | brush.w = c->tw; | ||
| 394 | brush.h = c->th; | 427 | brush.h = c->th; |
| 395 | 428 | ||
| 429 | brush.w = 0; | ||
| 430 | for(i = 0; i < TLast; i++) { | ||
| 431 | if(c->tags[i]) { | ||
| 432 | brush.x += brush.w; | ||
| 433 | brush.w = textw(&brush.font, c->tags[i]) + bh; | ||
| 434 | draw(dpy, &brush, True, c->tags[i]); | ||
| 435 | } | ||
| 436 | } | ||
| 437 | brush.x += brush.w; | ||
| 438 | brush.w = textw(&brush.font, c->name) + bh; | ||
| 396 | draw(dpy, &brush, True, c->name); | 439 | draw(dpy, &brush, True, c->name); |
| 397 | XCopyArea(dpy, brush.drawable, c->title, brush.gc, | 440 | XCopyArea(dpy, brush.drawable, c->title, brush.gc, |
| 398 | 0, 0, c->tw, c->th, 0, 0); | 441 | 0, 0, c->tw, c->th, 0, 0); |
| @@ -8,3 +8,8 @@ | |||
| 8 | #define FGCOLOR "#ffffff" | 8 | #define FGCOLOR "#ffffff" |
| 9 | #define BORDERCOLOR "#9999CC" | 9 | #define BORDERCOLOR "#9999CC" |
| 10 | #define STATUSDELAY 10 /* seconds */ | 10 | #define STATUSDELAY 10 /* seconds */ |
| 11 | |||
| 12 | /* tags, see wm.c for further config */ | ||
| 13 | enum { Tscratch, Tdev, Tirc, Twww, Twork, /* never remove: */ TLast }; | ||
| 14 | |||
| 15 | /* see kb.c for shortcut customization */ | ||
| @@ -126,7 +126,7 @@ enternotify(XEvent *e) | |||
| 126 | if((c = getclient(ev->window))) | 126 | if((c = getclient(ev->window))) |
| 127 | focus(c); | 127 | focus(c); |
| 128 | else if(ev->window == root) | 128 | else if(ev->window == root) |
| 129 | sel_screen = True; | 129 | issel = True; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | static void | 132 | static void |
| @@ -135,7 +135,7 @@ leavenotify(XEvent *e) | |||
| 135 | XCrossingEvent *ev = &e->xcrossing; | 135 | XCrossingEvent *ev = &e->xcrossing; |
| 136 | 136 | ||
| 137 | if((ev->window == root) && !ev->same_screen) | 137 | if((ev->window == root) && !ev->same_screen) |
| 138 | sel_screen = True; | 138 | issel = True; |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | static void | 141 | static void |
| @@ -7,27 +7,32 @@ | |||
| 7 | 7 | ||
| 8 | #include <X11/keysym.h> | 8 | #include <X11/keysym.h> |
| 9 | 9 | ||
| 10 | static const char *term[] = { | 10 | /********** CUSTOMIZE **********/ |
| 11 | |||
| 12 | char *cmdterm[] = { | ||
| 11 | "aterm", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn", | 13 | "aterm", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn", |
| 12 | "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0 | 14 | "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL |
| 13 | }; | 15 | }; |
| 14 | 16 | ||
| 15 | static const char *proglist[] = { | 17 | char *cmdproglist[] = { |
| 16 | "sh", "-c", "exec `ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null " | 18 | "sh", "-c", "exec `ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null " |
| 17 | "| awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`", 0 | 19 | "| awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`", 0 |
| 18 | }; | 20 | }; |
| 19 | 21 | ||
| 20 | static Key key[] = { | 22 | static Key key[] = { |
| 21 | { Mod1Mask, XK_Return, run, term }, | 23 | { Mod1Mask, XK_Return, run, cmdterm }, |
| 22 | { Mod1Mask, XK_p, run, proglist }, | 24 | { Mod1Mask, XK_p, run, cmdproglist}, |
| 23 | { Mod1Mask, XK_k, sel, "prev" }, | 25 | { Mod1Mask, XK_k, sel, "prev" }, |
| 24 | { Mod1Mask, XK_j, sel, "next" }, | 26 | { Mod1Mask, XK_j, sel, "next" }, |
| 25 | { Mod1Mask, XK_g, arrange, NULL }, | 27 | { Mod1Mask, XK_g, grid, NULL }, |
| 28 | { Mod1Mask, XK_f, floating, NULL }, | ||
| 26 | { Mod1Mask, XK_m, max, NULL }, | 29 | { Mod1Mask, XK_m, max, NULL }, |
| 27 | { Mod1Mask | ShiftMask, XK_c, kill, NULL }, | 30 | { Mod1Mask | ShiftMask, XK_c, kill, NULL }, |
| 28 | { Mod1Mask | ShiftMask, XK_q, quit, NULL }, | 31 | { Mod1Mask | ShiftMask, XK_q, quit, NULL }, |
| 29 | }; | 32 | }; |
| 30 | 33 | ||
| 34 | /********** CUSTOMIZE **********/ | ||
| 35 | |||
| 31 | void | 36 | void |
| 32 | update_keys() | 37 | update_keys() |
| 33 | { | 38 | { |
| @@ -12,9 +12,6 @@ | |||
| 12 | #include <stdlib.h> | 12 | #include <stdlib.h> |
| 13 | #include <stdio.h> | 13 | #include <stdio.h> |
| 14 | #include <string.h> | 14 | #include <string.h> |
| 15 | #include <sys/stat.h> | ||
| 16 | #include <sys/wait.h> | ||
| 17 | #include <time.h> | ||
| 18 | #include <unistd.h> | 15 | #include <unistd.h> |
| 19 | #include <X11/cursorfont.h> | 16 | #include <X11/cursorfont.h> |
| 20 | #include <X11/Xutil.h> | 17 | #include <X11/Xutil.h> |
| @@ -58,11 +55,7 @@ static void kpress(XKeyEvent * e); | |||
| 58 | static char version[] = "gridmenu - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; | 55 | static char version[] = "gridmenu - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; |
| 59 | 56 | ||
| 60 | static void | 57 | static void |
| 61 | usage() | 58 | usage() { error("usage: gridmenu [-v] [-t <title>]\n"); } |
| 62 | { | ||
| 63 | fprintf(stderr, "%s", "usage: gridmenu [-v] [-t <title>]\n"); | ||
| 64 | exit(1); | ||
| 65 | } | ||
| 66 | 59 | ||
| 67 | static void | 60 | static void |
| 68 | update_offsets() | 61 | update_offsets() |
| @@ -213,26 +206,12 @@ kpress(XKeyEvent * e) | |||
| 213 | /* first check if a control mask is omitted */ | 206 | /* first check if a control mask is omitted */ |
| 214 | if(e->state & ControlMask) { | 207 | if(e->state & ControlMask) { |
| 215 | switch (ksym) { | 208 | switch (ksym) { |
| 216 | case XK_H: | 209 | default: /* ignore other control sequences */ |
| 210 | return; | ||
| 211 | break; | ||
| 217 | case XK_h: | 212 | case XK_h: |
| 218 | ksym = XK_BackSpace; | 213 | ksym = XK_BackSpace; |
| 219 | break; | 214 | break; |
| 220 | case XK_I: | ||
| 221 | case XK_i: | ||
| 222 | ksym = XK_Tab; | ||
| 223 | break; | ||
| 224 | case XK_J: | ||
| 225 | case XK_j: | ||
| 226 | ksym = XK_Return; | ||
| 227 | break; | ||
| 228 | case XK_N: | ||
| 229 | case XK_n: | ||
| 230 | ksym = XK_Right; | ||
| 231 | break; | ||
| 232 | case XK_P: | ||
| 233 | case XK_p: | ||
| 234 | ksym = XK_Left; | ||
| 235 | break; | ||
| 236 | case XK_U: | 215 | case XK_U: |
| 237 | case XK_u: | 216 | case XK_u: |
| 238 | text[0] = 0; | 217 | text[0] = 0; |
| @@ -243,12 +222,9 @@ kpress(XKeyEvent * e) | |||
| 243 | case XK_bracketleft: | 222 | case XK_bracketleft: |
| 244 | ksym = XK_Escape; | 223 | ksym = XK_Escape; |
| 245 | break; | 224 | break; |
| 246 | default: /* ignore other control sequences */ | ||
| 247 | return; | ||
| 248 | break; | ||
| 249 | } | 225 | } |
| 250 | } | 226 | } |
| 251 | switch (ksym) { | 227 | switch(ksym) { |
| 252 | case XK_Left: | 228 | case XK_Left: |
| 253 | if(!(sel && sel->left)) | 229 | if(!(sel && sel->left)) |
| 254 | return; | 230 | return; |
| @@ -432,21 +408,18 @@ main(int argc, char *argv[]) | |||
| 432 | XFlush(dpy); | 408 | XFlush(dpy); |
| 433 | 409 | ||
| 434 | /* main event loop */ | 410 | /* main event loop */ |
| 435 | while(!XNextEvent(dpy, &ev)) { | 411 | while(!done && !XNextEvent(dpy, &ev)) { |
| 436 | switch (ev.type) { | 412 | switch (ev.type) { |
| 437 | case KeyPress: | 413 | case KeyPress: |
| 438 | kpress(&ev.xkey); | 414 | kpress(&ev.xkey); |
| 439 | break; | 415 | break; |
| 440 | case Expose: | 416 | case Expose: |
| 441 | if(ev.xexpose.count == 0) { | 417 | if(ev.xexpose.count == 0) |
| 442 | draw_menu(); | 418 | draw_menu(); |
| 443 | } | ||
| 444 | break; | ||
| 445 | default: | ||
| 446 | break; | ||
| 447 | } | ||
| 448 | if(done) | ||
| 449 | break; | 419 | break; |
| 420 | default: | ||
| 421 | break; | ||
| 422 | } | ||
| 450 | } | 423 | } |
| 451 | 424 | ||
| 452 | XUngrabKeyboard(dpy, CurrentTime); | 425 | XUngrabKeyboard(dpy, CurrentTime); |
| @@ -13,27 +13,6 @@ | |||
| 13 | #define ButtonMask (ButtonPressMask | ButtonReleaseMask) | 13 | #define ButtonMask (ButtonPressMask | ButtonReleaseMask) |
| 14 | #define MouseMask (ButtonMask | PointerMotionMask) | 14 | #define MouseMask (ButtonMask | PointerMotionMask) |
| 15 | 15 | ||
| 16 | static void | ||
| 17 | mmatch(Client *c, int x1, int y1, int x2, int y2) | ||
| 18 | { | ||
| 19 | c->w = abs(x1 - x2); | ||
| 20 | c->h = abs(y1 - y2); | ||
| 21 | if(c->incw) | ||
| 22 | c->w -= (c->w - c->basew) % c->incw; | ||
| 23 | if(c->inch) | ||
| 24 | c->h -= (c->h - c->baseh) % c->inch; | ||
| 25 | if(c->minw && c->w < c->minw) | ||
| 26 | c->w = c->minw; | ||
| 27 | if(c->minh && c->h < c->minh) | ||
| 28 | c->h = c->minh; | ||
| 29 | if(c->maxw && c->w > c->maxw) | ||
| 30 | c->w = c->maxw; | ||
| 31 | if(c->maxh && c->h > c->maxh) | ||
| 32 | c->h = c->maxh; | ||
| 33 | c->x = (x1 <= x2) ? x1 : x1 - c->w; | ||
| 34 | c->y = (y1 <= y2) ? y1 : y1 - c->h; | ||
| 35 | } | ||
| 36 | |||
| 37 | void | 16 | void |
| 38 | mresize(Client *c) | 17 | mresize(Client *c) |
| 39 | { | 18 | { |
| @@ -55,11 +34,13 @@ mresize(Client *c) | |||
| 55 | break; | 34 | break; |
| 56 | case MotionNotify: | 35 | case MotionNotify: |
| 57 | XFlush(dpy); | 36 | XFlush(dpy); |
| 58 | mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y); | 37 | c->w = abs(old_cx - ev.xmotion.x); |
| 59 | XResizeWindow(dpy, c->win, c->w, c->h); | 38 | c->h = abs(old_cy - ev.xmotion.y); |
| 39 | c->x = (old_cx <= ev.xmotion.x) ? old_cx : old_cx - c->w; | ||
| 40 | c->y = (old_cy <= ev.xmotion.y) ? old_cy : old_cy - c->h; | ||
| 41 | resize(c); | ||
| 60 | break; | 42 | break; |
| 61 | case ButtonRelease: | 43 | case ButtonRelease: |
| 62 | resize(c); | ||
| 63 | XUngrabPointer(dpy, CurrentTime); | 44 | XUngrabPointer(dpy, CurrentTime); |
| 64 | return; | 45 | return; |
| 65 | } | 46 | } |
| @@ -91,10 +72,9 @@ mmove(Client *c) | |||
| 91 | XFlush(dpy); | 72 | XFlush(dpy); |
| 92 | c->x = old_cx + (ev.xmotion.x - x1); | 73 | c->x = old_cx + (ev.xmotion.x - x1); |
| 93 | c->y = old_cy + (ev.xmotion.y - y1); | 74 | c->y = old_cy + (ev.xmotion.y - y1); |
| 94 | XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); | 75 | resize(c); |
| 95 | break; | 76 | break; |
| 96 | case ButtonRelease: | 77 | case ButtonRelease: |
| 97 | resize(c); | ||
| 98 | XUngrabPointer(dpy, CurrentTime); | 78 | XUngrabPointer(dpy, CurrentTime); |
| 99 | return; | 79 | return; |
| 100 | } | 80 | } |
| @@ -18,15 +18,39 @@ | |||
| 18 | 18 | ||
| 19 | #include "wm.h" | 19 | #include "wm.h" |
| 20 | 20 | ||
| 21 | /********** CUSTOMIZE **********/ | ||
| 22 | |||
| 23 | char *tags[TLast] = { | ||
| 24 | [Tscratch] = "scratch", | ||
| 25 | [Tdev] = "dev", | ||
| 26 | [Tirc] = "irc", | ||
| 27 | [Twww] = "www", | ||
| 28 | [Twork] = "work", | ||
| 29 | }; | ||
| 30 | |||
| 31 | /* commands */ | ||
| 32 | static char *cmdwallpaper[] = { | ||
| 33 | "feh", "--bg-scale", "/home/garbeam/wallpaper/bg.jpg", NULL | ||
| 34 | }; | ||
| 35 | |||
| 36 | static char *cmdstatus[] = { | ||
| 37 | "sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`" | ||
| 38 | " `uptime | sed 's/.*://; s/,//g'`" | ||
| 39 | " `acpi | awk '{print $4}' | sed 's/,//'`", NULL | ||
| 40 | }; | ||
| 41 | |||
| 42 | /********** CUSTOMIZE **********/ | ||
| 43 | |||
| 21 | /* X structs */ | 44 | /* X structs */ |
| 22 | Display *dpy; | 45 | Display *dpy; |
| 23 | Window root, barwin; | 46 | Window root, barwin; |
| 24 | Atom wm_atom[WMLast], net_atom[NetLast]; | 47 | Atom wm_atom[WMLast], net_atom[NetLast]; |
| 25 | Cursor cursor[CurLast]; | 48 | Cursor cursor[CurLast]; |
| 26 | Bool running = True; | 49 | Bool running = True; |
| 27 | Bool sel_screen; | 50 | Bool issel; |
| 28 | 51 | ||
| 29 | char statustext[1024], tag[256]; | 52 | char stext[1024]; |
| 53 | int tsel = Tdev; /* default tag */ | ||
| 30 | int screen, sx, sy, sw, sh, bx, by, bw, bh; | 54 | int screen, sx, sy, sw, sh, bx, by, bw, bh; |
| 31 | 55 | ||
| 32 | Brush brush = {0}; | 56 | Brush brush = {0}; |
| @@ -34,21 +58,12 @@ Client *clients = NULL; | |||
| 34 | Client *stack = NULL; | 58 | Client *stack = NULL; |
| 35 | 59 | ||
| 36 | static Bool other_wm_running; | 60 | static Bool other_wm_running; |
| 37 | static const char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; | 61 | static const char version[] = |
| 62 | "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; | ||
| 38 | static int (*x_error_handler) (Display *, XErrorEvent *); | 63 | static int (*x_error_handler) (Display *, XErrorEvent *); |
| 39 | 64 | ||
| 40 | static const char *status[] = { | ||
| 41 | "sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`" | ||
| 42 | " `uptime | sed 's/.*://; s/,//g'`" | ||
| 43 | " `acpi | awk '{print $4}' | sed 's/,//'`", 0 | ||
| 44 | }; | ||
| 45 | |||
| 46 | static void | 65 | static void |
| 47 | usage() | 66 | usage() { error("usage: gridwm [-v]\n"); } |
| 48 | { | ||
| 49 | fputs("usage: gridwm [-v]\n", stderr); | ||
| 50 | exit(1); | ||
| 51 | } | ||
| 52 | 67 | ||
| 53 | static void | 68 | static void |
| 54 | scan_wins() | 69 | scan_wins() |
| @@ -230,10 +245,11 @@ main(int argc, char *argv[]) | |||
| 230 | if(other_wm_running) | 245 | if(other_wm_running) |
| 231 | error("gridwm: another window manager is already running\n"); | 246 | error("gridwm: another window manager is already running\n"); |
| 232 | 247 | ||
| 248 | spawn(dpy, cmdwallpaper); | ||
| 233 | sx = sy = 0; | 249 | sx = sy = 0; |
| 234 | sw = DisplayWidth(dpy, screen); | 250 | sw = DisplayWidth(dpy, screen); |
| 235 | sh = DisplayHeight(dpy, screen); | 251 | sh = DisplayHeight(dpy, screen); |
| 236 | sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); | 252 | issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); |
| 237 | 253 | ||
| 238 | XSetErrorHandler(0); | 254 | XSetErrorHandler(0); |
| 239 | x_error_handler = XSetErrorHandler(error_handler); | 255 | x_error_handler = XSetErrorHandler(error_handler); |
| @@ -275,7 +291,7 @@ main(int argc, char *argv[]) | |||
| 275 | brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); | 291 | brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); |
| 276 | brush.gc = XCreateGC(dpy, root, 0, 0); | 292 | brush.gc = XCreateGC(dpy, root, 0, 0); |
| 277 | 293 | ||
| 278 | pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status); | 294 | pipe_spawn(stext, sizeof(stext), dpy, cmdstatus); |
| 279 | draw_bar(); | 295 | draw_bar(); |
| 280 | 296 | ||
| 281 | wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ | 297 | wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ |
| @@ -283,6 +299,7 @@ main(int argc, char *argv[]) | |||
| 283 | wa.cursor = cursor[CurNormal]; | 299 | wa.cursor = cursor[CurNormal]; |
| 284 | XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); | 300 | XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); |
| 285 | 301 | ||
| 302 | arrange = grid; | ||
| 286 | scan_wins(); | 303 | scan_wins(); |
| 287 | 304 | ||
| 288 | while(running) { | 305 | while(running) { |
| @@ -298,7 +315,7 @@ main(int argc, char *argv[]) | |||
| 298 | if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0) | 315 | if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0) |
| 299 | continue; | 316 | continue; |
| 300 | else if(errno != EINTR) { | 317 | else if(errno != EINTR) { |
| 301 | pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status); | 318 | pipe_spawn(stext, sizeof(stext), dpy, cmdstatus); |
| 302 | draw_bar(); | 319 | draw_bar(); |
| 303 | } | 320 | } |
| 304 | } | 321 | } |
| @@ -22,7 +22,8 @@ enum { NetSupported, NetWMName, NetLast }; | |||
| 22 | enum { CurNormal, CurResize, CurMove, CurInput, CurLast }; | 22 | enum { CurNormal, CurResize, CurMove, CurInput, CurLast }; |
| 23 | 23 | ||
| 24 | struct Client { | 24 | struct Client { |
| 25 | char name[256], tag[256]; | 25 | char name[256]; |
| 26 | char *tags[TLast]; | ||
| 26 | int proto; | 27 | int proto; |
| 27 | int x, y, w, h; | 28 | int x, y, w, h; |
| 28 | int tx, ty, tw, th; | 29 | int tx, ty, tw, th; |
| @@ -48,11 +49,12 @@ extern Display *dpy; | |||
| 48 | extern Window root, barwin; | 49 | extern Window root, barwin; |
| 49 | extern Atom wm_atom[WMLast], net_atom[NetLast]; | 50 | extern Atom wm_atom[WMLast], net_atom[NetLast]; |
| 50 | extern Cursor cursor[CurLast]; | 51 | extern Cursor cursor[CurLast]; |
| 51 | extern Bool running, sel_screen, grid; | 52 | extern Bool running, issel; |
| 52 | extern void (*handler[LASTEvent]) (XEvent *); | 53 | extern void (*handler[LASTEvent]) (XEvent *); |
| 54 | extern void (*arrange)(void *aux); | ||
| 53 | 55 | ||
| 54 | extern int screen, sx, sy, sw, sh, bx, by, bw, bh; | 56 | extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh; |
| 55 | extern char statustext[1024], tag[256]; | 57 | extern char stext[1024], *tags[TLast]; |
| 56 | 58 | ||
| 57 | extern Brush brush; | 59 | extern Brush brush; |
| 58 | extern Client *clients, *stack; | 60 | extern Client *clients, *stack; |
| @@ -75,7 +77,8 @@ extern void lower(Client *c); | |||
| 75 | extern void kill(void *aux); | 77 | extern void kill(void *aux); |
| 76 | extern void sel(void *aux); | 78 | extern void sel(void *aux); |
| 77 | extern void max(void *aux); | 79 | extern void max(void *aux); |
| 78 | extern void arrange(void *aux); | 80 | extern void floating(void *aux); |
| 81 | extern void grid(void *aux); | ||
| 79 | extern void gravitate(Client *c, Bool invert); | 82 | extern void gravitate(Client *c, Bool invert); |
| 80 | 83 | ||
| 81 | /* event.c */ | 84 | /* event.c */ |
