-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,
I have adapted some patches for dwm 5.6 yesterday, amongst that also
pertag and bstack, but I did not had the time to test them well. Since you
have added your patches, I will just add the others I've edited: gaplessgrid,
grid, push and tilemovemouse.

| PS: my C kungfu is a bit rusty and there is a compiler warning I haven't
| taken time to fix with the pertag patch. Boo-boo me at will

I think that should be:
~    m->lts[i] = (Layout*) &layouts[0];

ML
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkpeCFkACgkQ9vCoFTonULRi5QCfU3GixUdB1v6N89TH1uETExtq
T2cAnAjciUkxS8Wxlh/E/2o0w4Wowuab
=EG85
-----END PGP SIGNATURE-----

void
gaplessgrid(Monitor *m) {
	unsigned int n, cols, rows, cn, rn, i, cx, cy, cw, ch;
 	Client *c;
 
  for(n = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next))
		n++;
	if(n == 0)
		return;

	/* grid dimensions */
	for(cols = 0; cols <= n/2; cols++)
		if(cols*cols >= n)
			break;
	if(n == 5)		/* set layout against the general calculation: not 1:2:2, but 2:3 */
		cols = 2;
	rows = n/cols;

	/* window geometries (cell height/width/x/y) */
	cw = m->ww / (cols ? cols : 1);
	cn = 0; 			/* current column number */
	rn = 0; 			/* current row number */
	for(i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
		if(i/rows+1 > cols-n%cols)
			rows = n/cols+1;
		ch = m->wh / (rows ? rows : 1);
		cx = m->wx + cn*cw;
		cy = m->wy + rn*ch;
		resize(c, cx, cy, cw - 2 * c->bw, ch - 2 * c->bw, True);
		
		i++;
		rn++;
		if(rn >= rows) { 	/* jump to the next column */
			rn = 0;
			cn++;
		}
	}
}

void
grid(Monitor *m) {
	unsigned int i, n, cx, cy, cw, ch, aw, ah, cols, rows;
	Client *c;

	for(n = 0, c = nexttiled(selmon->clients); c; c = nexttiled(c->next))
		n++;

	/* grid dimensions */
	for(rows = 0; rows <= n/2; rows++)
		if(rows*rows >= n)
			break;
	cols = (rows && (rows - 1) * rows >= n) ? rows - 1 : rows;

	/* window geoms (cell height/width) */
	ch = m->wh / (rows ? rows : 1);
	cw = m->ww / (cols ? cols : 1);
	for(i = 0, c = nexttiled(selmon->clients); c; c = nexttiled(c->next)) {
		cx = m->wx + (i / rows) * cw;
		cy = m->wy + (i % rows) * ch;
		/* adjust height/width of last row/column's windows */
		ah = ((i + 1) % rows == 0) ? m->wh - ch * rows : 0;
		aw = (i >= rows * (cols - 1)) ? m->ww - cw * cols : 0;
		resize(c, cx, cy, cw - 2 * c->bw + aw, ch - 2 * c->bw + ah, True);
	 i++;
	}
}

static Client *
prevtiled(Client *c) {
	Client *p, *r;

	for(p = selmon->clients, r = NULL; p && p != c; p = p->next)
		if(!p->isfloating && ISVISIBLE(p))
			r = p;
	return r;
}

static void
pushup(const Arg *arg) {
	Client *c;

	if(!selmon->sel || selmon->sel->isfloating)
		return;
	if((c = prevtiled(selmon->sel))) {
		/* attach before c */
		detach(selmon->sel);
		selmon->sel->next = c;
		if(selmon->clients == c)
			selmon->clients = selmon->sel;
		else {
			for(c = selmon->clients; c->next != selmon->sel->next; c = c->next);
			c->next = selmon->sel;
		}
	} else {
		/* move to the end */
		for(c = selmon->sel; c->next; c = c->next);
		detach(selmon->sel);
		selmon->sel->next = NULL;
		c->next = selmon->sel;
	}
	focus(selmon->sel);
	arrange();
}

static void
pushdown(const Arg *arg) {
	Client *c;

	if(!selmon->sel || selmon->sel->isfloating)
		return;
	if((c = nexttiled(selmon->sel->next))) {
		/* attach after c */
		detach(selmon->sel);
		selmon->sel->next = c->next;
		c->next = selmon->sel;
	} else {
		/* move to the front */
		detach(selmon->sel);
		attach(selmon->sel);
	}
	focus(selmon->sel);
	arrange();
}
void
insertbefore(Client *a, Client *b)	/* insert a before b in the client list */
{
	Client **x = &selmon->clients;
	
	while(*x != b && *x)
		x = & (*x)->next;
	*x = a;
	a->next = b;
}

void
insertafter(Client *a, Client *b)	/* insert a after b in the client list */
{
	a->next = b->next;
	b->next = a;
}

void
tilemovemouse(const Arg *arg) {
	/* Could EnterNotify events be used instead? */
	Client *c, *d;
	XEvent ev;
	int x, y;
	Bool after;

	if(!(c = selmon->sel))
		return;
	if(c->isfloating || !selmon->lt[selmon->sellt]->arrange){
		movemouse(NULL);
		return;
	}
	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
	None, cursor[CurMove], CurrentTime) != GrabSuccess)
		return;
	do {
		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
		switch (ev.type) {
		case ConfigureRequest:
		case Expose:
		case MapRequest:
			handler[ev.type](&ev);
			break;
		case MotionNotify:
			x = ev.xmotion.x;
			y = ev.xmotion.y;
			after = False;
			for(d = nexttiled(selmon->clients); d; d = nexttiled(d->next)){
				if(d == c)
					after = True;
				else if(INRECT(x, y, d->x, d->y, d->w+2*borderpx, d->h+2*borderpx)){
					detach(c);
					after ? insertafter(c, d) : insertbefore(c,d);
					arrange();
					break;
				}
			}
		}
	} while(ev.type != ButtonRelease);
	XUngrabPointer(dpy, CurrentTime);
}

Reply via email to