Fixed bug 4748 - Calling WIN_UpdateClipCursor() / WIN_UpdateClipCursorForWindows() on WIN_PumpEvents() causes beeping and choppy mouse cursor movement, right-click doesn't work
authorSam Lantinga <slouken@libsdl.org>
Tue, 11 Feb 2020 10:08:22 -0800
changeset 13506d5109d6a9b98
parent 13505 0c62973859eb
child 13507 25c5f567de44
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
     1.1 --- a/src/video/windows/SDL_windowswindow.c	Tue Feb 11 09:41:55 2020 -0800
     1.2 +++ b/src/video/windows/SDL_windowswindow.c	Tue Feb 11 10:08:22 2020 -0800
     1.3 @@ -938,11 +938,14 @@
     1.4                  data->cursor_clipped_rect = rect;
     1.5              }
     1.6          } else {
     1.7 +            RECT clipped_rect;
     1.8              if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
     1.9                  ClientToScreen(data->hwnd, (LPPOINT) & rect);
    1.10                  ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
    1.11 -                if (ClipCursor(&rect)) {
    1.12 -                    data->cursor_clipped_rect = rect;
    1.13 +                if (!GetClipCursor(&clipped_rect) || SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
    1.14 +                    if (ClipCursor(&rect)) {
    1.15 +                        data->cursor_clipped_rect = rect;
    1.16 +                    }
    1.17                  }
    1.18              }
    1.19          }