Here comes the SmackPad
You probably have seen the SmackBook video where a guy smacks his laptop to switch workspace. Too bad that only works on Macs right? Not really, my ThinkPad has a device similar to the Apple Motion Sensor and it runs Linux, so it ought to be flexible and easy to tweak.
Well, I’m happy to announce that you can smack your laptop too!
Requirements:
- A ThinkPad with the IBM Active Protection System
- The hdaps kernel module (if
sudo modprobe hdapsfails, you’re not qualified) - The
wnckPython module, provided bygnome-python(ifpython -c "import wnck"fails, you’re not qualified either) - An EWMH compliant window manager (most modern WMs are)
- The
smack.pyscript
Run the script from a shell:
$ python smack.py
and smack your ThinkPad at will to change workspace back and forth.
Caveat: It’s not really reliable: sometimes it’ll switch in the wrong direction, especially if you try to rapdly switch more than once, but it’a toy, I don’t find it really useful.
You’re welcome to improve the detection algorithm. A basic setting is the SENS variable at the start of the script: the higher the less sensitive the script will be and the harder you’ll have to smack the laptop. Remember, ThinkPads are though, don’t risk hurting yourself with too high values.
Update: Francesco provided iSmack.py for iBooks and Powerbooks with the AMS driver.
Update 2: Andrew hacked a version that works with Compiz.
Update 3: Gervase Markham has an improved version with stabilization.
LOL, a pity it does not work with my X30.
Bravo! Works great on my T43.
Just waiting for the windows version. Then I’ll be set.
More people should take advantage of the IBM’s Active Protection System
Doesn’t work unfortunately. When I tried to run it and smack my T43, it says
File “smack.py”, line 85, in ?
main()
File “smack.py”, line 80, in main
loop()
File “smack.py”, line 73, in loop
swicthtoworkspaceatleft()
File “smack.py”, line 44, in swicthtoworkspaceatleft
workspaces[current_ws].activate(0)
TypeError: WnckWorkspace.activate() argument 1 must be long, not int
and crashes. I’m no python hacker, any idea about how to get it to work?
Geremy, I suspect you won’t be seeing that from me, I wouldn’t even know where to start…
Jiang, download the script again and retry, should work now.
Thanks a lot now it works very well! Thank you for fixing it so quickly!
Error on my T42p
lemerou@lemerou-laptop:~/mes/download$ python smack.py
Traceback (most recent call last):
File "smack.py", line 85, in ?
main()
File "smack.py", line 80, in main
loop()
File "smack.py", line 58, in loop
calx, caly = get_calibration()
File "smack.py", line 55, in get_calibration
return (int(match.groups()[0]), int(match.groups()[1]))
AttributeError: 'NoneType' object has no attribute 'groups'
hdaps works fine and no error with python -c “import wnck”
lemerou, I think you might have an old
hdapsversion. What doescat /sys/devices/platform/hdaps/calibratesays?It says:
lemerou@lemerou-laptop:~$ cat /sys/devices/platform/hdaps/calibrate
(-388,-387)
From what I understand, this uses the hard drive protection’s to detect the movement. Does anyone have any idea if this could be applied to the type of accelerometer inside many tablet PCs?
i have a tablet running ubuntu linix dapper, and would love to see this working on that. i have a portege m200. is there a way to code this differently to work with my tablet.
btw, this is a different jon then the guy above me.
Too bad, that seems like a great feature I wish I could do with my Gateway 7000 series notebook. =]
I’m a happy T42 Slapper running Ubuntu Dapper :D
Do you have this for a Toshiba Tecra M4?
Is there some sort of hardware I can add in to a Gateway 7000 series running XP, or is this machine a lost cause? I’m waiting to switch over to Mac as soon as the renovations on my house get paid. =[=[
lemerou, the problem is the negative value, I uploaded a modified version, try it.
To everybody else wanting this on a different hardware, the code is actually pretty simple and porting it would be easy, the problem is that you need a driver for the accelerometer in your laptop/tabled/whatever, and I don’t know if it exists for Toshiba, Gateway or others.
As for Windows, I have absolutely no idea :)
Heh, when people are starting to ask about what kind of hardware can I add to do this I think the whole purpose of it is going away :) Using shock-detection to do workspace swap is a hack, adding hardware for it is kind of doh… If your system has a paralell or serial port you could use a resistor from gnd to an I/O pin, loosely in there so that when you shake the machine it will toggle the bit, its fairly simple to read such I/O, python has some modules and stuff already for that. But now, is this really a hack? Next thing could then be to add something to your TV or Mediacenter remote control so you can smack it for previous channel instead of hitting a button… or why not add a clapper detector, that would be cooler I think :)
If you like to control stuff with simple scripts, look at some of the kits out there using the I2C protocol, or plain paralell IO even.. E.g. This one
I have all the requirments except one. A Linux OS. :( I’d wish someone could compile a Windows version. I’d give them a virtual hug.
Hi, this script doesn’t work with all of the new eyecandy goodness that can be found in the Compiz window manager and OpenGL compositor extraordinare. Here’s a hacky version that does. Caveat emptor: you need the ‘xte’ program from the xautomation package, and you have to edit the script if you’re not using the default Compiz keybindings.
What about the “Jedi” hack? Swing the laptop around and make light-sabre noises! This was on slashdot last week…
Even better, if you can merge it with xscreensaver.
Or, how about one of those games where you have a small ball bearing and have to roll it around in a maze?
I hope you will manage to make it works for windows xp !
Yeah, this works great. Thanks a lot!
@richard: The hdaps driver actually implements a joystick device you can use for ball games like neverball or even for some car racing games ;)