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 hdaps fails, you’re not qualified)
  • The wnck Python module, provided by gnome-python (if python -c "import wnck" fails, you’re not qualified either)
  • An EWMH compliant window manager (most modern WMs are)
  • The smack.py script

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.

Trackbacks
  1. Flying on a ThinkPad From micampe.it

    After my SmackPad article, some people asked in the comments if I could port that to Windows. I don

Comments
  1. ludo said Sun, 04 Jun 2006 09:49:03 GMT

    LOL, a pity it does not work with my X30.

  2. Thinker said Sun, 04 Jun 2006 10:49:04 GMT

    Bravo! Works great on my T43.

  3. Geremy F said Mon, 05 Jun 2006 02:46:53 GMT

    Just waiting for the windows version. Then I’ll be set.

    More people should take advantage of the IBM’s Active Protection System

  4. Jiang said Mon, 05 Jun 2006 05:21:11 GMT

    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?

  5. michele said Mon, 05 Jun 2006 07:11:20 GMT

    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.

  6. Jiang said Mon, 05 Jun 2006 07:24:17 GMT

    Thanks a lot now it works very well! Thank you for fixing it so quickly!

  7. lemerou said Mon, 05 Jun 2006 12:07:23 GMT

    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”

  8. michele said Mon, 05 Jun 2006 15:30:50 GMT

    lemerou, I think you might have an old hdaps version. What does cat /sys/devices/platform/hdaps/calibrate says?

  9. lemerou said Mon, 05 Jun 2006 19:50:21 GMT

    It says:

    lemerou@lemerou-laptop:~$ cat /sys/devices/platform/hdaps/calibrate
    (-388,-387)

  10. Jon said Mon, 05 Jun 2006 19:58:11 GMT

    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?

  11. jpn said Mon, 05 Jun 2006 21:25:44 GMT

    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.

  12. Cory said Mon, 05 Jun 2006 22:05:34 GMT

    Too bad, that seems like a great feature I wish I could do with my Gateway 7000 series notebook. =]

  13. Robbert said Mon, 05 Jun 2006 22:48:04 GMT

    I’m a happy T42 Slapper running Ubuntu Dapper :D

  14. Phil said Tue, 06 Jun 2006 01:49:47 GMT

    Do you have this for a Toshiba Tecra M4?

  15. Cory said Tue, 06 Jun 2006 03:44:42 GMT

    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. =[=[

  16. michele said Tue, 06 Jun 2006 07:48:30 GMT

    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 :)

  17. Stoker said Tue, 06 Jun 2006 14:55:49 GMT

    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

  18. Sam said Wed, 07 Jun 2006 03:06:22 GMT

    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.

  19. Andrew Barr said Wed, 07 Jun 2006 18:39:04 GMT

    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.

  20. Richard said Wed, 14 Jun 2006 20:30:10 GMT

    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?

  21. Borow said Tue, 20 Jun 2006 16:26:30 GMT

    I hope you will manage to make it works for windows xp !

  22. chris said Tue, 20 Jun 2006 19:26:15 GMT

    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 ;)