Most of the work in here was from akracun: I just added support for window switching and did some refactoring. I'm pretty new to the code base, so let me know if you'd like me to fix anything up.  

This code is in response to which I posted (anonymously I guess) some time ago.