Complement SetWindowMonitor SDL implementation 3

This commit is contained in:
ubkp 2023-10-20 00:28:28 -03:00
parent 13a66d8c72
commit c8e04b0af5

View File

@ -586,15 +586,19 @@ void SetWindowMonitor(int monitor)
const int monitorCount = SDL_GetNumVideoDisplays();
if ((monitor >= 0) && (monitor < monitorCount))
{
if (CORE.Window.fullscreen) ToggleFullscreen();
else
{
// NOTE:
// 1. SDL started supporting moving exclusive fullscreen windows between displays on SDL3,
// see commit https://github.com/libsdl-org/SDL/commit/3f5ef7dd422057edbcf3e736107e34be4b75d9ba
// 2. A workround for SDL2 is leaving fullscreen, moving the window, then entering full screen again.
const bool wasFullscreen = ((CORE.Window.flags & FLAG_FULLSCREEN_MODE) > 0) ? true : false;
const int screenWidth = CORE.Window.screen.width;
const int screenHeight = CORE.Window.screen.height;
SDL_Rect usableBounds;
if (SDL_GetDisplayUsableBounds(monitor, &usableBounds) == 0)
{
printf("usableBounds (%i) %i %i %i %i \n", monitor, usableBounds.w, usableBounds.h, usableBounds.x, usableBounds.y);
if (wasFullscreen == 1) ToggleFullscreen(); // Leave fullscreen.
// If the screen size is larger than the monitor usable area, anchor it on the top left corner, otherwise, center it
if ((screenWidth >= usableBounds.w) || (screenHeight >= usableBounds.h))
{
@ -607,8 +611,8 @@ void SetWindowMonitor(int monitor)
// 3. It was't done here because we can't assume changing the window size automatically
// is acceptable behavior by the user.
SDL_SetWindowPosition(platform.window, usableBounds.x, usableBounds.y);
CORE.Window.position.x = x;
CORE.Window.position.y = y;
CORE.Window.position.x = usableBounds.x;
CORE.Window.position.y = usableBounds.y;
}
else
{
@ -618,10 +622,11 @@ void SetWindowMonitor(int monitor)
CORE.Window.position.x = x;
CORE.Window.position.y = y;
}
if (wasFullscreen == 1) ToggleFullscreen(); // Re-enter fullscreen
}
else TRACELOG(LOG_WARNING, "SDL: Failed to get selected display usable bounds");
}
}
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
}