JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
applied nsz's patches (many thanks!)
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 3b6efaa..05fbf58 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -551,8 +551,7 @@ drawsquare(Bool filled, Bool empty, Bool invert, ulong col[ColLast]) {
 
 void
 drawtext(const char *text, ulong col[ColLast], Bool invert) {
-       int x, y, w, h;
-       uint len, olen;
+       int i, x, y, h, len, olen;
        XRectangle r = { dc.x, dc.y, dc.w, dc.h };
        char buf[256];
 
@@ -563,16 +562,15 @@ drawtext(const char *text, ulong col[ColLast], Bool invert) {
        olen = strlen(text);
        len = MIN(olen, sizeof buf);
        memcpy(buf, text, len);
-       w = 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 */
-       for(; len && (w = textnw(buf, len)) > dc.w - h; len--);
+       for(; len && (i = textnw(buf, len)) > dc.w - h; len--);
        if(!len)
                return;
        if(len < olen)
-               strncpy(&buf[MAX(0, len - 3)], "...", len);
+               for(i = len; i >= MAX(0, len - 3); buf[i--] = '.');
        XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
        if(dc.font.set)
                XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
@@ -613,7 +611,7 @@ expose(XEvent *e) {
 
 void
 focus(Client *c) {
-       if(!c || (c && c->isbanned))
+       if(!c || c->isbanned)
                for(c = stack; c && c->isbanned; c = c->snext);
        if(sel && sel != c) {
                grabbuttons(sel, False);
@@ -623,14 +621,12 @@ focus(Client *c) {
                detachstack(c);
                attachstack(c);
                grabbuttons(c, True);
-       }
-       sel = c;
-       if(c) {
                XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
                XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
        }
        else
                XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
+       sel = c;
        drawbar();
 }
 
@@ -1442,13 +1438,13 @@ tile(void) {
        /* master */
        c = nexttiled(clients);
        mw = mfact * ww;
-       resize(c, wx, wy, ((n == 1) ? ww : mw) - 2 * c->bw, wh - 2 * c->bw, resizehints);
+       resize(c, wx, wy, (n == 1 ? ww : mw) - 2 * c->bw, wh - 2 * c->bw, resizehints);
 
        if(--n == 0)
                return;
 
        /* tile stack */
-       x = (wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : ww - mw;
+       x = (wx + mw > c->x + c->w) ? c->x + c->w + 2 * c->bw : wx + mw;
        y = wy;
        w = (wx + mw > c->x + c->w) ? wx + ww - x : ww - mw;
        h = wh / n;
@@ -1566,8 +1562,8 @@ updatebar(void) {
 
 void
 updategeom(void) {
-       int i;
 #ifdef XINERAMA
+       int i;
        XineramaScreenInfo *info = NULL;
 
        /* window area geometry */