JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
implemented restack behavior (floats are on top in tiled mode)
[dwm.git] / client.c
index f4ed1a0..ecfd8f0 100644 (file)
--- a/client.c
+++ b/client.c
@@ -16,7 +16,7 @@ resizetitle(Client *c)
        int i;
 
        c->tw = 0;
-       for(i = 0; i < TLast; i++)
+       for(i = 0; i < ntags; i++)
                if(c->tags[i])
                        c->tw += textw(tags[i]);
        c->tw += textw(c->name);
@@ -24,7 +24,7 @@ resizetitle(Client *c)
                c->tw = c->w + 2;
        c->tx = c->x + c->w - c->tw + 2;
        c->ty = c->y;
-       if(c->tags[tsel])
+       if(isvisible(c))
                XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
        else
                XMoveResizeWindow(dpy, c->title, c->tx + 2 * sw, c->ty, c->tw, c->th);
@@ -49,6 +49,8 @@ ban(Client *c)
 void
 focus(Client *c)
 {
+       if (!issel)
+               return;
        Client *old = sel;
        XEvent ev;
 
@@ -57,8 +59,6 @@ focus(Client *c)
                drawtitle(old);
        drawtitle(c);
        XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
-       XSync(dpy, False);
-       while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
 }
 
 void
@@ -75,8 +75,8 @@ focusnext(Arg *arg)
        if(!(c = getnext(sel->next)))
                c = getnext(clients);
        if(c) {
-               higher(c);
                focus(c);
+               restack();
        }
 }
 
@@ -96,8 +96,8 @@ focusprev(Arg *arg)
                c = getprev(c);
        }
        if(c) {
-               higher(c);
                focus(c);
+               restack();
        }
 }
 
@@ -179,13 +179,6 @@ gravitate(Client *c, Bool invert)
 }
 
 void
-higher(Client *c)
-{
-       XRaiseWindow(dpy, c->win);
-       XRaiseWindow(dpy, c->title);
-}
-
-void
 killclient(Arg *arg)
 {
        if(!sel)
@@ -197,13 +190,6 @@ killclient(Arg *arg)
 }
 
 void
-lower(Client *c)
-{
-       XLowerWindow(dpy, c->title);
-       XLowerWindow(dpy, c->win);
-}
-
-void
 manage(Window w, XWindowAttributes *wa)
 {
        Client *c;
@@ -211,6 +197,7 @@ manage(Window w, XWindowAttributes *wa)
        XSetWindowAttributes twa;
 
        c = emallocz(sizeof(Client));
+       c->tags = emallocz(ntags * sizeof(Bool));
        c->win = w;
        c->x = c->tx = wa->x;
        c->y = c->ty = wa->y;
@@ -244,10 +231,30 @@ manage(Window w, XWindowAttributes *wa)
 
        XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
                        GrabModeAsync, GrabModeSync, None, None);
+       XGrabButton(dpy, Button1, MODKEY | LockMask, c->win, False, BUTTONMASK,
+                       GrabModeAsync, GrabModeSync, None, None);
+       XGrabButton(dpy, Button1, MODKEY | NUMLOCKMASK, c->win, False, BUTTONMASK,
+                       GrabModeAsync, GrabModeSync, None, None);
+       XGrabButton(dpy, Button1, MODKEY | NUMLOCKMASK | LockMask, c->win, False, BUTTONMASK,
+                       GrabModeAsync, GrabModeSync, None, None);
+
        XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
                        GrabModeAsync, GrabModeSync, None, None);
+       XGrabButton(dpy, Button2, MODKEY | LockMask, c->win, False, BUTTONMASK,
+                       GrabModeAsync, GrabModeSync, None, None);
+       XGrabButton(dpy, Button2, MODKEY | NUMLOCKMASK, c->win, False, BUTTONMASK,
+                       GrabModeAsync, GrabModeSync, None, None);
+       XGrabButton(dpy, Button2, MODKEY | NUMLOCKMASK | LockMask, c->win, False, BUTTONMASK,
+                       GrabModeAsync, GrabModeSync, None, None);
+
        XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
                        GrabModeAsync, GrabModeSync, None, None);
+       XGrabButton(dpy, Button3, MODKEY | LockMask, c->win, False, BUTTONMASK,
+                       GrabModeAsync, GrabModeSync, None, None);
+       XGrabButton(dpy, Button3, MODKEY | NUMLOCKMASK, c->win, False, BUTTONMASK,
+                       GrabModeAsync, GrabModeSync, None, None);
+       XGrabButton(dpy, Button3, MODKEY | NUMLOCKMASK | LockMask, c->win, False, BUTTONMASK,
+                       GrabModeAsync, GrabModeSync, None, None);
 
        settags(c);
        if(!c->isfloat)
@@ -255,13 +262,12 @@ manage(Window w, XWindowAttributes *wa)
                        || (c->maxw && c->minw &&
                                c->maxw == c->minw && c->maxh == c->minh);
        settitle(c);
-       arrange(NULL);
 
-       /* mapping the window now prevents flicker */
-       XMapRaised(dpy, c->win);
-       XMapRaised(dpy, c->title);
-       if(c->tags[tsel])
+       XMapWindow(dpy, c->win);
+       XMapWindow(dpy, c->title);
+       if(isvisible(c))
                focus(c);
+       arrange(NULL);
 }
 
 void
@@ -394,8 +400,8 @@ togglemax(Arg *arg)
                sel->w = sw - 2;
                sel->h = sh - 2 - bh;
 
-               higher(sel);
-               resize(sel, False, TopLeft);
+               restack();
+               resize(sel, arrange == dofloat, TopLeft);
 
                sel->x = ox;
                sel->y = oy;
@@ -422,21 +428,17 @@ unmanage(Client *c)
                c->next->prev = c->prev;
        if(c == clients)
                clients = c->next;
-       if(sel == c) {
-               sel = getnext(c->next);
-               if(!sel)
-                       sel = getprev(c->prev);
-               if(!sel)
-                       sel = clients;
-       }
+       if(sel == c)
+               sel = getnext(clients);
+       free(c->tags);
        free(c);
 
        XSync(dpy, False);
        XSetErrorHandler(xerror);
        XUngrabServer(dpy);
-       arrange(NULL);
        if(sel)
                focus(sel);
+       arrange(NULL);
 }
 
 void
@@ -444,24 +446,24 @@ zoom(Arg *arg)
 {
        Client *c;
 
-       if(!sel)
+       if(!sel || (arrange != dotile) || sel->isfloat || sel->ismax)
                return;
 
-       if(sel == getnext(clients) && sel->next)  {
+       if(sel == getnext(clients))  {
                if((c = getnext(sel->next)))
                        sel = c;
+               else
+                       return;
        }
 
        /* pop */
-       if(sel->prev)
-               sel->prev->next = sel->next;
+       sel->prev->next = sel->next;
        if(sel->next)
                sel->next->prev = sel->prev;
        sel->prev = NULL;
-       if(clients)
-               clients->prev = sel;
+       clients->prev = sel;
        sel->next = clients;
        clients = sel;
-       arrange(NULL);
        focus(sel);
+       arrange(NULL);
 }