X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=main.c;h=6da3ccd57495ed2a2eef005fb205793dd9da28d7;hb=8b4bc8270a975a14c1fb7db0a94d83f4ba4d2734;hp=d0048be0ec5083964fef56a9e1071422b9e39cc7;hpb=df74b26e5dfa3ae0f3f66107a562be6ac46ee0c3;p=dwm.git diff --git a/main.c b/main.c index d0048be..6da3ccd 100644 --- a/main.c +++ b/main.c @@ -18,16 +18,24 @@ /* static */ static int (*xerrorxlib)(Display *, XErrorEvent *); -static Bool otherwm; +static Bool otherwm, readin; static void cleanup() { + close(STDIN_FILENO); while(sel) { resize(sel, True, TopLeft); unmanage(sel); } + if(dc.font.set) + XFreeFontSet(dpy, dc.font.set); + else + XFreeFont(dpy, dc.font.xfont); XUngrabKey(dpy, AnyKey, AnyModifier, root); + XFreePixmap(dpy, dc.drawable); + XFreeGC(dpy, dc.gc); + XDestroyWindow(dpy, barwin); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XSync(dpy, False); } @@ -54,25 +62,6 @@ scan() XFree(wins); } -static int -win_property(Window w, Atom a, Atom t, long l, unsigned char **prop) -{ - int status, format; - unsigned long res, extra; - Atom real; - - status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, - &res, &extra, prop); - - if(status != Success || *prop == 0) { - return 0; - } - if(res == 0) { - free((void *) *prop); - } - return res; -} - /* * Startup Error handler to check if another window manager * is already running. @@ -103,21 +92,19 @@ Window root, barwin; int getproto(Window w) { - int protos = 0; - int i; - long res; - Atom *protocols; - - res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, - ((unsigned char **)&protocols)); - if(res <= 0) { + int i, format, protos, status; + unsigned long extra, res; + Atom *protocols, real; + + protos = 0; + status = XGetWindowProperty(dpy, w, wmatom[WMProtocols], 0L, 20L, False, + XA_ATOM, &real, &format, &res, &extra, (unsigned char **)&protocols); + if(status != Success || protocols == 0) return protos; - } - for(i = 0; i < res; i++) { + for(i = 0; i < res; i++) if(protocols[i] == wmatom[WMDelete]) protos |= PROTODELWIN; - } - free((char *) protocols); + free(protocols); return protos; } @@ -139,7 +126,7 @@ sendevent(Window w, Atom a, long value) void quit(Arg *arg) { - running = False; + readin = running = False; } /* @@ -169,7 +156,6 @@ main(int argc, char *argv[]) int i, j, xfd; unsigned int mask; fd_set rd; - Bool readin = True; Window w; XModifierKeymap *modmap; XSetWindowAttributes wa; @@ -234,7 +220,7 @@ main(int argc, char *argv[]) for(ntags = 0; tags[ntags]; ntags++); seltag = emallocz(sizeof(Bool) * ntags); - seltag[DEFTAG] = True; + seltag[0] = True; /* style */ dc.bg = getcolor(BGCOLOR); @@ -272,17 +258,16 @@ main(int argc, char *argv[]) /* main event loop, also reads status text from stdin */ XSync(dpy, False); procevent(); + readin = True; while(running) { FD_ZERO(&rd); if(readin) FD_SET(STDIN_FILENO, &rd); FD_SET(xfd, &rd); i = select(xfd + 1, &rd, NULL, NULL, NULL); - if(i == -1 && errno == EINTR) + if((i == -1) && (errno == EINTR)) continue; - if(i < 0) - eprint("select failed\n"); - else if(i > 0) { + if(i > 0) { if(readin && FD_ISSET(STDIN_FILENO, &rd)) { readin = NULL != fgets(stext, sizeof(stext), stdin); if(readin) @@ -292,6 +277,8 @@ main(int argc, char *argv[]) drawstatus(); } } + else if(i < 0) + eprint("select failed\n"); procevent(); } cleanup();