+static void (*arrange)(Arg *) = floating;
+
+static Client *
+next(Client *c)
+{
+ for(c = c->next; c && !c->tags[tsel]; c = c->next);
+ return c;
+}
+
+static Client *
+prev(Client *c)
+{
+ for(c = c->prev; c && !c->tags[tsel]; c = c->prev);
+ return c;
+}
+
+void
+max(Arg *arg)
+{
+ if(!csel)
+ return;
+ csel->x = sx;
+ csel->y = sy;
+ csel->w = sw - 2 * csel->border;
+ csel->h = sh - 2 * csel->border;
+ craise(csel);
+ resize(csel);
+ discard_events(EnterWindowMask);
+}
+
+void
+tag(Arg *arg)
+{
+ if(!csel)
+ return;
+
+ if(arg->i == tsel)
+ return;
+
+ if(csel->tags[arg->i])
+ csel->tags[arg->i] = NULL; /* toggle tag */
+ else
+ csel->tags[arg->i] = tags[arg->i];
+ arrange(NULL);
+}
+
+void
+floating(Arg *arg)
+{
+ Client *c;
+
+ arrange = floating;
+ if(!csel)
+ return;
+ for(c = csel; c; c = next(c))
+ resize(c);
+ discard_events(EnterWindowMask);
+}
+
+void
+tiling(Arg *arg)
+{
+ Client *c;
+ int n, cols, rows, gw, gh, i, j;
+ float rt, fd;
+
+ arrange = tiling;
+ if(!csel)
+ return;
+ for(n = 0, c = csel; c; c = next(c), 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 - 2) / cols;
+ gh = (sh - 2) / rows;
+
+ for(i = j = 0, c = csel; c; c = next(c)) {
+ c->x = i * gw;
+ c->y = j * gh;
+ c->w = gw;
+ c->h = gh;
+ resize(c);
+ if(++i == cols) {
+ j++;
+ i = 0;
+ }
+ }
+ discard_events(EnterWindowMask);
+}
+
+void
+prevc(Arg *arg)
+{
+ Client *c;
+
+ if(!csel)
+ return;
+
+ if(!(c = prev(csel)))
+ c = prev(cend);
+ if(c) {
+ craise(c);
+ XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
+ focus(c);
+ }
+}
+
+void
+nextc(Arg *arg)
+{
+ Client *c;
+
+ if(!csel)
+ return;
+
+ if(!(c = next(csel)))
+ c = next(cstart);
+
+ if(c) {
+ craise(c);
+ XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w / 2, c->h / 2);
+ focus(c);
+ }
+}
+
+void
+ckill(Arg *arg)
+{
+ Client *c = csel;
+
+ if(!c)
+ return;
+ if(c->proto & WM_PROTOCOL_DELWIN)
+ send_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
+ else
+ XKillClient(dpy, c->win);
+}
+
+static void
+resize_title(Client *c)
+{
+ int i;
+
+ c->tw = 0;
+ for(i = 0; i < TLast; i++)
+ if(c->tags[i])
+ c->tw += textw(c->tags[i]) + dc.font.height;
+ c->tw += textw(c->name) + dc.font.height;
+ if(c->tw > c->w)
+ c->tw = c->w + 2;
+ c->tx = c->x + c->w - c->tw + 2;
+ c->ty = c->y;
+ XMoveResizeWindow(dpy, c->title, c->tx, c->ty, c->tw, c->th);
+}