mirror of https://github.com/encounter/SDL.git
SDL_cocoamouse.m: SetRelativeMouseMode even if out of focus
Should fix #3087
This commit is contained in:
parent
d7c07d6b09
commit
e2d268a399
|
@ -259,7 +259,16 @@ Cocoa_WarpMouse(SDL_Window * window, int x, int y)
|
||||||
static int
|
static int
|
||||||
Cocoa_SetRelativeMouseMode(SDL_bool enabled)
|
Cocoa_SetRelativeMouseMode(SDL_bool enabled)
|
||||||
{
|
{
|
||||||
/* We will re-apply the relative mode when the window gets focus, if it
|
CGError result;
|
||||||
|
if (enabled) {
|
||||||
|
DLog("Turning on.");
|
||||||
|
result = CGAssociateMouseAndMouseCursorPosition(NO);
|
||||||
|
if (result != kCGErrorSuccess) {
|
||||||
|
return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We will re-apply the non-relative mode when the window gets focus, if it
|
||||||
* doesn't have focus right now.
|
* doesn't have focus right now.
|
||||||
*/
|
*/
|
||||||
SDL_Window *window = SDL_GetKeyboardFocus();
|
SDL_Window *window = SDL_GetKeyboardFocus();
|
||||||
|
@ -267,7 +276,7 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We will re-apply the relative mode when the window finishes being moved,
|
/* We will re-apply the non-relative mode when the window finishes being moved,
|
||||||
* if it is being moved right now.
|
* if it is being moved right now.
|
||||||
*/
|
*/
|
||||||
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
|
||||||
|
@ -275,17 +284,14 @@ Cocoa_SetRelativeMouseMode(SDL_bool enabled)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CGError result;
|
if (!enabled) {
|
||||||
if (enabled) {
|
|
||||||
DLog("Turning on.");
|
|
||||||
result = CGAssociateMouseAndMouseCursorPosition(NO);
|
|
||||||
} else {
|
|
||||||
DLog("Turning off.");
|
DLog("Turning off.");
|
||||||
result = CGAssociateMouseAndMouseCursorPosition(YES);
|
result = CGAssociateMouseAndMouseCursorPosition(YES);
|
||||||
}
|
|
||||||
if (result != kCGErrorSuccess) {
|
if (result != kCGErrorSuccess) {
|
||||||
return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed");
|
return SDL_SetError("CGAssociateMouseAndMouseCursorPosition() failed");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* The hide/unhide calls are redundant most of the time, but they fix
|
/* The hide/unhide calls are redundant most of the time, but they fix
|
||||||
* https://bugzilla.libsdl.org/show_bug.cgi?id=2550
|
* https://bugzilla.libsdl.org/show_bug.cgi?id=2550
|
||||||
|
|
Loading…
Reference in New Issue