$OpenBSD: patch-source_mupen64plus-input-sdl_src_plugin_c,v 1.1.1.1 2011/12/26 13:38:27 stsp Exp $
--- src/plugin.c.orig	Tue Nov 23 03:15:13 2010
+++ src/plugin.c	Sun Dec 18 23:59:37 2011
@@ -1,7 +1,7 @@
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  *   Mupen64plus-input-sdl - plugin.c                                      *
  *   Mupen64Plus homepage: http://code.google.com/p/mupen64plus/           *
- *   Copyright (C) 2008-2009 Richard Goedeken                              *
+ *   Copyright (C) 2008-2011 Richard Goedeken                              *
  *   Copyright (C) 2008 Tillin9                                            *
  *   Copyright (C) 2002 Blight                                             *
  *                                                                         *
@@ -29,6 +29,7 @@
 
 #include "m64p_types.h"
 #include "m64p_plugin.h"
+#include "m64p_common.h"
 #include "m64p_config.h"
 
 #include "plugin.h"
@@ -143,7 +144,7 @@ EXPORT m64p_error CALL PluginStartup(m64p_dynlib_handl
     /* first thing is to set the callback function for debug info */
     l_DebugCallback = DebugCallback;
     l_DebugCallContext = Context;
-
+    
     /* Get the core config function pointers from the library handle */
     ConfigOpenSection = (ptr_ConfigOpenSection) osal_dynlib_getproc(CoreLibHandle, "ConfigOpenSection");
     ConfigDeleteSection = (ptr_ConfigDeleteSection) osal_dynlib_getproc(CoreLibHandle, "ConfigDeleteSection");
@@ -428,6 +429,8 @@ EXPORT void CALL ControllerCommand(int Control, unsign
 *******************************************************************/
 EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
 {
+    static int mousex_residual = 0;
+    static int mousey_residual = 0;
     int b, axis_val;
     SDL_Event event;
     unsigned char mstate;
@@ -532,30 +535,43 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
             controller[Control].buttons.Value |= button_bits[b];
     }
 
-    if (controller[Control].mouse && SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON)
+    if (controller[Control].mouse)
     {
-        SDL_PumpEvents();
-        while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)) == 1)
+        if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON)
         {
-            if (event.motion.xrel)
+            SDL_PumpEvents();
+            while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)) == 1)
             {
-                axis_val = (event.motion.xrel * 10);
-                if (axis_val < -80)
-                    axis_val = -80;
-                else if (axis_val > 80)
-                    axis_val = 80;
-                controller[Control].buttons.X_AXIS = axis_val;
+                if (event.motion.xrel)
+                {
+                    mousex_residual += (int) (event.motion.xrel * controller[Control].mouse_sens[0]);
+                }
+                if (event.motion.yrel)
+                {
+                    mousey_residual += (int) (event.motion.yrel * controller[Control].mouse_sens[1]);
+                }
             }
-            if (event.motion.yrel)
-            {
-                axis_val = (event.motion.yrel * 10);
-                if (axis_val < -80)
-                    axis_val = -80;
-                else if (axis_val > 80)
-                    axis_val = 80;
-                controller[Control].buttons.Y_AXIS = -axis_val;
-            }
         }
+        else
+        {
+            mousex_residual = 0;
+            mousey_residual = 0;
+        }
+        axis_val = mousex_residual;
+        if (axis_val < -80)
+            axis_val = -80;
+        else if (axis_val > 80)
+            axis_val = 80;
+        controller[Control].buttons.X_AXIS = axis_val;
+        axis_val = mousey_residual;
+        if (axis_val < -80)
+            axis_val = -80;
+        else if (axis_val > 80)
+            axis_val = 80;
+        controller[Control].buttons.Y_AXIS = -axis_val;
+        /* the mouse x/y values decay exponentially */
+        mousex_residual = (mousex_residual * 224) / 256;
+        mousey_residual = (mousey_residual * 224) / 256;
     }
 
 #ifdef _DEBUG
