Skip to content

Commit

Permalink
SDL_WarpMouseGlobal() should return non-void.
Browse files Browse the repository at this point in the history
There are platforms it isn't implemented on (and currently can't be
implemented on!), and there's currently no way for an app to know this.

This shouldn't break ABI on apps that moved to a revision between 2.0.3 and
2.0.4.
  • Loading branch information
icculus committed Jul 18, 2015
1 parent a955bec commit e346f14
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 15 deletions.
3 changes: 2 additions & 1 deletion include/SDL_mouse.h
Expand Up @@ -137,10 +137,11 @@ extern DECLSPEC void SDLCALL SDL_WarpMouseInWindow(SDL_Window * window,
*
* \param x The x coordinate
* \param y The y coordinate
* \return 0 on success, -1 on error (usually: unsupported by a platform).
*
* \note This function generates a mouse motion event
*/
extern DECLSPEC void SDLCALL SDL_WarpMouseGlobal(int x, int y);
extern DECLSPEC int SDLCALL SDL_WarpMouseGlobal(int x, int y);

/**
* \brief Set relative mouse mode.
Expand Down
2 changes: 1 addition & 1 deletion src/dynapi/SDL_dynapi_procs.h
Expand Up @@ -612,7 +612,7 @@ SDL_DYNAPI_PROC(int,SDL_WinRTRunApp,(int a, char **b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(const wchar_t*,SDL_WinRTGetFSPathUNICODE,(SDL_WinRT_Path a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_WinRTGetFSPathUTF8,(SDL_WinRT_Path a),(a),return)
#endif
SDL_DYNAPI_PROC(void,SDL_WarpMouseGlobal,(int a, int b),(a,b),)
SDL_DYNAPI_PROC(int,SDL_WarpMouseGlobal,(int a, int b),(a,b),)
SDL_DYNAPI_PROC(float,SDL_sqrtf,(float a),(a),return)
SDL_DYNAPI_PROC(double,SDL_tan,(double a),(a),return)
SDL_DYNAPI_PROC(float,SDL_tanf,(float a),(a),return)
Expand Down
6 changes: 4 additions & 2 deletions src/events/SDL_mouse.c
Expand Up @@ -535,14 +535,16 @@ SDL_WarpMouseInWindow(SDL_Window * window, int x, int y)
}
}

void
int
SDL_WarpMouseGlobal(int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();

if (mouse->WarpMouseGlobal) {
mouse->WarpMouseGlobal(x, y);
return mouse->WarpMouseGlobal(x, y);
}

return SDL_Unsupported();
}

static SDL_bool
Expand Down
2 changes: 1 addition & 1 deletion src/events/SDL_mouse_c.h
Expand Up @@ -61,7 +61,7 @@ typedef struct
void (*WarpMouse) (SDL_Window * window, int x, int y);

/* Warp the mouse to (x,y) in screen space */
void (*WarpMouseGlobal) (int x, int y);
int (*WarpMouseGlobal) (int x, int y);

/* Set relative mode */
int (*SetRelativeMouseMode) (SDL_bool enabled);
Expand Down
6 changes: 4 additions & 2 deletions src/video/cocoa/SDL_cocoamouse.m
Expand Up @@ -210,7 +210,7 @@ + (NSCursor *)invisibleCursor
return NULL;
}

static void
static int
Cocoa_WarpMouseGlobal(int x, int y)
{
SDL_Mouse *mouse = SDL_GetMouse();
Expand All @@ -219,7 +219,7 @@ + (NSCursor *)invisibleCursor
if ([data->listener isMoving]) {
DLog("Postponing warp, window being moved.");
[data->listener setPendingMoveX:x Y:y];
return;
return 0;
}
}
const CGPoint point = CGPointMake((float)x, (float)y);
Expand All @@ -245,6 +245,8 @@ + (NSCursor *)invisibleCursor
SDL_SendMouseMotion(win, mouse->mouseID, 0, x - win->x, y - win->y);
}
}

return 0;
}

static void
Expand Down
4 changes: 2 additions & 2 deletions src/video/mir/SDL_mirmouse.c
Expand Up @@ -110,10 +110,10 @@ MIR_WarpMouse(SDL_Window* window, int x, int y)
SDL_Unsupported();
}

static void
static int
MIR_WarpMouseGlobal(int x, int y)
{
SDL_Unsupported();
return SDL_Unsupported();
}

static int
Expand Down
7 changes: 5 additions & 2 deletions src/video/raspberry/SDL_rpimouse.c
Expand Up @@ -216,18 +216,18 @@ RPI_WarpMouse(SDL_Window * window, int x, int y)
}

/* Warp the mouse to (x,y) */
static void
static int
RPI_WarpMouseGlobal(int x, int y)
{
RPI_CursorData *curdata;
DISPMANX_UPDATE_HANDLE_T update;
int ret;
VC_RECT_T dst_rect;
SDL_Mouse *mouse = SDL_GetMouse();

if (mouse != NULL && mouse->cur_cursor != NULL && mouse->cur_cursor->driverdata != NULL) {
curdata = (RPI_CursorData *) mouse->cur_cursor->driverdata;
if (curdata->element != DISPMANX_NO_HANDLE) {
int ret;
update = vc_dispmanx_update_start( 10 );
SDL_assert( update );
vc_dispmanx_rect_set( &dst_rect, x, y, curdata->w, curdata->h);
Expand All @@ -245,8 +245,11 @@ RPI_WarpMouseGlobal(int x, int y)
/* Submit asynchronously, otherwise the peformance suffers a lot */
ret = vc_dispmanx_update_submit( update, 0, NULL );
SDL_assert( ret == DISPMANX_SUCCESS );
return (ret == DISPMANX_SUCCESS) ? 0 : -1;
}
}

return -1; /* !!! FIXME: this should SDL_SetError() somewhere. */
}

void
Expand Down
4 changes: 2 additions & 2 deletions src/video/wayland/SDL_waylandmouse.c
Expand Up @@ -347,10 +347,10 @@ Wayland_WarpMouse(SDL_Window *window, int x, int y)
SDL_Unsupported();
}

static void
static int
Wayland_WarpMouseGlobal(int x, int y)
{
SDL_Unsupported();
return SDL_Unsupported();
}

static int
Expand Down
3 changes: 2 additions & 1 deletion src/video/windows/SDL_windowsmouse.c
Expand Up @@ -236,14 +236,15 @@ WIN_WarpMouse(SDL_Window * window, int x, int y)
SetCursorPos(pt.x, pt.y);
}

static void
static int
WIN_WarpMouseGlobal(int x, int y)
{
POINT pt;

pt.x = x;
pt.y = y;
SetCursorPos(pt.x, pt.y);
return 0;
}

static int
Expand Down
3 changes: 2 additions & 1 deletion src/video/x11/SDL_x11mouse.c
Expand Up @@ -318,13 +318,14 @@ X11_WarpMouse(SDL_Window * window, int x, int y)
X11_XSync(display, False);
}

static void
static int
X11_WarpMouseGlobal(int x, int y)
{
Display *display = GetDisplay();

X11_XWarpPointer(display, None, DefaultRootWindow(display), 0, 0, 0, 0, x, y);
X11_XSync(display, False);
return 0;
}

static int
Expand Down

0 comments on commit e346f14

Please sign in to comment.