From c31727c7e7c538ee5ee8452df7115e3e689dd0bf Mon Sep 17 00:00:00 2001
From: Sam Lantinga <slouken@libsdl.org>
Date: Tue, 11 Feb 2020 10:08:22 -0800
Subject: [PATCH] Fixed bug 4748 - Calling WIN_UpdateClipCursor() /
 WIN_UpdateClipCursorForWindows() on WIN_PumpEvents() causes beeping and
 choppy mouse cursor movement, right-click doesn't work

The problem here was calling ClipCursor() continuously in a tight loop. Fixed by only calling ClipCursor() if the clip area needs to be updated.
---
 src/video/windows/SDL_windowswindow.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index a9c404024..c2fd85c92 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -938,11 +938,14 @@ WIN_UpdateClipCursor(SDL_Window *window)
                 data->cursor_clipped_rect = rect;
             }
         } else {
+            RECT clipped_rect;
             if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
                 ClientToScreen(data->hwnd, (LPPOINT) & rect);
                 ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
-                if (ClipCursor(&rect)) {
-                    data->cursor_clipped_rect = rect;
+                if (!GetClipCursor(&clipped_rect) || SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
+                    if (ClipCursor(&rect)) {
+                        data->cursor_clipped_rect = rect;
+                    }
                 }
             }
         }