- for(n = 0, c = clients; c; c = c->next, n++);
- rt = sqrt(n);
- if(modff(rt, &fd) < 0.5)
- rows = floor(rt);
- else
- rows = ceil(rt);
- if(rows * rows < n)
- cols = rows + 1;
- else
- cols = rows;
-
- gw = (sw - 1) / cols;
- gh = (sh - bh - 1) / rows;
-
- for(i = j = 0, c = clients; c; c = c->next) {
- c->x = i * gw;
- c->y = j * gh + bh;
- c->w = gw;
- c->h = gh;
- resize(c);
- if(++i == cols) {
- j++;
- i = 0;
+
+ sel->tags[arg->i] = tags[arg->i];
+ arrange(NULL);
+}
+
+void
+ttrunc(Arg *arg)
+{
+ int i;
+ if(!sel)
+ return;
+
+ for(i = 0; i < TLast; i++)
+ sel->tags[i] = NULL;
+ tappend(arg);
+}
+
+static void
+ban_client(Client *c)
+{
+ XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
+ XMoveWindow(dpy, c->title, c->tx + 2 * sw, c->ty);
+}
+
+void
+floating(Arg *arg)
+{
+ Client *c;
+
+ arrange = floating;
+ for(c = clients; c; c = c->next) {
+ if(c->tags[tsel])
+ resize(c, True);
+ else
+ ban_client(c);
+ }
+ if(sel && !sel->tags[tsel]) {
+ if((sel = next(clients))) {
+ craise(sel);
+ focus(sel);
+ }
+ }
+ discard_events(EnterWindowMask);
+}
+
+void
+tiling(Arg *arg)
+{
+ Client *c;
+ int n, i, w, h;
+
+ w = sw - mw;
+ arrange = tiling;
+ for(n = 0, c = clients; c; c = c->next)
+ if(c->tags[tsel] && !c->floating)
+ n++;
+
+ h = (n > 1) ? sh / (n - 1) : sh;
+
+ for(i = 0, c = clients; c; c = c->next) {
+ if(c->tags[tsel]) {
+ if(c->floating) {
+ craise(c);
+ resize(c, True);
+ continue;
+ }
+ if(n == 1) {
+ c->x = sx;
+ c->y = sy;
+ c->w = sw - 2 * c->border;
+ c->h = sh - 2 * c->border;
+ }
+ else if(i == 0) {
+ c->x = sx;
+ c->y = sy;
+ c->w = mw - 2 * c->border;
+ c->h = sh - 2 * c->border;
+ }
+ else {
+ c->x = sx + mw;
+ c->y = sy + (i - 1) * h;
+ c->w = w - 2 * c->border;
+ c->h = h - 2 * c->border;
+ }
+ resize(c, False);
+ i++;
+ }
+ else
+ ban_client(c);
+ }
+ if(sel && !sel->tags[tsel]) {
+ if((sel = next(clients))) {
+ craise(sel);
+ focus(sel);