Fix SDL_SetWindowPosition on fullscreen windows.
authorJørgen P. Tjernø <jorgen@valvesoftware.com>
Mon, 07 Oct 2013 14:16:38 -0700
changeset 7792b8d4be87970a
parent 7791 d9f0067a5421
child 7793 6463a850229d
Fix SDL_SetWindowPosition on fullscreen windows.

This reverts http://hg.libsdl.org/SDL/rev/7cdeb64faa72 and fixes it in
the correct way. If you call SDL_SetWindowPosition on a fullscreen
window, it would update the x & y variables for the window, but not
actually move the window (since it was fullscreen). That would make the
internal state of the SDL_Window incorrect, causing
SDL_WarpMouseInWindow to offset incorrectly.

This makes it so SDL_SetWindowPosition updates the `windowed' x & y
coordinates, which take effect when you revert from fullscreen.
src/video/SDL_video.c
src/video/cocoa/SDL_cocoamouse.m
     1.1 --- a/src/video/SDL_video.c	Sun Oct 06 20:39:23 2013 -0700
     1.2 +++ b/src/video/SDL_video.c	Mon Oct 07 14:16:38 2013 -0700
     1.3 @@ -1551,14 +1551,21 @@
     1.4          }
     1.5      }
     1.6  
     1.7 -    if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
     1.8 -        window->x = x;
     1.9 -    }
    1.10 -    if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
    1.11 -        window->y = y;
    1.12 -    }
    1.13 -
    1.14 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.15 +    if ((window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.16 +        if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
    1.17 +            window->windowed.x = x;
    1.18 +        }
    1.19 +        if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
    1.20 +            window->windowed.y = y;
    1.21 +        }
    1.22 +    } else {
    1.23 +        if (!SDL_WINDOWPOS_ISUNDEFINED(x)) {
    1.24 +            window->x = x;
    1.25 +        }
    1.26 +        if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
    1.27 +            window->y = y;
    1.28 +        }
    1.29 +
    1.30          if (_this->SetWindowPosition) {
    1.31              _this->SetWindowPosition(_this, window);
    1.32          }
     2.1 --- a/src/video/cocoa/SDL_cocoamouse.m	Sun Oct 06 20:39:23 2013 -0700
     2.2 +++ b/src/video/cocoa/SDL_cocoamouse.m	Mon Oct 07 14:16:38 2013 -0700
     2.3 @@ -204,13 +204,7 @@
     2.4  Cocoa_WarpMouse(SDL_Window * window, int x, int y)
     2.5  {
     2.6      SDL_Mouse *mouse = SDL_GetMouse();
     2.7 -    CGPoint point = CGPointMake(x, y);
     2.8 -
     2.9 -    if (!(window->flags & SDL_WINDOW_FULLSCREEN))
    2.10 -    {
    2.11 -        point.x += window->x;
    2.12 -        point.y += window->y;
    2.13 -    }
    2.14 +    CGPoint point = CGPointMake(x + (float)window->x, y + (float)window->y);
    2.15  
    2.16      {
    2.17          /* This makes Cocoa_HandleMouseEvent ignore this delta in the next