Skip to content

Commit

Permalink
Enable relative mouse mode when 1.2 app hides and grabs the cursor.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Mar 1, 2019
1 parent aa99b4a commit 2927d9a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/SDL12_compat.c
Expand Up @@ -2951,11 +2951,34 @@ typedef enum
SDL12_GRAB_ON = 1
} SDL12_GrabMode;

static void
UpdateRelativeMouseMode(void)
{
// in SDL 1.2, hiding+grabbing the cursor was like SDL2's relative mouse mode.
if (VideoWindow20) {
const int visible = SDL20_ShowCursor(-1);
const SDL_bool grabbed = SDL20_GetWindowGrab(VideoWindow20);
SDL20_SetRelativeMouseMode((!visible && grabbed) ? SDL_TRUE : SDL_FALSE);
}
}

DECLSPEC int SDLCALL
SDL_ShowCursor(int toggle)
{
const int retval = SDL20_ShowCursor(toggle);
if (toggle >= 0) {
UpdateRelativeMouseMode();
}
return retval;
}


DECLSPEC SDL12_GrabMode SDLCALL
SDL_WM_GrabInput(SDL12_GrabMode mode)
{
if (mode != SDL12_GRAB_QUERY) {
SDL20_SetWindowGrab(VideoWindow20, (mode == SDL12_GRAB_ON));
UpdateRelativeMouseMode();
}
return SDL20_GetWindowGrab(VideoWindow20) ? SDL12_GRAB_ON : SDL12_GRAB_OFF;
}
Expand Down
4 changes: 2 additions & 2 deletions src/SDL20_syms.h
Expand Up @@ -125,8 +125,8 @@ SDL20_SYM_PASSTHROUGH(SDL_Keymod,GetModState,(void),(),return)

SDL20_SYM(Uint32,GetMouseState,(int *a, int *b),(a,b),return)
SDL20_SYM(void,WarpMouseInWindow,(SDL_Window *a, int b, int c),(a,b,c),)

SDL20_SYM_PASSTHROUGH(int,ShowCursor,(int a),(a),return)
SDL20_SYM(int,SetRelativeMouseMode,(SDL_bool a),(a),return)
SDL20_SYM(int,ShowCursor,(int a),(a),return)
SDL20_SYM(SDL_Cursor *,CreateCursor,(const Uint8 *a,const Uint8 *b,int c,int d,int e,int f),(a,b,c,d,e,f),return)
SDL20_SYM(void,SetCursor,(SDL_Cursor *a),(a),)
SDL20_SYM(SDL_Cursor *,GetCursor,(void),(),return)
Expand Down

0 comments on commit 2927d9a

Please sign in to comment.