all repos — dwm @ 3a69c5173cdd24959410870bec2a10a76272e034

my dwm build

implemented pipe_spawn
Anselm R. Garbe garbeam@wmii.de
Tue, 11 Jul 2006 11:10:05 +0200
commit

3a69c5173cdd24959410870bec2a10a76272e034

parent

439e15d09f6fa9271d3b49ef97194f0c80ebe161

7 files changed, 70 insertions(+), 15 deletions(-)

jump to
M config.hconfig.h

@@ -7,3 +7,5 @@ #define FONT "-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*"

#define BGCOLOR "#000000" #define FGCOLOR "#ffaa00" #define BORDERCOLOR "#000000" +#define STATUSCMD "echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \ + " `acpi | awk '{print $4}' | sed 's/,//'`"
M event.cevent.c

@@ -218,7 +218,6 @@

static void maprequest(XEvent *e) { -#if 0 XMapRequestEvent *ev = &e->xmaprequest; static XWindowAttributes wa;

@@ -231,9 +230,8 @@ (StructureNotifyMask | PropertyChangeMask));

return; } - if(!client_of_win(ev->window)) - manage_client(create_client(ev->window, &wa)); -#endif + /*if(!client_of_win(ev->window))*/ + manage(create_client(ev->window, &wa)); } static void
M util.cutil.c

@@ -13,6 +13,8 @@ #include <unistd.h>

#include "util.h" +static char *shell = NULL; + void error(char *errstr, ...) { va_list ap;

@@ -82,19 +84,65 @@ *p2 = tmp;

} void -spawn(Display *dpy, const char *shell, const char *cmd) +spawn(Display *dpy, const char *cmd) { - if(!cmd || !shell) + if(!shell && !(shell = getenv("SHELL"))) + shell = "/bin/sh"; + + if(!cmd) return; if(fork() == 0) { if(fork() == 0) { + setsid(); if(dpy) close(ConnectionNumber(dpy)); - execl(shell, shell, "-c", cmd, (const char *)0); - fprintf(stderr, "gridwm: execl %s", shell); + execlp(shell, "shell", "-c", cmd, NULL); + fprintf(stderr, "gridwm: execvp %s", cmd); perror(" failed"); } exit (0); } wait(0); } + +void +pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd) +{ + unsigned int l, n; + int pfd[2]; + + if(!shell && !(shell = getenv("SHELL"))) + shell = "/bin/sh"; + + if(!cmd) + return; + + if(pipe(pfd) == -1) { + perror("pipe"); + exit(1); + } + + if(fork() == 0) { + setsid(); + if(dpy) + close(ConnectionNumber(dpy)); + dup2(pfd[1], STDOUT_FILENO); + close(pfd[0]); + close(pfd[1]); + execlp(shell, "shell", "-c", cmd, NULL); + fprintf(stderr, "gridwm: execvp %s", cmd); + perror(" failed"); + } + else { + n = 0; + close(pfd[1]); + while(l > n) { + if((l = read(pfd[0], buf + n, len - n)) < 1) + break; + n += l; + } + close(pfd[0]); + buf[n - 1] = 0; + } + wait(0); +}
M util.hutil.h

@@ -14,5 +14,6 @@ if(!(a)) \

failed_assert(#a, __FILE__, __LINE__); \ } while (0) extern void failed_assert(char *a, char *file, int line); +void pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd); +extern void spawn(Display *dpy, const char *cmd); extern void swap(void **p1, void **p2); -extern void spawn(Display *dpy, const char *shell, const char *cmd);
M wm.cwm.c

@@ -21,7 +21,7 @@ Cursor cursor[CurLast];

XRectangle rect, barrect; Bool running = True; -char *bartext, *shell; +char *bartext; int screen, sel_screen; unsigned int lock_mask, numlock_mask;

@@ -56,7 +56,7 @@ continue;

if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) continue; if(wa.map_state == IsViewable) - /*manage*/; + manage(create_client(wins[i], &wa)); } } if(wins)

@@ -218,9 +218,6 @@ XFlush(dpy);

if(other_wm_running) error("gridwm: another window manager is already running\n"); - - if(!(shell = getenv("SHELL"))) - shell = "/bin/sh"; rect.x = rect.y = 0; rect.width = DisplayWidth(dpy, screen);
M wm.hwm.h

@@ -55,7 +55,7 @@ extern void (*handler[LASTEvent]) (XEvent *);

extern int screen, sel_screen; extern unsigned int lock_mask, numlock_mask; -extern char *bartext, *shell; +extern char *bartext; extern Brush brush;