Skip to content

Commit

Permalink
Fixed input grabbing.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Mar 6, 2019
1 parent 085551d commit 6cdbbf1
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/SDL12_compat.c
Expand Up @@ -719,6 +719,8 @@ typedef struct
static VideoModeList *VideoModes = NULL;
static int VideoModesCount = 0;
static SDL12_VideoInfo VideoInfo12;
static SDL_bool VideoWindowGrabbed = SDL_FALSE;
static SDL_bool VideoCursorHidden = SDL_FALSE;
static SDL_Window *VideoWindow20 = NULL;
static SDL_Renderer *VideoRenderer20 = NULL;
static SDL_Texture *VideoTexture20 = NULL;
Expand Down Expand Up @@ -1085,6 +1087,10 @@ Init12Video(void)
VideoDisplayIndex = GetVideoDisplay();
SwapInterval = 0;

VideoWindowGrabbed = SDL_FALSE;
VideoCursorHidden = SDL_FALSE;
SDL20_ShowCursor(1);

if (Init12VidModes() == -1) {
return -1;
}
Expand Down Expand Up @@ -3325,18 +3331,22 @@ 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);
SDL20_SetRelativeMouseMode((VideoWindowGrabbed && VideoCursorHidden) ? SDL_TRUE : SDL_FALSE);
}
}

DECLSPEC int SDLCALL
SDL_ShowCursor(int toggle)
{
const int retval = SDL20_ShowCursor(toggle);
const int retval = VideoCursorHidden ? 0 : 1;

if (toggle >= 0) {
UpdateRelativeMouseMode();
const SDL_bool wanthide = (toggle == 0) ? SDL_TRUE : SDL_FALSE;
if (VideoCursorHidden != wanthide) {
SDL20_ShowCursor(wanthide ? 0 : 1);
VideoCursorHidden = wanthide;
UpdateRelativeMouseMode();
}
}
return retval;
}
Expand All @@ -3346,10 +3356,14 @@ DECLSPEC SDL12_GrabMode SDLCALL
SDL_WM_GrabInput(SDL12_GrabMode mode)
{
if (mode != SDL12_GRAB_QUERY) {
SDL20_SetWindowGrab(VideoWindow20, (mode == SDL12_GRAB_ON));
UpdateRelativeMouseMode();
const SDL_bool wantgrab = (mode == SDL12_GRAB_ON) ? SDL_TRUE : SDL_FALSE;
if (VideoWindowGrabbed != wantgrab) {
SDL20_SetWindowGrab(VideoWindow20, wantgrab);
VideoWindowGrabbed = wantgrab;
UpdateRelativeMouseMode();
}
}
return SDL20_GetWindowGrab(VideoWindow20) ? SDL12_GRAB_ON : SDL12_GRAB_OFF;
return VideoWindowGrabbed ? SDL12_GRAB_ON : SDL12_GRAB_OFF;
}

DECLSPEC void SDLCALL
Expand Down

0 comments on commit 6cdbbf1

Please sign in to comment.