Add support for cycling through windows

Makes the window switching algorithm read much cleaner too.