Mac: Fix relative mode message after gaining focus.
This fixes a bug where relative mode would give a large jump if the cursor was moved when the app doesn't have focus. --HG-- extra : histedit_source : ff1b20a9e7f6e079c073c4ef761566b6c80b0f22%2C9879c6c838c69afea4aa2be80cbe137054600d12
This commit is contained in:
parent
22358fddd1
commit
9e4a519493
3 changed files with 32 additions and 3 deletions
|
@ -73,6 +73,9 @@ typedef struct
|
||||||
SDL_Cursor *def_cursor;
|
SDL_Cursor *def_cursor;
|
||||||
SDL_Cursor *cur_cursor;
|
SDL_Cursor *cur_cursor;
|
||||||
SDL_bool cursor_shown;
|
SDL_bool cursor_shown;
|
||||||
|
|
||||||
|
/* Driver-dependent data. */
|
||||||
|
void *driverdata;
|
||||||
} SDL_Mouse;
|
} SDL_Mouse;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,18 @@
|
||||||
#ifndef _SDL_cocoamouse_h
|
#ifndef _SDL_cocoamouse_h
|
||||||
#define _SDL_cocoamouse_h
|
#define _SDL_cocoamouse_h
|
||||||
|
|
||||||
|
#include "SDL_cocoavideo.h"
|
||||||
|
|
||||||
extern void Cocoa_InitMouse(_THIS);
|
extern void Cocoa_InitMouse(_THIS);
|
||||||
extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
|
extern void Cocoa_HandleMouseEvent(_THIS, NSEvent * event);
|
||||||
extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);
|
extern void Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent * event);
|
||||||
extern void Cocoa_QuitMouse(_THIS);
|
extern void Cocoa_QuitMouse(_THIS);
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int deltaXOffset;
|
||||||
|
int deltaYOffset;
|
||||||
|
} SDL_MouseData;
|
||||||
|
|
||||||
#endif /* _SDL_cocoamouse_h */
|
#endif /* _SDL_cocoamouse_h */
|
||||||
|
|
||||||
/* vi: set ts=4 sw=4 expandtab: */
|
/* vi: set ts=4 sw=4 expandtab: */
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include "SDL_assert.h"
|
#include "SDL_assert.h"
|
||||||
#include "SDL_events.h"
|
#include "SDL_events.h"
|
||||||
#include "SDL_cocoavideo.h"
|
#include "SDL_cocoamouse.h"
|
||||||
|
|
||||||
#include "../../events/SDL_mouse_c.h"
|
#include "../../events/SDL_mouse_c.h"
|
||||||
|
|
||||||
|
@ -193,6 +193,16 @@ Cocoa_WarpMouse(SDL_Window * window, int x, int y)
|
||||||
point.x = (float)window->x + x;
|
point.x = (float)window->x + x;
|
||||||
point.y = (float)window->y + y;
|
point.y = (float)window->y + y;
|
||||||
|
|
||||||
|
{
|
||||||
|
/* This makes Cocoa_HandleMouseEvent ignore this delta in the next
|
||||||
|
* movement event.
|
||||||
|
*/
|
||||||
|
SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
|
||||||
|
NSPoint location = [NSEvent mouseLocation];
|
||||||
|
driverdata->deltaXOffset = location.x - point.x;
|
||||||
|
driverdata->deltaYOffset = point.y - location.y;
|
||||||
|
}
|
||||||
|
|
||||||
/* According to the docs, this was deprecated in 10.6, but it's still
|
/* According to the docs, this was deprecated in 10.6, but it's still
|
||||||
* around. The substitute requires a CGEventSource, but I'm not entirely
|
* around. The substitute requires a CGEventSource, but I'm not entirely
|
||||||
* sure how we'd procure the right one for this event.
|
* sure how we'd procure the right one for this event.
|
||||||
|
@ -228,6 +238,8 @@ Cocoa_InitMouse(_THIS)
|
||||||
{
|
{
|
||||||
SDL_Mouse *mouse = SDL_GetMouse();
|
SDL_Mouse *mouse = SDL_GetMouse();
|
||||||
|
|
||||||
|
mouse->driverdata = SDL_calloc(1, sizeof(SDL_MouseData));
|
||||||
|
|
||||||
mouse->CreateCursor = Cocoa_CreateCursor;
|
mouse->CreateCursor = Cocoa_CreateCursor;
|
||||||
mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
|
mouse->CreateSystemCursor = Cocoa_CreateSystemCursor;
|
||||||
mouse->ShowCursor = Cocoa_ShowCursor;
|
mouse->ShowCursor = Cocoa_ShowCursor;
|
||||||
|
@ -248,8 +260,11 @@ Cocoa_HandleMouseEvent(_THIS, NSEvent *event)
|
||||||
[event type] == NSLeftMouseDragged ||
|
[event type] == NSLeftMouseDragged ||
|
||||||
[event type] == NSRightMouseDragged ||
|
[event type] == NSRightMouseDragged ||
|
||||||
[event type] == NSOtherMouseDragged)) {
|
[event type] == NSOtherMouseDragged)) {
|
||||||
float x = [event deltaX];
|
SDL_MouseData *driverdata = (SDL_MouseData*)mouse->driverdata;
|
||||||
float y = [event deltaY];
|
float x = [event deltaX] + driverdata->deltaXOffset;
|
||||||
|
float y = [event deltaY] + driverdata->deltaYOffset;
|
||||||
|
driverdata->deltaXOffset = driverdata->deltaYOffset = 0;
|
||||||
|
|
||||||
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)x, (int)y);
|
SDL_SendMouseMotion(mouse->focus, mouse->mouseID, 1, (int)x, (int)y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -278,6 +293,10 @@ Cocoa_HandleMouseWheel(SDL_Window *window, NSEvent *event)
|
||||||
void
|
void
|
||||||
Cocoa_QuitMouse(_THIS)
|
Cocoa_QuitMouse(_THIS)
|
||||||
{
|
{
|
||||||
|
SDL_Mouse *mouse = SDL_GetMouse();
|
||||||
|
if (mouse) {
|
||||||
|
SDL_free(mouse->driverdata);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
#endif /* SDL_VIDEO_DRIVER_COCOA */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue