Mercurial > dwm-meillo
comparison main.c @ 137:77922a389fa8
simplified main.c, switching back to single urxvt usage
author | arg@10ksloc.org |
---|---|
date | Fri, 21 Jul 2006 14:11:38 +0200 |
parents | 1489f6b97714 |
children | c1185dc7a36e |
comparison
equal
deleted
inserted
replaced
136:3a9caa6d565b | 137:77922a389fa8 |
---|---|
164 main(int argc, char *argv[]) | 164 main(int argc, char *argv[]) |
165 { | 165 { |
166 int i, n; | 166 int i, n; |
167 unsigned int mask; | 167 unsigned int mask; |
168 fd_set rd; | 168 fd_set rd; |
169 Bool readstdin = True; | 169 Bool readin = True; |
170 Window w; | 170 Window w; |
171 XEvent ev; | 171 XEvent ev; |
172 XSetWindowAttributes wa; | 172 XSetWindowAttributes wa; |
173 | 173 |
174 for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { | 174 if(argc == 2 && !strncmp("-v", argv[1], 3)) { |
175 switch (argv[i][1]) { | 175 fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); |
176 default: | 176 exit(EXIT_SUCCESS); |
177 eprint("usage: dwm [-v]\n"); | 177 } |
178 break; | 178 else if(argc != 1) |
179 case 'v': | 179 eprint("usage: dwm [-v]\n"); |
180 fputs("dwm-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); | |
181 exit(EXIT_SUCCESS); | |
182 break; | |
183 } | |
184 } | |
185 | 180 |
186 dpy = XOpenDisplay(0); | 181 dpy = XOpenDisplay(0); |
187 if(!dpy) | 182 if(!dpy) |
188 eprint("dwm: cannot connect X server\n"); | 183 eprint("dwm: cannot connect X server\n"); |
189 | 184 |
254 | 249 |
255 strcpy(stext, "dwm-"VERSION); | 250 strcpy(stext, "dwm-"VERSION); |
256 scan(); | 251 scan(); |
257 | 252 |
258 /* main event loop, reads status text from stdin as well */ | 253 /* main event loop, reads status text from stdin as well */ |
259 Mainloop: | |
260 while(running) { | 254 while(running) { |
261 FD_ZERO(&rd); | 255 FD_ZERO(&rd); |
262 if(readstdin) | 256 if(readin) |
263 FD_SET(STDIN_FILENO, &rd); | 257 FD_SET(STDIN_FILENO, &rd); |
264 FD_SET(ConnectionNumber(dpy), &rd); | 258 FD_SET(ConnectionNumber(dpy), &rd); |
265 | 259 |
266 i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0); | 260 i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0); |
267 if(i == -1 && errno == EINTR) | 261 if(i == -1 && errno == EINTR) |
274 XNextEvent(dpy, &ev); | 268 XNextEvent(dpy, &ev); |
275 if(handler[ev.type]) | 269 if(handler[ev.type]) |
276 (handler[ev.type])(&ev); /* call handler */ | 270 (handler[ev.type])(&ev); /* call handler */ |
277 } | 271 } |
278 } | 272 } |
279 if(readstdin && FD_ISSET(STDIN_FILENO, &rd)) { | 273 if(readin && FD_ISSET(STDIN_FILENO, &rd)) { |
280 i = n = 0; | 274 readin = NULL != fgets(stext, sizeof(stext), stdin); |
281 for(;;) { | 275 if(readin) |
282 if((i = getchar()) == EOF) { | 276 stext[strlen(stext) - 1] = 0; |
283 /* broken pipe/end of producer */ | 277 else |
284 readstdin = False; | 278 strcpy(stext, "broken pipe"); |
285 strcpy(stext, "broken pipe"); | |
286 goto Mainloop; | |
287 } | |
288 if(i == '\n' || n >= sizeof(stext) - 1) | |
289 break; | |
290 stext[n++] = i; | |
291 } | |
292 stext[n] = 0; | |
293 drawstatus(); | 279 drawstatus(); |
294 } | 280 } |
295 } | 281 } |
296 } | 282 } |
297 | 283 |