SDL_SetWindowPosition respects display num for SDL_WINDOWPOS_CENTERED_DISPLAY.
authorEdward Rudd <urkle@outoforder.cc>
Thu, 19 Feb 2015 19:40:58 -0500
changeset 9363c9a4d606f6db
parent 9362 dfd8202eb9a7
child 9364 ad9d35983de5
SDL_SetWindowPosition respects display num for SDL_WINDOWPOS_CENTERED_DISPLAY.

This allows for this kind of code in an application:

int monitorID = 1; // the second monitor!
SDL_SetWindowPosition(sdlWin,
SDL_WINDOWPOS_CENTERED_DISPLAY(monitorID),
SDL_WINDOWPOS_CENTERED_DISPLAY(monitorID));

Fixes Bugzilla #2849.
src/video/SDL_video.c
     1.1 --- a/src/video/SDL_video.c	Sat Jan 10 13:47:37 2015 +0100
     1.2 +++ b/src/video/SDL_video.c	Thu Feb 19 19:40:58 2015 -0500
     1.3 @@ -1607,13 +1607,14 @@
     1.4      CHECK_WINDOW_MAGIC(window,);
     1.5  
     1.6      if (SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) {
     1.7 -        SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);
     1.8 -        int displayIndex;
     1.9 +        int displayIndex = (x & 0xFFFF);
    1.10          SDL_Rect bounds;
    1.11 +        if (displayIndex > _this->num_displays) {
    1.12 +            displayIndex = 0;
    1.13 +        }
    1.14  
    1.15          SDL_zero(bounds);
    1.16  
    1.17 -        displayIndex = SDL_GetIndexOfDisplay(display);
    1.18          SDL_GetDisplayBounds(displayIndex, &bounds);
    1.19          if (SDL_WINDOWPOS_ISCENTERED(x)) {
    1.20              x = bounds.x + (bounds.w - window->w) / 2;