Cocoa: add in handling of "lost" touches on OS X. [bug #2635]

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)
Edward Rudd 2014-11-23 15:48:52 -05:00
parent 8c9341b92d
commit 084642d3f4
1 changed files with 19 additions and 0 deletions

View File

@ -856,6 +856,25 @@ SetWindowStyle(SDL_Window * window, unsigned int style)
- (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];
}