diff -uNr SDL2-2.0.1/include/SDL_video.h SDL2-2.0.1-mine/include/SDL_video.h --- SDL2-2.0.1/include/SDL_video.h 2013-10-24 06:05:29.000000000 +0200 +++ SDL2-2.0.1-mine/include/SDL_video.h 2013-11-03 16:07:50.115000082 +0100 @@ -115,16 +115,23 @@ * \brief Used to indicate that you don't care what the window position is. */ #define SDL_WINDOWPOS_UNDEFINED_MASK 0x1FFF0000 -#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) (SDL_WINDOWPOS_UNDEFINED_MASK|(X)) -#define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_DISPLAY(0) +#define SDL_WINDOWPOS_PROVIDED_DISPLAY 0x00008000 +#define SDL_WINDOWPOS_DISPLAY_MASK 0x00007fff +#define SDL_WINDOWPOS_DISPLAY_DEFAULT SDL_WINDOWPOS_DISPLAY_MASK +#define SDL_WINDOWPOS_UNDEFINED_DISPLAY(X) \ + (SDL_WINDOWPOS_UNDEFINED_MASK|SDL_WINDOWPOS_PROVIDED_DISPLAY|(X)) +#define SDL_WINDOWPOS_UNDEFINED SDL_WINDOWPOS_UNDEFINED_MASK #define SDL_WINDOWPOS_ISUNDEFINED(X) \ (((X)&0xFFFF0000) == SDL_WINDOWPOS_UNDEFINED_MASK) +#define SDL_WINDOWPOS_DISPLAYPROVIDED(X) \ + ((X)&SDL_WINDOWPOS_PROVIDED_DISPLAY) /** * \brief Used to indicate that the window position should be centered. */ #define SDL_WINDOWPOS_CENTERED_MASK 0x2FFF0000 -#define SDL_WINDOWPOS_CENTERED_DISPLAY(X) (SDL_WINDOWPOS_CENTERED_MASK|(X)) +#define SDL_WINDOWPOS_CENTERED_DISPLAY(X) \ + (SDL_WINDOWPOS_CENTERED_MASK|SDL_WINDOWPOS_PROVIDED_DISPLAY|(X)) #define SDL_WINDOWPOS_CENTERED SDL_WINDOWPOS_CENTERED_DISPLAY(0) #define SDL_WINDOWPOS_ISCENTERED(X) \ (((X)&0xFFFF0000) == SDL_WINDOWPOS_CENTERED_MASK) diff -uNr SDL2-2.0.1/src/video/SDL_sysvideo.h SDL2-2.0.1-mine/src/video/SDL_sysvideo.h --- SDL2-2.0.1/src/video/SDL_sysvideo.h 2013-10-24 06:05:29.000000000 +0200 +++ SDL2-2.0.1-mine/src/video/SDL_sysvideo.h 2013-11-03 14:45:01.650000102 +0100 @@ -78,6 +78,7 @@ int w, h; int min_w, min_h; int max_w, max_h; + int display; Uint32 flags; /* Stored position and size for windowed mode */ diff -uNr SDL2-2.0.1/src/video/SDL_video.c SDL2-2.0.1-mine/src/video/SDL_video.c --- SDL2-2.0.1/src/video/SDL_video.c 2013-10-24 06:05:29.000000000 +0200 +++ SDL2-2.0.1-mine/src/video/SDL_video.c 2013-11-03 16:31:08.332997907 +0100 @@ -945,51 +945,36 @@ CHECK_WINDOW_MAGIC(window, -1); - if (SDL_WINDOWPOS_ISUNDEFINED(window->x) || - SDL_WINDOWPOS_ISCENTERED(window->x)) { - displayIndex = (window->x & 0xFFFF); - if (displayIndex >= _this->num_displays) { - displayIndex = 0; - } - return displayIndex; - } - if (SDL_WINDOWPOS_ISUNDEFINED(window->y) || - SDL_WINDOWPOS_ISCENTERED(window->y)) { - displayIndex = (window->y & 0xFFFF); - if (displayIndex >= _this->num_displays) { - displayIndex = 0; - } - return displayIndex; - } + if (window->display == SDL_WINDOWPOS_DISPLAY_DEFAULT) + { + char *displayString = getenv("SDL_DISPLAY"); - /* Find the display containing the window */ - for (i = 0; i < _this->num_displays; ++i) { - SDL_VideoDisplay *display = &_this->displays[i]; + /* this is not secure/good... */ - if (display->fullscreen_window == window) { - return i; - } - } - center.x = window->x + window->w / 2; - center.y = window->y + window->h / 2; - for (i = 0; i < _this->num_displays; ++i) { - SDL_GetDisplayBounds(i, &rect); - if (SDL_EnclosePoints(¢er, 1, &rect, NULL)) { - return i; - } + if (displayString) + { + int display = atoi(displayString); + + if (display < SDL_GetNumVideoDisplays()) + { + return display; + } + else + { + fprintf(stderr, + "bad: SDL_DISPLAY points to nonexistent display\n"); + } + } + else + { + fprintf(stderr, "warning: don't know how to determine default " + "display; you could set SDL_DISPLAY instead.\n"); + } - delta.x = center.x - (rect.x + rect.w / 2); - delta.y = center.y - (rect.y + rect.h / 2); - dist = (delta.x*delta.x + delta.y*delta.y); - if (dist < closest_dist) { - closest = i; - closest_dist = dist; - } - } - if (closest < 0) { - SDL_SetError("Couldn't find any displays"); + return 0; } - return closest; + + return window->display; } SDL_VideoDisplay * @@ -1189,6 +1174,7 @@ SDL_Window * SDL_CreateWindow(const char *title, int x, int y, int w, int h, Uint32 flags) { + fprintf(stderr, "warning: you're running SDL2-2.0.1-mine\n"); SDL_Window *window; const char *hint; @@ -1231,6 +1217,16 @@ window->y = y; window->w = w; window->h = h; + window->display = SDL_WINDOWPOS_DISPLAY_DEFAULT; + + if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISUNDEFINED(y)) { + if (SDL_WINDOWPOS_DISPLAYPROVIDED(x)) { + window->display = x & SDL_WINDOWPOS_DISPLAY_MASK; + } + + /* SDL_WINDOWPOS_DISPLAYPROVIDED(x) is currently ignored... */ + } + if (SDL_WINDOWPOS_ISUNDEFINED(x) || SDL_WINDOWPOS_ISUNDEFINED(y) || SDL_WINDOWPOS_ISCENTERED(x) || SDL_WINDOWPOS_ISCENTERED(y)) { SDL_VideoDisplay *display = SDL_GetDisplayForWindow(window);