sdl2-compat: Only scale mouse coordinates if logical size is set

From 027034c2d553b3143b18c22849a1e11ef99a7833 Mon Sep 17 00:00:00 2001
From: Cameron Gutman <[EMAIL REDACTED]>
Date: Mon, 1 Apr 2024 20:39:16 -0500
Subject: [PATCH] Only scale mouse coordinates if logical size is set

---
 src/sdl2_compat.c | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 15a6765..f5cb2bb 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -1572,9 +1572,13 @@ Event3to2(const SDL_Event *event3, SDL2_Event *event2)
     case SDL_EVENT_MOUSE_MOTION:
         renderer = SDL3_GetRenderer(SDL3_GetWindowFromID(event3->motion.windowID));
         if (renderer) {
-            SDL3_memcpy(&cvtevent3, event3, sizeof (SDL_Event));
-            SDL3_ConvertEventToRenderCoordinates(renderer, &cvtevent3);
-            event3 = &cvtevent3;
+            SDL_RendererLogicalPresentation mode = SDL_LOGICAL_PRESENTATION_DISABLED;
+            SDL3_GetRenderLogicalPresentation(renderer, NULL, NULL, &mode, NULL);
+            if (mode != SDL_LOGICAL_PRESENTATION_DISABLED) {
+                SDL3_memcpy(&cvtevent3, event3, sizeof (SDL_Event));
+                SDL3_ConvertEventToRenderCoordinates(renderer, &cvtevent3);
+                event3 = &cvtevent3;
+            }
         }
         event2->motion.x = (Sint32)event3->motion.x;
         event2->motion.y = (Sint32)event3->motion.y;
@@ -1585,9 +1589,13 @@ Event3to2(const SDL_Event *event3, SDL2_Event *event2)
     case SDL_EVENT_MOUSE_BUTTON_UP:
         renderer = SDL3_GetRenderer(SDL3_GetWindowFromID(event3->button.windowID));
         if (renderer) {
-            SDL3_memcpy(&cvtevent3, event3, sizeof (SDL_Event));
-            SDL3_ConvertEventToRenderCoordinates(renderer, &cvtevent3);
-            event3 = &cvtevent3;
+            SDL_RendererLogicalPresentation mode = SDL_LOGICAL_PRESENTATION_DISABLED;
+            SDL3_GetRenderLogicalPresentation(renderer, NULL, NULL, &mode, NULL);
+            if (mode != SDL_LOGICAL_PRESENTATION_DISABLED) {
+                SDL3_memcpy(&cvtevent3, event3, sizeof (SDL_Event));
+                SDL3_ConvertEventToRenderCoordinates(renderer, &cvtevent3);
+                event3 = &cvtevent3;
+            }
         }
         event2->button.x = (Sint32)event3->button.x;
         event2->button.y = (Sint32)event3->button.y;
@@ -1595,9 +1603,13 @@ Event3to2(const SDL_Event *event3, SDL2_Event *event2)
     case SDL_EVENT_MOUSE_WHEEL:
         renderer = SDL3_GetRenderer(SDL3_GetWindowFromID(event3->wheel.windowID));
         if (renderer) {
-            SDL3_memcpy(&cvtevent3, event3, sizeof (SDL_Event));
-            SDL3_ConvertEventToRenderCoordinates(renderer, &cvtevent3);
-            event3 = &cvtevent3;
+            SDL_RendererLogicalPresentation mode = SDL_LOGICAL_PRESENTATION_DISABLED;
+            SDL3_GetRenderLogicalPresentation(renderer, NULL, NULL, &mode, NULL);
+            if (mode != SDL_LOGICAL_PRESENTATION_DISABLED) {
+                SDL3_memcpy(&cvtevent3, event3, sizeof (SDL_Event));
+                SDL3_ConvertEventToRenderCoordinates(renderer, &cvtevent3);
+                event3 = &cvtevent3;
+            }
         }
         event2->wheel.x = (Sint32)event3->wheel.x;
         event2->wheel.y = (Sint32)event3->wheel.y;