Allow loading window positions on 2nd monitor

This commit is contained in:
jacob1 2019-03-24 23:17:09 -04:00
parent 89c7d9ea02
commit e9011033eb

View File

@ -95,8 +95,21 @@ void LoadWindowPosition()
if (borderTop == 0)
borderTop = 5;
if (savedWindowX + borderLeft > 0 && savedWindowX + borderLeft < desktopWidth
&& savedWindowY + borderTop > 0 && savedWindowY + borderTop < desktopHeight)
int numDisplays = SDL_GetNumVideoDisplays();
SDL_Rect displayBounds;
bool ok = false;
for (int i = 0; i < numDisplays; i++)
{
SDL_GetDisplayBounds(i, &displayBounds);
if (savedWindowX + borderTop > displayBounds.x && savedWindowY + borderLeft > displayBounds.y &&
savedWindowX + borderTop < displayBounds.x + displayBounds.w &&
savedWindowY + borderLeft < displayBounds.y + displayBounds.h)
{
ok = true;
break;
}
}
if (ok)
SDL_SetWindowPosition(sdl_window, savedWindowX + borderLeft, savedWindowY + borderTop);
}