From beacd9d2cd7d345f0f0f6dc2f58a18bdac28e0d6 Mon Sep 17 00:00:00 2001 From: milkdropper <59471060+milkdropper@users.noreply.github.com> Date: Sat, 2 May 2020 13:50:21 +0400 Subject: [PATCH] SDL Monitor Fixes (#343) * Rewrite of stretchMonitors to support abnormal layouts (not perfect vertical or horizontal layouts) * Fix monitor swap. * More fixes to stretching after testing on another computer. * Typo fix --- src/projectM-sdl/pmSDL.cpp | 65 +++++++++++--------------------------- 1 file changed, 19 insertions(+), 46 deletions(-) diff --git a/src/projectM-sdl/pmSDL.cpp b/src/projectM-sdl/pmSDL.cpp index 944c18e9e..11a9daa01 100644 --- a/src/projectM-sdl/pmSDL.cpp +++ b/src/projectM-sdl/pmSDL.cpp @@ -187,55 +187,29 @@ void projectMSDL::stretchMonitors() SDL_GetDisplayBounds(i, &displayBounds.back()); } - int furthestX = 0; - int furthestY = 0; - int widest = 0; - int highest = 0; - int spanX = 0; - int spanY = 0; - int spanWidth = 0; - int spanHeight = 0; - - bool horizontal = true; - bool vertical = true; + int mostXLeft = 0; + int mostXRight = 0; + int mostWide = 0; + int mostYUp = 0; + int mostYDown = 0; + int mostHigh = 0; for (int i = 0; i < displayCount; i++) { - if (displayBounds[0].x != displayBounds[i].x) vertical = false; - if (displayBounds[0].y != displayBounds[i].y) horizontal = false; + if (displayBounds[i].x < mostXLeft) mostXLeft = displayBounds[i].x; + if ((displayBounds[i].x + displayBounds[i].w) > mostXRight) mostXRight = displayBounds[i].x + displayBounds[i].w; + } + for (int i = 0; i < displayCount; i++) + { + if (displayBounds[i].y < mostYUp) mostYUp = displayBounds[i].y; + if ((displayBounds[i].y + displayBounds[i].h) > mostYDown) mostYDown = displayBounds[i].y + displayBounds[i].h; } - if (!vertical && !horizontal) - { - // If multiple montors are not perfectly aligned it's a bit of work to get the correct x,y and - // dimensions But in my testing on Windows 10 even with the screen did not render correctly. - // @todo more testing and make it work. - SDL_Log( - "SDL currently only supports multiple monitors that are aligned evenly in a vertical or " - "horizontal position."); - } - else - { - for (int i = 0; i < displayCount; i++) - { - if (displayBounds[i].x < furthestX) spanX = displayBounds[i].x; // X furthest left device - if (displayBounds[i].y < furthestY) spanY = displayBounds[i].y; // Y highest device - if (displayBounds[i].h > highest) highest = displayBounds[i].h; // highest resolution Height - if (displayBounds[i].h > widest) widest = displayBounds[i].w; // highest resolution Width - if (horizontal) // perfectly aligned horizonal monitors. - { - spanHeight = highest; - spanWidth = spanWidth + displayBounds[i].w; - } - else if (vertical) // perfectly aligned vertical monitors. - { - spanHeight = spanHeight + displayBounds[i].h; - spanWidth = widest; - } - } - SDL_SetWindowPosition(win, spanX, spanY); - SDL_SetWindowSize(win, spanWidth, spanHeight); - } + mostWide = abs(mostXLeft) + abs(mostXRight); + mostHigh = abs(mostYUp) + abs(mostYDown); + + SDL_SetWindowPosition(win, mostXLeft, mostYUp); + SDL_SetWindowSize(win, mostWide, mostHigh); } } @@ -248,7 +222,7 @@ void projectMSDL::nextMonitor() { std::vector displayBounds; int nextWindow = currentWindowIndex + 1; - if (nextWindow > displayCount) nextWindow = 0; + if (nextWindow >= displayCount) nextWindow = 0; for (int i = 0; i < displayCount; i++) { @@ -257,7 +231,6 @@ void projectMSDL::nextMonitor() } SDL_SetWindowPosition(win, displayBounds[nextWindow].x, displayBounds[nextWindow].y); SDL_SetWindowSize(win, displayBounds[nextWindow].w, displayBounds[nextWindow].h); - maximize(); } }