X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=413e79541b2b0d5b1abca311df621a779f58fc48;hp=1b30cae1b02dc1f5d58366267e4979092b7fb23b;hb=eb260b1a414fb82fc01d3638e3e77495297c45d5;hpb=33fe200b521b19a089d39aca247bb78432e02e6d diff --git a/dwm.c b/dwm.c index 1b30cae..413e795 100644 --- a/dwm.c +++ b/dwm.c @@ -218,7 +218,7 @@ static void togglefloating(const Arg *arg); static void toggletag(const Arg *arg); static void toggleview(const Arg *arg); static void unfocus(Client *c); -static void unmanage(Client *c); +static void unmanage(Client *c, Bool destroyed); static void unmapnotify(XEvent *e); static void updategeom(void); static void updatebarpos(Monitor *m); @@ -466,7 +466,7 @@ cleanup(void) { selmon->lt[selmon->sellt] = &foo; for(m = mons; m; m = m->next) while(m->stack) - unmanage(m->stack); + unmanage(m->stack, False); if(dc.font.set) XFreeFontSet(dpy, dc.font.set); else @@ -530,7 +530,7 @@ configurenotify(XEvent *e) { Monitor *m; XConfigureEvent *ev = &e->xconfigure; - if(ev->window == root && (ev->width != sw || ev->height != sh)) { + if(ev->window == root) { sw = ev->width; sh = ev->height; updategeom(); @@ -564,9 +564,9 @@ configurerequest(XEvent *e) { c->w = ev->width; if(ev->value_mask & CWHeight) c->h = ev->height; - if((c->x - m->mx + c->w) > m->mw && c->isfloating) + if((c->x + c->w) > m->mx + m->mw && c->isfloating) c->x = m->mx + (m->mw / 2 - c->w / 2); /* center in x direction */ - if((c->y - m->my + c->h) > m->mh && c->isfloating) + if((c->y + c->h) > m->my + m->mh && c->isfloating) c->y = m->my + (m->mh / 2 - c->h / 2); /* center in y direction */ if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight))) configure(c); @@ -595,7 +595,7 @@ destroynotify(XEvent *e) { XDestroyWindowEvent *ev = &e->xdestroywindow; if((c = wintoclient(ev->window))) - unmanage(c); + unmanage(c, True); } void @@ -1041,6 +1041,7 @@ killclient(const Arg *arg) { } else XKillClient(dpy, selmon->sel->win); + XSync(dpy, False); } void @@ -1235,8 +1236,8 @@ propertynotify(XEvent *e) { } if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) { updatetitle(c); - if(c == selmon->sel) - drawbars(); + if(c == c->mon->sel) + drawbar(c->mon); } } } @@ -1429,7 +1430,6 @@ setup(void) { XSetWindowAttributes wa; /* clean up any zombies immediately */ - signal(SIGCHLD, sigchld); sigchld(0); /* init screen */ @@ -1501,8 +1501,9 @@ showhide(Client *c) { void sigchld(int unused) { + if(signal(SIGCHLD, sigchld) == SIG_ERR) + die("Can't install SIGCHLD handler"); while(0 < waitpid(-1, NULL, WNOHANG)); - signal(SIGCHLD, sigchld); } void @@ -1595,23 +1596,23 @@ togglefloating(const Arg *arg) { void toggletag(const Arg *arg) { - unsigned int mask; + unsigned int newtags; if(!selmon->sel) return; - mask = selmon->sel->tags ^ (arg->ui & TAGMASK); - if(mask) { - selmon->sel->tags = mask; + newtags = selmon->sel->tags ^ (arg->ui & TAGMASK); + if(newtags) { + selmon->sel->tags = newtags; arrange(); } } void toggleview(const Arg *arg) { - unsigned int mask = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); + unsigned int newtagset = selmon->tagset[selmon->seltags] ^ (arg->ui & TAGMASK); - if(mask) { - selmon->tagset[selmon->seltags] = mask; + if(newtagset) { + selmon->tagset[selmon->seltags] = newtagset; arrange(); } } @@ -1626,24 +1627,25 @@ unfocus(Client *c) { } void -unmanage(Client *c) { +unmanage(Client *c, Bool destroyed) { XWindowChanges wc; - wc.border_width = c->oldbw; /* The server grab construct avoids race conditions. */ - XGrabServer(dpy); - XSetErrorHandler(xerrordummy); - XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */ detach(c); detachstack(c); - XUngrabButton(dpy, AnyButton, AnyModifier, c->win); - setclientstate(c, WithdrawnState); + if(!destroyed) { + wc.border_width = c->oldbw; + XGrabServer(dpy); + XSetErrorHandler(xerrordummy); + XConfigureWindow(dpy, c->win, CWBorderWidth, &wc); /* restore border */ + XUngrabButton(dpy, AnyButton, AnyModifier, c->win); + setclientstate(c, WithdrawnState); + XSync(dpy, False); + XSetErrorHandler(xerror); + XUngrabServer(dpy); + } free(c); - XSync(dpy, False); - XSetErrorHandler(xerror); - XUngrabServer(dpy); focus(NULL); - arrange(); } void @@ -1652,7 +1654,7 @@ unmapnotify(XEvent *e) { XUnmapEvent *ev = &e->xunmap; if((c = wintoclient(ev->window))) - unmanage(c); + unmanage(c, False); } void