summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bar.c12
-rw-r--r--client.c9
-rw-r--r--cmd.c10
-rw-r--r--config.h12
-rw-r--r--key.c16
-rw-r--r--util.c25
-rw-r--r--util.h12
-rw-r--r--wm.c33
-rw-r--r--wm.h9
9 files changed, 87 insertions, 51 deletions
diff --git a/bar.c b/bar.c
index 8d4fb36..17db8cd 100644
--- a/bar.c
+++ b/bar.c
@@ -5,12 +5,22 @@
5 5
6#include "wm.h" 6#include "wm.h"
7 7
8static const char *status[] = {
9 "sh", "-c", "echo -n `date` `uptime | sed 's/.*://; s/,//g'`"
10 " `acpi | awk '{print $4}' | sed 's/,//'`", 0 \
11};
12
8void 13void
9draw_bar() 14draw_bar()
10{ 15{
16 static char buf[1024];
17
18 buf[0] = 0;
19 pipe_spawn(buf, sizeof(buf), dpy, (char **)status);
20
11 brush.rect = barrect; 21 brush.rect = barrect;
12 brush.rect.x = brush.rect.y = 0; 22 brush.rect.x = brush.rect.y = 0;
13 draw(dpy, &brush, False, 0); 23 draw(dpy, &brush, False, buf);
14 24
15 XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width, 25 XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, barrect.width,
16 barrect.height, 0, 0); 26 barrect.height, 0, 0);
diff --git a/client.c b/client.c
index caa523c..f87fb80 100644
--- a/client.c
+++ b/client.c
@@ -122,6 +122,8 @@ unmanage(Client *c)
122 XSetErrorHandler(error_handler); 122 XSetErrorHandler(error_handler);
123 XUngrabServer(dpy); 123 XUngrabServer(dpy);
124 flush_events(EnterWindowMask); 124 flush_events(EnterWindowMask);
125 if(stack)
126 focus(stack);
125} 127}
126 128
127 129
@@ -135,3 +137,10 @@ getclient(Window w)
135 return NULL; 137 return NULL;
136} 138}
137 139
140void
141draw_client(Client *c)
142{
143
144
145
146}
diff --git a/cmd.c b/cmd.c
index 9ac4e72..4f1c84b 100644
--- a/cmd.c
+++ b/cmd.c
@@ -5,22 +5,22 @@
5 5
6#include "wm.h" 6#include "wm.h"
7#include <stdio.h> 7#include <stdio.h>
8#include <string.h>
8 9
9void 10void
10run(char *arg) 11run(void *aux)
11{ 12{
12 spawn(dpy, arg); 13 spawn(dpy, aux);
13} 14}
14 15
15void 16void
16quit(char *arg) 17quit(void *aux)
17{ 18{
18 fputs("quit\n", stderr);
19 running = False; 19 running = False;
20} 20}
21 21
22void 22void
23kill(char *arg) 23kill(void *aux)
24{ 24{
25 Client *c = stack; 25 Client *c = stack;
26 26
diff --git a/config.h b/config.h
index adca4e5..ce9e7ab 100644
--- a/config.h
+++ b/config.h
@@ -3,16 +3,8 @@
3 * See LICENSE file for license details. 3 * See LICENSE file for license details.
4 */ 4 */
5 5
6#define FONT "-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*" 6#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
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'`" \ 10#define STATUSDELAY 1 /* milliseconds */
11 " `acpi | awk '{print $4}' | sed 's/,//'`"
12#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`"
13
14#define KEYS \
15 { Mod1Mask, XK_Return, run, "xterm -u8 -bg black -fg white -fn '-*-terminus-medium-*-*-*-14-*-*-*-*-*-iso10646-*'" }, \
16 { Mod1Mask, XK_p, run, PLCMD }, \
17 { Mod1Mask | ShiftMask, XK_q, quit, NULL},
18
diff --git a/key.c b/key.c
index b5d46c6..7caae15 100644
--- a/key.c
+++ b/key.c
@@ -7,8 +7,20 @@
7 7
8#include <X11/keysym.h> 8#include <X11/keysym.h>
9 9
10static const char *term[] = {
11 "xterm", "-u8", "-bg", "black", "-fg", "white", "-fn",
12 "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0
13};
14
15static const char *proglist[] = {
16 "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
17};
18
10static Key key[] = { 19static Key key[] = {
11 KEYS 20 { Mod1Mask, XK_Return, run, term },
21 { Mod1Mask, XK_p, run, proglist },
22 { Mod1Mask | ShiftMask, XK_c, kill, NULL},
23 { Mod1Mask | ShiftMask, XK_q, quit, NULL},
12}; 24};
13 25
14void 26void
@@ -37,7 +49,7 @@ keypress(XEvent *e)
37 for(i = 0; i < len; i++) 49 for(i = 0; i < len; i++)
38 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) { 50 if((keysym == key[i].keysym) && (key[i].mod == ev->state)) {
39 if(key[i].func) 51 if(key[i].func)
40 key[i].func(key[i].arg); 52 key[i].func(key[i].aux);
41 return; 53 return;
42 } 54 }
43} 55}
diff --git a/util.c b/util.c
index 052d535..2cc2d4d 100644
--- a/util.c
+++ b/util.c
@@ -14,8 +14,6 @@
14 14
15#include "util.h" 15#include "util.h"
16 16
17static char *shell = NULL;
18
19void 17void
20error(char *errstr, ...) { 18error(char *errstr, ...) {
21 va_list ap; 19 va_list ap;
@@ -85,21 +83,17 @@ swap(void **p1, void **p2)
85} 83}
86 84
87void 85void
88spawn(Display *dpy, const char *cmd) 86spawn(Display *dpy, char *argv[])
89{ 87{
90 if(!shell && !(shell = getenv("SHELL"))) 88 if(!argv || !argv[0])
91 shell = "/bin/sh";
92
93 if(!cmd)
94 return; 89 return;
95 if(fork() == 0) { 90 if(fork() == 0) {
96 if(fork() == 0) { 91 if(fork() == 0) {
97 if(dpy) 92 if(dpy)
98 close(ConnectionNumber(dpy)); 93 close(ConnectionNumber(dpy));
99 setsid(); 94 setsid();
100 fprintf(stderr, "gridwm: execlp %s %s -c %s", shell, shell, cmd); 95 execvp(argv[0], argv);
101 execlp(shell, shell, "-c", cmd, NULL); 96 fprintf(stderr, "gridwm: execvp %s", argv[0]);
102 fprintf(stderr, "gridwm: execlp %s", cmd);
103 perror(" failed"); 97 perror(" failed");
104 } 98 }
105 exit (0); 99 exit (0);
@@ -108,15 +102,12 @@ spawn(Display *dpy, const char *cmd)
108} 102}
109 103
110void 104void
111pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd) 105pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[])
112{ 106{
113 unsigned int l, n; 107 unsigned int l, n;
114 int pfd[2]; 108 int pfd[2];
115 109
116 if(!shell && !(shell = getenv("SHELL"))) 110 if(!argv || !argv[0])
117 shell = "/bin/sh";
118
119 if(!cmd)
120 return; 111 return;
121 112
122 if(pipe(pfd) == -1) { 113 if(pipe(pfd) == -1) {
@@ -131,8 +122,8 @@ pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd)
131 dup2(pfd[1], STDOUT_FILENO); 122 dup2(pfd[1], STDOUT_FILENO);
132 close(pfd[0]); 123 close(pfd[0]);
133 close(pfd[1]); 124 close(pfd[1]);
134 execlp(shell, shell, "-c", cmd, NULL); 125 execvp(argv[0], argv);
135 fprintf(stderr, "gridwm: execlp %s", cmd); 126 fprintf(stderr, "gridwm: execvp %s", argv[0]);
136 perror(" failed"); 127 perror(" failed");
137 } 128 }
138 else { 129 else {
diff --git a/util.h b/util.h
index 51b0871..00f0714 100644
--- a/util.h
+++ b/util.h
@@ -9,12 +9,16 @@ extern void *emallocz(unsigned int size);
9extern void *emalloc(unsigned int size); 9extern void *emalloc(unsigned int size);
10extern void *erealloc(void *ptr, unsigned int size); 10extern void *erealloc(void *ptr, unsigned int size);
11extern char *estrdup(const char *str); 11extern char *estrdup(const char *str);
12#define eassert(a) do { \ 12#define eassert(a) \
13 do { \
13 if(!(a)) \ 14 if(!(a)) \
14 failed_assert(#a, __FILE__, __LINE__); \ 15 failed_assert(#a, __FILE__, __LINE__); \
15 } while (0) 16 } while (0)
16extern void failed_assert(char *a, char *file, int line); 17extern void failed_assert(char *a, char *file, int line);
17void pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd); 18extern void pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]);
18extern void spawn(Display *dpy, const char *cmd); 19extern void spawn(Display *dpy, char *argv[]);
19extern void swap(void **p1, void **p2); 20extern void swap(void **p1, void **p2);
20unsigned char *getselection(unsigned long offset, unsigned long *len, unsigned long *remain); 21extern unsigned char *getselection(unsigned long offset, unsigned long *len,
22 unsigned long *remain);
23extern unsigned int tokenize(char **result, unsigned int reslen,
24 char *str, char delim);
diff --git a/wm.c b/wm.c
index b156cba..f247372 100644
--- a/wm.c
+++ b/wm.c
@@ -3,10 +3,15 @@
3 * See LICENSE file for license details. 3 * See LICENSE file for license details.
4 */ 4 */
5 5
6#include <errno.h>
7
6#include <stdarg.h> 8#include <stdarg.h>
7#include <stdio.h> 9#include <stdio.h>
8#include <stdlib.h> 10#include <stdlib.h>
9 11
12#include <sys/types.h>
13#include <sys/time.h>
14
10#include <X11/cursorfont.h> 15#include <X11/cursorfont.h>
11#include <X11/Xatom.h> 16#include <X11/Xatom.h>
12#include <X11/Xproto.h> 17#include <X11/Xproto.h>
@@ -160,12 +165,9 @@ startup_error_handler(Display *dpy, XErrorEvent *error)
160static void 165static void
161cleanup() 166cleanup()
162{ 167{
163 /* 168 while(clients)
164 Client *c; 169 unmanage(clients);
165 for(c=client; c; c=c->next)
166 reparent_client(c, root, c->sel->rect.x, c->sel->rect.y);
167 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); 170 XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
168 */
169} 171}
170 172
171int 173int
@@ -176,6 +178,11 @@ main(int argc, char *argv[])
176 unsigned int mask; 178 unsigned int mask;
177 Window w; 179 Window w;
178 XEvent ev; 180 XEvent ev;
181 fd_set fds;
182 struct timeval t, timeout = {
183 .tv_usec = 0,
184 .tv_sec = STATUSDELAY,
185 };
179 186
180 /* command line args */ 187 /* command line args */
181 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { 188 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
@@ -264,9 +271,19 @@ main(int argc, char *argv[])
264 scan_wins(); 271 scan_wins();
265 272
266 while(running) { 273 while(running) {
267 XNextEvent(dpy, &ev); 274 if(XPending(dpy) > 0) {
268 if(handler[ev.type]) 275 XNextEvent(dpy, &ev);
269 (handler[ev.type]) (&ev); /* call handler */ 276 if(handler[ev.type])
277 (handler[ev.type]) (&ev); /* call handler */
278 continue;
279 }
280 FD_ZERO(&fds);
281 FD_SET(ConnectionNumber(dpy), &fds);
282 t = timeout;
283 if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0)
284 continue;
285 else if(errno != EINTR)
286 draw_bar();
270 } 287 }
271 288
272 cleanup(); 289 cleanup();
diff --git a/wm.h b/wm.h
index b9ba8f7..24662fa 100644
--- a/wm.h
+++ b/wm.h
@@ -42,8 +42,8 @@ struct Client {
42struct Key { 42struct Key {
43 unsigned long mod; 43 unsigned long mod;
44 KeySym keysym; 44 KeySym keysym;
45 void (*func)(char *arg); 45 void (*func)(void *aux);
46 char *arg; 46 void *aux;
47}; 47};
48 48
49extern Display *dpy; 49extern Display *dpy;
@@ -64,8 +64,9 @@ extern Client *clients, *stack;
64extern void draw_bar(); 64extern void draw_bar();
65 65
66/* cmd.c */ 66/* cmd.c */
67extern void run(char *arg); 67extern void run(void *aux);
68extern void quit(char *arg); 68extern void quit(void *aux);
69extern void kill(void *aux);
69 70
70/* client.c */ 71/* client.c */
71extern void manage(Window w, XWindowAttributes *wa); 72extern void manage(Window w, XWindowAttributes *wa);