added bar event timer
586f6633
9 file(s) · +87 −51
| 5 | 5 | ||
| 6 | 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 | 13 | void |
|
| 9 | 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 | 21 | brush.rect = barrect; |
|
| 12 | 22 | brush.rect.x = brush.rect.y = 0; |
|
| 13 | - | draw(dpy, &brush, False, 0); |
|
| 23 | + | draw(dpy, &brush, False, buf); |
|
| 14 | 24 | ||
| 15 | 25 | XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width, |
|
| 16 | 26 | barrect.height, 0, 0); |
| 122 | 122 | XSetErrorHandler(error_handler); |
|
| 123 | 123 | XUngrabServer(dpy); |
|
| 124 | 124 | flush_events(EnterWindowMask); |
|
| 125 | + | if(stack) |
|
| 126 | + | focus(stack); |
|
| 125 | 127 | } |
|
| 126 | 128 | ||
| 127 | 129 | ||
| 135 | 137 | return NULL; |
|
| 136 | 138 | } |
|
| 137 | 139 | ||
| 140 | + | void |
|
| 141 | + | draw_client(Client *c) |
|
| 142 | + | { |
|
| 143 | + | ||
| 144 | + | ||
| 145 | + | ||
| 146 | + | } |
|
| 5 | 5 | ||
| 6 | 6 | #include "wm.h" |
|
| 7 | 7 | #include <stdio.h> |
|
| 8 | + | #include <string.h> |
|
| 8 | 9 | ||
| 9 | 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 | 16 | void |
|
| 16 | - | quit(char *arg) |
|
| 17 | + | quit(void *aux) |
|
| 17 | 18 | { |
|
| 18 | - | fputs("quit\n", stderr); |
|
| 19 | 19 | running = False; |
|
| 20 | 20 | } |
|
| 21 | 21 | ||
| 22 | 22 | void |
|
| 23 | - | kill(char *arg) |
|
| 23 | + | kill(void *aux) |
|
| 24 | 24 | { |
|
| 25 | 25 | Client *c = stack; |
|
| 26 | 26 |
| 3 | 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 | 7 | #define BGCOLOR "#000000" |
|
| 8 | 8 | #define FGCOLOR "#ffaa00" |
|
| 9 | 9 | #define BORDERCOLOR "#000000" |
|
| 10 | - | #define STATUSCMD "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \ |
|
| 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 | - | ||
| 10 | + | #define STATUSDELAY 1 /* milliseconds */ |
| 7 | 7 | ||
| 8 | 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 | 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 | 26 | void |
|
| 37 | 49 | for(i = 0; i < len; i++) |
|
| 38 | 50 | if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { |
|
| 39 | 51 | if(key[i].func) |
|
| 40 | - | key[i].func(key[i].arg); |
|
| 52 | + | key[i].func(key[i].aux); |
|
| 41 | 53 | return; |
|
| 42 | 54 | } |
|
| 43 | 55 | } |
|
| 14 | 14 | ||
| 15 | 15 | #include "util.h" |
|
| 16 | 16 | ||
| 17 | - | static char *shell = NULL; |
|
| 18 | - | ||
| 19 | 17 | void |
|
| 20 | 18 | error(char *errstr, ...) { |
|
| 21 | 19 | va_list ap; |
|
| 85 | 83 | } |
|
| 86 | 84 | ||
| 87 | 85 | void |
|
| 88 | - | spawn(Display *dpy, const char *cmd) |
|
| 86 | + | spawn(Display *dpy, char *argv[]) |
|
| 89 | 87 | { |
|
| 90 | - | if(!shell && !(shell = getenv("SHELL"))) |
|
| 91 | - | shell = "/bin/sh"; |
|
| 92 | - | ||
| 93 | - | if(!cmd) |
|
| 88 | + | if(!argv || !argv[0]) |
|
| 94 | 89 | return; |
|
| 95 | 90 | if(fork() == 0) { |
|
| 96 | 91 | if(fork() == 0) { |
|
| 97 | 92 | if(dpy) |
|
| 98 | 93 | close(ConnectionNumber(dpy)); |
|
| 99 | 94 | setsid(); |
|
| 100 | - | fprintf(stderr, "gridwm: execlp %s %s -c %s", shell, shell, cmd); |
|
| 101 | - | execlp(shell, shell, "-c", cmd, NULL); |
|
| 102 | - | fprintf(stderr, "gridwm: execlp %s", cmd); |
|
| 95 | + | execvp(argv[0], argv); |
|
| 96 | + | fprintf(stderr, "gridwm: execvp %s", argv[0]); |
|
| 103 | 97 | perror(" failed"); |
|
| 104 | 98 | } |
|
| 105 | 99 | exit (0); |
|
| 108 | 102 | } |
|
| 109 | 103 | ||
| 110 | 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 | 107 | unsigned int l, n; |
|
| 114 | 108 | int pfd[2]; |
|
| 115 | 109 | ||
| 116 | - | if(!shell && !(shell = getenv("SHELL"))) |
|
| 117 | - | shell = "/bin/sh"; |
|
| 118 | - | ||
| 119 | - | if(!cmd) |
|
| 110 | + | if(!argv || !argv[0]) |
|
| 120 | 111 | return; |
|
| 121 | 112 | ||
| 122 | 113 | if(pipe(pfd) == -1) { |
|
| 131 | 122 | dup2(pfd[1], STDOUT_FILENO); |
|
| 132 | 123 | close(pfd[0]); |
|
| 133 | 124 | close(pfd[1]); |
|
| 134 | - | execlp(shell, shell, "-c", cmd, NULL); |
|
| 135 | - | fprintf(stderr, "gridwm: execlp %s", cmd); |
|
| 125 | + | execvp(argv[0], argv); |
|
| 126 | + | fprintf(stderr, "gridwm: execvp %s", argv[0]); |
|
| 136 | 127 | perror(" failed"); |
|
| 137 | 128 | } |
|
| 138 | 129 | else { |
|
| 9 | 9 | extern void *emalloc(unsigned int size); |
|
| 10 | 10 | extern void *erealloc(void *ptr, unsigned int size); |
|
| 11 | 11 | extern char *estrdup(const char *str); |
|
| 12 | - | #define eassert(a) do { \ |
|
| 12 | + | #define eassert(a) \ |
|
| 13 | + | do { \ |
|
| 13 | 14 | if(!(a)) \ |
|
| 14 | 15 | failed_assert(#a, __FILE__, __LINE__); \ |
|
| 15 | 16 | } while (0) |
|
| 16 | 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 spawn(Display *dpy, const char *cmd); |
|
| 18 | + | extern void pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]); |
|
| 19 | + | extern void spawn(Display *dpy, char *argv[]); |
|
| 19 | 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 | 3 | * See LICENSE file for license details. |
|
| 4 | 4 | */ |
|
| 5 | 5 | ||
| 6 | + | #include <errno.h> |
|
| 7 | + | ||
| 6 | 8 | #include <stdarg.h> |
|
| 7 | 9 | #include <stdio.h> |
|
| 8 | 10 | #include <stdlib.h> |
|
| 11 | + | ||
| 12 | + | #include <sys/types.h> |
|
| 13 | + | #include <sys/time.h> |
|
| 9 | 14 | ||
| 10 | 15 | #include <X11/cursorfont.h> |
|
| 11 | 16 | #include <X11/Xatom.h> |
|
| 160 | 165 | static void |
|
| 161 | 166 | cleanup() |
|
| 162 | 167 | { |
|
| 163 | - | /* |
|
| 164 | - | Client *c; |
|
| 165 | - | for(c=client; c; c=c->next) |
|
| 166 | - | reparent_client(c, root, c->sel->rect.x, c->sel->rect.y); |
|
| 168 | + | while(clients) |
|
| 169 | + | unmanage(clients); |
|
| 167 | 170 | XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); |
|
| 168 | - | */ |
|
| 169 | 171 | } |
|
| 170 | 172 | ||
| 171 | 173 | int |
|
| 176 | 178 | unsigned int mask; |
|
| 177 | 179 | Window w; |
|
| 178 | 180 | XEvent ev; |
|
| 181 | + | fd_set fds; |
|
| 182 | + | struct timeval t, timeout = { |
|
| 183 | + | .tv_usec = 0, |
|
| 184 | + | .tv_sec = STATUSDELAY, |
|
| 185 | + | }; |
|
| 179 | 186 | ||
| 180 | 187 | /* command line args */ |
|
| 181 | 188 | for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { |
|
| 264 | 271 | scan_wins(); |
|
| 265 | 272 | ||
| 266 | 273 | while(running) { |
|
| 267 | - | XNextEvent(dpy, &ev); |
|
| 268 | - | if(handler[ev.type]) |
|
| 269 | - | (handler[ev.type]) (&ev); /* call handler */ |
|
| 274 | + | if(XPending(dpy) > 0) { |
|
| 275 | + | XNextEvent(dpy, &ev); |
|
| 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 | 289 | cleanup(); |
|
| 42 | 42 | struct Key { |
|
| 43 | 43 | unsigned long mod; |
|
| 44 | 44 | KeySym keysym; |
|
| 45 | - | void (*func)(char *arg); |
|
| 46 | - | char *arg; |
|
| 45 | + | void (*func)(void *aux); |
|
| 46 | + | void *aux; |
|
| 47 | 47 | }; |
|
| 48 | 48 | ||
| 49 | 49 | extern Display *dpy; |
|
| 64 | 64 | extern void draw_bar(); |
|
| 65 | 65 | ||
| 66 | 66 | /* cmd.c */ |
|
| 67 | - | extern void run(char *arg); |
|
| 68 | - | extern void quit(char *arg); |
|
| 67 | + | extern void run(void *aux); |
|
| 68 | + | extern void quit(void *aux); |
|
| 69 | + | extern void kill(void *aux); |
|
| 69 | 70 | ||
| 70 | 71 | /* client.c */ |
|
| 71 | 72 | extern void manage(Window w, XWindowAttributes *wa); |
|