src/video/SDL_video.c
changeset 9447 728a4bf8e02f
parent 9416 d5c12b28df2d
child 9461 409b20ba3e70
child 9536 3c87b8f9dc58
     1.1 --- a/src/video/SDL_video.c	Fri Mar 27 18:09:51 2015 -0400
     1.2 +++ b/src/video/SDL_video.c	Sat Mar 28 00:48:03 2015 -0400
     1.3 @@ -2116,6 +2116,7 @@
     1.4  SDL_UpdateWindowGrab(SDL_Window * window)
     1.5  {
     1.6      if (_this->SetWindowGrab) {
     1.7 +        SDL_Window *grabbed_window;
     1.8          SDL_bool grabbed;
     1.9          if ((SDL_GetMouse()->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
    1.10               (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
    1.11 @@ -2123,6 +2124,19 @@
    1.12          } else {
    1.13              grabbed = SDL_FALSE;
    1.14          }
    1.15 +
    1.16 +        grabbed_window = _this->grabbed_window;
    1.17 +        if (grabbed) {
    1.18 +            if (grabbed_window && (grabbed_window != window)) {
    1.19 +                /* stealing a grab from another window! */
    1.20 +                grabbed_window->flags &= ~SDL_WINDOW_INPUT_GRABBED;
    1.21 +                _this->SetWindowGrab(_this, grabbed_window, SDL_FALSE);
    1.22 +            }
    1.23 +            _this->grabbed_window = window;
    1.24 +        } else if (grabbed_window == window) {
    1.25 +            _this->grabbed_window = NULL;  /* ungrabbing. */
    1.26 +        }
    1.27 +
    1.28          _this->SetWindowGrab(_this, window, grabbed);
    1.29      }
    1.30  }
    1.31 @@ -2147,8 +2161,15 @@
    1.32  SDL_GetWindowGrab(SDL_Window * window)
    1.33  {
    1.34      CHECK_WINDOW_MAGIC(window, SDL_FALSE);
    1.35 -
    1.36 -    return ((window->flags & SDL_WINDOW_INPUT_GRABBED) != 0);
    1.37 +    SDL_assert(!_this->grabbed_window || ((_this->grabbed_window->flags & SDL_WINDOW_INPUT_GRABBED) != 0));
    1.38 +    return window == _this->grabbed_window;
    1.39 +}
    1.40 +
    1.41 +SDL_Window *
    1.42 +SDL_GetGrabbedWindow(void)
    1.43 +{
    1.44 +    SDL_assert(!_this->grabbed_window || ((_this->grabbed_window->flags & SDL_WINDOW_INPUT_GRABBED) != 0));
    1.45 +    return _this->grabbed_window;
    1.46  }
    1.47  
    1.48  void