Hi,

attached are 3 patches:
-clean:
        small cleanup of layout.c for loop in floating() - to have it same
        styled as loop in tile()
-focusmerge:
        merges function of focus() and focustopvisible() into one function
        focus(). It has parameter Client *c and this behaviour:
                - c == NULL: if selscreen then select topvisible window else
                  deselect sel (used in leavenotify, while pointer goes to
                  another screen in multihead setup).
                - c && isvisible(c): focus that client

                - else: select topvisible client
        this makes behaviour of focus(NULL) more intuitive, the function do
        the best to select the client AND everytime has some client selected
        - if there is someone visible (and if selscreen, of course :). Also
        allow some cleanup in layout functions, too;
-un_ban:
        refactor (un)banning of (in)visible clients from layouts functions.
        Their code is then more readable and it ease creation of another
        layouts, too


--anydot 
diff -r 467c754b607d layout.c
--- a/layout.c  Mon May 28 15:05:47 2007 +0200
+++ b/layout.c  Mon May 28 16:25:12 2007 +0200
@@ -77,7 +77,7 @@ floating(void) {
 floating(void) {
        Client *c;
 
-       for(c = clients; c; c = c->next) {
+       for(c = clients; c; c = c->next)
                if(isvisible(c)) {
                        if(c->isbanned)
                                XMoveWindow(dpy, c->win, c->x, c->y);
@@ -88,7 +88,6 @@ floating(void) {
                        c->isbanned = True;
                        XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
                }
-       }
        if(!sel || !isvisible(sel))
                focustopvisible();
        restack();
diff -r 1fa515fbcb90 client.c
--- a/client.c  Mon May 28 20:59:49 2007 +0200
+++ b/client.c  Mon May 28 20:59:50 2007 +0200
@@ -129,8 +129,8 @@ detach(Client *c) {
 
 void
 focus(Client *c) {
-       if(c && !isvisible(c))
-               return;
+       if( !c && selscreen || c && !isvisible(c))
+               for(c = stack; c && !isvisible(c); c = c->snext);
        if(sel && sel != c) {
                grabbuttons(sel, False);
                XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
@@ -150,14 +150,6 @@ focus(Client *c) {
        }
        else
                XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
-}
-
-void
-focustopvisible(void) {
-       Client *c;
-
-       for(c = stack; c && !isvisible(c); c = c->snext);
-       focus(c);
 }
 
 void
@@ -230,8 +222,7 @@ manage(Window w, XWindowAttributes *wa) 
        XMoveWindow(dpy, w, c->x + 2 * sw, c->y);
        XMapWindow(dpy, w);
        setclientstate(c, NormalState);
-       if(isvisible(c))
-               focus(c);
+       focus(c);
        lt->arrange();
 }
 
@@ -401,7 +392,7 @@ unmanage(Client *c) {
        detach(c);
        detachstack(c);
        if(sel == c)
-               focustopvisible();
+               focus(NULL);
        XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
        setclientstate(c, WithdrawnState);
        free(c->tags);
diff -r 1fa515fbcb90 dwm.h
--- a/dwm.h     Mon May 28 20:59:49 2007 +0200
+++ b/dwm.h     Mon May 28 20:59:50 2007 +0200
@@ -100,8 +100,7 @@ void attach(Client *c);                     /* attaches c 
 void attach(Client *c);                        /* attaches c to global client 
list */
 void configure(Client *c);             /* send synthetic configure event */
 void detach(Client *c);                        /* detaches c from global 
client list */
-void focus(Client *c);                 /* focus c, c may be NULL */
-void focustopvisible(void);            /* focus top visible window on stack */
+void focus(Client *c);                 /* focus c if visible && !NULL, or 
focus top visible */
 void killclient(const char *arg);      /* kill sel  nicely */
 void manage(Window w, XWindowAttributes *wa);  /* manage new client */
 void resize(Client *c, int x, int y,
diff -r 1fa515fbcb90 event.c
--- a/event.c   Mon May 28 20:59:49 2007 +0200
+++ b/event.c   Mon May 28 20:59:50 2007 +0200
@@ -242,11 +242,11 @@ enternotify(XEvent *e) {
 
        if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
                return;
-       if((c = getclient(ev->window)) && isvisible(c))
+       if(c = getclient(ev->window))
                focus(c);
        else if(ev->window == root) {
                selscreen = True;
-               focustopvisible();
+               focus(NULL);
        }
 }
 
diff -r 1fa515fbcb90 layout.c
--- a/layout.c  Mon May 28 20:59:49 2007 +0200
+++ b/layout.c  Mon May 28 21:00:59 2007 +0200
@@ -64,8 +64,7 @@ tile(void) {
                        c->isbanned = True;
                        XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
                }
-       if(!sel || !isvisible(sel)) 
-               focustopvisible();
+       focus(NULL);
        restack();
 }
 
@@ -88,8 +87,7 @@ floating(void) {
                        c->isbanned = True;
                        XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
                }
-       if(!sel || !isvisible(sel))
-               focustopvisible();
+       focus(NULL);
        restack();
 }
 
diff -r c742c339c6ce layout.c
--- a/layout.c  Mon May 28 21:01:38 2007 +0200
+++ b/layout.c  Mon May 28 21:01:40 2007 +0200
@@ -12,6 +12,22 @@ static unsigned int nlayouts = 0;
 static unsigned int nlayouts = 0;
 static unsigned int masterw = MASTERWIDTH;
 static unsigned int nmaster = NMASTER;
+
+static void
+ban(Client *c) {
+       if (c->isbanned)
+               return;
+       XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
+       c->isbanned = True;
+}
+
+static void
+unban(Client *c) {
+       if (!c->isbanned)
+               return;
+       XMoveWindow(dpy, c->win, c->x, c->y);
+       c->isbanned = False;
+}
 
 static void
 tile(void) {
@@ -28,9 +44,7 @@ tile(void) {
 
        for(i = 0, c = clients; c; c = c->next)
                if(isvisible(c)) {
-                       if(c->isbanned)
-                               XMoveWindow(dpy, c->win, c->x, c->y);
-                       c->isbanned = False;
+                       unban(c);
                        if(c->isfloating)
                                continue;
                        c->ismax = False;
@@ -60,10 +74,8 @@ tile(void) {
                        resize(c, nx, ny, nw, nh, False);
                        i++;
                }
-               else {
-                       c->isbanned = True;
-                       XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
-               }
+               else
+                       ban(c);
        focus(NULL);
        restack();
 }
@@ -83,10 +95,8 @@ floating(void) {
                        c->isbanned = False;
                        resize(c, c->x, c->y, c->w, c->h, True);
                }
-               else {
-                       c->isbanned = True;
-                       XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
-               }
+               else
+                       ban(c);
        focus(NULL);
        restack();
 }

Reply via email to