Whoops, lost this in the merge.
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
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 5ad3a72..41653a4 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -614,6 +614,41 @@ SDL_GetRelativeMouseMode()
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)