Refactor client position loops

Move common client detection code to its own loop and use that to test.
Should probably be inlined.
Crude snap functionality

Cribbed from goomwwm.