mirror of
https://github.com/Ryujinx/SDL.git
synced 2025-01-12 09:35:31 +00:00
cocoa: Ignore first mouse motion event after enabling relative mode.
Fixes #7918.
This commit is contained in:
parent
3030fd815c
commit
dc5dda0f31
|
@ -40,6 +40,8 @@ typedef struct {
|
||||||
/* What location we last saw the cursor move to. */
|
/* What location we last saw the cursor move to. */
|
||||||
CGFloat lastMoveX;
|
CGFloat lastMoveX;
|
||||||
CGFloat lastMoveY;
|
CGFloat lastMoveY;
|
||||||
|
/* If we just turned on relative mode, and should skip a single mouse motion event. */
|
||||||
|
SDL_bool justEnabledRelative;
|
||||||
} SDL_MouseData;
|
} SDL_MouseData;
|
||||||
|
|
||||||
@interface NSCursor (InvisibleCursor)
|
@interface NSCursor (InvisibleCursor)
|
||||||
|
|
|
@ -293,8 +293,11 @@ static int Cocoa_SetRelativeMouseMode(SDL_bool enabled)
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
if (window) {
|
if (window) {
|
||||||
/* make sure the mouse isn't at the corner of the window, as this can confuse things if macOS thinks a window resize is happening on the first click. */
|
/* make sure the mouse isn't at the corner of the window, as this can confuse things if macOS thinks a window resize is happening on the first click. */
|
||||||
|
SDL_MouseData *mousedriverdata = (SDL_MouseData*)SDL_GetMouse()->driverdata;
|
||||||
const CGPoint point = CGPointMake((float)(window->x + (window->w / 2)), (float)(window->y + (window->h / 2)));
|
const CGPoint point = CGPointMake((float)(window->x + (window->w / 2)), (float)(window->y + (window->h / 2)));
|
||||||
Cocoa_HandleMouseWarp(point.x, point.y);
|
if (mousedriverdata) {
|
||||||
|
mousedriverdata->justEnabledRelative = SDL_TRUE;
|
||||||
|
}
|
||||||
CGWarpMouseCursorPosition(point);
|
CGWarpMouseCursorPosition(point);
|
||||||
}
|
}
|
||||||
DLog("Turning on.");
|
DLog("Turning on.");
|
||||||
|
@ -465,6 +468,11 @@ void Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
||||||
seenWarp = driverdata->seenWarp;
|
seenWarp = driverdata->seenWarp;
|
||||||
driverdata->seenWarp = NO;
|
driverdata->seenWarp = NO;
|
||||||
|
|
||||||
|
if (driverdata->justEnabledRelative) {
|
||||||
|
driverdata->justEnabledRelative = SDL_FALSE;
|
||||||
|
return; // dump the first event back.
|
||||||
|
}
|
||||||
|
|
||||||
location = [NSEvent mouseLocation];
|
location = [NSEvent mouseLocation];
|
||||||
lastMoveX = driverdata->lastMoveX;
|
lastMoveX = driverdata->lastMoveX;
|
||||||
lastMoveY = driverdata->lastMoveY;
|
lastMoveY = driverdata->lastMoveY;
|
||||||
|
|
Loading…
Reference in a new issue