JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
revert of introduced problem
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index 90ce40d..dbc4997 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -166,7 +166,7 @@ void setmfact(const void *arg);
 void setup(void);
 void spawn(const void *arg);
 void tag(const void *arg);
-uint textnw(const char *text, uint len);
+int textnw(const char *text, uint len);
 void tile(void);
 void togglebar(const void *arg);
 void togglefloating(const void *arg);
@@ -296,7 +296,8 @@ attachstack(Client *c) {
 
 void
 buttonpress(XEvent *e) {
-       uint i, x, mask;
+       uint i, mask;
+       int x;
        Client *c;
        XButtonPressedEvent *ev = &e->xbutton;
 
@@ -551,8 +552,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 +563,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)
-               memcpy(&buf[MAX(0, len - 3)], "...", 3);
+               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 +612,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 +622,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();
 }
 
@@ -740,8 +737,7 @@ void
 grabbuttons(Client *c, Bool focused) {
        int i, j;
        uint buttons[]   = { Button1, Button2, Button3 };
-       uint modifiers[] = { MODKEY, MODKEY|LockMask, MODKEY|numlockmask,
-                               MODKEY|numlockmask|LockMask} ;
+       uint modifiers[] = { MODKEY, MODKEY|LockMask, MODKEY|numlockmask, MODKEY|numlockmask|LockMask };
 
        XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
        if(focused)
@@ -1313,7 +1309,8 @@ setmfact(const void *arg) {
 
 void
 setup(void) {
-       uint i, w;
+       uint i;
+       int w;
        XSetWindowAttributes wa;
 
        /* init screen */
@@ -1418,7 +1415,7 @@ tag(const void *arg) {
        }
 }
 
-uint
+int
 textnw(const char *text, uint len) {
        XRectangle r;
 
@@ -1442,13 +1439,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 +1563,8 @@ updatebar(void) {
 
 void
 updategeom(void) {
-       int i;
 #ifdef XINERAMA
+       int i;
        XineramaScreenInfo *info = NULL;
 
        /* window area geometry */