Package: mupen64plus-input-sdl / 2.0-4

sdl2_mousemode.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
Description: Add support for mouse based analog stick using SDL2
Author: Sven Eckelmann <sven@narfation.org>

---
diff --git a/src/plugin.c b/src/plugin.c
index 9e553b1463040b1359e95667e6de2957e8e0abf1..16ad6f7c146c77ef0daf677f22e6a077d8ceec42 100644
--- a/src/plugin.c
+++ b/src/plugin.c
@@ -306,7 +306,7 @@ doSdlKeys(unsigned char* keystate)
                     grabmouse = !grabmouse;
                     // grab/ungrab mouse
 #if SDL_VERSION_ATLEAST(2,0,0)
-#warning SDL mouse grabbing not yet supported with SDL 2.0
+                    SDL_SetRelativeMouseMode(grabmouse ? SDL_TRUE : SDL_FALSE);
 #else
                     SDL_WM_GrabInput( grabmouse ? SDL_GRAB_ON : SDL_GRAB_OFF );
 #endif
@@ -575,9 +575,10 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
     if (controller[Control].mouse)
     {
 #if SDL_VERSION_ATLEAST(2,0,0)
-#warning SDL mouse grabbing not yet supported with SDL 2.0
+        if (SDL_GetRelativeMouseMode())
 #else
         if (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON)
+#endif
         {
             SDL_PumpEvents();
 #if SDL_VERSION_ATLEAST(1,3,0)
@@ -586,6 +587,11 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
             while (SDL_PeepEvents(&event, 1, SDL_GETEVENT, SDL_EVENTMASK(SDL_MOUSEMOTION)) == 1)
 #endif
             {
+#if SDL_VERSION_ATLEAST(2,0,0)
+                int w, h;
+                SDL_Window *focus;
+#endif
+
                 if (event.motion.xrel)
                 {
                     mousex_residual += (int) (event.motion.xrel * controller[Control].mouse_sens[0]);
@@ -594,10 +600,20 @@ EXPORT void CALL GetKeys( int Control, BUTTONS *Keys )
                 {
                     mousey_residual += (int) (event.motion.yrel * controller[Control].mouse_sens[1]);
                 }
+
+#if SDL_VERSION_ATLEAST(2,0,0)
+                focus = SDL_GetKeyboardFocus();
+                if (focus) {
+                    SDL_GetWindowSize(focus, &w, &h);
+                    SDL_WarpMouseInWindow(focus, w / 2, h / 2);
+                } else {
+                    mousex_residual = 0;
+                    mousey_residual = 0;
+                }
+#endif
             }
         }
         else
-#endif
         {
             mousex_residual = 0;
             mousey_residual = 0;
@@ -944,7 +960,7 @@ EXPORT void CALL RomClosed(void)
 
     // release/ungrab mouse
 #if SDL_VERSION_ATLEAST(2,0,0)
-#warning SDL mouse grabbing not yet supported with SDL 2.0
+    SDL_SetRelativeMouseMode(SDL_FALSE);
 #else
     SDL_WM_GrabInput( SDL_GRAB_OFF );
 #endif
@@ -981,10 +997,12 @@ EXPORT int CALL RomOpen(void)
     // grab mouse
     if (controller[0].mouse || controller[1].mouse || controller[2].mouse || controller[3].mouse)
     {
-#if SDL_VERSION_ATLEAST(2,0,0)
-#warning SDL mouse grabbing not yet supported with SDL 2.0
-#else
         SDL_ShowCursor( 0 );
+#if SDL_VERSION_ATLEAST(2,0,0)
+        if (SDL_SetRelativeMouseMode(SDL_TRUE) < 0) {
+            DebugMessage(M64MSG_WARNING, "Couldn't grab input! Mouse support won't work!");
+        }
+#else
         if (SDL_WM_GrabInput( SDL_GRAB_ON ) != SDL_GRAB_ON)
         {
             DebugMessage(M64MSG_WARNING, "Couldn't grab input! Mouse support won't work!");