X-Git-Url: https://jasonwoof.com/gitweb/?p=dwm.git;a=blobdiff_plain;f=dwm.c;h=413e79541b2b0d5b1abca311df621a779f58fc48;hp=289b508ff286030ee8c17f8d67dc44c76d3d2a30;hb=eb260b1a414fb82fc01d3638e3e77495297c45d5;hpb=6877a00033f4785049928bfe7e98d754e1c757a9 diff --git a/dwm.c b/dwm.c index 289b508..413e795 100644 --- a/dwm.c +++ b/dwm.c @@ -207,7 +207,7 @@ static void setlayout(const Arg *arg); static void setmfact(const Arg *arg); static void setup(void); static void showhide(Client *c); -static void sigchld(int signal); +static void sigchld(int unused); static void spawn(const Arg *arg); static void tag(const Arg *arg); static void tagmon(const Arg *arg); @@ -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); @@ -350,9 +350,9 @@ applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact) { /* adjust for aspect limits */ if(c->mina > 0 && c->maxa > 0) { if(c->maxa < (float)*w / *h) - *w = *h * c->maxa + 0.5; /* -Os double upcast workaround */ + *w = *h * c->maxa + 0.5; else if(c->mina < (float)*h / *w) - *h = *w * c->mina + 0.5; /* -Os double upcast workaround */ + *h = *w * c->mina + 0.5; } if(baseismin) { /* increment calculation requires this */ *w -= c->basew; @@ -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); } } } @@ -1428,6 +1429,9 @@ setup(void) { int w; XSetWindowAttributes wa; + /* clean up any zombies immediately */ + sigchld(0); + /* init screen */ screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); @@ -1496,13 +1500,14 @@ showhide(Client *c) { void -sigchld(int signal) { +sigchld(int unused) { + if(signal(SIGCHLD, sigchld) == SIG_ERR) + die("Can't install SIGCHLD handler"); while(0 < waitpid(-1, NULL, WNOHANG)); } void spawn(const Arg *arg) { - signal(SIGCHLD, sigchld); if(fork() == 0) { if(dpy) close(ConnectionNumber(dpy)); @@ -1591,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(); } } @@ -1622,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 @@ -1648,7 +1654,7 @@ unmapnotify(XEvent *e) { XUnmapEvent *ev = &e->xunmap; if((c = wintoclient(ev->window))) - unmanage(c); + unmanage(c, False); } void @@ -1688,10 +1694,16 @@ updategeom(void) { Monitor *newmons = NULL, *m = NULL, *tm; #ifdef XINERAMA + int nn; XineramaScreenInfo *info = NULL; if(XineramaIsActive(dpy)) info = XineramaQueryScreens(dpy, &n); + for(i = 1, nn = n; i < n; i++) + if(info[i - 1].x_org == info[i].x_org && info[i - 1].y_org == info[i].y_org + && info[i - 1].width == info[i].width && info[i - 1].height == info[i].height) + --nn; + n = nn; /* we only consider unique geometries as separate screens */ #endif /* XINERAMA */ /* allocate monitor(s) for the new geometry setup */ for(i = 0; i < n; i++) {