It’s been almost two months since I first used OS X on my new MacBook, but I still miss Kubuntu (I’ll have a separate post soon on why). I decided to switch back (well, triple boot–mostly in Kubuntu), but in doing so there have been a few roadblocks. One of these is the trackpad (touchpad) working smoothly–both in terms of moving the mouse and also advanced features of two-finger scrolling, two/three finger taps (for right click and 3rd button click), etc. I changed a few things in the appletouch kernel driver, and the results are pretty good!
The first issue I had was the mouse pointer jumping a few pixels constantly when moving around. The trackpad consists of many sensors (20 on the X axis, 10 on the Y axis for the MacBooks), so when you glide your finger across, each sensor on your finger’s path will go high as the finger approaches/hovers (and go low once your finger leaves the sensor’s ‘zone’). For the trackpad to be used for neat functions (two/three finger functionality), the synaptics X driver should be used, and in order for it to be used, the trackpad must give off absolute coordinates instead of relative (so the actual position of your finger(s) as opposed to the change in your finger(s)’s position). There is thresholding for each of the sensors in order to discard jitter when the finger isn’t triggering a sensor. As soon as a sensor passes the threshold, its value is used (along with the other sensors that are over the threshold) to calculate the absolute coordinates. So, when a finger is approaching a sensor, the sensor’s contribution to the absolute coordinate calculation is 0, but when the finger gets close enough to allow the sensor to pass the threshold, the sensor’s contribution becomes at minimum the threshold value. The default threshold level is 10, so this causes the sensor to go from giving 0 feedback on coordinates, to giving a value of 10 (not exactly) to the function to give coordinates. So instead, I subtract the threshold from each sensor that contributes to the absolute coordinate function. This ends up giving a smooth mouse movement when a sensor suddenly goes from below the threshold, to above.
The second issue was the accuracy of two finger (and three finger) detection. These are used for two-finger scrolling, two-finger clicks, and three-finger clicks, so it’s pretty important in day-to-day use. I found it difficult to trigger the multiple fingers properly (I couldn’t have my two fingers touching each other and I would have to make sure they maintained a good gap when scrolling), so two-finger scrolling was difficult to do. The way it checked for multiple fingers is to count how many sensors that has passed the threshold are preceded by a sensor that is below the threshold. So, the first finger would obviously pass, and then if there is a sensor gap between the first and second finger, the second finger would get triggered. I didn’t like this as I don’t usually leave a gap between my two fingers (OS X didn’t have this constraint). I changed it to check for ‘humps’ in the sensors, so basically check for transitions from nonincreasing to increasing sequential sensor readings on each X/Y axis. This works since the middle sensor(s) (sensors are close enough so when having two fingers down, there will be one sensor between the two) can still be over the threshold and still count as the lower part between humps. After the patch, the two-finger scrolling works as well as OS X (from what I can tell).
The last small issue is being able to change the threshold value. I turned this into a kernel module option (modinfo appletouch).
This patches against Mactel appletouch patch that allows MacBooks to work with that driver. I’ve submitted it to the maintainer of the appletouch kernel driver, so we’ll hopefully see it there!
appletouch-2finger_det-threshold_opt.patch