about summary refs log tree commit diff stats
path: root/main.c
diff options
context:
space:
mode:
authorAnselm R.Garbe <arg@10ksloc.org>2006-08-15 07:31:42 +0200
committerAnselm R.Garbe <arg@10ksloc.org>2006-08-15 07:31:42 +0200
commitb6ad663f87b195b1494798030f826cb2fbc71a23 (patch)
treeff6cc4878eba5d2abaf0f10d318effd99acb16ce /main.c
parentee31e38dc75832a66cb0fc01bcf2f419ac96a20b (diff)
downloaddwm-b6ad663f87b195b1494798030f826cb2fbc71a23.tar.gz
changed main event loop
Diffstat (limited to 'main.c')
-rw-r--r--main.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/main.c b/main.c
index 8699284..b348598 100644
--- a/main.c
+++ b/main.c
@@ -27,7 +27,9 @@ cleanup()
 		resize(sel, True, TopLeft);
 		unmanage(sel);
 	}
+	XUngrabKey(dpy, AnyKey, AnyModifier, root);
 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
+	XSync(dpy, False);
 }
 
 static void
@@ -37,6 +39,7 @@ scan()
 	Window *wins, d1, d2;
 	XWindowAttributes wa;
 
+	wins = NULL;
 	if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
 		for(i = 0; i < num; i++) {
 			if(!XGetWindowAttributes(dpy, wins[i], &wa))
@@ -168,7 +171,6 @@ main(int argc, char *argv[])
 	fd_set rd;
 	Bool readin = True;
 	Window w;
-	XEvent ev;
 	XModifierKeymap *modmap;
 	XSetWindowAttributes wa;
 
@@ -196,6 +198,7 @@ main(int argc, char *argv[])
 	if(otherwm)
 		eprint("dwm: another window manager is already running\n");
 
+	XSync(dpy, False);
 	XSetErrorHandler(NULL);
 	xerrorxlib = XSetErrorHandler(xerror);
 	XSync(dpy, False);
@@ -268,7 +271,7 @@ main(int argc, char *argv[])
 
 	/* main event loop, also reads status text from stdin */
 	XSync(dpy, False);
-	goto XLoop;
+	procevent();
 	while(running) {
 		FD_ZERO(&rd);
 		if(readin)
@@ -288,14 +291,8 @@ main(int argc, char *argv[])
 					strcpy(stext, "broken pipe");
 				drawstatus();
 			}
-			if(FD_ISSET(xfd, &rd)) {
-XLoop:
-				while(XPending(dpy)) {
-					XNextEvent(dpy, &ev);
-					if(handler[ev.type])
-						(handler[ev.type])(&ev); /* call handler */
-				}
-			}
+			if(FD_ISSET(xfd, &rd))
+				procevent();
 		}
 	}
 	cleanup();