aewl

changeset 6:e0cefb3981c8

implemented pipe_spawn
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 11:10:05 +0200
parents e5018cae273f
children 49e2fc9fb94f
files config.h event.c menu.c util.c util.h wm.c wm.h
diffstat 7 files changed, 70 insertions(+), 15 deletions(-) [+]
line diff
     1.1 --- a/config.h	Mon Jul 10 22:16:48 2006 +0200
     1.2 +++ b/config.h	Tue Jul 11 11:10:05 2006 +0200
     1.3 @@ -7,3 +7,5 @@
     1.4  #define BGCOLOR		"#000000"
     1.5  #define FGCOLOR		"#ffaa00"
     1.6  #define BORDERCOLOR	"#000000"
     1.7 +#define STATUSCMD	"echo -n `date` `uptime | sed 's/.*://; s/,//g'`" \
     1.8 +					" `acpi | awk '{print $4}' | sed 's/,//'`"
     2.1 --- a/event.c	Mon Jul 10 22:16:48 2006 +0200
     2.2 +++ b/event.c	Tue Jul 11 11:10:05 2006 +0200
     2.3 @@ -218,7 +218,6 @@
     2.4  static void
     2.5  maprequest(XEvent *e)
     2.6  {
     2.7 -#if 0
     2.8  	XMapRequestEvent *ev = &e->xmaprequest;
     2.9  	static XWindowAttributes wa;
    2.10  
    2.11 @@ -231,9 +230,8 @@
    2.12  		return;
    2.13  	}
    2.14  
    2.15 -	if(!client_of_win(ev->window))
    2.16 -		manage_client(create_client(ev->window, &wa));
    2.17 -#endif
    2.18 +	/*if(!client_of_win(ev->window))*/
    2.19 +		manage(create_client(ev->window, &wa));
    2.20  }
    2.21  
    2.22  static void
     3.1 --- a/menu.c	Mon Jul 10 22:16:48 2006 +0200
     3.2 +++ b/menu.c	Tue Jul 11 11:10:05 2006 +0200
     3.3 @@ -356,6 +356,15 @@
     3.4  	char *maxname;
     3.5  	XEvent ev;
     3.6  
     3.7 +	char buf[256];
     3.8 +
     3.9 +	fputs(STATUSCMD, stdout);
    3.10 +	fputs("\n", stdout);
    3.11 +	pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD);
    3.12 +	fputs(buf, stderr);
    3.13 +
    3.14 +	return 0;
    3.15 +
    3.16  	/* command line args */
    3.17  	for(i = 1; i < argc; i++) {
    3.18  		if (argv[i][0] == '-')
     4.1 --- a/util.c	Mon Jul 10 22:16:48 2006 +0200
     4.2 +++ b/util.c	Tue Jul 11 11:10:05 2006 +0200
     4.3 @@ -13,6 +13,8 @@
     4.4  
     4.5  #include "util.h"
     4.6  
     4.7 +static char *shell = NULL;
     4.8 +
     4.9  void
    4.10  error(char *errstr, ...) {
    4.11  	va_list ap;
    4.12 @@ -82,19 +84,65 @@
    4.13  }
    4.14  
    4.15  void
    4.16 -spawn(Display *dpy, const char *shell, const char *cmd)
    4.17 +spawn(Display *dpy, const char *cmd)
    4.18  {
    4.19 -	if(!cmd || !shell)
    4.20 +	if(!shell && !(shell = getenv("SHELL")))
    4.21 +		shell = "/bin/sh";
    4.22 +
    4.23 +	if(!cmd)
    4.24  		return;
    4.25  	if(fork() == 0) {
    4.26  		if(fork() == 0) {
    4.27 +			setsid();
    4.28  			if(dpy)
    4.29  				close(ConnectionNumber(dpy));
    4.30 -			execl(shell, shell, "-c", cmd, (const char *)0);
    4.31 -			fprintf(stderr, "gridwm: execl %s", shell);
    4.32 +			execlp(shell, "shell", "-c", cmd, NULL);
    4.33 +			fprintf(stderr, "gridwm: execvp %s", cmd);
    4.34  			perror(" failed");
    4.35  		}
    4.36  		exit (0);
    4.37  	}
    4.38  	wait(0);
    4.39  }
    4.40 +
    4.41 +void
    4.42 +pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd)
    4.43 +{
    4.44 +	unsigned int l, n;
    4.45 +	int pfd[2];
    4.46 +
    4.47 +	if(!shell && !(shell = getenv("SHELL")))
    4.48 +		shell = "/bin/sh";
    4.49 +
    4.50 +	if(!cmd)
    4.51 +		return;
    4.52 +
    4.53 +	if(pipe(pfd) == -1) {
    4.54 +		perror("pipe");
    4.55 +		exit(1);
    4.56 +	}
    4.57 +
    4.58 +	if(fork() == 0) {
    4.59 +		setsid();
    4.60 +		if(dpy)
    4.61 +			close(ConnectionNumber(dpy));
    4.62 +		dup2(pfd[1], STDOUT_FILENO);
    4.63 +		close(pfd[0]);
    4.64 +		close(pfd[1]);
    4.65 +		execlp(shell, "shell", "-c", cmd, NULL);
    4.66 +		fprintf(stderr, "gridwm: execvp %s", cmd);
    4.67 +		perror(" failed");
    4.68 +	}
    4.69 +	else {
    4.70 +		n = 0;
    4.71 +		close(pfd[1]);
    4.72 +		while(l > n) {
    4.73 +			if((l = read(pfd[0], buf + n, len - n)) < 1)
    4.74 +				break;
    4.75 +			n += l;
    4.76 +		}
    4.77 +		close(pfd[0]);
    4.78 +		buf[n - 1] = 0;
    4.79 +	}
    4.80 +	wait(0);
    4.81 +}
     5.1 --- a/util.h	Mon Jul 10 22:16:48 2006 +0200
     5.2 +++ b/util.h	Tue Jul 11 11:10:05 2006 +0200
     5.3 @@ -14,5 +14,6 @@
     5.4  			failed_assert(#a, __FILE__, __LINE__); \
     5.5  	} while (0)
     5.6  extern void failed_assert(char *a, char *file, int line);
     5.7 +void pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd);
     5.8 +extern void spawn(Display *dpy, const char *cmd);
     5.9  extern void swap(void **p1, void **p2);
    5.10 -extern void spawn(Display *dpy, const char *shell, const char *cmd);
     6.1 --- a/wm.c	Mon Jul 10 22:16:48 2006 +0200
     6.2 +++ b/wm.c	Tue Jul 11 11:10:05 2006 +0200
     6.3 @@ -21,7 +21,7 @@
     6.4  XRectangle rect, barrect;
     6.5  Bool running = True;
     6.6  
     6.7 -char *bartext, *shell;
     6.8 +char *bartext;
     6.9  int screen, sel_screen;
    6.10  unsigned int lock_mask, numlock_mask;
    6.11  
    6.12 @@ -56,7 +56,7 @@
    6.13  			if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
    6.14  				continue;
    6.15  			if(wa.map_state == IsViewable)
    6.16 -				/*manage*/;
    6.17 +				manage(create_client(wins[i], &wa));
    6.18  		}
    6.19  	}
    6.20  	if(wins)
    6.21 @@ -219,9 +219,6 @@
    6.22  	if(other_wm_running)
    6.23  		error("gridwm: another window manager is already running\n");
    6.24  
    6.25 -	if(!(shell = getenv("SHELL")))
    6.26 -		shell = "/bin/sh";
    6.27 -
    6.28  	rect.x = rect.y = 0;
    6.29  	rect.width = DisplayWidth(dpy, screen);
    6.30  	rect.height = DisplayHeight(dpy, screen);
     7.1 --- a/wm.h	Mon Jul 10 22:16:48 2006 +0200
     7.2 +++ b/wm.h	Tue Jul 11 11:10:05 2006 +0200
     7.3 @@ -55,7 +55,7 @@
     7.4  
     7.5  extern int screen, sel_screen;
     7.6  extern unsigned int lock_mask, numlock_mask;
     7.7 -extern char *bartext, *shell;
     7.8 +extern char *bartext;
     7.9  
    7.10  extern Brush brush;
    7.11