Fixed bug 1167 (SDL_WINDOWPOS_CENTERED doesn't work if used right after fullscreen -> windowed switch)
authorSam Lantinga <slouken@libsdl.org>
Fri, 11 Mar 2011 16:54:43 -0800
changeset 54786b65ff3cee62
parent 5477 50cd1fb880e5
child 5479 5c4635640bf9
Fixed bug 1167 (SDL_WINDOWPOS_CENTERED doesn't work if used right after fullscreen -> windowed switch)

The top level code handles SDL_WINDOWPOS_CENTERED now, and the Cocoa SetWindowPosition call will clear the moveHack before adjusting the window position.
src/video/SDL_video.c
src/video/cocoa/SDL_cocoawindow.m
src/video/directfb/SDL_DirectFB_window.c
src/video/windows/SDL_windowswindow.c
src/video/x11/SDL_x11window.c
     1.1 --- a/src/video/SDL_video.c	Fri Mar 11 16:03:23 2011 -0800
     1.2 +++ b/src/video/SDL_video.c	Fri Mar 11 16:54:43 2011 -0800
     1.3 @@ -1413,6 +1413,20 @@
     1.4      if (!SDL_WINDOWPOS_ISUNDEFINED(y)) {
     1.5          window->y = y;
     1.6      }
     1.7 +    if (SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
     1.8 +        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     1.9 +        int displayIndex;
    1.10 +        SDL_Rect bounds;
    1.11 +
    1.12 +        displayIndex = SDL_GetIndexOfDisplay(display);
    1.13 +        SDL_GetDisplayBounds(displayIndex, &bounds);
    1.14 +        if (SDL_WINDOWPOS_ISCENTERED(x)) {
    1.15 +            window->x = bounds.x + (bounds.w - window->w) / 2;
    1.16 +        }
    1.17 +        if (SDL_WINDOWPOS_ISCENTERED(y)) {
    1.18 +            window->y = bounds.y + (bounds.h - window->h) / 2;
    1.19 +        }
    1.20 +    }
    1.21      if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
    1.22          if (_this->SetWindowPosition) {
    1.23              _this->SetWindowPosition(_this, window);
     2.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Fri Mar 11 16:03:23 2011 -0800
     2.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Fri Mar 11 16:54:43 2011 -0800
     2.3 @@ -670,26 +670,20 @@
     2.4  {
     2.5      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
     2.6      NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
     2.7 -    SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     2.8      NSRect rect;
     2.9 -    SDL_Rect bounds;
    2.10 +    Uint32 moveHack;
    2.11  
    2.12 -    Cocoa_GetDisplayBounds(_this, display, &bounds);
    2.13 -    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
    2.14 -        rect.origin.x = bounds.x + (bounds.w - window->w) / 2;
    2.15 -    } else {
    2.16 -        rect.origin.x = window->x;
    2.17 -    }
    2.18 -    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
    2.19 -        rect.origin.y = bounds.y + (bounds.h - window->h) / 2;
    2.20 -    } else {
    2.21 -        rect.origin.y = window->y;
    2.22 -    }
    2.23 +    rect.origin.x = window->x;
    2.24 +    rect.origin.y = window->y;
    2.25      rect.size.width = window->w;
    2.26      rect.size.height = window->h;
    2.27      ConvertNSRect(&rect);
    2.28 -    rect = [nswindow frameRectForContentRect:rect];
    2.29 +
    2.30 +    moveHack = s_moveHack;
    2.31 +    s_moveHack = 0;
    2.32      [nswindow setFrameOrigin:rect.origin];
    2.33 +    s_moveHack = moveHack;
    2.34 +
    2.35      [pool release];
    2.36  }
    2.37  
     3.1 --- a/src/video/directfb/SDL_DirectFB_window.c	Fri Mar 11 16:03:23 2011 -0800
     3.2 +++ b/src/video/directfb/SDL_DirectFB_window.c	Fri Mar 11 16:54:43 2011 -0800
     3.3 @@ -260,29 +260,11 @@
     3.4  DirectFB_SetWindowPosition(_THIS, SDL_Window * window)
     3.5  {
     3.6      SDL_DFB_WINDOWDATA(window);
     3.7 -    SDL_DFB_DISPLAYDATA(window);
     3.8      int x, y;
     3.9  
    3.10 -    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
    3.11 -        x = (dispdata->cw - window->w) / 2;
    3.12 -    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->x)) {
    3.13 -        x = 0;
    3.14 -    } else {
    3.15 -        x = window->x;
    3.16 -    }
    3.17 -    
    3.18 -    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
    3.19 -        y = (dispdata->ch - window->h) / 2;
    3.20 -    } else if (SDL_WINDOWPOS_ISUNDEFINED(window->y)) {
    3.21 -        y = 0;
    3.22 -    } else {
    3.23 -        y = window->y;
    3.24 -    }
    3.25 +    x = window->x;
    3.26 +    y = window->y;
    3.27  
    3.28 -    if (window->flags & SDL_WINDOW_FULLSCREEN) {
    3.29 -        x = 0;
    3.30 -        y = 0;
    3.31 -    }
    3.32      DirectFB_WM_AdjustWindowLayout(window, window->flags, window->w, window->h);
    3.33      SDL_DFB_CHECK(windata->dfbwin->MoveTo(windata->dfbwin, x, y));
    3.34  }
     4.1 --- a/src/video/windows/SDL_windowswindow.c	Fri Mar 11 16:03:23 2011 -0800
     4.2 +++ b/src/video/windows/SDL_windowswindow.c	Fri Mar 11 16:54:43 2011 -0800
     4.3 @@ -371,18 +371,8 @@
     4.4      AdjustWindowRectEx(&rect, style, menu, 0);
     4.5      w = (rect.right - rect.left);
     4.6      h = (rect.bottom - rect.top);
     4.7 -
     4.8 -    WIN_GetDisplayBounds(_this, display, &bounds);
     4.9 -    if (SDL_WINDOWPOS_ISCENTERED(window->x)) {
    4.10 -        x = bounds.x + (bounds.w - w) / 2;
    4.11 -    } else {
    4.12 -        x = window->x + rect.left;
    4.13 -    }
    4.14 -    if (SDL_WINDOWPOS_ISCENTERED(window->y)) {
    4.15 -        y = bounds.y + (bounds.h - h) / 2;
    4.16 -    } else {
    4.17 -        y = window->y + rect.top;
    4.18 -    }
    4.19 +    x = window->x + rect.left;
    4.20 +    y = window->y + rect.top;
    4.21  
    4.22      SetWindowPos(hwnd, top, x, y, 0, 0, (SWP_NOCOPYBITS | SWP_NOSIZE));
    4.23  }
     5.1 --- a/src/video/x11/SDL_x11window.c	Fri Mar 11 16:03:23 2011 -0800
     5.2 +++ b/src/video/x11/SDL_x11window.c	Fri Mar 11 16:54:43 2011 -0800
     5.3 @@ -756,27 +756,9 @@
     5.4  {
     5.5      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     5.6      Display *display = data->videodata->display;
     5.7 -    SDL_bool oldstyle_fullscreen;
     5.8      int x, y;
     5.9  
    5.10 -    /* ICCCM2.0-compliant window managers can handle fullscreen windows */
    5.11 -    oldstyle_fullscreen = X11_IsWindowOldFullscreen(_this, window);
    5.12 -
    5.13 -    if (oldstyle_fullscreen
    5.14 -        || SDL_WINDOWPOS_ISCENTERED(window->x)) {
    5.15 -        X11_GetDisplaySize(_this, window, &x, NULL);
    5.16 -        x = (x - window->w) / 2;
    5.17 -    } else {
    5.18 -        x = window->x;
    5.19 -    }
    5.20 -    if (oldstyle_fullscreen
    5.21 -        || SDL_WINDOWPOS_ISCENTERED(window->y)) {
    5.22 -        X11_GetDisplaySize(_this, window, NULL, &y);
    5.23 -        y = (y - window->h) / 2;
    5.24 -    } else {
    5.25 -        y = window->y;
    5.26 -    }
    5.27 -    XMoveWindow(display, data->xwindow, x, y);
    5.28 +    XMoveWindow(display, data->xwindow, window->x, window->y);
    5.29      XFlush(display);
    5.30  }
    5.31