aewl
changeset 27:f96fb3fd8203
added grid mode on Mod1Mask g
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Wed, 12 Jul 2006 16:00:51 +0200 |
parents | e8f627998d6f |
children | 3dceb132082d |
files | Makefile client.c config.mk kb.c wm.c wm.h |
diffstat | 7 files changed, 97 insertions(+), 66 deletions(-) [+] |
line diff
1.1 --- a/Makefile Wed Jul 12 15:17:22 2006 +0200 1.2 +++ b/Makefile Wed Jul 12 16:00:51 2006 +0200 1.3 @@ -3,7 +3,7 @@ 1.4 1.5 include config.mk 1.6 1.7 -WMSRC = bar.c client.c cmd.c draw.c event.c kb.c mouse.c util.c wm.c 1.8 +WMSRC = bar.c client.c draw.c event.c kb.c mouse.c util.c wm.c 1.9 WMOBJ = ${WMSRC:.c=.o} 1.10 MENSRC = menu.c draw.c util.c 1.11 MENOBJ = ${MENSRC:.c=.o}
2.1 --- a/client.c Wed Jul 12 15:17:22 2006 +0200 2.2 +++ b/client.c Wed Jul 12 16:00:51 2006 +0200 2.3 @@ -3,6 +3,7 @@ 2.4 * See LICENSE file for license details. 2.5 */ 2.6 2.7 +#include <math.h> 2.8 #include <stdlib.h> 2.9 #include <string.h> 2.10 #include <X11/Xatom.h> 2.11 @@ -10,6 +11,73 @@ 2.12 #include "util.h" 2.13 #include "wm.h" 2.14 2.15 +void 2.16 +arrange(void *aux) 2.17 +{ 2.18 + Client *c; 2.19 + int n, cols, rows, gw, gh, i, j; 2.20 + float rt, fd; 2.21 + 2.22 + if(!clients) 2.23 + return; 2.24 + for(n = 0, c = clients; c; c = c->next, n++); 2.25 + rt = sqrt(n); 2.26 + if(modff(rt, &fd) < 0.5) 2.27 + rows = floor(rt); 2.28 + else 2.29 + rows = ceil(rt); 2.30 + if(rows * rows < n) 2.31 + cols = rows + 1; 2.32 + else 2.33 + cols = rows; 2.34 + 2.35 + gw = (sw - 1) / cols; 2.36 + gh = (sh - bh - 1) / rows; 2.37 + 2.38 + for(i = j = 0, c = clients; c; c = c->next) { 2.39 + c->x = i * gw; 2.40 + c->y = j * gh + bh; 2.41 + c->w = gw; 2.42 + c->h = gh; 2.43 + resize(c); 2.44 + if(++i == cols) { 2.45 + j++; 2.46 + i = 0; 2.47 + } 2.48 + } 2.49 +} 2.50 + 2.51 +void 2.52 +sel(void *aux) 2.53 +{ 2.54 + const char *arg = aux; 2.55 + Client *c = NULL; 2.56 + 2.57 + if(!arg || !stack) 2.58 + return; 2.59 + if(!strncmp(arg, "next", 5)) 2.60 + c = stack->snext ? stack->snext : stack; 2.61 + else if(!strncmp(arg, "prev", 5)) 2.62 + for(c = stack; c && c->snext; c = c->snext); 2.63 + if(!c) 2.64 + c = stack; 2.65 + raise(c); 2.66 + focus(c); 2.67 +} 2.68 + 2.69 +void 2.70 +kill(void *aux) 2.71 +{ 2.72 + Client *c = stack; 2.73 + 2.74 + if(!c) 2.75 + return; 2.76 + if(c->proto & WM_PROTOCOL_DELWIN) 2.77 + send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]); 2.78 + else 2.79 + XKillClient(dpy, c->win); 2.80 +} 2.81 + 2.82 static void 2.83 resize_title(Client *c) 2.84 { 2.85 @@ -113,7 +181,7 @@ 2.86 draw_client(old); 2.87 } 2.88 XUnmapWindow(dpy, c->title); 2.89 - draw_client(old); 2.90 + draw_client(c); 2.91 XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime); 2.92 XFlush(dpy); 2.93 }
3.1 --- a/cmd.c Wed Jul 12 15:17:22 2006 +0200 3.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 3.3 @@ -1,52 +0,0 @@ 3.4 -/* 3.5 - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> 3.6 - * See LICENSE file for license details. 3.7 - */ 3.8 - 3.9 -#include "wm.h" 3.10 -#include <stdio.h> 3.11 -#include <string.h> 3.12 - 3.13 -void 3.14 -run(void *aux) 3.15 -{ 3.16 - spawn(dpy, aux); 3.17 -} 3.18 - 3.19 -void 3.20 -quit(void *aux) 3.21 -{ 3.22 - running = False; 3.23 -} 3.24 - 3.25 -void 3.26 -sel(void *aux) 3.27 -{ 3.28 - const char *arg = aux; 3.29 - Client *c = NULL; 3.30 - 3.31 - if(!arg || !stack) 3.32 - return; 3.33 - if(!strncmp(arg, "next", 5)) 3.34 - c = stack->snext ? stack->snext : stack; 3.35 - else if(!strncmp(arg, "prev", 5)) 3.36 - for(c = stack; c && c->snext; c = c->snext); 3.37 - if(!c) 3.38 - c = stack; 3.39 - raise(c); 3.40 - focus(c); 3.41 -} 3.42 - 3.43 -void 3.44 -kill(void *aux) 3.45 -{ 3.46 - Client *c = stack; 3.47 - 3.48 - if(!c) 3.49 - return; 3.50 - if(c->proto & WM_PROTOCOL_DELWIN) 3.51 - send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]); 3.52 - else 3.53 - XKillClient(dpy, c->win); 3.54 -} 3.55 -
4.1 --- a/config.mk Wed Jul 12 15:17:22 2006 +0200 4.2 +++ b/config.mk Wed Jul 12 16:00:51 2006 +0200 4.3 @@ -11,7 +11,7 @@ 4.4 VERSION = 0.0 4.5 4.6 # includes and libs 4.7 -LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11 4.8 +LIBS = -L${PREFIX}/lib -L/usr/lib -lc -lm -L${X11LIB} -lX11 4.9 4.10 # Linux/BSD 4.11 CFLAGS = -g -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
5.1 --- a/kb.c Wed Jul 12 15:17:22 2006 +0200 5.2 +++ b/kb.c Wed Jul 12 16:00:51 2006 +0200 5.3 @@ -13,16 +13,18 @@ 5.4 }; 5.5 5.6 static const char *proglist[] = { 5.7 - "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 5.8 + "sh", "-c", "exec `ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null " 5.9 + "| awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`", 0 5.10 }; 5.11 5.12 static Key key[] = { 5.13 { Mod1Mask, XK_Return, run, term }, 5.14 { Mod1Mask, XK_p, run, proglist }, 5.15 - { Mod1Mask, XK_k, sel, "prev"}, 5.16 - { Mod1Mask, XK_j, sel, "next"}, 5.17 - { Mod1Mask | ShiftMask, XK_c, kill, NULL}, 5.18 - { Mod1Mask | ShiftMask, XK_q, quit, NULL}, 5.19 + { Mod1Mask, XK_k, sel, "prev" }, 5.20 + { Mod1Mask, XK_j, sel, "next" }, 5.21 + { Mod1Mask, XK_g, arrange, NULL }, 5.22 + { Mod1Mask | ShiftMask, XK_c, kill, NULL }, 5.23 + { Mod1Mask | ShiftMask, XK_q, quit, NULL }, 5.24 }; 5.25 5.26 void
6.1 --- a/wm.c Wed Jul 12 15:17:22 2006 +0200 6.2 +++ b/wm.c Wed Jul 12 16:00:51 2006 +0200 6.3 @@ -175,6 +175,18 @@ 6.4 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); 6.5 } 6.6 6.7 +void 6.8 +run(void *aux) 6.9 +{ 6.10 + spawn(dpy, aux); 6.11 +} 6.12 + 6.13 +void 6.14 +quit(void *aux) 6.15 +{ 6.16 + running = False; 6.17 +} 6.18 + 6.19 int 6.20 main(int argc, char *argv[]) 6.21 {
7.1 --- a/wm.h Wed Jul 12 15:17:22 2006 +0200 7.2 +++ b/wm.h Wed Jul 12 16:00:51 2006 +0200 7.3 @@ -58,12 +58,6 @@ 7.4 /* bar.c */ 7.5 extern void draw_bar(); 7.6 7.7 -/* cmd.c */ 7.8 -extern void run(void *aux); 7.9 -extern void quit(void *aux); 7.10 -extern void kill(void *aux); 7.11 -extern void sel(void *aux); 7.12 - 7.13 /* client.c */ 7.14 extern void manage(Window w, XWindowAttributes *wa); 7.15 extern void unmanage(Client *c); 7.16 @@ -76,10 +70,15 @@ 7.17 extern Client *gettitle(Window w); 7.18 extern void raise(Client *c); 7.19 extern void lower(Client *c); 7.20 +extern void kill(void *aux); 7.21 +extern void sel(void *aux); 7.22 7.23 /* event.c */ 7.24 extern void discard_events(long even_mask); 7.25 7.26 +/* grid.c */ 7.27 +extern void arrange(); 7.28 + 7.29 /* key.c */ 7.30 extern void update_keys(); 7.31 extern void keypress(XEvent *e); 7.32 @@ -92,3 +91,5 @@ 7.33 extern int error_handler(Display *dpy, XErrorEvent *error); 7.34 extern void send_message(Window w, Atom a, long value); 7.35 extern int win_proto(Window w); 7.36 +extern void run(void *aux); 7.37 +extern void quit(void *aux);