Skip to content

Commit

Permalink
Cocoa: add in handling of "lost" touches on OS X. [bug #2635]
Browse files Browse the repository at this point in the history
This scenario can occur, for example, when the 4-finger touch sequence is used to switch spaces.  the SDL window does not receive the touch up events and ends up thinking there are far more fingers on the pad than there are.

So the solution here is everytime a new "touch" appears we can through and check if there are any existing known touches by the OS and if there are none, abut SDL things there are, we simply go through and cancel the SDL touches.

Side affects.
- the "touch up" won't occur until the users sends a new touch (could be well after the actual release really did occur)
  • Loading branch information
urkle committed Nov 23, 2014
1 parent 8c9341b commit 084642d
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -856,6 +856,25 @@ - (void)scrollWheel:(NSEvent *)theEvent

- (void)touchesBeganWithEvent:(NSEvent *) theEvent
{
NSSet *touches = [theEvent touchesMatchingPhase:NSTouchPhaseAny inView:nil];
int existingTouchCount = 0;

for (NSTouch* touch in touches) {
if ([touch phase] != NSTouchPhaseBegan) {
existingTouchCount++;
}
}
if (existingTouchCount == 0) {
SDL_TouchID touchID = (SDL_TouchID)(intptr_t)[[touches anyObject] device];
int numFingers = SDL_GetNumTouchFingers(touchID);
DLog("Reset Lost Fingers: %d", numFingers);
for (--numFingers; numFingers >= 0; --numFingers) {
SDL_Finger* finger = SDL_GetTouchFinger(touchID, numFingers);
SDL_SendTouch(touchID, finger->id, SDL_FALSE, 0, 0, 0);
}
}

DLog("Began Fingers: %lu .. existing: %d", (unsigned long)[touches count], existingTouchCount);
[self handleTouches:NSTouchPhaseBegan withEvent:theEvent];
}

Expand Down

0 comments on commit 084642d

Please sign in to comment.