From ba650a3df412d8fbcbb2e2eeefbf2df7c50dd8e3 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Sun, 23 Nov 2014 15:48:52 -0500 Subject: [PATCH] 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) --- src/video/cocoa/SDL_cocoawindow.m | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/video/cocoa/SDL_cocoawindow.m b/src/video/cocoa/SDL_cocoawindow.m index 29bba457c..48621a4f1 100644 --- a/src/video/cocoa/SDL_cocoawindow.m +++ b/src/video/cocoa/SDL_cocoawindow.m @@ -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]; }