diff options
Diffstat (limited to '')
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | client.c | 70 | ||||
| -rw-r--r-- | cmd.c | 52 | ||||
| -rw-r--r-- | config.mk | 2 | ||||
| -rw-r--r-- | kb.c | 12 | ||||
| -rw-r--r-- | wm.c | 12 | ||||
| -rw-r--r-- | wm.h | 13 |
7 files changed, 97 insertions, 66 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | 3 | ||
| 4 | include config.mk | 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 | WMOBJ = ${WMSRC:.c=.o} | 7 | WMOBJ = ${WMSRC:.c=.o} |
| 8 | MENSRC = menu.c draw.c util.c | 8 | MENSRC = menu.c draw.c util.c |
| 9 | MENOBJ = ${MENSRC:.c=.o} | 9 | MENOBJ = ${MENSRC:.c=.o} |
| @@ -3,6 +3,7 @@ | |||
| 3 | * See LICENSE file for license details. | 3 | * See LICENSE file for license details. |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #include <math.h> | ||
| 6 | #include <stdlib.h> | 7 | #include <stdlib.h> |
| 7 | #include <string.h> | 8 | #include <string.h> |
| 8 | #include <X11/Xatom.h> | 9 | #include <X11/Xatom.h> |
| @@ -10,6 +11,73 @@ | |||
| 10 | #include "util.h" | 11 | #include "util.h" |
| 11 | #include "wm.h" | 12 | #include "wm.h" |
| 12 | 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 | } | ||
| 80 | |||
| 13 | static void | 81 | static void |
| 14 | resize_title(Client *c) | 82 | resize_title(Client *c) |
| 15 | { | 83 | { |
| @@ -113,7 +181,7 @@ focus(Client *c) | |||
| 113 | draw_client(old); | 181 | draw_client(old); |
| 114 | } | 182 | } |
| 115 | XUnmapWindow(dpy, c->title); | 183 | XUnmapWindow(dpy, c->title); |
| 116 | draw_client(old); | 184 | draw_client(c); |
| 117 | XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); | 185 | XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); |
| 118 | XFlush(dpy); | 186 | XFlush(dpy); |
| 119 | } | 187 | } |
| @@ -1,52 +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 "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,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 -L${X11LIB} -lX11 | 14 | LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11 |
| 15 | 15 | ||
| 16 | # Linux/BSD | 16 | # Linux/BSD |
| 17 | CFLAGS = -g -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ | 17 | CFLAGS = -g -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ |
| @@ -13,16 +13,18 @@ static const char *term[] = { | |||
| 13 | }; | 13 | }; |
| 14 | 14 | ||
| 15 | static const char *proglist[] = { | 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 | static Key key[] = { | 20 | static Key key[] = { |
| 20 | { Mod1Mask, XK_Return, run, term }, | 21 | { Mod1Mask, XK_Return, run, term }, |
| 21 | { Mod1Mask, XK_p, run, proglist }, | 22 | { Mod1Mask, XK_p, run, proglist }, |
| 22 | { Mod1Mask, XK_k, sel, "prev"}, | 23 | { Mod1Mask, XK_k, sel, "prev" }, |
| 23 | { Mod1Mask, XK_j, sel, "next"}, | 24 | { Mod1Mask, XK_j, sel, "next" }, |
| 24 | { Mod1Mask | ShiftMask, XK_c, kill, NULL}, | 25 | { Mod1Mask, XK_g, arrange, NULL }, |
| 25 | { Mod1Mask | ShiftMask, XK_q, quit, NULL}, | 26 | { Mod1Mask | ShiftMask, XK_c, kill, NULL }, |
| 27 | { Mod1Mask | ShiftMask, XK_q, quit, NULL }, | ||
| 26 | }; | 28 | }; |
| 27 | 29 | ||
| 28 | void | 30 | void |
| @@ -175,6 +175,18 @@ cleanup() | |||
| 175 | XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); | 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 | int | 190 | int |
| 179 | main(int argc, char *argv[]) | 191 | main(int argc, char *argv[]) |
| 180 | { | 192 | { |
| @@ -58,12 +58,6 @@ extern Client *clients, *stack; | |||
| 58 | /* bar.c */ | 58 | /* bar.c */ |
| 59 | extern void draw_bar(); | 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 | /* client.c */ | 61 | /* client.c */ |
| 68 | extern void manage(Window w, XWindowAttributes *wa); | 62 | extern void manage(Window w, XWindowAttributes *wa); |
| 69 | extern void unmanage(Client *c); | 63 | extern void unmanage(Client *c); |
| @@ -76,10 +70,15 @@ extern void update_size(Client *c); | |||
| 76 | extern Client *gettitle(Window w); | 70 | extern Client *gettitle(Window w); |
| 77 | extern void raise(Client *c); | 71 | extern void raise(Client *c); |
| 78 | extern void lower(Client *c); | 72 | extern void lower(Client *c); |
| 73 | extern void kill(void *aux); | ||
| 74 | extern void sel(void *aux); | ||
| 79 | 75 | ||
| 80 | /* event.c */ | 76 | /* event.c */ |
| 81 | extern void discard_events(long even_mask); | 77 | extern void discard_events(long even_mask); |
| 82 | 78 | ||
| 79 | /* grid.c */ | ||
| 80 | extern void arrange(); | ||
| 81 | |||
| 83 | /* key.c */ | 82 | /* key.c */ |
| 84 | extern void update_keys(); | 83 | extern void update_keys(); |
| 85 | extern void keypress(XEvent *e); | 84 | extern void keypress(XEvent *e); |
| @@ -92,3 +91,5 @@ extern void mmove(Client *c); | |||
| 92 | extern int error_handler(Display *dpy, XErrorEvent *error); | 91 | extern int error_handler(Display *dpy, XErrorEvent *error); |
| 93 | extern void send_message(Window w, Atom a, long value); | 92 | extern void send_message(Window w, Atom a, long value); |
| 94 | extern int win_proto(Window w); | 93 | extern int win_proto(Window w); |
| 94 | extern void run(void *aux); | ||
| 95 | extern void quit(void *aux); | ||
