dwm

[fork] dynamic window manager
Log | Files | Refs | README | LICENSE

commit 6651dd7fd9e8e95cfc6c472f1adfeff41735d798
parent acdea319162a5a51703a88ca7a8a1b17534be616
Author: Anselm R. Garbe <arg@10kloc.org>
Date:   Fri,  6 Oct 2006 11:50:15 +0200

code polishing, removed unnecessary newlines
Diffstat:
Mclient.c | 18+-----------------
Mconfig.arg.h | 3+--
Mconfig.default.h | 3+--
Mdraw.c | 14+-------------
Mdwm.h | 3+--
Mevent.c | 9++-------
Mmain.c | 30+++++++++---------------------
Mtag.c | 6+-----
Mutil.c | 5++---
Mview.c | 18++++--------------
10 files changed, 23 insertions(+), 86 deletions(-)

diff --git a/client.c b/client.c @@ -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 @@ gravitate(Client *c, Bool invert) { dy = -(c->h); break; } - switch (c->grav) { default: break; @@ -177,7 +175,6 @@ gravitate(Client *c, Bool invert) { dx = -(c->w + c->border); break; } - if(invert) { dx = -dx; dy = -dy; @@ -210,10 +207,8 @@ manage(Window w, XWindowAttributes *wa) { 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 @@ manage(Window w, XWindowAttributes *wa) { 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 @@ manage(Window w, XWindowAttributes *wa) { 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 @@ manage(Window w, XWindowAttributes *wa) { || (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 @@ resize(Client *c, Bool sizehints, Corner sticky) { 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 @@ resize(Client *c, Bool sizehints, Corner sticky) { 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 @@ unmanage(Client *c) { /* 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); diff --git a/config.arg.h b/config.arg.h @@ -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. */ diff --git a/config.default.h b/config.default.h @@ -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. */ diff --git a/draw.c b/draw.c @@ -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 @@ drawtext(const char *text, unsigned long col[ColLast], Bool highlight) { 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 @@ drawtext(const char *text, unsigned long col[ColLast], Bool highlight) { 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 @@ drawstatus(void) { 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 @@ drawstatus(void) { 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 @@ drawtitle(Client *c) { 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 @@ setfont(const char *fontstr) { 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); diff --git a/dwm.h b/dwm.h @@ -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. * * dynamic window manager is designed like any other X client as well. It is diff --git a/event.c b/event.c @@ -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 @@ resizemouse(Client *c) { 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 @@ enternotify(XEvent *e) { 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 @@ maprequest(XEvent *e) { 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 @@ propertynotify(XEvent *e) { if(ev->state == PropertyDelete) return; /* ignore */ - if((c = getclient(ev->window))) { if(ev->atom == wmatom[WMProtocols]) { c->proto = getproto(c->win); diff --git a/main.c b/main.c @@ -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 @@ setup(void) { 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 @@ setup(void) { } } 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 @@ setup(void) { 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 @@ setup(void) { 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 @@ main(int argc, char *argv[]) { } 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 @@ main(int argc, char *argv[]) { XSetErrorHandler(NULL); xerrorxlib = XSetErrorHandler(xerror); XSync(dpy, False); - setup(); drawstatus(); scan(); @@ -291,6 +280,5 @@ main(int argc, char *argv[]) { } cleanup(); XCloseDisplay(dpy); - return 0; } diff --git a/tag.c b/tag.c @@ -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 @@ initrregs(void) { 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 @@ tag(Arg *arg) { if(!sel) return; - for(i = 0; i < ntags; i++) sel->tags[i] = False; sel->tags[arg->i] = True; @@ -129,7 +126,6 @@ toggletag(Arg *arg) { if(!sel) return; - sel->tags[arg->i] = !sel->tags[arg->i]; for(i = 0; i < ntags && !sel->tags[i]; i++); if(i == ntags) diff --git a/util.c b/util.c @@ -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 @@ eprint(const char *errstr, ...) { 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 @@ spawn(Arg *arg) { if(!shell && !(shell = getenv("SHELL"))) shell = "/bin/sh"; - if(!arg->cmd) return; /* The double-fork construct avoids zombie processes and keeps the code diff --git a/view.c b/view.c @@ -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 @@ reorder(void) { } 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 @@ dotile(Arg *arg) { 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 @@ dotile(Arg *arg) { } else ban(c); + if(!sel || !isvisible(sel)) { for(c = stack; c && !isvisible(c); c = c->snext); focus(c); @@ -158,7 +156,6 @@ focusnext(Arg *arg) { if(!sel) return; - if(!(c = getnext(sel->next))) c = getnext(clients); if(c) { @@ -173,7 +170,6 @@ focusprev(Arg *arg) { if(!sel) return; - if(!(c = getprev(sel->prev))) { for(c = clients; c && c->next; c = c->next); c = getprev(c); @@ -204,7 +200,6 @@ resizecol(Arg *arg) { 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 @@ viewall(Arg *arg) { arrange(NULL); } - - void zoom(Arg *arg) { unsigned int n; @@ -299,18 +292,15 @@ zoom(Arg *arg) { 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;