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.
LeftMouseDown suppression works when the
trackpadCallback
detects two fingers and sets a global variabletrackpadNFingers
, and then theCGEventCallback
checks thattrackpadNFingers == 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
andCGEventCallback
are not synchronized, there is the potential for race conditions that preventCGEventCallback
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 iftrackpadCallback
setstrackpadNFingers = 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 beforetrackpadCallback
, but that seems much less likely. The first commit in this PR also adds a minuscule delay toCGEventCallback
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