X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=dwm.c;h=09f3ae14adbd8179e616a4b514641684c070b67a;hb=53cac176928b67db4eb551295291ab09650927eb;hp=12871cd8568bbeeb284c49a2d9ce67a5e7170884;hpb=d15d4ba45abe06f5ac069e384bd7b46b55c0d286;p=dwm.git diff --git a/dwm.c b/dwm.c index 12871cd..09f3ae1 100644 --- a/dwm.c +++ b/dwm.c @@ -180,6 +180,7 @@ static void setclientstate(Client *c, long state); static void setlayout(const Arg *arg); static void setmfact(const Arg *arg); static void setup(void); +static void showhide(Client *c); static void spawn(const Arg *arg); static void tag(const Arg *arg); static int textnw(const char *text, unsigned int len); @@ -271,18 +272,7 @@ applyrules(Client *c) { void arrange(void) { - Client *c; - - for(c = clients; c; c = c->next) - if(ISVISIBLE(c)) { - 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); - } - else { - XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); - } - + showhide(stack); focus(NULL); if(lt[sellt]->arrange) lt[sellt]->arrange(); @@ -337,15 +327,14 @@ buttonpress(XEvent *e) { void checkotherwm(void) { otherwm = False; - XSetErrorHandler(xerrorstart); + xerrorxlib = XSetErrorHandler(xerrorstart); /* this causes an error if some other window manager is running */ XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask); XSync(dpy, False); if(otherwm) die("dwm: another window manager is already running\n"); - XSetErrorHandler(NULL); - xerrorxlib = XSetErrorHandler(xerror); + XSetErrorHandler(xerror); XSync(dpy, False); } @@ -763,10 +752,10 @@ grabkeys(void) { XUngrabKey(dpy, AnyKey, AnyModifier, root); for(i = 0; i < LENGTH(keys); i++) { - code = XKeysymToKeycode(dpy, keys[i].keysym); - for(j = 0; j < LENGTH(modifiers); j++) - XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, True, - GrabModeAsync, GrabModeAsync); + if((code = XKeysymToKeycode(dpy, keys[i].keysym))) + for(j = 0; j < LENGTH(modifiers); j++) + XGrabKey(dpy, code, keys[i].mod | modifiers[j], root, + True, GrabModeAsync, GrabModeAsync); } } } @@ -857,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 */ @@ -1056,9 +1047,9 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) { /* adjust for aspect limits */ if(c->mina > 0 && c->maxa > 0) { - if(c->maxa < (float)(w / h)) + if(c->maxa < (float)w / h) w = h * c->maxa; - else if(c->mina < (float)(h / w)) + else if(c->mina < (float)h / w) h = w * c->mina; } @@ -1378,6 +1369,22 @@ 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); + } + else { /* hide clients bottom up */ + showhide(c->snext); + XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y); + } +} + +void spawn(const Arg *arg) { /* The double-fork construct avoids zombie processes and keeps the code * clean from stupid signal handlers. */ @@ -1585,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; @@ -1625,7 +1634,7 @@ updatesizehints(Client *c) { else c->maxa = c->mina = 0.0; c->isfixed = (c->maxw && c->minw && c->maxh && c->minh - && c->maxw == c->minw && c->maxh == c->minh); + && c->maxw == c->minw && c->maxh == c->minh); } void