JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
non-zero
[dwm.git] / dwm.c
diff --git a/dwm.c b/dwm.c
index d531965..85292a9 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -59,8 +59,8 @@ enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
 enum { NetSupported, NetWMName, NetLast };              /* EWMH atoms */
 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
-enum { ClkLtSymbol = -1, ClkStatusText = -2, ClkWinTitle = -3,
-       ClkClientWin = -4, ClkRootWin = -5, ClkLast = -6};/* clicks */
+enum { ClkLtSymbol = 64, ClkStatusText, ClkWinTitle,
+       ClkClientWin, ClkRootWin, ClkLast };             /* clicks */
 
 /* typedefs */
 typedef unsigned int uint;
@@ -84,12 +84,12 @@ typedef struct {
 typedef struct Client Client;
 struct Client {
        char name[256];
+       float mina, maxa;
        int x, y, w, h;
        int basew, baseh, incw, inch, maxw, maxh, minw, minh;
-       float mina, maxa;
        int bw, oldbw;
-       Bool isbanned, isfixed, isfloating, ismoved, isurgent;
        uint tags;
+       Bool isbanned, isfixed, isfloating, ismoved, isurgent;
        Client *next;
        Client *snext;
        Window win;
@@ -314,11 +314,12 @@ buttonpress(XEvent *e) {
 
        click = ClkRootWin;
        if(ev->window == barwin) {
-               x = 0;
-               for(i = 0; i < LENGTH(tags) && ev->x >= x; i++)
+               i = x = 0;
+               do
                        x += TEXTW(tags[i]);
-               if(i < LENGTH(tags) || ev->x <= x)
-                       click = i - 1;
+               while(ev->x >= x && ++i < LENGTH(tags));
+               if(i < LENGTH(tags))
+                       click = i;
                else if(ev->x < x + blw)
                        click = ClkLtSymbol;
                else if(ev->x > wx + ww - TEXTW(stext))
@@ -326,8 +327,10 @@ buttonpress(XEvent *e) {
                else
                        click = ClkWinTitle;
        }
-       else if((c = getclient(ev->window)))
+       else if((c = getclient(ev->window))) {
+               focus(c);
                click = ClkClientWin;
+       }
 
        for(i = 0; i < LENGTH(buttons); i++)
                if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
@@ -910,7 +913,8 @@ manage(Window w, XWindowAttributes *wa) {
                if(c->y + c->h + 2 * c->bw > sy + sh)
                        c->y = sy + sh - c->h - 2 * c->bw;
                c->x = MAX(c->x, sx);
-               c->y = MAX(c->y, by == 0 ? bh : sy);
+               /* only fix client y-offset, if the client center might cover the bar */
+               c->y = MAX(c->y, ((by == 0) && (c->x + (c->w / 2) >= wx) && (c->x + (c->w / 2) < wx + ww)) ? bh : sy);
                c->bw = borderpx;
        }
 
@@ -979,11 +983,6 @@ movemouse(const Arg *arg) {
        None, cursor[CurMove], CurrentTime) != GrabSuccess)
                return;
        XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
-       if(x1 < c->x || x1 > c->x + c->w || y1 < c->y || y1 > c->y + c->h) {
-               XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, 0, 0);
-               x1 = c->x + 1;
-               y1 = c->y + 1;
-       }
        for(;;) {
                XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
                switch (ev.type) {
@@ -1095,11 +1094,11 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
 
                w = MAX(w, c->minw);
                h = MAX(h, c->minh);
-               
-               if (c->maxw)
+
+               if(c->maxw)
                        w = MIN(w, c->maxw);
 
-               if (c->maxh)
+               if(c->maxh)
                        h = MIN(h, c->maxh);
        }
        if(w <= 0 || h <= 0)
@@ -1320,12 +1319,12 @@ setup(void) {
        /* init screen */
        screen = DefaultScreen(dpy);
        root = RootWindow(dpy, screen);
-       initfont(FONT);
+       initfont(font);
        sx = 0;
        sy = 0;
        sw = DisplayWidth(dpy, screen);
        sh = DisplayHeight(dpy, screen);
-       bh = dc.font.height + 2;
+       bh = dc.h = dc.font.height + 2;
        lt = layouts;
        updategeom();
 
@@ -1343,14 +1342,12 @@ setup(void) {
        cursor[CurMove] = XCreateFontCursor(dpy, XC_fleur);
 
        /* init appearance */
-       dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR);
-       dc.norm[ColBG] = getcolor(NORMBGCOLOR);
-       dc.norm[ColFG] = getcolor(NORMFGCOLOR);
-       dc.sel[ColBorder] = getcolor(SELBORDERCOLOR);
-       dc.sel[ColBG] = getcolor(SELBGCOLOR);
-       dc.sel[ColFG] = getcolor(SELFGCOLOR);
-       initfont(FONT);
-       dc.h = bh;
+       dc.norm[ColBorder] = getcolor(normbordercolor);
+       dc.norm[ColBG] = getcolor(normbgcolor);
+       dc.norm[ColFG] = getcolor(normfgcolor);
+       dc.sel[ColBorder] = getcolor(selbordercolor);
+       dc.sel[ColBG] = getcolor(selbgcolor);
+       dc.sel[ColFG] = getcolor(selfgcolor);
        dc.drawable = XCreatePixmap(dpy, root, DisplayWidth(dpy, screen), bh, DefaultDepth(dpy, screen));
        dc.gc = XCreateGC(dpy, root, 0, 0);
        XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
@@ -1499,14 +1496,22 @@ togglemax(const Arg *arg) {
 
 void
 toggletag(const Arg *arg) {
-       if(sel && (sel->tags ^= (arg->ui & TAGMASK)))
+       uint mask = sel->tags ^ (arg->ui & TAGMASK);
+
+       if(sel && mask) {
+               sel->tags = mask;
                arrange();
+       }
 }
 
 void
 toggleview(const Arg *arg) {
-       if((tagset[seltags] ^= (arg->ui & TAGMASK)))
+       uint mask = tagset[seltags] ^ (arg->ui & TAGMASK);
+
+       if(mask) {
+               tagset[seltags] = mask;
                arrange();
+       }
 }
 
 void