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]);
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
}
-void
-focustopvisible(void) {
- Client *c;
-
- for(c = stack; c && !isvisible(c); c = c->snext);
- focus(c);
-}
-
void
killclient(const char *arg) {
XEvent ev;
XMoveWindow(dpy, w, c->x + 2 * sw, c->y);
XMapWindow(dpy, w);
setclientstate(c, NormalState);
- if(isvisible(c))
- focus(c);
+ focus(c);
lt->arrange();
}
detach(c);
detachstack(c);
if(sel == c)
- focustopvisible();
+ focus(NULL);
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
setclientstate(c, WithdrawnState);
free(c->tags);
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,
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) {
unsigned int i, n, nx, ny, nw, nh, mw, mh, tw, th;
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;
resize(c, nx, ny, nw, nh, False);
i++;
}
- else {
- c->isbanned = True;
- XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
- }
- if(!sel || !isvisible(sel))
- focustopvisible();
+ else
+ ban(c);
+ focus(NULL);
restack();
}
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);
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);
- }
- }
- if(!sel || !isvisible(sel))
- focustopvisible();
+ else
+ ban(c);
+ focus(NULL);
restack();
}