BlueDragonX/xf86-input-mtrack — pull request #44 by patrakov (2013-01-03 06:55:15+00:00)
Title: Fix Button Zones

I have a Sony VAIO VPCZ23A4R laptop. It has a multitouch-capable clickpad that does not work well with your driver. I fixed it, please pull the two commits. Note: they have been tested only in the mode with button zones, and only on Sony hardware.

This clickpad has the integrated button. The user is supposed to click in the bottom area (which is smooth, unlike the rest of the surface). Clicks in the left half of the bottom area are to be interpreted as left-clicks, and clicks in the right half - as right clicks.

Unfortunatelty, the original code incorrectly assumes that it has to add half of the width of the trackpad to the current X coordinate in order to get something usable for determining the virtual button number. This only holds for trackpads that return coordinates in the [-width/2, width/2] range. Sony trackpad has an asymmetrical range.

A similar bad assumption has crept into the code that determines whether the touch should be invalidated due to being in the bottom area - the assumption is that y=0 is the top, which is, again, wrong for Sony.

So, the first commit here sanitizes the coordinate handling. Now coordinates are converted so that (0,0) is always the center of the trackpad, and the bottom-area condition is adjusted to fit this assumption.

OTOH I don't really know if the code does anything meaningful in the inverted-axis case - please test.

Then, there remained three annoyances related to the code that determines the virtual button number.

First, the user is supposed to click in the bottom area - but any touch there is invalid. So, in order to determine the correct virtual button number, we have to consider invalid touches, too.

Second, let's supposes that the user carefully positions the pointer with the right hand, and, without releasing the right finger, clicks with the left hand on the button area. Then, contrary to his expectation, the position of his right finger (the one used to position the cursor) would be used to determine the virtual button number. This is wrong, the touch that clicked is usually the latest, so the driver should use it.

And the third, on a Sony trackpad, it is possible to touch and click outside of the official trackpad area (e.g. slightly to the left of the reported left edge). This fooled the logic: clicks in the very left corner were reported as being in the rightmost zone.

All of the three annoyances above are fixed with the second commit.