cocoa: report proper input IDs for mouse/touch events.
Otherwise, we generate incorrect mouse events for MacBook trackpads (which are also multitouch devices), etc. Partially fixes Bugzilla #4576.
parent
e43550c039
commit
781692c03c
|
@ -408,7 +408,8 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
||||||
DLog("Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
|
DLog("Motion was (%g, %g), offset to (%g, %g)", [event deltaX], [event deltaY], deltaX, deltaY);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)deltaX, (int)deltaY);
|
const SDL_MouseID mouseID = ([event subtype] == NSEventSubtypeTouch) ? SDL_TOUCH_MOUSEID : mouse->mouseID;
|
||||||
|
SDL_SendMouseMotion(mouse->focus, mouseID, 1, (int)deltaX, (int)deltaY);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -436,7 +437,8 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
|
||||||
} else if (y < 0) {
|
} else if (y < 0) {
|
||||||
y = SDL_floor(y);
|
y = SDL_floor(y);
|
||||||
}
|
}
|
||||||
SDL_SendMouseWheel(window, mouse->mouseID, x, y, direction);
|
const SDL_MouseID mouseID = ([event subtype] == NSEventSubtypeTouch) ? SDL_TOUCH_MOUSEID : mouse->mouseID;
|
||||||
|
SDL_SendMouseWheel(window, mouseID, x, y, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -622,7 +622,7 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
|
||||||
y = (int)(window->h - point.y);
|
y = (int)(window->h - point.y);
|
||||||
|
|
||||||
if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
|
if (x >= 0 && x < window->w && y >= 0 && y < window->h) {
|
||||||
SDL_SendMouseMotion(window, 0, 0, x, y);
|
SDL_SendMouseMotion(window, mouse->mouseID, 0, x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -932,7 +932,16 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
|
||||||
}
|
}
|
||||||
|
|
||||||
clicks = (int) [theEvent clickCount];
|
clicks = (int) [theEvent clickCount];
|
||||||
SDL_SendMouseButtonClicks(_data->window, 0, SDL_PRESSED, button, clicks);
|
|
||||||
|
SDL_MouseID mouseID;
|
||||||
|
if ([theEvent subtype] == NSEventSubtypeTouch) {
|
||||||
|
mouseID = SDL_TOUCH_MOUSEID;
|
||||||
|
} else {
|
||||||
|
SDL_Mouse *mouse = SDL_GetMouse();
|
||||||
|
mouseID = mouse ? mouse->mouseID : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SendMouseButtonClicks(_data->window, mouseID, SDL_PRESSED, button, clicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)rightMouseDown:(NSEvent *)theEvent
|
- (void)rightMouseDown:(NSEvent *)theEvent
|
||||||
|
@ -976,7 +985,16 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
|
||||||
}
|
}
|
||||||
|
|
||||||
clicks = (int) [theEvent clickCount];
|
clicks = (int) [theEvent clickCount];
|
||||||
SDL_SendMouseButtonClicks(_data->window, 0, SDL_RELEASED, button, clicks);
|
|
||||||
|
SDL_MouseID mouseID;
|
||||||
|
if ([theEvent subtype] == NSEventSubtypeTouch) {
|
||||||
|
mouseID = SDL_TOUCH_MOUSEID;
|
||||||
|
} else {
|
||||||
|
SDL_Mouse *mouse = SDL_GetMouse();
|
||||||
|
mouseID = mouse ? mouse->mouseID : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_SendMouseButtonClicks(_data->window, mouseID, SDL_RELEASED, button, clicks);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)rightMouseUp:(NSEvent *)theEvent
|
- (void)rightMouseUp:(NSEvent *)theEvent
|
||||||
|
@ -1039,7 +1057,9 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SDL_SendMouseMotion(window, 0, 0, x, y);
|
|
||||||
|
const SDL_MouseID mouseID = ([theEvent subtype] == NSEventSubtypeTouch) ? SDL_TOUCH_MOUSEID : mouse->mouseID;
|
||||||
|
SDL_SendMouseMotion(window, mouseID, 0, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)mouseDragged:(NSEvent *)theEvent
|
- (void)mouseDragged:(NSEvent *)theEvent
|
||||||
|
@ -1073,7 +1093,8 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (existingTouchCount == 0) {
|
if (existingTouchCount == 0) {
|
||||||
SDL_TouchID touchID = (SDL_TouchID)(intptr_t)[[touches anyObject] device];
|
const BOOL ismouse = ([theEvent subtype] == NSEventSubtypeMouseEvent);
|
||||||
|
const SDL_TouchID touchID = ismouse ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[[touches anyObject] device];
|
||||||
int numFingers = SDL_GetNumTouchFingers(touchID);
|
int numFingers = SDL_GetNumTouchFingers(touchID);
|
||||||
DLog("Reset Lost Fingers: %d", numFingers);
|
DLog("Reset Lost Fingers: %d", numFingers);
|
||||||
for (--numFingers; numFingers >= 0; --numFingers) {
|
for (--numFingers; numFingers >= 0; --numFingers) {
|
||||||
|
@ -1103,10 +1124,11 @@ SetWindowStyle(SDL_Window * window, NSUInteger style)
|
||||||
|
|
||||||
- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
|
- (void)handleTouches:(NSTouchPhase) phase withEvent:(NSEvent *) theEvent
|
||||||
{
|
{
|
||||||
|
const BOOL ismouse = ([theEvent subtype] == NSEventSubtypeMouseEvent);
|
||||||
NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
|
NSSet *touches = [theEvent touchesMatchingPhase:phase inView:nil];
|
||||||
|
|
||||||
for (NSTouch *touch in touches) {
|
for (NSTouch *touch in touches) {
|
||||||
const SDL_TouchID touchId = (SDL_TouchID)(intptr_t)[touch device];
|
const SDL_TouchID touchId = ismouse ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t)[touch device];
|
||||||
SDL_TouchDeviceType devtype = SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE;
|
SDL_TouchDeviceType devtype = SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE;
|
||||||
|
|
||||||
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 /* Added in the 10.12.2 SDK. */
|
#if MAC_OS_X_VERSION_MAX_ALLOWED >= 101202 /* Added in the 10.12.2 SDK. */
|
||||||
|
|
Loading…
Reference in New Issue