Monday, 11 June 2012

Using Apple Magic Trackpad with Slackware

I am not an Apple fanboy, but I should admit that their hardware have one of the best build quality around. I bought an Apple Magic Trackpad quite sometime ago and it has been sitting in it's box not being used even with the Macbook. So I decided to use it with my PC running Slackware Linux.

I found a guide detailing how to use it with Ubuntu at https://wiki.ubuntu.com/Multitouch/AppleMagicTrackpad but it didn't work for me straightaway.

The Hardware:

Apple Magic Trackpad
For those who do not know what a Apple Magic Trackpad is, it is a multi touch external Touchpad made by Apple. It is a wireless pointing device which connects to the host machine using Bluetooth. More details here: http://www.apple.com/magictrackpad/. It is advertised to work only with a Mac/Macbook either with the OS X10.6.4 or on Windows with Bootcamp. Officially it is not advertised to work elsewhere, but it does.


Tiny Bluetooth Adaptor
 My PC does not have a built-in Bluetooth adapter. I bought a cheap adapter from Amazon which costed me just £0.99(I did say cheap).

The Software:

The PC has Slackware64-Current. The Desktop Environment is KDE 4.8.3 installed from AlienBob's Ktown. Pat's Slackware currently has KDE 4.8.2. Make sure you have Bluetooth modules enabled especially CONFIG_BT_HCIBTUSB.

The Configuration

KDE has both blueman and bluedevil which you can use to configure the bluetooth and add the devices. 

In order to connect to the Magic Trackpad you need to make sure that your Bluetooth Adapter is configured in hci mode. To check this run the following on console:

bash$ lsusb
Here is an example from my machine:

bash$ lsusb
Bus 005 Device 002: ID 0a12:0001 Cambridge Silicon Radio, Ltd Bluetooth Dongle (HID mode)
Bus 004 Device 002: ID 067b:2303 Prolific Technology, Inc. PL2303 Serial Port



I have marked the Bluetooth Dongle in bold from my example output. Note the words (HID mode)  at the end. This indicates that your bluetooth is in HID mode. We need to first change this to HCI mode.

To do this we need to use a tool called hid2hci. This tool requires the vendor id and product id of the bluetooth adapter. You can find this in the lsusb output after the keyword ID.

In our above example VendorID = 0a12 and ProductID = 0001

Run the following command to switch the bluetooth adapter to hci mode.

bash$ sudo /usr/sbin/hid2hci -v 0a12 -p 0001 -r hci -m csr

The last parameter -m accepts any of the three possible modes: csr, logitech and dell. You will need to experiment with the three modes to figure out exactly which one your bluetooth adapter supports. The one I am using supports csr mode.

Once the Bluetooth adapter is switched to hci mode, it will remain in hci mode even if you unplug and plug it back in.

Now you need to modify the udev rules so that udev knows what to do when your bluetooth adapter is inserted. To this open the file /lib/udev/rules.d/97-bluetooth-hid2hci.rules using your favourite editor. Remember to open as root or with sudo.

Note that, by default the entire section on CSR Devices (in HCI Mode) will be commented out. Uncomment the line corresponding to your bluetooth device by removing the hash(#) from the beginning of the line.

Now restart rc.udev and rc.bluetooth by running as root

# /etc/rc.d/rc.udev restart
# /etc/rc.d/rc.bluetooth restart

Now put the Magic Trackpad is discoverable mode by long pressing the button on the top right side of the trackpad. The Green LED should start blinking indicating that it is in discoverable mode.

Run the following command to scan for avaialble devices:

$ sudo hcitool scan

Once you find your trackpad, you can connect to it using:

$ sudo hidd --connect AA:BB:CC:DD:EE:FF



Assuming AA:BB:CC:DD:EE:FF is the MAC address of your Magic Trackpad.

KDE should now prompt you for entering the PIN for your device. Enter 0000 and connect. Your Magic Trackpad is now paired and usable with your Linux Machine.

What works

The following is the list of gestures that works by default on KDE 4.8.3 without adding any additional software.
  1. Two finger Vertical Scroll
  2. Two finger tap for paste(Works like middle click). Pastes using the select to copy method, not the same as Ctrl+C copy.
  3. Two finger click for Context Menu(Right Click)
  4. One finger Tap and drag for selection
  5. Click and Drag for Selection
  6. Pinch and Zoom in Marble.
  7. One finger Double tap and drag for move

Additional Gesture support

Other gestures can be supported by adding additional software like ginn or utouch, but I am a bit reluctant to do so. I would prefer if KDE would add builtin multitouch gesture support. Since I have seen some videos on the net which show the proof of concept, I'll wait for it to come.