changed main event loop

This commit is contained in:
Anselm R.Garbe 2006-08-15 07:31:42 +02:00
parent ee31e38dc7
commit b6ad663f87
3 changed files with 21 additions and 10 deletions

1
dwm.h
View File

@ -108,6 +108,7 @@ extern unsigned int textw(const char *text);
/* event.c */ /* event.c */
extern void grabkeys(); extern void grabkeys();
extern void procevent();
/* main.c */ /* main.c */
extern int getproto(Window w); extern int getproto(Window w);

13
event.c
View File

@ -384,3 +384,16 @@ grabkeys()
GrabModeAsync, GrabModeAsync); GrabModeAsync, GrabModeAsync);
} }
} }
void
procevent()
{
XEvent ev;
while(XPending(dpy)) {
XNextEvent(dpy, &ev);
if(handler[ev.type])
(handler[ev.type])(&ev); /* call handler */
}
}

17
main.c
View File

@ -27,7 +27,9 @@ cleanup()
resize(sel, True, TopLeft); resize(sel, True, TopLeft);
unmanage(sel); unmanage(sel);
} }
XUngrabKey(dpy, AnyKey, AnyModifier, root);
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
XSync(dpy, False);
} }
static void static void
@ -37,6 +39,7 @@ scan()
Window *wins, d1, d2; Window *wins, d1, d2;
XWindowAttributes wa; XWindowAttributes wa;
wins = NULL;
if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
for(i = 0; i < num; i++) { for(i = 0; i < num; i++) {
if(!XGetWindowAttributes(dpy, wins[i], &wa)) if(!XGetWindowAttributes(dpy, wins[i], &wa))
@ -168,7 +171,6 @@ main(int argc, char *argv[])
fd_set rd; fd_set rd;
Bool readin = True; Bool readin = True;
Window w; Window w;
XEvent ev;
XModifierKeymap *modmap; XModifierKeymap *modmap;
XSetWindowAttributes wa; XSetWindowAttributes wa;
@ -196,6 +198,7 @@ main(int argc, char *argv[])
if(otherwm) if(otherwm)
eprint("dwm: another window manager is already running\n"); eprint("dwm: another window manager is already running\n");
XSync(dpy, False);
XSetErrorHandler(NULL); XSetErrorHandler(NULL);
xerrorxlib = XSetErrorHandler(xerror); xerrorxlib = XSetErrorHandler(xerror);
XSync(dpy, False); XSync(dpy, False);
@ -268,7 +271,7 @@ main(int argc, char *argv[])
/* main event loop, also reads status text from stdin */ /* main event loop, also reads status text from stdin */
XSync(dpy, False); XSync(dpy, False);
goto XLoop; procevent();
while(running) { while(running) {
FD_ZERO(&rd); FD_ZERO(&rd);
if(readin) if(readin)
@ -288,14 +291,8 @@ main(int argc, char *argv[])
strcpy(stext, "broken pipe"); strcpy(stext, "broken pipe");
drawstatus(); drawstatus();
} }
if(FD_ISSET(xfd, &rd)) { if(FD_ISSET(xfd, &rd))
XLoop: procevent();
while(XPending(dpy)) {
XNextEvent(dpy, &ev);
if(handler[ev.type])
(handler[ev.type])(&ev); /* call handler */
}
}
} }
} }
cleanup(); cleanup();