The problem with Michele’s code is that it had an unacceptably high rate of false positives. So, while here at EuroOSCON, I’ve added stabilisation. That is, my version is very careful about only allowing a desktop switch when the laptop starts in and returns to a stable, non-moving state. So you can tap the desktop backwards and forwards, then pick the laptop up, wave it around, and set it back down again without triggering a false switch. It’s very cool :-)
It does this by keeping an archive of data, and only allowing smacks when the standard deviation is less than a certain value. More details of the exact algorithm are in the comments at the top of the file.
Stabilised SmackPad requires the hdaps driver; “sudo modprobe hdaps” in Ubuntu. More details of the requirements are on the original blog post. Once you’ve loaded the driver and started the script, short, sharp thumps on the side of the screen with two fingers should do it. Remember, you can’t switch it more often than about once every two seconds.