src/SDL12_compat.c
changeset 106 8948c4b1ef8d
parent 105 5eca9fdcac0c
child 107 675826327470
     1.1 --- a/src/SDL12_compat.c	Wed Mar 06 16:53:01 2019 -0500
     1.2 +++ b/src/SDL12_compat.c	Wed Mar 06 16:53:24 2019 -0500
     1.3 @@ -719,6 +719,8 @@
     1.4  static VideoModeList *VideoModes = NULL;
     1.5  static int VideoModesCount = 0;
     1.6  static SDL12_VideoInfo VideoInfo12;
     1.7 +static SDL_bool VideoWindowGrabbed = SDL_FALSE;
     1.8 +static SDL_bool VideoCursorHidden = SDL_FALSE;
     1.9  static SDL_Window *VideoWindow20 = NULL;
    1.10  static SDL_Renderer *VideoRenderer20 = NULL;
    1.11  static SDL_Texture *VideoTexture20 = NULL;
    1.12 @@ -1085,6 +1087,10 @@
    1.13      VideoDisplayIndex = GetVideoDisplay();
    1.14      SwapInterval = 0;
    1.15  
    1.16 +    VideoWindowGrabbed = SDL_FALSE;
    1.17 +    VideoCursorHidden = SDL_FALSE;
    1.18 +    SDL20_ShowCursor(1);
    1.19 +
    1.20      if (Init12VidModes() == -1) {
    1.21          return -1;
    1.22      }
    1.23 @@ -3325,18 +3331,22 @@
    1.24  {
    1.25      // in SDL 1.2, hiding+grabbing the cursor was like SDL2's relative mouse mode.
    1.26      if (VideoWindow20) {
    1.27 -        const int visible = SDL20_ShowCursor(-1);
    1.28 -        const SDL_bool grabbed = SDL20_GetWindowGrab(VideoWindow20);
    1.29 -        SDL20_SetRelativeMouseMode((!visible && grabbed) ? SDL_TRUE : SDL_FALSE);
    1.30 +        SDL20_SetRelativeMouseMode((VideoWindowGrabbed && VideoCursorHidden) ? SDL_TRUE : SDL_FALSE);
    1.31      }
    1.32  }
    1.33  
    1.34  DECLSPEC int SDLCALL
    1.35  SDL_ShowCursor(int toggle)
    1.36  {
    1.37 -    const int retval = SDL20_ShowCursor(toggle);
    1.38 +    const int retval = VideoCursorHidden ? 0 : 1;
    1.39 +
    1.40      if (toggle >= 0) {
    1.41 -        UpdateRelativeMouseMode();
    1.42 +        const SDL_bool wanthide = (toggle == 0) ? SDL_TRUE : SDL_FALSE;
    1.43 +        if (VideoCursorHidden != wanthide) {
    1.44 +            SDL20_ShowCursor(wanthide ? 0 : 1);
    1.45 +            VideoCursorHidden = wanthide;
    1.46 +            UpdateRelativeMouseMode();
    1.47 +        }
    1.48      }
    1.49      return retval;
    1.50  }
    1.51 @@ -3346,10 +3356,14 @@
    1.52  SDL_WM_GrabInput(SDL12_GrabMode mode)
    1.53  {
    1.54      if (mode != SDL12_GRAB_QUERY) {
    1.55 -        SDL20_SetWindowGrab(VideoWindow20, (mode == SDL12_GRAB_ON));
    1.56 -        UpdateRelativeMouseMode();
    1.57 +        const SDL_bool wantgrab = (mode == SDL12_GRAB_ON) ? SDL_TRUE : SDL_FALSE;
    1.58 +        if (VideoWindowGrabbed != wantgrab) {
    1.59 +            SDL20_SetWindowGrab(VideoWindow20, wantgrab);
    1.60 +            VideoWindowGrabbed = wantgrab;
    1.61 +            UpdateRelativeMouseMode();
    1.62 +        }
    1.63      }
    1.64 -    return SDL20_GetWindowGrab(VideoWindow20) ? SDL12_GRAB_ON : SDL12_GRAB_OFF;
    1.65 +    return VideoWindowGrabbed ? SDL12_GRAB_ON : SDL12_GRAB_OFF;
    1.66  }
    1.67  
    1.68  DECLSPEC void SDLCALL