code polishing, removed unnecessary newlines
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */ #include "dwm.h"@@ -156,7 +155,6 @@ case SouthWestGravity:
dy = -(c->h); break; } - switch (c->grav) { default: break;@@ -177,7 +175,6 @@ case SouthEastGravity:
dx = -(c->w + c->border); break; } - if(invert) { dx = -dx; dy = -dy;@@ -210,10 +207,8 @@ c->y = c->ty = wa->y;
c->w = c->tw = wa->width; c->h = wa->height; c->th = bh; - c->border = 0; updatesize(c); - if(c->x + c->w + 2 * BORDERPX > sw) c->x = sw - c->w - 2 * BORDERPX; if(c->x < sx)@@ -222,7 +217,6 @@ if(c->y + c->h + 2 * BORDERPX > sh)
c->y = sh - c->h - 2 * BORDERPX; if(c->h != sh && c->y < bh) c->y = bh; - c->proto = getproto(c->win); XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);@@ -230,12 +224,10 @@ XGetTransientForHint(dpy, c->win, &trans);
twa.override_redirect = 1; twa.background_pixmap = ParentRelative; twa.event_mask = ExposureMask | EnterWindowMask; - c->twin = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); - grabbuttons(c, False); updatetitle(c); settags(c, getclient(trans));@@ -244,13 +236,11 @@ c->isfloat = trans
|| (c->maxw && c->minw && c->maxw == c->minw && c->maxh == c->minh); resizetitle(c); - if(clients) clients->prev = c; c->next = clients; c->snext = stack; stack = clients = c; - ban(c); XMapWindow(dpy, c->win); XMapWindow(dpy, c->twin);@@ -283,7 +273,6 @@ if(sticky == TopRight || sticky == BotRight)
c->x = right - c->w; if(sticky == BotLeft || sticky == BotRight) c->y = bottom - c->h; - /* offscreen appearance fixes */ if(c->x + c->w < sx) c->x = sx;@@ -293,7 +282,6 @@ if(c->x > sw)
c->x = sw - c->w; if(c->y > sh) c->y = sh - c->h; - resizetitle(c); wc.x = c->x; wc.y = c->y;@@ -392,20 +380,16 @@
/* The server grab construct avoids race conditions. */ XGrabServer(dpy); XSetErrorHandler(xerrordummy); - detach(c); detachstack(c); if(sel == c) { for(nc = stack; nc && !isvisible(nc); nc = nc->snext); focus(nc); } - XUngrabButton(dpy, AnyButton, AnyModifier, c->win); XDestroyWindow(dpy, c->twin); - free(c->tags); free(c); - XSync(dpy, False); XSetErrorHandler(xerror); XUngrabServer(dpy);
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */ #include "dwm.h"@@ -30,21 +29,17 @@ XRectangle r = { dc.x, dc.y, dc.w, dc.h };
XSetForeground(dpy, dc.gc, col[ColBG]); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); - if(!text) return; - w = 0; olen = len = strlen(text); if(len >= sizeof(buf)) len = sizeof(buf) - 1; memcpy(buf, text, len); buf[len] = 0; - h = dc.font.ascent + dc.font.descent; y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; x = dc.x + (h / 2); - /* shorten text if necessary */ while(len && (w = textnw(buf, len)) > dc.w - h) buf[--len] = 0;@@ -56,7 +51,6 @@ buf[len - 2] = '.';
if(len > 3) buf[len - 3] = '.'; } - if(w > dc.w) return; /* too long */ gcv.foreground = col[ColFG];@@ -93,7 +87,6 @@ drawstatus(void) {
int i, x; dc.x = dc.y = 0; - for(i = 0; i < ntags; i++) { dc.w = textw(tags[i]); if(seltag[i])@@ -102,10 +95,8 @@ else
drawtext(tags[i], dc.norm, sel && sel->tags[i]); dc.x += dc.w; } - dc.w = bmw; drawtext(arrange == dofloat ? FLOATSYMBOL : TILESYMBOL, dc.status, False); - x = dc.x + dc.w; dc.w = textw(stext); dc.x = bx + bw - dc.w;@@ -114,7 +105,6 @@ dc.x = x;
dc.w = bw - x; } drawtext(stext, dc.status, False); - if((dc.w = dc.x - x) > bh) { dc.x = x; if(sel)@@ -134,7 +124,6 @@ XUnmapWindow(dpy, c->twin);
XSetWindowBorder(dpy, c->win, dc.sel[ColBG]); return; } - XSetWindowBorder(dpy, c->win, dc.norm[ColBG]); XMapWindow(dpy, c->twin); dc.x = dc.y = 0;@@ -177,7 +166,6 @@ if(dc.font.set) {
XFontSetExtents *font_extents; XFontStruct **xfonts; char **font_names; - dc.font.ascent = dc.font.descent = 0; font_extents = XExtentsOfFontSet(dc.font.set); n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */ #include "dwm.h"@@ -64,7 +63,7 @@
ocx = c->x; ocy = c->y; if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync, - None, cursor[CurResize], CurrentTime) != GrabSuccess) + None, cursor[CurResize], CurrentTime) != GrabSuccess) return; c->ismax = False; XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w, c->h);@@ -211,7 +210,6 @@ XCrossingEvent *ev = &e->xcrossing;
if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) return; - if(((c = getclient(ev->window)) || (c = getctitle(ev->window))) && isvisible(c)) focus(c); else if(ev->window == root) {@@ -279,13 +277,11 @@ XMapRequestEvent *ev = &e->xmaprequest;
if(!XGetWindowAttributes(dpy, ev->window, &wa)) return; - if(wa.override_redirect) { XSelectInput(dpy, ev->window, (StructureNotifyMask | PropertyChangeMask)); return; } - if(!getclient(ev->window)) manage(ev->window, &wa); }@@ -298,7 +294,6 @@ XPropertyEvent *ev = &e->xproperty;
if(ev->state == PropertyDelete) return; /* ignore */ - if((c = getclient(ev->window))) { if(ev->atom == wmatom[WMProtocols]) { c->proto = getproto(c->win);
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */@@ -93,12 +92,11 @@ netatom[NetSupported] = XInternAtom(dpy, "_NET_SUPPORTED", False);
netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False); XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32, PropModeReplace, (unsigned char *) netatom, NetLast); - /* init cursors */ cursor[CurNormal] = XCreateFontCursor(dpy, XC_left_ptr); cursor[CurResize] = XCreateFontCursor(dpy, XC_sizing); cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur); - + /* init modifier map */ modmap = XGetModifierMapping(dpy); for (i = 0; i < 8; i++) { for (j = 0; j < modmap->max_keypermod; j++) {@@ -107,19 +105,16 @@ numlockmask = (1 << i);
} } XFree(modmap); - + /* select for events */ wa.event_mask = SubstructureRedirectMask | SubstructureNotifyMask | EnterWindowMask | LeaveWindowMask; wa.cursor = cursor[CurNormal]; XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); - grabkeys(); initrregs(); - for(ntags = 0; tags[ntags]; ntags++); seltag = emallocz(sizeof(Bool) * ntags); seltag[0] = True; - /* style */ dc.norm[ColBG] = getcolor(NORMBGCOLOR); dc.norm[ColFG] = getcolor(NORMFGCOLOR);@@ -128,13 +123,13 @@ dc.sel[ColFG] = getcolor(SELFGCOLOR);
dc.status[ColBG] = getcolor(STATUSBGCOLOR); dc.status[ColFG] = getcolor(STATUSFGCOLOR); setfont(FONT); - + /* geometry */ bmw = textw(TILESYMBOL) > textw(FLOATSYMBOL) ? textw(TILESYMBOL) : textw(FLOATSYMBOL); sx = sy = 0; sw = DisplayWidth(dpy, screen); sh = DisplayHeight(dpy, screen); master = MASTER; - + /* bar */ bx = by = 0; bw = sw; dc.h = bh = dc.font.height + 2;@@ -146,13 +141,13 @@ CopyFromParent, DefaultVisual(dpy, screen),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(dpy, barwin, cursor[CurNormal]); XMapRaised(dpy, barwin); - + strcpy(stext, "dwm-"VERSION); + /* pixmap for everything */ dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); dc.gc = XCreateGC(dpy, root, 0, 0); XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); - + /* multihead support */ issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); - strcpy(stext, "dwm-"VERSION); } /*@@ -204,8 +199,7 @@ quit(Arg *arg) {
readin = running = False; } -/* - * There's no way to check accesses to destroyed windows, thus those cases are +/* There's no way to check accesses to destroyed windows, thus those cases are * ignored (especially on UnmapNotify's). Other types of errors call Xlibs * default error handler, which may call exit. */@@ -236,21 +230,17 @@ exit(EXIT_SUCCESS);
} else if(argc != 1) eprint("usage: dwm [-v]\n"); - dpy = XOpenDisplay(0); if(!dpy) eprint("dwm: cannot open display\n"); - xfd = ConnectionNumber(dpy); screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); - otherwm = False; XSetErrorHandler(xerrorstart); /* this causes an error if some other window manager is running */ XSelectInput(dpy, root, SubstructureRedirectMask); XSync(dpy, False); - if(otherwm) eprint("dwm: another window manager is already running\n");@@ -258,7 +248,6 @@ XSync(dpy, False);
XSetErrorHandler(NULL); xerrorxlib = XSetErrorHandler(xerror); XSync(dpy, False); - setup(); drawstatus(); scan();@@ -291,6 +280,5 @@ procevent();
} cleanup(); XCloseDisplay(dpy); - return 0; }
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */ #include "dwm.h"@@ -53,7 +52,6 @@ if(rreg)
return; len = sizeof(rule) / sizeof(rule[0]); rreg = emallocz(len * sizeof(RReg)); - for(i = 0; i < len; i++) { if(rule[i].clpattern) { reg = emallocz(sizeof(regex_t));@@ -115,7 +113,6 @@ unsigned int i;
if(!sel) return; - for(i = 0; i < ntags; i++) sel->tags[i] = False; sel->tags[arg->i] = True;@@ -129,7 +126,6 @@ unsigned int i;
if(!sel) return; - sel->tags[arg->i] = !sel->tags[arg->i]; for(i = 0; i < ntags && !sel->tags[i]; i++); if(i == ntags)
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */ #include "dwm.h"@@ -33,6 +32,7 @@
void * erealloc(void *ptr, unsigned int size) { void *res = realloc(ptr, size); + if(!res) eprint("fatal: could not malloc() %u bytes\n", size); return res;@@ -44,7 +44,6 @@ static char *shell = NULL;
if(!shell && !(shell = getenv("SHELL"))) shell = "/bin/sh"; - if(!arg->cmd) return; /* The double-fork construct avoids zombie processes and keeps the code
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */ #include "dwm.h"@@ -43,9 +42,9 @@ clients = newclients;
} static void -togglemax(Client *c) -{ +togglemax(Client *c) { XEvent ev; + if((c->ismax = !c->ismax)) { c->rx = c->x; c->x = sx; c->ry = c->y; c->y = bh;@@ -102,11 +101,9 @@ Client *c;
for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next)) n++; - mpx = (sw * master) / 1000; stackw = sw - mpx; stackh = sh - bh; - th = stackh; if(n > 1) th /= (n - 1);@@ -145,6 +142,7 @@ resize(c, False, TopLeft);
} else ban(c); + if(!sel || !isvisible(sel)) { for(c = stack; c && !isvisible(c); c = c->snext); focus(c);@@ -158,7 +156,6 @@ Client *c;
if(!sel) return; - if(!(c = getnext(sel->next))) c = getnext(clients); if(c) {@@ -173,7 +170,6 @@ Client *c;
if(!sel) return; - if(!(c = getprev(sel->prev))) { for(c = clients; c && c->next; c = c->next); c = getprev(c);@@ -204,7 +200,6 @@ if(isvisible(c) && !c->isfloat)
n++; if(!sel || sel->isfloat || n < 2 || (arrange == dofloat)) return; - if(sel == getnext(clients)) { if(master + arg->i > 950 || master + arg->i < 50) return;@@ -290,8 +285,6 @@ reorder();
arrange(NULL); } - - void zoom(Arg *arg) { unsigned int n;@@ -299,18 +292,15 @@ Client *c;
if(!sel) return; - if(sel->isfloat || (arrange == dofloat)) { togglemax(sel); return; } - for(n = 0, c = clients; c; c = c->next) if(isvisible(c) && !c->isfloat) n++; if(n < 2 || (arrange == dofloat)) return; - if((c = sel) == nexttiled(clients)) if(!(c = nexttiled(c->next))) return;