From e5b0d796e2f5bd20dc7bd73787302df35cf84855 Mon Sep 17 00:00:00 2001 From: ubkp <118854183+ubkp@users.noreply.github.com> Date: Fri, 20 Oct 2023 01:04:19 -0300 Subject: [PATCH] Complement GetMonitorPosition SDL implementation --- src/platforms/rcore_desktop_sdl.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/platforms/rcore_desktop_sdl.c b/src/platforms/rcore_desktop_sdl.c index 978ef7924..ea669bc6b 100644 --- a/src/platforms/rcore_desktop_sdl.c +++ b/src/platforms/rcore_desktop_sdl.c @@ -693,20 +693,18 @@ int GetCurrentMonitor(void) // Get selected monitor position Vector2 GetMonitorPosition(int monitor) { - if (monitor < 0 || monitor >= SDL_GetNumVideoDisplays()) + const int monitorCount = SDL_GetNumVideoDisplays(); + if ((monitor >= 0) && (monitor < monitorCount)) { - TRACELOG(LOG_ERROR, "Invalid monitor index"); - return (Vector2) { 0, 0 }; + SDL_Rect displayBounds; + if (SDL_GetDisplayUsableBounds(monitor, &displayBounds) == 0) + { + return (Vector2){ (float)displayBounds.x, (float)displayBounds.y }; + } + else TRACELOG(LOG_WARNING, "SDL: Failed to get selected display usable bounds"); } - - SDL_Rect displayBounds; - if (SDL_GetDisplayBounds(monitor, &displayBounds) != 0) - { - TRACELOG(LOG_ERROR, "Failed to get display bounds"); - return (Vector2) { 0, 0 }; - } - - return (Vector2) { displayBounds.x, displayBounds.y }; + else TRACELOG(LOG_WARNING, "SDL: Failed to find selected monitor"); + return (Vector2){ 0.0f, 0.0f }; } // Get selected monitor width (currently used by monitor)