dwm-meillo

diff wm.c @ 14:5c078b66347b

added bar event timer
author Anselm R. Garbe <garbeam@wmii.de>
date Tue, 11 Jul 2006 18:15:11 +0200
parents 5cc5e55a132d
children 359b6e563b95
line diff
     1.1 --- a/wm.c	Tue Jul 11 16:14:22 2006 +0200
     1.2 +++ b/wm.c	Tue Jul 11 18:15:11 2006 +0200
     1.3 @@ -3,10 +3,15 @@
     1.4   * See LICENSE file for license details.
     1.5   */
     1.6  
     1.7 +#include <errno.h>
     1.8 +
     1.9  #include <stdarg.h>
    1.10  #include <stdio.h>
    1.11  #include <stdlib.h>
    1.12  
    1.13 +#include <sys/types.h>
    1.14 +#include <sys/time.h>
    1.15 +
    1.16  #include <X11/cursorfont.h>
    1.17  #include <X11/Xatom.h>
    1.18  #include <X11/Xproto.h>
    1.19 @@ -160,12 +165,9 @@
    1.20  static void
    1.21  cleanup()
    1.22  {
    1.23 -	/*
    1.24 -	Client *c;
    1.25 -	for(c=client; c; c=c->next)
    1.26 -		reparent_client(c, root, c->sel->rect.x, c->sel->rect.y);
    1.27 +	while(clients)
    1.28 +		unmanage(clients);
    1.29  	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
    1.30 -	*/
    1.31  }
    1.32  
    1.33  int
    1.34 @@ -176,6 +178,11 @@
    1.35  	unsigned int mask;
    1.36  	Window w;
    1.37  	XEvent ev;
    1.38 +	fd_set fds;
    1.39 +	struct timeval t, timeout = {
    1.40 +		.tv_usec = 0,
    1.41 +		.tv_sec = STATUSDELAY,
    1.42 +	};
    1.43  
    1.44  	/* command line args */
    1.45  	for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
    1.46 @@ -264,9 +271,19 @@
    1.47  	scan_wins();
    1.48  
    1.49  	while(running) {
    1.50 -		XNextEvent(dpy, &ev);
    1.51 -		if(handler[ev.type])
    1.52 -			(handler[ev.type]) (&ev); /* call handler */
    1.53 +		if(XPending(dpy) > 0) {
    1.54 +			XNextEvent(dpy, &ev);
    1.55 +			if(handler[ev.type])
    1.56 +				(handler[ev.type]) (&ev); /* call handler */
    1.57 +			continue;
    1.58 +		}
    1.59 +		FD_ZERO(&fds);
    1.60 +		FD_SET(ConnectionNumber(dpy), &fds);
    1.61 +		t = timeout;
    1.62 +		if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0)
    1.63 +			continue;
    1.64 +		else if(errno != EINTR)
    1.65 +			draw_bar();
    1.66  	}
    1.67  
    1.68  	cleanup();