aewl
changeset 31:386649deb651
before leaning things up
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Thu, 13 Jul 2006 01:04:38 +0200 |
parents | 2e0fb4130bfb |
children | 082c75b937b5 |
files | bar.c client.c config.h event.c kb.c menu.c mouse.c wm.c wm.h |
diffstat | 9 files changed, 150 insertions(+), 112 deletions(-) [+] |
line diff
1.1 --- a/bar.c Wed Jul 12 17:50:31 2006 +0200 1.2 +++ b/bar.c Thu Jul 13 01:04:38 2006 +0200 1.3 @@ -8,22 +8,34 @@ 1.4 void 1.5 draw_bar() 1.6 { 1.7 + int i; 1.8 brush.x = brush.y = 0; 1.9 brush.w = bw; 1.10 brush.h = bh; 1.11 draw(dpy, &brush, False, NULL); 1.12 1.13 + brush.w = 0; 1.14 + for(i = 0; i < TLast; i++) { 1.15 + brush.x += brush.w; 1.16 + brush.w = textw(&brush.font, tags[i]) + bh; 1.17 + if(i == tsel) { 1.18 + swap((void **)&brush.fg, (void **)&brush.bg); 1.19 + draw(dpy, &brush, True, tags[i]); 1.20 + swap((void **)&brush.fg, (void **)&brush.bg); 1.21 + } 1.22 + else 1.23 + draw(dpy, &brush, True, tags[i]); 1.24 + } 1.25 if(stack) { 1.26 + swap((void **)&brush.fg, (void **)&brush.bg); 1.27 + brush.x += brush.w; 1.28 brush.w = textw(&brush.font, stack->name) + bh; 1.29 - swap((void **)&brush.fg, (void **)&brush.bg); 1.30 draw(dpy, &brush, True, stack->name); 1.31 swap((void **)&brush.fg, (void **)&brush.bg); 1.32 - brush.x += brush.w; 1.33 } 1.34 - 1.35 - brush.w = textw(&brush.font, statustext) + bh; 1.36 + brush.w = textw(&brush.font, stext) + bh; 1.37 brush.x = bx + bw - brush.w; 1.38 - draw(dpy, &brush, False, statustext); 1.39 + draw(dpy, &brush, False, stext); 1.40 XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, bw, bh, 0, 0); 1.41 XFlush(dpy); 1.42 }
2.1 --- a/client.c Wed Jul 12 17:50:31 2006 +0200 2.2 +++ b/client.c Thu Jul 13 01:04:38 2006 +0200 2.3 @@ -11,6 +11,8 @@ 2.4 #include "util.h" 2.5 #include "wm.h" 2.6 2.7 +void (*arrange)(void *aux); 2.8 + 2.9 void 2.10 max(void *aux) 2.11 { 2.12 @@ -25,12 +27,24 @@ 2.13 } 2.14 2.15 void 2.16 -arrange(void *aux) 2.17 +floating(void *aux) 2.18 +{ 2.19 + Client *c; 2.20 + 2.21 + arrange = floating; 2.22 + for(c = stack; c; c = c->snext) 2.23 + resize(c); 2.24 + discard_events(EnterWindowMask); 2.25 +} 2.26 + 2.27 +void 2.28 +grid(void *aux) 2.29 { 2.30 Client *c; 2.31 int n, cols, rows, gw, gh, i, j; 2.32 float rt, fd; 2.33 2.34 + arrange = grid; 2.35 if(!clients) 2.36 return; 2.37 for(n = 0, c = clients; c; c = c->next, n++); 2.38 @@ -95,7 +109,13 @@ 2.39 static void 2.40 resize_title(Client *c) 2.41 { 2.42 - c->tw = textw(&brush.font, c->name) + bh; 2.43 + int i; 2.44 + 2.45 + c->tw = 0; 2.46 + for(i = 0; i < TLast; i++) 2.47 + if(c->tags[i]) 2.48 + c->tw += textw(&brush.font, c->tags[i]) + bh; 2.49 + c->tw += textw(&brush.font, c->name) + bh; 2.50 if(c->tw > c->w) 2.51 c->tw = c->w + 2; 2.52 c->tx = c->x + c->w - c->tw + 2; 2.53 @@ -190,8 +210,8 @@ 2.54 2.55 old = stack; 2.56 for(l = &stack; *l && *l != c; l = &(*l)->snext); 2.57 - eassert(*l == c); 2.58 - *l = c->snext; 2.59 + if(*l) 2.60 + *l = c->snext; 2.61 c->snext = stack; 2.62 stack = c; 2.63 if(old && old != c) { 2.64 @@ -230,17 +250,16 @@ 2.65 twa.background_pixmap = ParentRelative; 2.66 twa.event_mask = ExposureMask; 2.67 2.68 + c->tags[tsel] = tags[tsel]; 2.69 c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th, 2.70 0, DefaultDepth(dpy, screen), CopyFromParent, 2.71 DefaultVisual(dpy, screen), 2.72 CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); 2.73 + 2.74 update_name(c); 2.75 - 2.76 for(l=&clients; *l; l=&(*l)->next); 2.77 c->next = *l; /* *l == nil */ 2.78 *l = c; 2.79 - c->snext = stack; 2.80 - stack = c; 2.81 XMapRaised(dpy, c->win); 2.82 XMapRaised(dpy, c->title); 2.83 XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask, 2.84 @@ -249,7 +268,7 @@ 2.85 GrabModeAsync, GrabModeSync, None, None); 2.86 XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask, 2.87 GrabModeAsync, GrabModeSync, None, None); 2.88 - resize(c); 2.89 + arrange(NULL); 2.90 focus(c); 2.91 } 2.92 2.93 @@ -308,11 +327,24 @@ 2.94 c->y += dy; 2.95 } 2.96 2.97 + 2.98 void 2.99 resize(Client *c) 2.100 { 2.101 XConfigureEvent e; 2.102 2.103 + if(c->incw) 2.104 + c->w -= (c->w - c->basew) % c->incw; 2.105 + if(c->inch) 2.106 + c->h -= (c->h - c->baseh) % c->inch; 2.107 + if(c->minw && c->w < c->minw) 2.108 + c->w = c->minw; 2.109 + if(c->minh && c->h < c->minh) 2.110 + c->h = c->minh; 2.111 + if(c->maxw && c->w > c->maxw) 2.112 + c->w = c->maxw; 2.113 + if(c->maxh && c->h > c->maxh) 2.114 + c->h = c->maxh; 2.115 resize_title(c); 2.116 XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); 2.117 e.type = ConfigureNotify; 2.118 @@ -357,6 +389,7 @@ 2.119 XFlush(dpy); 2.120 XSetErrorHandler(error_handler); 2.121 XUngrabServer(dpy); 2.122 + arrange(NULL); 2.123 if(stack) 2.124 focus(stack); 2.125 } 2.126 @@ -384,15 +417,25 @@ 2.127 void 2.128 draw_client(Client *c) 2.129 { 2.130 + int i; 2.131 if(c == stack) { 2.132 draw_bar(); 2.133 return; 2.134 } 2.135 2.136 brush.x = brush.y = 0; 2.137 - brush.w = c->tw; 2.138 brush.h = c->th; 2.139 2.140 + brush.w = 0; 2.141 + for(i = 0; i < TLast; i++) { 2.142 + if(c->tags[i]) { 2.143 + brush.x += brush.w; 2.144 + brush.w = textw(&brush.font, c->tags[i]) + bh; 2.145 + draw(dpy, &brush, True, c->tags[i]); 2.146 + } 2.147 + } 2.148 + brush.x += brush.w; 2.149 + brush.w = textw(&brush.font, c->name) + bh; 2.150 draw(dpy, &brush, True, c->name); 2.151 XCopyArea(dpy, brush.drawable, c->title, brush.gc, 2.152 0, 0, c->tw, c->th, 0, 0);
3.1 --- a/config.h Wed Jul 12 17:50:31 2006 +0200 3.2 +++ b/config.h Thu Jul 13 01:04:38 2006 +0200 3.3 @@ -8,3 +8,8 @@ 3.4 #define FGCOLOR "#ffffff" 3.5 #define BORDERCOLOR "#9999CC" 3.6 #define STATUSDELAY 10 /* seconds */ 3.7 + 3.8 +/* tags, see wm.c for further config */ 3.9 +enum { Tscratch, Tdev, Tirc, Twww, Twork, /* never remove: */ TLast }; 3.10 + 3.11 +/* see kb.c for shortcut customization */
4.1 --- a/event.c Wed Jul 12 17:50:31 2006 +0200 4.2 +++ b/event.c Thu Jul 13 01:04:38 2006 +0200 4.3 @@ -126,7 +126,7 @@ 4.4 if((c = getclient(ev->window))) 4.5 focus(c); 4.6 else if(ev->window == root) 4.7 - sel_screen = True; 4.8 + issel = True; 4.9 } 4.10 4.11 static void 4.12 @@ -135,7 +135,7 @@ 4.13 XCrossingEvent *ev = &e->xcrossing; 4.14 4.15 if((ev->window == root) && !ev->same_screen) 4.16 - sel_screen = True; 4.17 + issel = True; 4.18 } 4.19 4.20 static void
5.1 --- a/kb.c Wed Jul 12 17:50:31 2006 +0200 5.2 +++ b/kb.c Thu Jul 13 01:04:38 2006 +0200 5.3 @@ -7,27 +7,32 @@ 5.4 5.5 #include <X11/keysym.h> 5.6 5.7 -static const char *term[] = { 5.8 +/********** CUSTOMIZE **********/ 5.9 + 5.10 +char *cmdterm[] = { 5.11 "aterm", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn", 5.12 - "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0 5.13 + "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL 5.14 }; 5.15 5.16 -static const char *proglist[] = { 5.17 +char *cmdproglist[] = { 5.18 "sh", "-c", "exec `ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null " 5.19 "| awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`", 0 5.20 }; 5.21 5.22 static Key key[] = { 5.23 - { Mod1Mask, XK_Return, run, term }, 5.24 - { Mod1Mask, XK_p, run, proglist }, 5.25 + { Mod1Mask, XK_Return, run, cmdterm }, 5.26 + { Mod1Mask, XK_p, run, cmdproglist}, 5.27 { Mod1Mask, XK_k, sel, "prev" }, 5.28 { Mod1Mask, XK_j, sel, "next" }, 5.29 - { Mod1Mask, XK_g, arrange, NULL }, 5.30 + { Mod1Mask, XK_g, grid, NULL }, 5.31 + { Mod1Mask, XK_f, floating, NULL }, 5.32 { Mod1Mask, XK_m, max, NULL }, 5.33 { Mod1Mask | ShiftMask, XK_c, kill, NULL }, 5.34 { Mod1Mask | ShiftMask, XK_q, quit, NULL }, 5.35 }; 5.36 5.37 +/********** CUSTOMIZE **********/ 5.38 + 5.39 void 5.40 update_keys() 5.41 {
6.1 --- a/menu.c Wed Jul 12 17:50:31 2006 +0200 6.2 +++ b/menu.c Thu Jul 13 01:04:38 2006 +0200 6.3 @@ -12,9 +12,6 @@ 6.4 #include <stdlib.h> 6.5 #include <stdio.h> 6.6 #include <string.h> 6.7 -#include <sys/stat.h> 6.8 -#include <sys/wait.h> 6.9 -#include <time.h> 6.10 #include <unistd.h> 6.11 #include <X11/cursorfont.h> 6.12 #include <X11/Xutil.h> 6.13 @@ -58,11 +55,7 @@ 6.14 static char version[] = "gridmenu - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; 6.15 6.16 static void 6.17 -usage() 6.18 -{ 6.19 - fprintf(stderr, "%s", "usage: gridmenu [-v] [-t <title>]\n"); 6.20 - exit(1); 6.21 -} 6.22 +usage() { error("usage: gridmenu [-v] [-t <title>]\n"); } 6.23 6.24 static void 6.25 update_offsets() 6.26 @@ -213,26 +206,12 @@ 6.27 /* first check if a control mask is omitted */ 6.28 if(e->state & ControlMask) { 6.29 switch (ksym) { 6.30 - case XK_H: 6.31 + default: /* ignore other control sequences */ 6.32 + return; 6.33 + break; 6.34 case XK_h: 6.35 ksym = XK_BackSpace; 6.36 break; 6.37 - case XK_I: 6.38 - case XK_i: 6.39 - ksym = XK_Tab; 6.40 - break; 6.41 - case XK_J: 6.42 - case XK_j: 6.43 - ksym = XK_Return; 6.44 - break; 6.45 - case XK_N: 6.46 - case XK_n: 6.47 - ksym = XK_Right; 6.48 - break; 6.49 - case XK_P: 6.50 - case XK_p: 6.51 - ksym = XK_Left; 6.52 - break; 6.53 case XK_U: 6.54 case XK_u: 6.55 text[0] = 0; 6.56 @@ -243,12 +222,9 @@ 6.57 case XK_bracketleft: 6.58 ksym = XK_Escape; 6.59 break; 6.60 - default: /* ignore other control sequences */ 6.61 - return; 6.62 - break; 6.63 } 6.64 } 6.65 - switch (ksym) { 6.66 + switch(ksym) { 6.67 case XK_Left: 6.68 if(!(sel && sel->left)) 6.69 return; 6.70 @@ -432,21 +408,18 @@ 6.71 XFlush(dpy); 6.72 6.73 /* main event loop */ 6.74 - while(!XNextEvent(dpy, &ev)) { 6.75 + while(!done && !XNextEvent(dpy, &ev)) { 6.76 switch (ev.type) { 6.77 - case KeyPress: 6.78 - kpress(&ev.xkey); 6.79 - break; 6.80 - case Expose: 6.81 - if(ev.xexpose.count == 0) { 6.82 - draw_menu(); 6.83 - } 6.84 - break; 6.85 - default: 6.86 - break; 6.87 + case KeyPress: 6.88 + kpress(&ev.xkey); 6.89 + break; 6.90 + case Expose: 6.91 + if(ev.xexpose.count == 0) 6.92 + draw_menu(); 6.93 + break; 6.94 + default: 6.95 + break; 6.96 } 6.97 - if(done) 6.98 - break; 6.99 } 6.100 6.101 XUngrabKeyboard(dpy, CurrentTime);
7.1 --- a/mouse.c Wed Jul 12 17:50:31 2006 +0200 7.2 +++ b/mouse.c Thu Jul 13 01:04:38 2006 +0200 7.3 @@ -13,27 +13,6 @@ 7.4 #define ButtonMask (ButtonPressMask | ButtonReleaseMask) 7.5 #define MouseMask (ButtonMask | PointerMotionMask) 7.6 7.7 -static void 7.8 -mmatch(Client *c, int x1, int y1, int x2, int y2) 7.9 -{ 7.10 - c->w = abs(x1 - x2); 7.11 - c->h = abs(y1 - y2); 7.12 - if(c->incw) 7.13 - c->w -= (c->w - c->basew) % c->incw; 7.14 - if(c->inch) 7.15 - c->h -= (c->h - c->baseh) % c->inch; 7.16 - if(c->minw && c->w < c->minw) 7.17 - c->w = c->minw; 7.18 - if(c->minh && c->h < c->minh) 7.19 - c->h = c->minh; 7.20 - if(c->maxw && c->w > c->maxw) 7.21 - c->w = c->maxw; 7.22 - if(c->maxh && c->h > c->maxh) 7.23 - c->h = c->maxh; 7.24 - c->x = (x1 <= x2) ? x1 : x1 - c->w; 7.25 - c->y = (y1 <= y2) ? y1 : y1 - c->h; 7.26 -} 7.27 - 7.28 void 7.29 mresize(Client *c) 7.30 { 7.31 @@ -55,11 +34,13 @@ 7.32 break; 7.33 case MotionNotify: 7.34 XFlush(dpy); 7.35 - mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y); 7.36 - XResizeWindow(dpy, c->win, c->w, c->h); 7.37 + c->w = abs(old_cx - ev.xmotion.x); 7.38 + c->h = abs(old_cy - ev.xmotion.y); 7.39 + c->x = (old_cx <= ev.xmotion.x) ? old_cx : old_cx - c->w; 7.40 + c->y = (old_cy <= ev.xmotion.y) ? old_cy : old_cy - c->h; 7.41 + resize(c); 7.42 break; 7.43 case ButtonRelease: 7.44 - resize(c); 7.45 XUngrabPointer(dpy, CurrentTime); 7.46 return; 7.47 } 7.48 @@ -91,10 +72,9 @@ 7.49 XFlush(dpy); 7.50 c->x = old_cx + (ev.xmotion.x - x1); 7.51 c->y = old_cy + (ev.xmotion.y - y1); 7.52 - XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); 7.53 + resize(c); 7.54 break; 7.55 case ButtonRelease: 7.56 - resize(c); 7.57 XUngrabPointer(dpy, CurrentTime); 7.58 return; 7.59 }
8.1 --- a/wm.c Wed Jul 12 17:50:31 2006 +0200 8.2 +++ b/wm.c Thu Jul 13 01:04:38 2006 +0200 8.3 @@ -18,15 +18,39 @@ 8.4 8.5 #include "wm.h" 8.6 8.7 +/********** CUSTOMIZE **********/ 8.8 + 8.9 +char *tags[TLast] = { 8.10 + [Tscratch] = "scratch", 8.11 + [Tdev] = "dev", 8.12 + [Tirc] = "irc", 8.13 + [Twww] = "www", 8.14 + [Twork] = "work", 8.15 +}; 8.16 + 8.17 +/* commands */ 8.18 +static char *cmdwallpaper[] = { 8.19 + "feh", "--bg-scale", "/home/garbeam/wallpaper/bg.jpg", NULL 8.20 +}; 8.21 + 8.22 +static char *cmdstatus[] = { 8.23 + "sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`" 8.24 + " `uptime | sed 's/.*://; s/,//g'`" 8.25 + " `acpi | awk '{print $4}' | sed 's/,//'`", NULL 8.26 +}; 8.27 + 8.28 +/********** CUSTOMIZE **********/ 8.29 + 8.30 /* X structs */ 8.31 Display *dpy; 8.32 Window root, barwin; 8.33 Atom wm_atom[WMLast], net_atom[NetLast]; 8.34 Cursor cursor[CurLast]; 8.35 Bool running = True; 8.36 -Bool sel_screen; 8.37 +Bool issel; 8.38 8.39 -char statustext[1024], tag[256]; 8.40 +char stext[1024]; 8.41 +int tsel = Tdev; /* default tag */ 8.42 int screen, sx, sy, sw, sh, bx, by, bw, bh; 8.43 8.44 Brush brush = {0}; 8.45 @@ -34,21 +58,12 @@ 8.46 Client *stack = NULL; 8.47 8.48 static Bool other_wm_running; 8.49 -static const char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; 8.50 +static const char version[] = 8.51 + "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; 8.52 static int (*x_error_handler) (Display *, XErrorEvent *); 8.53 8.54 -static const char *status[] = { 8.55 - "sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`" 8.56 - " `uptime | sed 's/.*://; s/,//g'`" 8.57 - " `acpi | awk '{print $4}' | sed 's/,//'`", 0 8.58 -}; 8.59 - 8.60 static void 8.61 -usage() 8.62 -{ 8.63 - fputs("usage: gridwm [-v]\n", stderr); 8.64 - exit(1); 8.65 -} 8.66 +usage() { error("usage: gridwm [-v]\n"); } 8.67 8.68 static void 8.69 scan_wins() 8.70 @@ -230,10 +245,11 @@ 8.71 if(other_wm_running) 8.72 error("gridwm: another window manager is already running\n"); 8.73 8.74 + spawn(dpy, cmdwallpaper); 8.75 sx = sy = 0; 8.76 sw = DisplayWidth(dpy, screen); 8.77 sh = DisplayHeight(dpy, screen); 8.78 - sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 8.79 + issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 8.80 8.81 XSetErrorHandler(0); 8.82 x_error_handler = XSetErrorHandler(error_handler); 8.83 @@ -275,7 +291,7 @@ 8.84 brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); 8.85 brush.gc = XCreateGC(dpy, root, 0, 0); 8.86 8.87 - pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status); 8.88 + pipe_spawn(stext, sizeof(stext), dpy, cmdstatus); 8.89 draw_bar(); 8.90 8.91 wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ 8.92 @@ -283,6 +299,7 @@ 8.93 wa.cursor = cursor[CurNormal]; 8.94 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); 8.95 8.96 + arrange = grid; 8.97 scan_wins(); 8.98 8.99 while(running) { 8.100 @@ -298,7 +315,7 @@ 8.101 if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0) 8.102 continue; 8.103 else if(errno != EINTR) { 8.104 - pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status); 8.105 + pipe_spawn(stext, sizeof(stext), dpy, cmdstatus); 8.106 draw_bar(); 8.107 } 8.108 }
9.1 --- a/wm.h Wed Jul 12 17:50:31 2006 +0200 9.2 +++ b/wm.h Thu Jul 13 01:04:38 2006 +0200 9.3 @@ -22,7 +22,8 @@ 9.4 enum { CurNormal, CurResize, CurMove, CurInput, CurLast }; 9.5 9.6 struct Client { 9.7 - char name[256], tag[256]; 9.8 + char name[256]; 9.9 + char *tags[TLast]; 9.10 int proto; 9.11 int x, y, w, h; 9.12 int tx, ty, tw, th; 9.13 @@ -48,11 +49,12 @@ 9.14 extern Window root, barwin; 9.15 extern Atom wm_atom[WMLast], net_atom[NetLast]; 9.16 extern Cursor cursor[CurLast]; 9.17 -extern Bool running, sel_screen, grid; 9.18 +extern Bool running, issel; 9.19 extern void (*handler[LASTEvent]) (XEvent *); 9.20 +extern void (*arrange)(void *aux); 9.21 9.22 -extern int screen, sx, sy, sw, sh, bx, by, bw, bh; 9.23 -extern char statustext[1024], tag[256]; 9.24 +extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh; 9.25 +extern char stext[1024], *tags[TLast]; 9.26 9.27 extern Brush brush; 9.28 extern Client *clients, *stack; 9.29 @@ -75,7 +77,8 @@ 9.30 extern void kill(void *aux); 9.31 extern void sel(void *aux); 9.32 extern void max(void *aux); 9.33 -extern void arrange(void *aux); 9.34 +extern void floating(void *aux); 9.35 +extern void grid(void *aux); 9.36 extern void gravitate(Client *c, Bool invert); 9.37 9.38 /* event.c */