Leap Motion window manager controls

Sooner or later, I generally push git repos of my side projects to GitHub, once they've reached an interesting point. I don't expect them to work on anyone else's machines out of the box, but hopefully they're good examples or fun toys. This project requires nc, xwininfo, xdotool, a Leap Motion, and the leapd daemon running. If you're using a linux-based machine, chances are you have nc and xwininfo already installed.

https://github.com/AlexWillisson/leapwm

https://www.youtube.com/watch?v=oc-LuqZBVD8

This was mostly an experiment to learn about the Leap, but if I push it far enough I might start actively using it on my desktop. The idea is to be able to move windows on the screen without having to click and drag. It's a spiritual successor to my Metacity window manager hack that added physics to the windows. You can see a demo of that here:

https://www.youtube.com/watch?v=F8wo1QD_nco

leapwm doesn't have the bouncing affect yet and only handles horizontal motion, but instead of clicks it uses swipes as detected by the Leap's Python API. Right now, the window's ID must be hardcoded into the script. If I ever get back to the project, I'll add automatic detection of the active window. In the meantime, you can find a window's ID by running

xwininfo | grep -i "window id"

and clicking on the target window.

If xwininfo didn't come installed, it's probably in your package manager.

Under the hood, leapwm is broken up into two main parts, swipe.py and mpu.py. The two processes communicate over a TCP socket with mpu.py as the server. Whenever the Leap's API reports a swipe gesture, swipe.py translates it into a force to be applied to the window, then outsources all the work of the TCP socket by running nc as a command line program. Using nc also means that the whole system is much more resilient to bugs, since there's no persistent connection that needs to be maintained.

mpu.py handles the actual window motion. It collects force information from its TCP socket, keeps a queue of those forces and for how long they should be applied, and does a bit of math to figure out how the window should be moved. mpu.py is entirely independent of the Leap and can be used with any programs that send it force information in the proper format.

Ideally, all the window manager-specific pieces of leapwm would be in mpu.py, and all the Leap-specific parts would be in swipe.py. Because they use a TCP socket, it'd be a simple matter to put the two scripts on different computers. mpu.py absolutely needs a layer of authentication that I didn't bother with for this prototype. swipe.py uses xdotool in a few places to help scale the coordinates.

My development has been on fluxbox with the default theme, so there will probably be a few hiccups on other systems. If you want to make this system work for yourself, you'll probably need to change the x and y offsets at swipe.py:110 and mpu.py:106, since they match my window decorations. Unfortunately the geometry I can extract from xdotool gives me the corner of the X window, but not the corner of the decorations that the window manager applies around the X window. If your window is mysteriously moving especially jerkily and downward as well as whatever direction it's supposed to be moving in, chances are it's because your offset doesn't match the height of the bar at the top of the window.