Workaround for relative mouse issue on OS X

After setting relative mouse mode on OS X, the first time the mouse is
moved a big delta is given (I guess some delta from the mouse position
at the time to the fixed point it then reports delta from).

In my case, an FPS with mouse controlling the view angle, this means
the view jumps to some crazy orientation the first time you touch the
mouse.

I tried working around it in various ways, but the only solution I
found that worked was to simply ignore the first event the comes in
after setting relative mouse mode.

Does the attached seem like a reasonable workaround?

Kevin.
-------------- next part --------------
diff -r 398073b195bb src/video/cocoa/SDL_cocoamouse.m
— a/src/video/cocoa/SDL_cocoamouse.m Fri Dec 14 23:05:34 2012 -0800
+++ b/src/video/cocoa/SDL_cocoamouse.m Sat Dec 15 20:18:07 2012 +1030
@@ -179,6 +179,14 @@
CGWarpMouseCursorPosition(point);
}

+/*

    • It seems that after calling CGAssociateMouseAndMouseCursorPosition(false),
    • the first relative event will report the jump from current position back to
    • whatever fixed point it is going to report from then onwards. Simplest
    • thing to do seems to be just ignore the first relative event.
  • */
    +static SDL_bool ignore_one_relative_event = SDL_FALSE;+
    static int
    Cocoa_SetRelativeMouseMode(SDL_bool enabled)
    {
    @@ -193,6 +201,9 @@
    SDL_SetError(“CGAssociateMouseAndMouseCursorPosition() failed”);
    return -1;
    }
  • ignore_one_relative_event = enabled;
  • return 0;
    }

@@ -216,6 +227,11 @@
{
SDL_Mouse *mouse = SDL_GetMouse();

  • if (mouse->relative_mode && ignore_one_relative_event) {
  •    ignore_one_relative_event = SDL_FALSE;
    
  •    return;
    
  • }
  • if (mouse->relative_mode &&
    ([event type] == NSMouseMoved ||
    [event type] == NSLeftMouseDragged ||

Hey, would you mind creating a bug on
http://bugzilla.libsdl.org/enter_bug.cgi?product=SDL so that this doesn’t
get forgotten in the mailing list?
Thanks,
VittorioOn Sat, Dec 15, 2012 at 11:08 AM, Kevin Shanahan wrote:

After setting relative mouse mode on OS X, the first time the mouse is
moved a big delta is given (I guess some delta from the mouse position
at the time to the fixed point it then reports delta from).

In my case, an FPS with mouse controlling the view angle, this means
the view jumps to some crazy orientation the first time you touch the
mouse.

I tried working around it in various ways, but the only solution I
found that worked was to simply ignore the first event the comes in
after setting relative mouse mode.

Does the attached seem like a reasonable workaround?

Kevin.


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org