about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-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 @@
 #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/,//'`"
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)
 static void
 maprequest(XEvent *e)
 {
-#if 0
 	XMapRequestEvent *ev = &e->xmaprequest;
 	static XWindowAttributes wa;
 
@@ -231,9 +230,8 @@ maprequest(XEvent *e)
 		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
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[])
 	char *maxname;
 	XEvent ev;
 
+	char buf[256];
+
+	fputs(STATUSCMD, stdout);
+	fputs("\n", stdout);
+	pipe_spawn(buf, sizeof(buf), NULL, STATUSCMD);
+	fputs(buf, stderr);
+
+	return 0;
+
 	/* command line args */
 	for(i = 1; i < argc; i++) {
 		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 @@
 
 #include "util.h"
 
+static char *shell = NULL;
+
 void
 error(char *errstr, ...) {
 	va_list ap;
@@ -82,19 +84,65 @@ swap(void **p1, void **p2)
 }
 
 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);
+}
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);
 			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);
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];
 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 @@ scan_wins()
 			if(wa.override_redirect || XGetTransientForHint(dpy, wins[i], &d1))
 				continue;
 			if(wa.map_state == IsViewable)
-				/*manage*/;
+				manage(create_client(wins[i], &wa));
 		}
 	}
 	if(wins)
@@ -219,9 +219,6 @@ main(int argc, char *argv[])
 	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);
 	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 *);
 
 extern int screen, sel_screen;
 extern unsigned int lock_mask, numlock_mask;
-extern char *bartext, *shell;
+extern char *bartext;
 
 extern Brush brush;
 
commit/lib/core/seqs.nim?h=devel&id=a34ce2714a11595808cd8421636a89f44c1feb7b'>a34ce2714 ^
899076470 ^

4005f0d0e ^
899076470 ^


b68eb1cad ^



0956a9953 ^
4f9366975 ^
b68eb1cad ^
4f9366975 ^

b68eb1cad ^

0956a9953 ^
b68eb1cad ^
4f9366975 ^
32afdc09c ^
309ec7167 ^
84861eb48 ^
b936bfd01 ^

84861eb48 ^
67d71bb76 ^
84861eb48 ^

4a1128d16 ^
84861eb48 ^
8a19ac207 ^

32afdc09c ^


282128ab6 ^
32afdc09c ^

79ac242c7 ^
4005f0d0e ^
32afdc09c ^

413580bc0 ^
32afdc09c ^
6efac7018 ^
1f7615ad9 ^





3812d9139 ^


79ac242c7 ^
3812d9139 ^






1f7615ad9 ^
32afdc09c ^
350396e1c ^

c94647aec ^
350396e1c ^
124a584eb ^
c94647aec ^
124a584eb ^
79ac242c7 ^
4005f0d0e ^
c94647aec ^
f89ba2c95 ^

53935b8b2 ^



ebb1b7af2 ^


79ac242c7 ^
ebb1b7af2 ^











148ff74c9 ^


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159