Complement SetWindowMonitor SDL implementation 3
This commit is contained in:
parent
13a66d8c72
commit
c8e04b0af5
|
|
@ -586,41 +586,46 @@ void SetWindowMonitor(int monitor)
|
||||||
const int monitorCount = SDL_GetNumVideoDisplays();
|
const int monitorCount = SDL_GetNumVideoDisplays();
|
||||||
if ((monitor >= 0) && (monitor < monitorCount))
|
if ((monitor >= 0) && (monitor < monitorCount))
|
||||||
{
|
{
|
||||||
if (CORE.Window.fullscreen) ToggleFullscreen();
|
// NOTE:
|
||||||
else
|
// 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)
|
||||||
{
|
{
|
||||||
const int screenWidth = CORE.Window.screen.width;
|
if (wasFullscreen == 1) ToggleFullscreen(); // Leave fullscreen.
|
||||||
const int screenHeight = CORE.Window.screen.height;
|
|
||||||
SDL_Rect usableBounds;
|
// If the screen size is larger than the monitor usable area, anchor it on the top left corner, otherwise, center it
|
||||||
if (SDL_GetDisplayUsableBounds(monitor, &usableBounds) == 0)
|
if ((screenWidth >= usableBounds.w) || (screenHeight >= usableBounds.h))
|
||||||
{
|
{
|
||||||
printf("usableBounds (%i) %i %i %i %i \n", monitor, usableBounds.w, usableBounds.h, usableBounds.x, usableBounds.y);
|
// NOTE:
|
||||||
// If the screen size is larger than the monitor usable area, anchor it on the top left corner, otherwise, center it
|
// 1. There's a known issue where if the window larger than the target display bounds,
|
||||||
if ((screenWidth >= usableBounds.w) || (screenHeight >= usableBounds.h))
|
// when moving the windows to that display, the window could be clipped back
|
||||||
{
|
// ending up positioned partly outside the target display.
|
||||||
// NOTE:
|
// 2. The workaround for that is, previously to moving the window,
|
||||||
// 1. There's a known issue where if the window larger than the target display bounds,
|
// setting the window size to the target display size, so they match.
|
||||||
// when moving the windows to that display, the window could be clipped back
|
// 3. It was't done here because we can't assume changing the window size automatically
|
||||||
// ending up positioned partly outside the target display.
|
// is acceptable behavior by the user.
|
||||||
// 2. The workaround for that is, previously to moving the window,
|
SDL_SetWindowPosition(platform.window, usableBounds.x, usableBounds.y);
|
||||||
// setting the window size to the target display size, so they match.
|
CORE.Window.position.x = usableBounds.x;
|
||||||
// 3. It was't done here because we can't assume changing the window size automatically
|
CORE.Window.position.y = usableBounds.y;
|
||||||
// is acceptable behavior by the user.
|
|
||||||
SDL_SetWindowPosition(platform.window, usableBounds.x, usableBounds.y);
|
|
||||||
CORE.Window.position.x = x;
|
|
||||||
CORE.Window.position.y = y;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
const int x = usableBounds.x + (usableBounds.w/2) - (screenWidth/2);
|
|
||||||
const int y = usableBounds.y + (usableBounds.h/2) - (screenHeight/2);
|
|
||||||
SDL_SetWindowPosition(platform.window, x, y);
|
|
||||||
CORE.Window.position.x = x;
|
|
||||||
CORE.Window.position.y = y;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else TRACELOG(LOG_WARNING, "SDL: Failed to get selected display usable bounds");
|
else
|
||||||
|
{
|
||||||
|
const int x = usableBounds.x + (usableBounds.w/2) - (screenWidth/2);
|
||||||
|
const int y = usableBounds.y + (usableBounds.h/2) - (screenHeight/2);
|
||||||
|
SDL_SetWindowPosition(platform.window, x, y);
|
||||||
|
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");
|
else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user