cocoa: Another attempt at synthesized mouse/touch events.

This commit is contained in:
Ryan C. Gordon
2019-06-13 21:31:03 -04:00
parent 294574647d
commit d9a2eff26f
4 changed files with 64 additions and 11 deletions

View File

@@ -103,11 +103,7 @@ 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
}
}
@@ -387,11 +383,13 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
mouse->has_position = SDL_TRUE;
}
#ifndef __MACOSX__ /* all your trackpad input would lack relative motion when not dragging in this case. */
/* Ignore relative motion positioning the first touch */
if (mouseID == SDL_TOUCH_MOUSEID && !mouse->buttonstate) {
xrel = 0;
yrel = 0;
}
#endif
/* Update internal mouse coordinates */
if (!mouse->relative_mode) {

View File

@@ -32,9 +32,18 @@ static int SDL_num_touch = 0;
static SDL_Touch **SDL_touchDevices = NULL;
/* for mapping touch events to mice */
#ifndef __MACOSX__ /* don't generate mouse events from touch on macOS, the OS handles that. */
#define SYNTHESIZE_TOUCH_TO_MOUSE 1
#else
#define SYNTHESIZE_TOUCH_TO_MOUSE 0
#endif
#if SYNTHESIZE_TOUCH_TO_MOUSE
static SDL_bool finger_touching = SDL_FALSE;
static SDL_FingerID track_fingerid;
static SDL_TouchID track_touchid;
#endif
/* Public functions */
int
@@ -245,6 +254,7 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
return -1;
}
#if SYNTHESIZE_TOUCH_TO_MOUSE
/* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
{
SDL_Mouse *mouse = SDL_GetMouse();
@@ -284,6 +294,7 @@ SDL_SendTouch(SDL_TouchID id, SDL_FingerID fingerid,
}
}
}
#endif
finger = SDL_GetFinger(touch, fingerid);
if (down) {
@@ -349,6 +360,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
return -1;
}
#if SYNTHESIZE_TOUCH_TO_MOUSE
/* SDL_HINT_TOUCH_MOUSE_EVENTS: controlling whether touch events should generate synthetic mouse events */
{
SDL_Mouse *mouse = SDL_GetMouse();
@@ -369,6 +381,7 @@ SDL_SendTouchMotion(SDL_TouchID id, SDL_FingerID fingerid,
}
}
}
#endif
finger = SDL_GetFinger(touch,fingerid);
if (!finger) {