comparison main.c @ 60:24f9c674d03f

made stdin reader more robust
author Anselm R. Garbe <garbeam@wmii.de>
date Fri, 14 Jul 2006 12:08:32 +0200
parents 5d4653de9a1c
children db93644de522
comparison
equal deleted inserted replaced
59:5d4653de9a1c 60:24f9c674d03f
262 CopyFromParent, DefaultVisual(dpy, screen), 262 CopyFromParent, DefaultVisual(dpy, screen),
263 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); 263 CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
264 XDefineCursor(dpy, barwin, cursor[CurNormal]); 264 XDefineCursor(dpy, barwin, cursor[CurNormal]);
265 XMapRaised(dpy, barwin); 265 XMapRaised(dpy, barwin);
266 266
267 dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
268 dc.gc = XCreateGC(dpy, root, 0, 0);
269 draw_bar();
270
267 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); 271 issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
268 272
269 wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ 273 wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
270 | LeaveWindowMask; 274 | LeaveWindowMask;
271 wa.cursor = cursor[CurNormal]; 275 wa.cursor = cursor[CurNormal];
272 276
273 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); 277 XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
274 278
275 dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
276 dc.gc = XCreateGC(dpy, root, 0, 0);
277
278 strcpy(stext, "dwm-"VERSION); 279 strcpy(stext, "dwm-"VERSION);
279 scan_wins(); 280 scan_wins();
280 draw_bar();
281 281
282 /* main event loop, reads status text from stdin as well */ 282 /* main event loop, reads status text from stdin as well */
283 while(running) { 283 while(running) {
284 Mainloop:
284 FD_ZERO(&rd); 285 FD_ZERO(&rd);
285 FD_SET(0, &rd); 286 FD_SET(0, &rd);
286 FD_SET(ConnectionNumber(dpy), &rd); 287 FD_SET(ConnectionNumber(dpy), &rd);
287 288
288 i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0); 289 i = select(ConnectionNumber(dpy) + 1, &rd, 0, 0, 0);
296 if(handler[ev.type]) 297 if(handler[ev.type])
297 (handler[ev.type])(&ev); /* call handler */ 298 (handler[ev.type])(&ev); /* call handler */
298 } 299 }
299 if(FD_ISSET(0, &rd)) { 300 if(FD_ISSET(0, &rd)) {
300 i = n = 0; 301 i = n = 0;
301 while((i = getchar()) != '\n' && n < sizeof(stext) - 1) 302 for(;;) {
303 if((i = getchar()) == EOF) {
304 stext[0] = 0;
305 goto Mainloop;
306 }
307 if(i == '\n' || n >= sizeof(stext) - 1)
308 break;
302 stext[n++] = i; 309 stext[n++] = i;
310 }
303 stext[n] = 0; 311 stext[n] = 0;
304 draw_bar(); 312 draw_bar();
305 } 313 }
306 } 314 }
307 } 315 }