return c;
}
+static Bool
+ismaster(Client *c) {
+ Client *cl;
+ unsigned int i;
+
+ for(cl = nexttiled(clients), i = 0; cl && cl != c; cl = nexttiled(cl->next), i++);
+ return i < nmaster;
+}
+
+static void
+pop(Client *c) {
+ detach(c);
+ if(clients)
+ clients->prev = c;
+ c->next = clients;
+ clients = c;
+}
+
+static void
+swap(Client *c1, Client *c2) {
+ Client tmp = *c1;
+ Client *c1p = c1->prev;
+ Client *c1n = c1->next;
+ Client *c1s = c1->snext;
+ Client *c2p = c2->prev;
+ Client *c2n = c2->next;
+ Client *c2s = c2->snext;
+
+ *c1 = *c2;
+ *c2 = tmp;
+ c1->prev = c1p;
+ c1->next = c1n;
+ c1->snext = c1s;
+ c2->prev = c2p;
+ c2->next = c2n;
+ c2->snext = c2s;
+}
+
static void
togglemax(Client *c) {
XEvent ev;
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
}
+static Client *
+topofstack() {
+ Client *c;
+ unsigned int i;
+
+ for(c = nexttiled(clients), i = 0; c && i < nmaster; c = nexttiled(c->next), i++);
+ return (i < nmaster) ? NULL : c;
+}
+
/* extern */
void (*arrange)(void) = DEFMODE;
void
incnmaster(Arg *arg) {
- if(nmaster + arg->i < 1)
+ if((nmaster + arg->i < 1) || (wah / (nmaster + arg->i) < bh))
return;
nmaster += arg->i;
arrange();
void
zoom(Arg *arg) {
- unsigned int i, n;
+ unsigned int n;
Client *c;
if(!sel)
}
for(n = 0, c = nexttiled(clients); c; c = nexttiled(c->next))
n++;
- if(n <= nmaster || (arrange == dofloat))
- return;
- for(c = nexttiled(clients), i = 0; c && (c != sel) && i < nmaster; c = nexttiled(c->next))
- i++;
- if(c == sel && i < nmaster)
- for(; c && i < nmaster; c = nexttiled(c->next))
- i++;
- if(!c)
+ c = sel;
+ if(arrange == dofloat)
return;
+ else if(n <= nmaster)
+ pop(c);
+ else if(ismaster(sel)) {
+ if(!(c = topofstack()))
+ return;
+ swap(c, sel);
+ c = sel;
+ }
+ else
+ pop(c);
- detach(c);
- if(clients)
- clients->prev = c;
- c->next = clients;
- clients = c;
focus(c);
arrange();
}