Skip to content

Commit

Permalink
cocoa: Revised synthesized mouse/touch event strategy.
Browse files Browse the repository at this point in the history
I _think_ I understand what Sylvain is working on here now, so hopefully I
got this right.

Fixes Bugzilla #4576.

(I think!)
  • Loading branch information
icculus committed Jun 13, 2019
1 parent 50f5123 commit 2945746
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
4 changes: 4 additions & 0 deletions src/events/SDL_mouse.c
Expand Up @@ -103,7 +103,11 @@ SDL_TouchMouseEventsChanged(void *userdata, const char *name, const char *oldVal
if (hint && (*hint == '0' || SDL_strcasecmp(hint, "false") == 0)) {
mouse->touch_mouse_events = SDL_FALSE;
} else {
#if defined(__MACOSX__) /* macOS synthesizes its own events for this. */
mouse->touch_mouse_events = SDL_FALSE;
#else
mouse->touch_mouse_events = SDL_TRUE;
#endif
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/video/cocoa/SDL_cocoamouse.m
Expand Up @@ -408,8 +408,7 @@ + (NSCursor *)invisibleCursor
DLog("Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
}

const SDL_MouseID mouseID = ([event subtype] == NSEventSubtypeTouch) ? SDL_TOUCH_MOUSEID : mouse->mouseID;
SDL_SendMouseMotion(mouse->focus, mouseID, 1, (int)deltaX, (int)deltaY);
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)deltaX, (int)deltaY);
}

void
Expand Down Expand Up @@ -437,8 +436,8 @@ + (NSCursor *)invisibleCursor
} else if (y < 0) {
y = SDL_floor(y);
}
const SDL_MouseID mouseID = ([event subtype] == NSEventSubtypeTouch) ? SDL_TOUCH_MOUSEID : mouse->mouseID;
SDL_SendMouseWheel(window, mouseID, x, y, direction);

SDL_SendMouseWheel(window, mouse->mouseID, x, y, direction);
}

void
Expand Down
29 changes: 7 additions & 22 deletions src/video/cocoa/SDL_cocoawindow.m
Expand Up @@ -933,14 +933,8 @@ - (void)mouseDown:(NSEvent *)theEvent

clicks = (int) [theEvent clickCount];

SDL_MouseID mouseID;
if ([theEvent subtype] == NSEventSubtypeTouch) {
mouseID = SDL_TOUCH_MOUSEID;
} else {
SDL_Mouse *mouse = SDL_GetMouse();
mouseID = mouse ? mouse->mouseID : 0;
}

const SDL_Mouse *mouse = SDL_GetMouse();
const SDL_MouseID mouseID = mouse ? mouse->mouseID : 0;
SDL_SendMouseButtonClicks(_data->window, mouseID, SDL_PRESSED, button, clicks);
}

Expand Down Expand Up @@ -986,14 +980,8 @@ - (void)mouseUp:(NSEvent *)theEvent

clicks = (int) [theEvent clickCount];

SDL_MouseID mouseID;
if ([theEvent subtype] == NSEventSubtypeTouch) {
mouseID = SDL_TOUCH_MOUSEID;
} else {
SDL_Mouse *mouse = SDL_GetMouse();
mouseID = mouse ? mouse->mouseID : 0;
}

const SDL_Mouse *mouse = SDL_GetMouse();
const SDL_MouseID mouseID = mouse ? mouse->mouseID : 0;
SDL_SendMouseButtonClicks(_data->window, mouseID, SDL_RELEASED, button, clicks);
}

Expand Down Expand Up @@ -1058,8 +1046,7 @@ - (void)mouseMoved:(NSEvent *)theEvent
}
}

const SDL_MouseID mouseID = ([theEvent subtype] == NSEventSubtypeTouch) ? SDL_TOUCH_MOUSEID : mouse->mouseID;
SDL_SendMouseMotion(window, mouseID, 0, x, y);
SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
}

- (void)mouseDragged:(NSEvent *)theEvent
Expand Down Expand Up @@ -1093,8 +1080,7 @@ - (void)touchesBeganWithEvent:(NSEvent *) theEvent
}
}
if (existingTouchCount == 0) {
const BOOL ismouse = ([theEvent subtype] == NSEventSubtypeMouseEvent);
const SDL_TouchID touchID = ismouse ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[[touches anyObject] device];
const 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) {
Expand Down Expand Up @@ -1124,11 +1110,10 @@ - (void)touchesCancelledWithEvent:(NSEvent *) theEvent

- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
{
const BOOL ismouse = ([theEvent subtype] == NSEventSubtypeMouseEvent);
NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];

for (NSTouch *touch in touches) {
const SDL_TouchID touchId = ismouse ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[touch device];
const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
SDL_TouchDeviceType devtype = SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE;

#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 /* Added in the 10.12.2 SDK. */
Expand Down

0 comments on commit 2945746

Please sign in to comment.