dwm-meillo
changeset 14:5c078b66347b
added bar event timer
author | Anselm R. Garbe <garbeam@wmii.de> |
---|---|
date | Tue, 11 Jul 2006 18:15:11 +0200 |
parents | 5cc5e55a132d |
children | 00d4d52b231f |
files | bar.c client.c cmd.c config.h key.c util.c util.h wm.c wm.h |
diffstat | 9 files changed, 87 insertions(+), 51 deletions(-) [+] |
line diff
1.1 --- a/bar.c Tue Jul 11 16:14:22 2006 +0200 1.2 +++ b/bar.c Tue Jul 11 18:15:11 2006 +0200 1.3 @@ -5,12 +5,22 @@ 1.4 1.5 #include "wm.h" 1.6 1.7 +static const char *status[] = { 1.8 + "sh", "-c", "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" 1.9 + " `acpi | awk '{print $4}' | sed 's/,//'`", 0 \ 1.10 +}; 1.11 + 1.12 void 1.13 draw_bar() 1.14 { 1.15 + static char buf[1024]; 1.16 + 1.17 + buf[0] = 0; 1.18 + pipe_spawn(buf, sizeof(buf), dpy, (char **)status); 1.19 + 1.20 brush.rect = barrect; 1.21 brush.rect.x = brush.rect.y = 0; 1.22 - draw(dpy, &brush, False, 0); 1.23 + draw(dpy, &brush, False, buf); 1.24 1.25 XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width, 1.26 barrect.height, 0, 0);
2.1 --- a/client.c Tue Jul 11 16:14:22 2006 +0200 2.2 +++ b/client.c Tue Jul 11 18:15:11 2006 +0200 2.3 @@ -122,6 +122,8 @@ 2.4 XSetErrorHandler(error_handler); 2.5 XUngrabServer(dpy); 2.6 flush_events(EnterWindowMask); 2.7 + if(stack) 2.8 + focus(stack); 2.9 } 2.10 2.11 2.12 @@ -135,3 +137,10 @@ 2.13 return NULL; 2.14 } 2.15 2.16 +void 2.17 +draw_client(Client *c) 2.18 +{ 2.19 + 2.20 + 2.21 + 2.22 +}
3.1 --- a/cmd.c Tue Jul 11 16:14:22 2006 +0200 3.2 +++ b/cmd.c Tue Jul 11 18:15:11 2006 +0200 3.3 @@ -5,22 +5,22 @@ 3.4 3.5 #include "wm.h" 3.6 #include <stdio.h> 3.7 +#include <string.h> 3.8 3.9 void 3.10 -run(char *arg) 3.11 +run(void *aux) 3.12 { 3.13 - spawn(dpy, arg); 3.14 + spawn(dpy, aux); 3.15 } 3.16 3.17 void 3.18 -quit(char *arg) 3.19 +quit(void *aux) 3.20 { 3.21 - fputs("quit\n", stderr); 3.22 running = False; 3.23 } 3.24 3.25 void 3.26 -kill(char *arg) 3.27 +kill(void *aux) 3.28 { 3.29 Client *c = stack; 3.30
4.1 --- a/config.h Tue Jul 11 16:14:22 2006 +0200 4.2 +++ b/config.h Tue Jul 11 18:15:11 2006 +0200 4.3 @@ -3,16 +3,8 @@ 4.4 * See LICENSE file for license details. 4.5 */ 4.6 4.7 -#define FONT "-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*" 4.8 +#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*" 4.9 #define BGCOLOR "#000000" 4.10 #define FGCOLOR "#ffaa00" 4.11 #define BORDERCOLOR "#000000" 4.12 -#define STATUSCMD "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \ 4.13 - " `acpi | awk '{print $4}' | sed 's/,//'`" 4.14 -#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`" 4.15 - 4.16 -#define KEYS \ 4.17 - { Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn '-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*'" }, \ 4.18 - { Mod1Mask, XK_p, run, PLCMD }, \ 4.19 - { Mod1Mask | ShiftMask, XK_q, quit, NULL}, 4.20 - 4.21 +#define STATUSDELAY 1 /* milliseconds */
5.1 --- a/key.c Tue Jul 11 16:14:22 2006 +0200 5.2 +++ b/key.c Tue Jul 11 18:15:11 2006 +0200 5.3 @@ -7,8 +7,20 @@ 5.4 5.5 #include <X11/keysym.h> 5.6 5.7 +static const char *term[] = { 5.8 + "xterm", "-u8", "-bg", "black", "-fg", "white", "-fn", 5.9 + "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0 5.10 +}; 5.11 + 5.12 +static const char *proglist[] = { 5.13 + "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.14 +}; 5.15 + 5.16 static Key key[] = { 5.17 - KEYS 5.18 + { Mod1Mask, XK_Return, run, term }, 5.19 + { Mod1Mask, XK_p, run, proglist }, 5.20 + { Mod1Mask | ShiftMask, XK_c, kill, NULL}, 5.21 + { Mod1Mask | ShiftMask, XK_q, quit, NULL}, 5.22 }; 5.23 5.24 void 5.25 @@ -37,7 +49,7 @@ 5.26 for(i = 0; i < len; i++) 5.27 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { 5.28 if(key[i].func) 5.29 - key[i].func(key[i].arg); 5.30 + key[i].func(key[i].aux); 5.31 return; 5.32 } 5.33 }
6.1 --- a/util.c Tue Jul 11 16:14:22 2006 +0200 6.2 +++ b/util.c Tue Jul 11 18:15:11 2006 +0200 6.3 @@ -14,8 +14,6 @@ 6.4 6.5 #include "util.h" 6.6 6.7 -static char *shell = NULL; 6.8 - 6.9 void 6.10 error(char *errstr, ...) { 6.11 va_list ap; 6.12 @@ -85,21 +83,17 @@ 6.13 } 6.14 6.15 void 6.16 -spawn(Display *dpy, const char *cmd) 6.17 +spawn(Display *dpy, char *argv[]) 6.18 { 6.19 - if(!shell && !(shell = getenv("SHELL"))) 6.20 - shell = "/bin/sh"; 6.21 - 6.22 - if(!cmd) 6.23 + if(!argv || !argv[0]) 6.24 return; 6.25 if(fork() == 0) { 6.26 if(fork() == 0) { 6.27 if(dpy) 6.28 close(ConnectionNumber(dpy)); 6.29 setsid(); 6.30 - fprintf(stderr, "gridwm: execlp %s %s -c %s", shell, shell, cmd); 6.31 - execlp(shell, shell, "-c", cmd, NULL); 6.32 - fprintf(stderr, "gridwm: execlp %s", cmd); 6.33 + execvp(argv[0], argv); 6.34 + fprintf(stderr, "gridwm: execvp %s", argv[0]); 6.35 perror(" failed"); 6.36 } 6.37 exit (0); 6.38 @@ -108,15 +102,12 @@ 6.39 } 6.40 6.41 void 6.42 -pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd) 6.43 +pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]) 6.44 { 6.45 unsigned int l, n; 6.46 int pfd[2]; 6.47 6.48 - if(!shell && !(shell = getenv("SHELL"))) 6.49 - shell = "/bin/sh"; 6.50 - 6.51 - if(!cmd) 6.52 + if(!argv || !argv[0]) 6.53 return; 6.54 6.55 if(pipe(pfd) == -1) { 6.56 @@ -131,8 +122,8 @@ 6.57 dup2(pfd[1], STDOUT_FILENO); 6.58 close(pfd[0]); 6.59 close(pfd[1]); 6.60 - execlp(shell, shell, "-c", cmd, NULL); 6.61 - fprintf(stderr, "gridwm: execlp %s", cmd); 6.62 + execvp(argv[0], argv); 6.63 + fprintf(stderr, "gridwm: execvp %s", argv[0]); 6.64 perror(" failed"); 6.65 } 6.66 else {
7.1 --- a/util.h Tue Jul 11 16:14:22 2006 +0200 7.2 +++ b/util.h Tue Jul 11 18:15:11 2006 +0200 7.3 @@ -9,12 +9,16 @@ 7.4 extern void *emalloc(unsigned int size); 7.5 extern void *erealloc(void *ptr, unsigned int size); 7.6 extern char *estrdup(const char *str); 7.7 -#define eassert(a) do { \ 7.8 +#define eassert(a) \ 7.9 + do { \ 7.10 if(!(a)) \ 7.11 failed_assert(#a, __FILE__, __LINE__); \ 7.12 } while (0) 7.13 extern void failed_assert(char *a, char *file, int line); 7.14 -void pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd); 7.15 -extern void spawn(Display *dpy, const char *cmd); 7.16 +extern void pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]); 7.17 +extern void spawn(Display *dpy, char *argv[]); 7.18 extern void swap(void **p1, void **p2); 7.19 -unsigned char *getselection(unsigned long offset, unsigned long *len, unsigned long *remain); 7.20 +extern unsigned char *getselection(unsigned long offset, unsigned long *len, 7.21 + unsigned long *remain); 7.22 +extern unsigned int tokenize(char **result, unsigned int reslen, 7.23 + char *str, char delim);
8.1 --- a/wm.c Tue Jul 11 16:14:22 2006 +0200 8.2 +++ b/wm.c Tue Jul 11 18:15:11 2006 +0200 8.3 @@ -3,10 +3,15 @@ 8.4 * See LICENSE file for license details. 8.5 */ 8.6 8.7 +#include <errno.h> 8.8 + 8.9 #include <stdarg.h> 8.10 #include <stdio.h> 8.11 #include <stdlib.h> 8.12 8.13 +#include <sys/types.h> 8.14 +#include <sys/time.h> 8.15 + 8.16 #include <X11/cursorfont.h> 8.17 #include <X11/Xatom.h> 8.18 #include <X11/Xproto.h> 8.19 @@ -160,12 +165,9 @@ 8.20 static void 8.21 cleanup() 8.22 { 8.23 - /* 8.24 - Client *c; 8.25 - for(c=client; c; c=c->next) 8.26 - reparent_client(c, root, c->sel->rect.x, c->sel->rect.y); 8.27 + while(clients) 8.28 + unmanage(clients); 8.29 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); 8.30 - */ 8.31 } 8.32 8.33 int 8.34 @@ -176,6 +178,11 @@ 8.35 unsigned int mask; 8.36 Window w; 8.37 XEvent ev; 8.38 + fd_set fds; 8.39 + struct timeval t, timeout = { 8.40 + .tv_usec = 0, 8.41 + .tv_sec = STATUSDELAY, 8.42 + }; 8.43 8.44 /* command line args */ 8.45 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { 8.46 @@ -264,9 +271,19 @@ 8.47 scan_wins(); 8.48 8.49 while(running) { 8.50 - XNextEvent(dpy, &ev); 8.51 - if(handler[ev.type]) 8.52 - (handler[ev.type]) (&ev); /* call handler */ 8.53 + if(XPending(dpy) > 0) { 8.54 + XNextEvent(dpy, &ev); 8.55 + if(handler[ev.type]) 8.56 + (handler[ev.type]) (&ev); /* call handler */ 8.57 + continue; 8.58 + } 8.59 + FD_ZERO(&fds); 8.60 + FD_SET(ConnectionNumber(dpy), &fds); 8.61 + t = timeout; 8.62 + if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0) 8.63 + continue; 8.64 + else if(errno != EINTR) 8.65 + draw_bar(); 8.66 } 8.67 8.68 cleanup();
9.1 --- a/wm.h Tue Jul 11 16:14:22 2006 +0200 9.2 +++ b/wm.h Tue Jul 11 18:15:11 2006 +0200 9.3 @@ -42,8 +42,8 @@ 9.4 struct Key { 9.5 unsigned long mod; 9.6 KeySym keysym; 9.7 - void (*func)(char *arg); 9.8 - char *arg; 9.9 + void (*func)(void *aux); 9.10 + void *aux; 9.11 }; 9.12 9.13 extern Display *dpy; 9.14 @@ -64,8 +64,9 @@ 9.15 extern void draw_bar(); 9.16 9.17 /* cmd.c */ 9.18 -extern void run(char *arg); 9.19 -extern void quit(char *arg); 9.20 +extern void run(void *aux); 9.21 +extern void quit(void *aux); 9.22 +extern void kill(void *aux); 9.23 9.24 /* client.c */ 9.25 extern void manage(Window w, XWindowAttributes *wa);