diff options
Diffstat (limited to '')
| -rw-r--r-- | bar.c | 12 | ||||
| -rw-r--r-- | client.c | 9 | ||||
| -rw-r--r-- | cmd.c | 10 | ||||
| -rw-r--r-- | config.h | 12 | ||||
| -rw-r--r-- | key.c | 16 | ||||
| -rw-r--r-- | util.c | 25 | ||||
| -rw-r--r-- | util.h | 12 | ||||
| -rw-r--r-- | wm.c | 33 | ||||
| -rw-r--r-- | wm.h | 9 |
9 files changed, 87 insertions, 51 deletions
| @@ -5,12 +5,22 @@ | |||
| 5 | 5 | ||
| 6 | #include "wm.h" | 6 | #include "wm.h" |
| 7 | 7 | ||
| 8 | static const char *status[] = { | ||
| 9 | "sh", "-c", "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" | ||
| 10 | " `acpi | awk '{print $4}' | sed 's/,//'`", 0 \ | ||
| 11 | }; | ||
| 12 | |||
| 8 | void | 13 | void |
| 9 | draw_bar() | 14 | draw_bar() |
| 10 | { | 15 | { |
| 16 | static char buf[1024]; | ||
| 17 | |||
| 18 | buf[0] = 0; | ||
| 19 | pipe_spawn(buf, sizeof(buf), dpy, (char **)status); | ||
| 20 | |||
| 11 | brush.rect = barrect; | 21 | brush.rect = barrect; |
| 12 | brush.rect.x = brush.rect.y = 0; | 22 | brush.rect.x = brush.rect.y = 0; |
| 13 | draw(dpy, &brush, False, 0); | 23 | draw(dpy, &brush, False, buf); |
| 14 | 24 | ||
| 15 | XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width, | 25 | XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width, |
| 16 | barrect.height, 0, 0); | 26 | barrect.height, 0, 0); |
| @@ -122,6 +122,8 @@ unmanage(Client *c) | |||
| 122 | XSetErrorHandler(error_handler); | 122 | XSetErrorHandler(error_handler); |
| 123 | XUngrabServer(dpy); | 123 | XUngrabServer(dpy); |
| 124 | flush_events(EnterWindowMask); | 124 | flush_events(EnterWindowMask); |
| 125 | if(stack) | ||
| 126 | focus(stack); | ||
| 125 | } | 127 | } |
| 126 | 128 | ||
| 127 | 129 | ||
| @@ -135,3 +137,10 @@ getclient(Window w) | |||
| 135 | return NULL; | 137 | return NULL; |
| 136 | } | 138 | } |
| 137 | 139 | ||
| 140 | void | ||
| 141 | draw_client(Client *c) | ||
| 142 | { | ||
| 143 | |||
| 144 | |||
| 145 | |||
| 146 | } | ||
| @@ -5,22 +5,22 @@ | |||
| 5 | 5 | ||
| 6 | #include "wm.h" | 6 | #include "wm.h" |
| 7 | #include <stdio.h> | 7 | #include <stdio.h> |
| 8 | #include <string.h> | ||
| 8 | 9 | ||
| 9 | void | 10 | void |
| 10 | run(char *arg) | 11 | run(void *aux) |
| 11 | { | 12 | { |
| 12 | spawn(dpy, arg); | 13 | spawn(dpy, aux); |
| 13 | } | 14 | } |
| 14 | 15 | ||
| 15 | void | 16 | void |
| 16 | quit(char *arg) | 17 | quit(void *aux) |
| 17 | { | 18 | { |
| 18 | fputs("quit\n", stderr); | ||
| 19 | running = False; | 19 | running = False; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | void | 22 | void |
| 23 | kill(char *arg) | 23 | kill(void *aux) |
| 24 | { | 24 | { |
| 25 | Client *c = stack; | 25 | Client *c = stack; |
| 26 | 26 | ||
| @@ -3,16 +3,8 @@ | |||
| 3 | * See LICENSE file for license details. | 3 | * See LICENSE file for license details. |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #define FONT "-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*" | 6 | #define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*" |
| 7 | #define BGCOLOR "#000000" | 7 | #define BGCOLOR "#000000" |
| 8 | #define FGCOLOR "#ffaa00" | 8 | #define FGCOLOR "#ffaa00" |
| 9 | #define BORDERCOLOR "#000000" | 9 | #define BORDERCOLOR "#000000" |
| 10 | #define STATUSCMD "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \ | 10 | #define STATUSDELAY 1 /* milliseconds */ |
| 11 | " `acpi | awk '{print $4}' | sed 's/,//'`" | ||
| 12 | #define PLCMD "`ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null | awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`" | ||
| 13 | |||
| 14 | #define KEYS \ | ||
| 15 | { Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn '-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*'" }, \ | ||
| 16 | { Mod1Mask, XK_p, run, PLCMD }, \ | ||
| 17 | { Mod1Mask | ShiftMask, XK_q, quit, NULL}, | ||
| 18 | |||
| @@ -7,8 +7,20 @@ | |||
| 7 | 7 | ||
| 8 | #include <X11/keysym.h> | 8 | #include <X11/keysym.h> |
| 9 | 9 | ||
| 10 | static const char *term[] = { | ||
| 11 | "xterm", "-u8", "-bg", "black", "-fg", "white", "-fn", | ||
| 12 | "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0 | ||
| 13 | }; | ||
| 14 | |||
| 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 | ||
| 17 | }; | ||
| 18 | |||
| 10 | static Key key[] = { | 19 | static Key key[] = { |
| 11 | KEYS | 20 | { Mod1Mask, XK_Return, run, term }, |
| 21 | { Mod1Mask, XK_p, run, proglist }, | ||
| 22 | { Mod1Mask | ShiftMask, XK_c, kill, NULL}, | ||
| 23 | { Mod1Mask | ShiftMask, XK_q, quit, NULL}, | ||
| 12 | }; | 24 | }; |
| 13 | 25 | ||
| 14 | void | 26 | void |
| @@ -37,7 +49,7 @@ keypress(XEvent *e) | |||
| 37 | for(i = 0; i < len; i++) | 49 | for(i = 0; i < len; i++) |
| 38 | if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { | 50 | if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { |
| 39 | if(key[i].func) | 51 | if(key[i].func) |
| 40 | key[i].func(key[i].arg); | 52 | key[i].func(key[i].aux); |
| 41 | return; | 53 | return; |
| 42 | } | 54 | } |
| 43 | } | 55 | } |
| @@ -14,8 +14,6 @@ | |||
| 14 | 14 | ||
| 15 | #include "util.h" | 15 | #include "util.h" |
| 16 | 16 | ||
| 17 | static char *shell = NULL; | ||
| 18 | |||
| 19 | void | 17 | void |
| 20 | error(char *errstr, ...) { | 18 | error(char *errstr, ...) { |
| 21 | va_list ap; | 19 | va_list ap; |
| @@ -85,21 +83,17 @@ swap(void **p1, void **p2) | |||
| 85 | } | 83 | } |
| 86 | 84 | ||
| 87 | void | 85 | void |
| 88 | spawn(Display *dpy, const char *cmd) | 86 | spawn(Display *dpy, char *argv[]) |
| 89 | { | 87 | { |
| 90 | if(!shell && !(shell = getenv("SHELL"))) | 88 | if(!argv || !argv[0]) |
| 91 | shell = "/bin/sh"; | ||
| 92 | |||
| 93 | if(!cmd) | ||
| 94 | return; | 89 | return; |
| 95 | if(fork() == 0) { | 90 | if(fork() == 0) { |
| 96 | if(fork() == 0) { | 91 | if(fork() == 0) { |
| 97 | if(dpy) | 92 | if(dpy) |
| 98 | close(ConnectionNumber(dpy)); | 93 | close(ConnectionNumber(dpy)); |
| 99 | setsid(); | 94 | setsid(); |
| 100 | fprintf(stderr, "gridwm: execlp %s %s -c %s", shell, shell, cmd); | 95 | execvp(argv[0], argv); |
| 101 | execlp(shell, shell, "-c", cmd, NULL); | 96 | fprintf(stderr, "gridwm: execvp %s", argv[0]); |
| 102 | fprintf(stderr, "gridwm: execlp %s", cmd); | ||
| 103 | perror(" failed"); | 97 | perror(" failed"); |
| 104 | } | 98 | } |
| 105 | exit (0); | 99 | exit (0); |
| @@ -108,15 +102,12 @@ spawn(Display *dpy, const char *cmd) | |||
| 108 | } | 102 | } |
| 109 | 103 | ||
| 110 | void | 104 | void |
| 111 | pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd) | 105 | pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]) |
| 112 | { | 106 | { |
| 113 | unsigned int l, n; | 107 | unsigned int l, n; |
| 114 | int pfd[2]; | 108 | int pfd[2]; |
| 115 | 109 | ||
| 116 | if(!shell && !(shell = getenv("SHELL"))) | 110 | if(!argv || !argv[0]) |
| 117 | shell = "/bin/sh"; | ||
| 118 | |||
| 119 | if(!cmd) | ||
| 120 | return; | 111 | return; |
| 121 | 112 | ||
| 122 | if(pipe(pfd) == -1) { | 113 | if(pipe(pfd) == -1) { |
| @@ -131,8 +122,8 @@ pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd) | |||
| 131 | dup2(pfd[1], STDOUT_FILENO); | 122 | dup2(pfd[1], STDOUT_FILENO); |
| 132 | close(pfd[0]); | 123 | close(pfd[0]); |
| 133 | close(pfd[1]); | 124 | close(pfd[1]); |
| 134 | execlp(shell, shell, "-c", cmd, NULL); | 125 | execvp(argv[0], argv); |
| 135 | fprintf(stderr, "gridwm: execlp %s", cmd); | 126 | fprintf(stderr, "gridwm: execvp %s", argv[0]); |
| 136 | perror(" failed"); | 127 | perror(" failed"); |
| 137 | } | 128 | } |
| 138 | else { | 129 | else { |
| @@ -9,12 +9,16 @@ extern void *emallocz(unsigned int size); | |||
| 9 | extern void *emalloc(unsigned int size); | 9 | extern void *emalloc(unsigned int size); |
| 10 | extern void *erealloc(void *ptr, unsigned int size); | 10 | extern void *erealloc(void *ptr, unsigned int size); |
| 11 | extern char *estrdup(const char *str); | 11 | extern char *estrdup(const char *str); |
| 12 | #define eassert(a) do { \ | 12 | #define eassert(a) \ |
| 13 | do { \ | ||
| 13 | if(!(a)) \ | 14 | if(!(a)) \ |
| 14 | failed_assert(#a, __FILE__, __LINE__); \ | 15 | failed_assert(#a, __FILE__, __LINE__); \ |
| 15 | } while (0) | 16 | } while (0) |
| 16 | extern void failed_assert(char *a, char *file, int line); | 17 | extern void failed_assert(char *a, char *file, int line); |
| 17 | void pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd); | 18 | extern void pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]); |
| 18 | extern void spawn(Display *dpy, const char *cmd); | 19 | extern void spawn(Display *dpy, char *argv[]); |
| 19 | extern void swap(void **p1, void **p2); | 20 | extern void swap(void **p1, void **p2); |
| 20 | unsigned char *getselection(unsigned long offset, unsigned long *len, unsigned long *remain); | 21 | extern unsigned char *getselection(unsigned long offset, unsigned long *len, |
| 22 | unsigned long *remain); | ||
| 23 | extern unsigned int tokenize(char **result, unsigned int reslen, | ||
| 24 | char *str, char delim); | ||
| @@ -3,10 +3,15 @@ | |||
| 3 | * See LICENSE file for license details. | 3 | * See LICENSE file for license details. |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | #include <errno.h> | ||
| 7 | |||
| 6 | #include <stdarg.h> | 8 | #include <stdarg.h> |
| 7 | #include <stdio.h> | 9 | #include <stdio.h> |
| 8 | #include <stdlib.h> | 10 | #include <stdlib.h> |
| 9 | 11 | ||
| 12 | #include <sys/types.h> | ||
| 13 | #include <sys/time.h> | ||
| 14 | |||
| 10 | #include <X11/cursorfont.h> | 15 | #include <X11/cursorfont.h> |
| 11 | #include <X11/Xatom.h> | 16 | #include <X11/Xatom.h> |
| 12 | #include <X11/Xproto.h> | 17 | #include <X11/Xproto.h> |
| @@ -160,12 +165,9 @@ startup_error_handler(Display *dpy, XErrorEvent *error) | |||
| 160 | static void | 165 | static void |
| 161 | cleanup() | 166 | cleanup() |
| 162 | { | 167 | { |
| 163 | /* | 168 | while(clients) |
| 164 | Client *c; | 169 | unmanage(clients); |
| 165 | for(c=client; c; c=c->next) | ||
| 166 | reparent_client(c, root, c->sel->rect.x, c->sel->rect.y); | ||
| 167 | XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); | 170 | XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); |
| 168 | */ | ||
| 169 | } | 171 | } |
| 170 | 172 | ||
| 171 | int | 173 | int |
| @@ -176,6 +178,11 @@ main(int argc, char *argv[]) | |||
| 176 | unsigned int mask; | 178 | unsigned int mask; |
| 177 | Window w; | 179 | Window w; |
| 178 | XEvent ev; | 180 | XEvent ev; |
| 181 | fd_set fds; | ||
| 182 | struct timeval t, timeout = { | ||
| 183 | .tv_usec = 0, | ||
| 184 | .tv_sec = STATUSDELAY, | ||
| 185 | }; | ||
| 179 | 186 | ||
| 180 | /* command line args */ | 187 | /* command line args */ |
| 181 | for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { | 188 | for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { |
| @@ -264,9 +271,19 @@ main(int argc, char *argv[]) | |||
| 264 | scan_wins(); | 271 | scan_wins(); |
| 265 | 272 | ||
| 266 | while(running) { | 273 | while(running) { |
| 267 | XNextEvent(dpy, &ev); | 274 | if(XPending(dpy) > 0) { |
| 268 | if(handler[ev.type]) | 275 | XNextEvent(dpy, &ev); |
| 269 | (handler[ev.type]) (&ev); /* call handler */ | 276 | if(handler[ev.type]) |
| 277 | (handler[ev.type]) (&ev); /* call handler */ | ||
| 278 | continue; | ||
| 279 | } | ||
| 280 | FD_ZERO(&fds); | ||
| 281 | FD_SET(ConnectionNumber(dpy), &fds); | ||
| 282 | t = timeout; | ||
| 283 | if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0) | ||
| 284 | continue; | ||
| 285 | else if(errno != EINTR) | ||
| 286 | draw_bar(); | ||
| 270 | } | 287 | } |
| 271 | 288 | ||
| 272 | cleanup(); | 289 | cleanup(); |
| @@ -42,8 +42,8 @@ struct Client { | |||
| 42 | struct Key { | 42 | struct Key { |
| 43 | unsigned long mod; | 43 | unsigned long mod; |
| 44 | KeySym keysym; | 44 | KeySym keysym; |
| 45 | void (*func)(char *arg); | 45 | void (*func)(void *aux); |
| 46 | char *arg; | 46 | void *aux; |
| 47 | }; | 47 | }; |
| 48 | 48 | ||
| 49 | extern Display *dpy; | 49 | extern Display *dpy; |
| @@ -64,8 +64,9 @@ extern Client *clients, *stack; | |||
| 64 | extern void draw_bar(); | 64 | extern void draw_bar(); |
| 65 | 65 | ||
| 66 | /* cmd.c */ | 66 | /* cmd.c */ |
| 67 | extern void run(char *arg); | 67 | extern void run(void *aux); |
| 68 | extern void quit(char *arg); | 68 | extern void quit(void *aux); |
| 69 | extern void kill(void *aux); | ||
| 69 | 70 | ||
| 70 | /* client.c */ | 71 | /* client.c */ |
| 71 | extern void manage(Window w, XWindowAttributes *wa); | 72 | extern void manage(Window w, XWindowAttributes *wa); |
