@@ -1359,26 +1359,39 @@ - (void)scrollWheel:(NSEvent *)theEvent
1359
1359
Cocoa_HandleMouseWheel (_data.window , theEvent);
1360
1360
}
1361
1361
1362
+
1363
+ - (BOOL )isTouchFromTrackpad : (NSEvent *)theEvent
1364
+ {
1365
+ SDL_Window *window = _data.window ;
1366
+ SDL_VideoData *videodata = ((__bridge SDL_WindowData *) window->driverdata ).videodata ;
1367
+
1368
+ /* if this a MacBook trackpad, we'll make input look like a synthesized
1369
+ event. This is backwards from reality, but better matches user
1370
+ expectations. You can make it look like a generic touch device instead
1371
+ with the SDL_HINT_TRACKPAD_IS_TOUCH_ONLY hint. */
1372
+ BOOL istrackpad = NO ;
1373
+ if (!videodata.trackpad_is_touch_only ) {
1374
+ @try {
1375
+ istrackpad = ([theEvent subtype ] == NSEventSubtypeMouseEvent);
1376
+ }
1377
+ @catch (NSException *e) {
1378
+ /* if NSEvent type doesn't have subtype, such as NSEventTypeBeginGesture on
1379
+ * macOS 10.5 to 10.10, then NSInternalInconsistencyException is thrown.
1380
+ * This still prints a message to terminal so catching it's not an ideal solution.
1381
+ *
1382
+ * *** Assertion failure in -[NSEvent subtype]
1383
+ */
1384
+ }
1385
+ }
1386
+ return istrackpad;
1387
+ }
1388
+
1362
1389
- (void )touchesBeganWithEvent : (NSEvent *) theEvent
1363
1390
{
1364
1391
NSSet *touches;
1365
1392
SDL_TouchID touchID;
1366
1393
int existingTouchCount;
1367
-
1368
- /* probably a MacBook trackpad; make this look like a synthesized event.
1369
- This is backwards from reality, but better matches user expectations. */
1370
- BOOL istrackpad = NO ;
1371
- @try {
1372
- istrackpad = ([theEvent subtype ] == NSEventSubtypeMouseEvent);
1373
- }
1374
- @catch (NSException *e) {
1375
- /* if NSEvent type doesn't have subtype, such as NSEventTypeBeginGesture on
1376
- * macOS 10.5 to 10.10, then NSInternalInconsistencyException is thrown.
1377
- * This still prints a message to terminal so catching it's not an ideal solution.
1378
- *
1379
- * *** Assertion failure in -[NSEvent subtype]
1380
- */
1381
- }
1394
+ const BOOL istrackpad = [self isTouchFromTrackpad: theEvent];
1382
1395
1383
1396
touches = [theEvent touchesMatchingPhase: NSTouchPhaseAny inView: nil ];
1384
1397
touchID = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t )[[touches anyObject ] device ];
@@ -1426,24 +1439,10 @@ - (void)touchesCancelledWithEvent:(NSEvent *) theEvent
1426
1439
- (void )handleTouches : (NSTouchPhase ) phase withEvent : (NSEvent *) theEvent
1427
1440
{
1428
1441
NSSet *touches = [theEvent touchesMatchingPhase: phase inView: nil ];
1442
+ const BOOL istrackpad = [self isTouchFromTrackpad: theEvent];
1429
1443
SDL_FingerID fingerId;
1430
1444
float x, y;
1431
1445
1432
- /* probably a MacBook trackpad; make this look like a synthesized event.
1433
- This is backwards from reality, but better matches user expectations. */
1434
- BOOL istrackpad = NO ;
1435
- @try {
1436
- istrackpad = ([theEvent subtype ] == NSEventSubtypeMouseEvent);
1437
- }
1438
- @catch (NSException *e) {
1439
- /* if NSEvent type doesn't have subtype, such as NSEventTypeBeginGesture on
1440
- * macOS 10.5 to 10.10, then NSInternalInconsistencyException is thrown.
1441
- * This still prints a message to terminal so catching it's not an ideal solution.
1442
- *
1443
- * *** Assertion failure in -[NSEvent subtype]
1444
- */
1445
- }
1446
-
1447
1446
for (NSTouch *touch in touches) {
1448
1447
const SDL_TouchID touchId = istrackpad ? SDL_MOUSE_TOUCHID : (SDL_TouchID)(intptr_t )[touch device ];
1449
1448
SDL_TouchDeviceType devtype = SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE;
0 commit comments