diff options
| author | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-11 11:10:05 +0200 |
|---|---|---|
| committer | Anselm R. Garbe <garbeam@wmii.de> | 2006-07-11 11:10:05 +0200 |
| commit | 3a69c5173cdd24959410870bec2a10a76272e034 (patch) | |
| tree | 993f2fb75b1c44213d0c95a4da8b3a18daa739fe | |
| parent | added several other stuff (diff) | |
| download | dwm-3a69c5173cdd24959410870bec2a10a76272e034.tar.gz dwm-3a69c5173cdd24959410870bec2a10a76272e034.zip | |
implemented pipe_spawn
| -rw-r--r-- | config.h | 2 | ||||
| -rw-r--r-- | event.c | 6 | ||||
| -rw-r--r-- | menu.c | 9 | ||||
| -rw-r--r-- | util.c | 56 | ||||
| -rw-r--r-- | util.h | 3 | ||||
| -rw-r--r-- | wm.c | 7 | ||||
| -rw-r--r-- | wm.h | 2 |
7 files changed, 70 insertions, 15 deletions
| @@ -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/,//'`" | ||
| @@ -218,7 +218,6 @@ keymapnotify(XEvent *e) | |||
| 218 | static void | 218 | static void |
| 219 | maprequest(XEvent *e) | 219 | maprequest(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 | ||
| 239 | static void | 237 | static void |
| @@ -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] == '-') |
| @@ -13,6 +13,8 @@ | |||
| 13 | 13 | ||
| 14 | #include "util.h" | 14 | #include "util.h" |
| 15 | 15 | ||
| 16 | static char *shell = NULL; | ||
| 17 | |||
| 16 | void | 18 | void |
| 17 | error(char *errstr, ...) { | 19 | error(char *errstr, ...) { |
| 18 | va_list ap; | 20 | va_list ap; |
| @@ -82,19 +84,65 @@ swap(void **p1, void **p2) | |||
| 82 | } | 84 | } |
| 83 | 85 | ||
| 84 | void | 86 | void |
| 85 | spawn(Display *dpy, const char *shell, const char *cmd) | 87 | spawn(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 | |||
| 108 | void | ||
| 109 | pipe_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 | } | ||
| @@ -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) |
| 16 | extern void failed_assert(char *a, char *file, int line); | 16 | extern void failed_assert(char *a, char *file, int line); |
| 17 | void pipe_spawn(char *buf, unsigned int len, Display *dpy, const char *cmd); | ||
| 18 | extern void spawn(Display *dpy, const char *cmd); | ||
| 17 | extern void swap(void **p1, void **p2); | 19 | extern void swap(void **p1, void **p2); |
| 18 | extern void spawn(Display *dpy, const char *shell, const char *cmd); | ||
| @@ -21,7 +21,7 @@ Cursor cursor[CurLast]; | |||
| 21 | XRectangle rect, barrect; | 21 | XRectangle rect, barrect; |
| 22 | Bool running = True; | 22 | Bool running = True; |
| 23 | 23 | ||
| 24 | char *bartext, *shell; | 24 | char *bartext; |
| 25 | int screen, sel_screen; | 25 | int screen, sel_screen; |
| 26 | unsigned int lock_mask, numlock_mask; | 26 | unsigned 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); |
| @@ -55,7 +55,7 @@ extern void (*handler[LASTEvent]) (XEvent *); | |||
| 55 | 55 | ||
| 56 | extern int screen, sel_screen; | 56 | extern int screen, sel_screen; |
| 57 | extern unsigned int lock_mask, numlock_mask; | 57 | extern unsigned int lock_mask, numlock_mask; |
| 58 | extern char *bartext, *shell; | 58 | extern char *bartext; |
| 59 | 59 | ||
| 60 | extern Brush brush; | 60 | extern Brush brush; |
| 61 | 61 | ||
