JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
using malloc() instead of calloc() and sticking to static initializer and struct...
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 50bbd6a..09f3ae1 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -272,8 +272,7 @@ applyrules(Client *c) {
 
 void
 arrange(void) {
-       if(stack)
-               showhide(stack);
+       showhide(stack);
        focus(NULL);
        if(lt[sellt]->arrange)
                lt[sellt]->arrange();
@@ -847,12 +846,14 @@ killclient(const Arg *arg) {
 
 void
 manage(Window w, XWindowAttributes *wa) {
+       static Client cz;
        Client *c, *t = NULL;
        Window trans = None;
        XWindowChanges wc;
 
-       if(!(c = calloc(1, sizeof(Client))))
-               die("fatal: could not calloc() %u bytes\n", sizeof(Client));
+       if(!(c = malloc(sizeof(Client))))
+               die("fatal: could not malloc() %u bytes\n", sizeof(Client));
+       *c = cz;
        c->win = w;
 
        /* geometry */
@@ -1369,15 +1370,18 @@ setup(void) {
 
 void
 showhide(Client *c) {
+       if(!c)
+               return;
        if(ISVISIBLE(c)) { /* show clients top down */
                XMoveWindow(dpy, c->win, c->x, c->y);
                if(!lt[sellt]->arrange || c->isfloating)
                        resize(c, c->x, c->y, c->w, c->h, True);
+               showhide(c->snext);
        }
-       if(c->snext) /* hide clients bottom up */
+       else { /* hide clients bottom up */
                showhide(c->snext);
-       if(!ISVISIBLE(c))
                XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
+       }
 }
 
 void
@@ -1588,7 +1592,9 @@ updatesizehints(Client *c) {
        long msize;
        XSizeHints size;
 
-       XGetWMNormalHints(dpy, c->win, &size, &msize);
+       if(!XGetWMNormalHints(dpy, c->win, &size, &msize))
+               /* size is uninitialized, ensure that size.flags aren't used */
+               size.flags = PSize; 
        if(size.flags & PBaseSize) {
                c->basew = size.base_width;
                c->baseh = size.base_height;