[SDL1.3 hg] Multitouch & Window IDs

Hi.

I’m observing some multitouch incorrectness in a multi-sdl-window
environment, with the hg version of SDL (updated today), on OSX Snow
Leopard.

The problems:

  • event.mgesture.windowID is never set, and arrives to the user as
    garbage.
  • If I have two SDL windows, and window1 has focus, and my mouse is
    hovering over window2, the program’s sdl-multitouch system can permanently
    enter an incorrect state.

I have a proposed fix for the first issue, and some questions.

SDL_gesture.c: Making event.mgesture.windowID not garbage

Currently, event.mgesture.windowID isn’t set to anything, so it arrives to
the user as unpredictable garbage.

My diff to fix this:

diff -r fc718f26c15e src/events/SDL_gesture.c
— a/src/events/SDL_gesture.c Wed Dec 15 21:31:12 2010 -0500
+++ b/src/events/SDL_gesture.c Sat Dec 18 19:56:37 2010 -0800
@@ -452,9 +452,10 @@
return NULL;
}

-int SDL_SendGestureMulti(SDL_GestureTouch* touch,float dTheta,float dDist)
{
+int SDL_SendGestureMulti(SDL_GestureTouch* touch,float dTheta,float
dDist,Uint32 windowID) {
SDL_Event event;
event.mgesture.type = SDL_MULTIGESTURE;

  • event.mgesture.windowID = windowID;
    event.mgesture.touchId = touch->id;
    event.mgesture.x = touch->centroid.x;
    event.mgesture.y = touch->centroid.y;
    @@ -626,7 +627,7 @@
    //knob.ang += dtheta;
    //printf(“thetaSum = %f, distSum = %f\n”,gdtheta,gdDist);
    //printf(“id: %i dTheta = %f, dDist = %f\n”,j,dtheta,dDist);
  •    SDL_SendGestureMulti(inTouch,dtheta,dDist);
    
  •    SDL_SendGestureMulti(inTouch,dtheta,dDist,event->tfinger.windowID);
     }
     else {
       //inTouch->gestureLast[j].dDist = 0;
    

This is better, but event.mgesture.windowID now is always NULL, because
event->tfinger.windowID is always NULL, because I don’t see anything that
actually calls SDL_SetTouchFocus().

At this point, I’m not sure what to do.

I observe that SDL only sends touch / mgesture events to the user when the
mouse is hovering over the window with focus. Thus, it seems like, at least
on this platform, all event.mgestures should arrive with mgesture.windowID
equal to SDL_GetMouseFocus(). I mean, could SDL_GetMouseFocus() and
SDL_GetTouchFocus() ever be different? Since they’re distinct variables, the
answer almost seems to necessarily be “yes”, but I can’t envision a concrete
case where this makes sense… I don’t know. Can somebody with more
experience in these things comment, help me understand and hopefully suggest
a better solution?

Multitouch and two SDL_Windows*
*
I didn’t figure out how to fix this one, but I can report what’s happening.

I have two SDL_Windows, one on each display.

If window1 has focus, and I hover my mouse over window2, I get no
MOUSEMOTION events, and would expect to get no touch events, either.
However, when I touch two fingers and swipe down, or
"random-downwards-jitter" with 3 fingers, I observe SDL_cocoawindow.m’s
handleTouches() being called when it seems like it shouldn’t, and with
unusual patterns of frequent up/motion, and only the very occasional
down-event. This down-event sends incorrect calls to
SDL_SendFingerDown(true), which causes every subsequent
event.mgesture.numFingers to be incorrect when it arrives to the user,
effectively breaking the multitouch aspect of the program, reporting more
fingers down than there are.

I don’t know what to make of this, or how to fix it properly. For my own
purposes, I’ve implemented a cheesy hack such that handleTouches() returns
early if self != the first window to call Cocoa_WindowListener::listen().
This prevents SDL’s state from being corrupted, but isn’t at all a proper
general solution.