sdl12-compat: Prevent continuous round trips to the X server when warping

From 2d3c96bf024153ed18cb1e41ce8e452fbcc4dc9e Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 25 Oct 2025 18:52:41 -0700
Subject: [PATCH] Prevent continuous round trips to the X server when warping

Fixes https://github.com/libsdl-org/sdl12-compat/issues/340
---
 src/SDL12_compat.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index e9c08602c..c7051ca8c 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -7702,6 +7702,17 @@ SDL_WarpMouse(Uint16 x, Uint16 y)
     if (MouseInputIsRelative) {  /* we have to track this ourselves, in case app calls SDL_GetMouseState(). */
         MousePosition.x = (int) x;
         MousePosition.y = (int) y;
+    } else if (x == MousePosition.x && y == MousePosition.y) {
+        /* There's no movement needed, just generate an internal event */
+        SDL12_Event event;
+        event.type = SDL12_MOUSEMOTION;
+        event.motion.which = 0;
+        event.motion.state = SDL_GetMouseState(NULL, NULL);
+        event.motion.x = x;
+        event.motion.y = y;
+        event.motion.xrel = 0;
+        event.motion.yrel = 0;
+        PushEventIfNotFiltered(&event);
     } else {
         if (VideoWindow20) {
             SDL_Rect viewport;