JitouchApp / Jitouch

A multi-touch extension for MacBook, Magic Mouse, and Magic Trackpad
GNU General Public License v3.0
396 stars 28 forks source link

Fix LeftMouseDown suppression race condition #33

Closed aaronkollasch closed 2 years ago

aaronkollasch commented 2 years ago

LeftMouseDown suppression works when the trackpadCallback detects two fingers and sets a global variable trackpadNFingers, and then the CGEventCallback checks that trackpadNFingers == 2 (and also the distance between fingers). If the check passes, CGEventCallback knows a gesture was performed and drops the mouse click.

However, because trackpadCallback and CGEventCallback are not synchronized, there is the potential for race conditions that prevent CGEventCallback from knowing a gesture was performed, allowing a click to occur along with a gesture (see #31).

To prevent this, I added a global variable lastGestureDate so that if trackpadCallback sets trackpadNFingers = 2 but then changes it to a different value, CGEventCallback still knows that a gesture was recently seen and can drop the mouse click accordingly. This virtually eliminates the gesture+click issue.

Another potential version of the race condition is if CGEventCallback is called before trackpadCallback, but that seems much less likely. The first commit in this PR also adds a minuscule delay to CGEventCallback to address this, but it does not seem necessary so I have removed it.

The increased robustness in LeftMouseDown suppression means it should be possible to re-add the LeftMouseUp suppression removed in #22, but I will leave that for now, as the cost of an error is a UI freeze until the next mouse click.

Fixes #31

aaronkollasch commented 2 years ago

Note that this PR broke the three-finger tap gesture, which was fixed in the next commit (0826270783606289a38b33204d234fde82b27989).