added grid mode on Mod1Mask g
4641aa29
7 file(s) · +97 −66
| 3 | 3 | ||
| 4 | 4 | include config.mk |
|
| 5 | 5 | ||
| 6 | - | WMSRC = bar.c client.c cmd.c draw.c event.c kb.c mouse.c util.c wm.c |
|
| 6 | + | WMSRC = bar.c client.c draw.c event.c kb.c mouse.c util.c wm.c |
|
| 7 | 7 | WMOBJ = ${WMSRC:.c=.o} |
|
| 8 | 8 | MENSRC = menu.c draw.c util.c |
|
| 9 | 9 | MENOBJ = ${MENSRC:.c=.o} |
| 3 | 3 | * See LICENSE file for license details. |
|
| 4 | 4 | */ |
|
| 5 | 5 | ||
| 6 | + | #include <math.h> |
|
| 6 | 7 | #include <stdlib.h> |
|
| 7 | 8 | #include <string.h> |
|
| 8 | 9 | #include <X11/Xatom.h> |
|
| 9 | 10 | ||
| 10 | 11 | #include "util.h" |
|
| 11 | 12 | #include "wm.h" |
|
| 13 | + | ||
| 14 | + | void |
|
| 15 | + | arrange(void *aux) |
|
| 16 | + | { |
|
| 17 | + | Client *c; |
|
| 18 | + | int n, cols, rows, gw, gh, i, j; |
|
| 19 | + | float rt, fd; |
|
| 20 | + | ||
| 21 | + | if(!clients) |
|
| 22 | + | return; |
|
| 23 | + | for(n = 0, c = clients; c; c = c->next, n++); |
|
| 24 | + | rt = sqrt(n); |
|
| 25 | + | if(modff(rt, &fd) < 0.5) |
|
| 26 | + | rows = floor(rt); |
|
| 27 | + | else |
|
| 28 | + | rows = ceil(rt); |
|
| 29 | + | if(rows * rows < n) |
|
| 30 | + | cols = rows + 1; |
|
| 31 | + | else |
|
| 32 | + | cols = rows; |
|
| 33 | + | ||
| 34 | + | gw = (sw - 1) / cols; |
|
| 35 | + | gh = (sh - bh - 1) / rows; |
|
| 36 | + | ||
| 37 | + | for(i = j = 0, c = clients; c; c = c->next) { |
|
| 38 | + | c->x = i * gw; |
|
| 39 | + | c->y = j * gh + bh; |
|
| 40 | + | c->w = gw; |
|
| 41 | + | c->h = gh; |
|
| 42 | + | resize(c); |
|
| 43 | + | if(++i == cols) { |
|
| 44 | + | j++; |
|
| 45 | + | i = 0; |
|
| 46 | + | } |
|
| 47 | + | } |
|
| 48 | + | } |
|
| 49 | + | ||
| 50 | + | void |
|
| 51 | + | sel(void *aux) |
|
| 52 | + | { |
|
| 53 | + | const char *arg = aux; |
|
| 54 | + | Client *c = NULL; |
|
| 55 | + | ||
| 56 | + | if(!arg || !stack) |
|
| 57 | + | return; |
|
| 58 | + | if(!strncmp(arg, "next", 5)) |
|
| 59 | + | c = stack->snext ? stack->snext : stack; |
|
| 60 | + | else if(!strncmp(arg, "prev", 5)) |
|
| 61 | + | for(c = stack; c && c->snext; c = c->snext); |
|
| 62 | + | if(!c) |
|
| 63 | + | c = stack; |
|
| 64 | + | raise(c); |
|
| 65 | + | focus(c); |
|
| 66 | + | } |
|
| 67 | + | ||
| 68 | + | void |
|
| 69 | + | kill(void *aux) |
|
| 70 | + | { |
|
| 71 | + | Client *c = stack; |
|
| 72 | + | ||
| 73 | + | if(!c) |
|
| 74 | + | return; |
|
| 75 | + | if(c->proto & WM_PROTOCOL_DELWIN) |
|
| 76 | + | send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]); |
|
| 77 | + | else |
|
| 78 | + | XKillClient(dpy, c->win); |
|
| 79 | + | } |
|
| 12 | 80 | ||
| 13 | 81 | static void |
|
| 14 | 82 | resize_title(Client *c) |
|
| 113 | 181 | draw_client(old); |
|
| 114 | 182 | } |
|
| 115 | 183 | XUnmapWindow(dpy, c->title); |
|
| 116 | - | draw_client(old); |
|
| 184 | + | draw_client(c); |
|
| 117 | 185 | XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); |
|
| 118 | 186 | XFlush(dpy); |
|
| 119 | 187 | } |
|
| 1 | - | /* |
|
| 2 | - | * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> |
|
| 3 | - | * See LICENSE file for license details. |
|
| 4 | - | */ |
|
| 5 | - | ||
| 6 | - | #include "wm.h" |
|
| 7 | - | #include <stdio.h> |
|
| 8 | - | #include <string.h> |
|
| 9 | - | ||
| 10 | - | void |
|
| 11 | - | run(void *aux) |
|
| 12 | - | { |
|
| 13 | - | spawn(dpy, aux); |
|
| 14 | - | } |
|
| 15 | - | ||
| 16 | - | void |
|
| 17 | - | quit(void *aux) |
|
| 18 | - | { |
|
| 19 | - | running = False; |
|
| 20 | - | } |
|
| 21 | - | ||
| 22 | - | void |
|
| 23 | - | sel(void *aux) |
|
| 24 | - | { |
|
| 25 | - | const char *arg = aux; |
|
| 26 | - | Client *c = NULL; |
|
| 27 | - | ||
| 28 | - | if(!arg || !stack) |
|
| 29 | - | return; |
|
| 30 | - | if(!strncmp(arg, "next", 5)) |
|
| 31 | - | c = stack->snext ? stack->snext : stack; |
|
| 32 | - | else if(!strncmp(arg, "prev", 5)) |
|
| 33 | - | for(c = stack; c && c->snext; c = c->snext); |
|
| 34 | - | if(!c) |
|
| 35 | - | c = stack; |
|
| 36 | - | raise(c); |
|
| 37 | - | focus(c); |
|
| 38 | - | } |
|
| 39 | - | ||
| 40 | - | void |
|
| 41 | - | kill(void *aux) |
|
| 42 | - | { |
|
| 43 | - | Client *c = stack; |
|
| 44 | - | ||
| 45 | - | if(!c) |
|
| 46 | - | return; |
|
| 47 | - | if(c->proto & WM_PROTOCOL_DELWIN) |
|
| 48 | - | send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]); |
|
| 49 | - | else |
|
| 50 | - | XKillClient(dpy, c->win); |
|
| 51 | - | } |
|
| 52 | - |
| 11 | 11 | VERSION = 0.0 |
|
| 12 | 12 | ||
| 13 | 13 | # includes and libs |
|
| 14 | - | LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11 |
|
| 14 | + | LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11 |
|
| 15 | 15 | ||
| 16 | 16 | # Linux/BSD |
|
| 17 | 17 | CFLAGS = -g -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ |
| 13 | 13 | }; |
|
| 14 | 14 | ||
| 15 | 15 | static const char *proglist[] = { |
|
| 16 | - | "sh", "-c", "exec `ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null | awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`", 0 |
|
| 16 | + | "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 |
|
| 17 | 18 | }; |
|
| 18 | 19 | ||
| 19 | 20 | static Key key[] = { |
|
| 20 | 21 | { Mod1Mask, XK_Return, run, term }, |
|
| 21 | 22 | { Mod1Mask, XK_p, run, proglist }, |
|
| 22 | - | { Mod1Mask, XK_k, sel, "prev"}, |
|
| 23 | - | { Mod1Mask, XK_j, sel, "next"}, |
|
| 24 | - | { Mod1Mask | ShiftMask, XK_c, kill, NULL}, |
|
| 25 | - | { Mod1Mask | ShiftMask, XK_q, quit, NULL}, |
|
| 23 | + | { Mod1Mask, XK_k, sel, "prev" }, |
|
| 24 | + | { Mod1Mask, XK_j, sel, "next" }, |
|
| 25 | + | { Mod1Mask, XK_g, arrange, NULL }, |
|
| 26 | + | { Mod1Mask | ShiftMask, XK_c, kill, NULL }, |
|
| 27 | + | { Mod1Mask | ShiftMask, XK_q, quit, NULL }, |
|
| 26 | 28 | }; |
|
| 27 | 29 | ||
| 28 | 30 | void |
| 175 | 175 | XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); |
|
| 176 | 176 | } |
|
| 177 | 177 | ||
| 178 | + | void |
|
| 179 | + | run(void *aux) |
|
| 180 | + | { |
|
| 181 | + | spawn(dpy, aux); |
|
| 182 | + | } |
|
| 183 | + | ||
| 184 | + | void |
|
| 185 | + | quit(void *aux) |
|
| 186 | + | { |
|
| 187 | + | running = False; |
|
| 188 | + | } |
|
| 189 | + | ||
| 178 | 190 | int |
|
| 179 | 191 | main(int argc, char *argv[]) |
|
| 180 | 192 | { |
| 58 | 58 | /* bar.c */ |
|
| 59 | 59 | extern void draw_bar(); |
|
| 60 | 60 | ||
| 61 | - | /* cmd.c */ |
|
| 62 | - | extern void run(void *aux); |
|
| 63 | - | extern void quit(void *aux); |
|
| 64 | - | extern void kill(void *aux); |
|
| 65 | - | extern void sel(void *aux); |
|
| 66 | - | ||
| 67 | 61 | /* client.c */ |
|
| 68 | 62 | extern void manage(Window w, XWindowAttributes *wa); |
|
| 69 | 63 | extern void unmanage(Client *c); |
|
| 76 | 70 | extern Client *gettitle(Window w); |
|
| 77 | 71 | extern void raise(Client *c); |
|
| 78 | 72 | extern void lower(Client *c); |
|
| 73 | + | extern void kill(void *aux); |
|
| 74 | + | extern void sel(void *aux); |
|
| 79 | 75 | ||
| 80 | 76 | /* event.c */ |
|
| 81 | 77 | extern void discard_events(long even_mask); |
|
| 78 | + | ||
| 79 | + | /* grid.c */ |
|
| 80 | + | extern void arrange(); |
|
| 82 | 81 | ||
| 83 | 82 | /* key.c */ |
|
| 84 | 83 | extern void update_keys(); |
|
| 92 | 91 | extern int error_handler(Display *dpy, XErrorEvent *error); |
|
| 93 | 92 | extern void send_message(Window w, Atom a, long value); |
|
| 94 | 93 | extern int win_proto(Window w); |
|
| 94 | + | extern void run(void *aux); |
|
| 95 | + | extern void quit(void *aux); |
|