Whoops, lost this in the merge.
authorRyan C. Gordon <icculus@icculus.org>
Wed, 25 Jun 2014 17:20:22 -0400
changeset 8955 7a74b402790c
parent 8954 7bcc8257809d
child 8956 a99e30f2bf0a
Whoops, lost this in the merge.
src/events/SDL_mouse.c
--- a/src/events/SDL_mouse.c	Wed Jun 25 17:13:43 2014 -0400
+++ b/src/events/SDL_mouse.c	Wed Jun 25 17:20:22 2014 -0400
@@ -614,6 +614,41 @@
     return mouse->relative_mode;
 }
 
+int
+SDL_CaptureMouse(SDL_bool enabled)
+{
+    SDL_Mouse *mouse = SDL_GetMouse();
+    SDL_Window *focusWindow;
+    SDL_bool isCaptured;
+
+    if (!mouse->CaptureMouse) {
+        return SDL_Unsupported();
+    }
+
+    focusWindow = SDL_GetKeyboardFocus();
+
+    isCaptured = focusWindow && (focusWindow->flags & SDL_WINDOW_MOUSE_CAPTURE);
+    if (isCaptured == enabled) {
+        return 0;  /* already done! */
+    }
+
+    if (enabled) {
+        if (!focusWindow) {
+            return SDL_SetError("No window has focus");
+        } else if (mouse->CaptureMouse(focusWindow) == -1) {
+            return -1;  /* CaptureMouse() should call SetError */
+        }
+        focusWindow->flags |= SDL_WINDOW_MOUSE_CAPTURE;
+    } else {
+        if (mouse->CaptureMouse(NULL) == -1) {
+            return -1;  /* CaptureMouse() should call SetError */
+        }
+        focusWindow->flags &= ~SDL_WINDOW_MOUSE_CAPTURE;
+    }
+
+    return 0;
+}
+
 SDL_Cursor *
 SDL_CreateCursor(const Uint8 * data, const Uint8 * mask,
                  int w, int h, int hot_x, int hot_y)