summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@wmii.de>2006-07-11 11:10:05 +0200
committerAnselm R. Garbe <garbeam@wmii.de>2006-07-11 11:10:05 +0200
commit3a69c5173cdd24959410870bec2a10a76272e034 (patch)
tree993f2fb75b1c44213d0c95a4da8b3a18daa739fe
parentadded several other stuff (diff)
downloaddwm-3a69c5173cdd24959410870bec2a10a76272e034.tar.gz
dwm-3a69c5173cdd24959410870bec2a10a76272e034.zip
implemented pipe_spawn
Diffstat (limited to '')
-rw-r--r--config.h2
-rw-r--r--event.c6
-rw-r--r--menu.c9
-rw-r--r--util.c56
-rw-r--r--util.h3
-rw-r--r--wm.c7
-rw-r--r--wm.h2
7 files changed, 70 insertions, 15 deletions
diff --git a/config.h b/config.h
index ca05aa2..58ed8ea 100644
--- a/config.h
+++ b/config.h
@@ -7,3 +7,5 @@
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'`" \
11 " `acpi | awk '{print $4}' | sed 's/,//'`"
diff --git a/event.c b/event.c
index d6977d3..b31c94f 100644
--- a/event.c
+++ b/event.c
@@ -218,7 +218,6 @@ keymapnotify(XEvent *e)
218static void 218static void
219maprequest(XEvent *e) 219maprequest(XEvent *e)
220{ 220{
221#if 0
222 XMapRequestEvent *ev = &e->xmaprequest; 221 XMapRequestEvent *ev = &e->xmaprequest;
223 static XWindowAttributes wa; 222 static XWindowAttributes wa;
224 223
@@ -231,9 +230,8 @@ maprequest(XEvent *e)
231 return; 230 return;
232 } 231 }
233 232
234 if(!client_of_win(ev->window)) 233 /*if(!client_of_win(ev->window))*/
235 manage_client(create_client(ev->window, &wa)); 234 manage(create_client(ev->window, &wa));
236#endif
237} 235}
238 236
239static void 237static void
diff --git a/menu.c b/menu.c
index 7c84305..d2e50ec 100644
--- a/menu.c
+++ b/menu.c
@@ -356,6 +356,15 @@ main(int argc, char *argv[])
356 char *maxname; 356 char *maxname;
357 XEvent ev; 357 XEvent ev;
358 358
359 char buf[256];
360
361 fputs(STATUSCMD, stdout);
362 fputs("\n", stdout);
363 pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD);
364 fputs(buf, stderr);
365
366 return 0;
367
359 /* command line args */ 368 /* command line args */
360 for(i = 1; i < argc; i++) { 369 for(i = 1; i < argc; i++) {
361 if (argv[i][0] == '-') 370 if (argv[i][0] == '-')
diff --git a/util.c b/util.c
index 435069f..de4df98 100644
--- a/util.c
+++ b/util.c
@@ -13,6 +13,8 @@
13 13
14#include "util.h" 14#include "util.h"
15 15
16static char *shell = NULL;
17
16void 18void
17error(char *errstr, ...) { 19error(char *errstr, ...) {
18 va_list ap; 20 va_list ap;
@@ -82,19 +84,65 @@ swap(void **p1, void **p2)
82} 84}
83 85
84void 86void
85spawn(Display *dpy, const char *shell, const char *cmd) 87spawn(Display *dpy, const char *cmd)
86{ 88{
87 if(!cmd || !shell) 89 if(!shell && !(shell = getenv("SHELL")))
90 shell = "/bin/sh";
91
92 if(!cmd)
88 return; 93 return;
89 if(fork() == 0) { 94 if(fork() == 0) {
90 if(fork() == 0) { 95 if(fork() == 0) {
96 setsid();
91 if(dpy) 97 if(dpy)
92 close(ConnectionNumber(dpy)); 98 close(ConnectionNumber(dpy));
93 execl(shell, shell, "-c", cmd, (const char *)0); 99 execlp(shell, "shell", "-c", cmd, NULL);
94 fprintf(stderr, "gridwm: execl %s", shell); 100 fprintf(stderr, "gridwm: execvp %s", cmd);
95 perror(" failed"); 101 perror(" failed");
96 } 102 }
97 exit (0); 103 exit (0);
98 } 104 }
99 wait(0); 105 wait(0);
100} 106}
107
108void
109pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd)
110{
111 unsigned int l, n;
112 int pfd[2];
113
114 if(!shell && !(shell = getenv("SHELL")))
115 shell = "/bin/sh";
116
117 if(!cmd)
118 return;
119
120 if(pipe(pfd) == -1) {
121 perror("pipe");
122 exit(1);
123 }
124
125 if(fork() == 0) {
126 setsid();
127 if(dpy)
128 close(ConnectionNumber(dpy));
129 dup2(pfd[1], STDOUT_FILENO);
130 close(pfd[0]);
131 close(pfd[1]);
132 execlp(shell, "shell", "-c", cmd, NULL);
133 fprintf(stderr, "gridwm: execvp %s", cmd);
134 perror(" failed");
135 }
136 else {
137 n = 0;
138 close(pfd[1]);
139 while(l > n) {
140 if((l = read(pfd[0], buf + n, len - n)) < 1)
141 break;
142 n += l;
143 }
144 close(pfd[0]);
145 buf[n - 1] = 0;
146 }
147 wait(0);
148}
diff --git a/util.h b/util.h
index cac3df0..4b82cef 100644
--- a/util.h
+++ b/util.h
@@ -14,5 +14,6 @@ extern char *estrdup(const char *str);
14 failed_assert(#a, __FILE__, __LINE__); \ 14 failed_assert(#a, __FILE__, __LINE__); \
15 } while (0) 15 } while (0)
16extern void failed_assert(char *a, char *file, int line); 16extern void failed_assert(char *a, char *file, int line);
17void pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd);
18extern void spawn(Display *dpy, const char *cmd);
17extern void swap(void **p1, void **p2); 19extern void swap(void **p1, void **p2);
18extern void spawn(Display *dpy, const char *shell, const char *cmd);
diff --git a/wm.c b/wm.c
index b8b3053..843aaac 100644
--- a/wm.c
+++ b/wm.c
@@ -21,7 +21,7 @@ Cursor cursor[CurLast];
21XRectangle rect, barrect; 21XRectangle rect, barrect;
22Bool running = True; 22Bool running = True;
23 23
24char *bartext, *shell; 24char *bartext;
25int screen, sel_screen; 25int screen, sel_screen;
26unsigned int lock_mask, numlock_mask; 26unsigned int lock_mask, numlock_mask;
27 27
@@ -56,7 +56,7 @@ scan_wins()
56 if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1)) 56 if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
57 continue; 57 continue;
58 if(wa.map_state == IsViewable) 58 if(wa.map_state == IsViewable)
59 /*manage*/; 59 manage(create_client(wins[i], &wa));
60 } 60 }
61 } 61 }
62 if(wins) 62 if(wins)
@@ -219,9 +219,6 @@ main(int argc, char *argv[])
219 if(other_wm_running) 219 if(other_wm_running)
220 error("gridwm: another window manager is already running\n"); 220 error("gridwm: another window manager is already running\n");
221 221
222 if(!(shell = getenv("SHELL")))
223 shell = "/bin/sh";
224
225 rect.x = rect.y = 0; 222 rect.x = rect.y = 0;
226 rect.width = DisplayWidth(dpy, screen); 223 rect.width = DisplayWidth(dpy, screen);
227 rect.height = DisplayHeight(dpy, screen); 224 rect.height = DisplayHeight(dpy, screen);
diff --git a/wm.h b/wm.h
index 038078f..c4d65ea 100644
--- a/wm.h
+++ b/wm.h
@@ -55,7 +55,7 @@ extern void (*handler[LASTEvent]) (XEvent *);
55 55
56extern int screen, sel_screen; 56extern int screen, sel_screen;
57extern unsigned int lock_mask, numlock_mask; 57extern unsigned int lock_mask, numlock_mask;
58extern char *bartext, *shell; 58extern char *bartext;
59 59
60extern Brush brush; 60extern Brush brush;
61 61