From e9011033eb9677651433b288743e241d78b1c546 Mon Sep 17 00:00:00 2001 From: jacob1 Date: Sun, 24 Mar 2019 23:17:09 -0400 Subject: [PATCH] Allow loading window positions on 2nd monitor --- src/PowderToySDL.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/PowderToySDL.cpp b/src/PowderToySDL.cpp index 5f7234d86..cbce6b010 100644 --- a/src/PowderToySDL.cpp +++ b/src/PowderToySDL.cpp @@ -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); }