Skip to content

Commit

Permalink
Use NSEvent.subtype to detect mouse/trackpad. pilotmoon#129
Browse files Browse the repository at this point in the history
(Only tested with a MacBook and a non-continuous mouse - probably
causes issues with Apple mice.)
  • Loading branch information
maximile committed Mar 15, 2022
1 parent 68db560 commit 68fd1b9
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions MouseTap.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,28 +130,17 @@ static CGEventRef _callback(CGEventTapProxy proxy,
// work out the event source
const ScrollEventSource lastSource=tap->lastSource;
const ScrollEventSource source=(^{

if (!continuous)
{
[tap->logger logBool:YES forKey:@"usingNotContinuous"];
return ScrollEventSourceMouse; // assume anything not-continuous is a mouse
}

if (touching>=2 && touchElapsed<(MILLISECOND*222))
{
[tap->logger logBool:YES forKey:@"usingTouches"];
return ScrollEventSourceTrackpad;
switch (event.subtype) {
case NSEventSubtypeMouseEvent:
[tap->logger logBool:YES forKey:@"subtypeMouse"];
return ScrollEventSourceMouse;
case NSEventSubtypeTabletPoint:
[tap->logger logBool:YES forKey:@"subtypeTabletPoint"];
return ScrollEventSourceTrackpad;
default:
[tap->logger logBool:YES forKey:@"subtypeOther"];
return ScrollEventSourceMouse;
}

if (phase==ScrollPhaseNormal && touchElapsed>(MILLISECOND*333))
{
[tap->logger logBool:YES forKey:@"usingTouchElapsed"];
return ScrollEventSourceMouse;
}

// not enough information to decide. assume the same as last time. ha!
[tap->logger logBool:YES forKey:@"usingPrevious"];
return tap->lastSource;
})();
tap->lastSource=source;

Expand Down

0 comments on commit 68fd1b9

Please sign in to comment.