Improved fix for 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>
Wed, 12 Feb 2020 12:26:27 -0800
changeset 13514529fc1a611e8
parent 13513 af27f52d379a
child 13515 9d631a3485a5
Improved fix for bug 4748 - Calling WIN_UpdateClipCursor() / WIN_UpdateClipCursorForWindows() on WIN_PumpEvents() causes beeping and choppy mouse cursor movement, right-click doesn't work
src/video/windows/SDL_windowswindow.c
     1.1 --- a/src/video/windows/SDL_windowswindow.c	Wed Feb 12 13:09:38 2020 -0500
     1.2 +++ b/src/video/windows/SDL_windowswindow.c	Wed Feb 12 12:26:27 2020 -0800
     1.3 @@ -909,7 +909,7 @@
     1.4  {
     1.5      SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
     1.6      SDL_Mouse *mouse = SDL_GetMouse();
     1.7 -    RECT rect;
     1.8 +    RECT rect, clipped_rect;
     1.9  
    1.10      if (data->in_title_click || data->focus_click_pending) {
    1.11          return;
    1.12 @@ -918,38 +918,43 @@
    1.13          data->skip_update_clipcursor = SDL_FALSE;
    1.14          return;
    1.15      }
    1.16 +    if (!GetClipCursor(&clipped_rect)) {
    1.17 +        return;
    1.18 +    }
    1.19  
    1.20      if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
    1.21          (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
    1.22          if (mouse->relative_mode && !mouse->relative_mode_warp) {
    1.23 -            LONG cx, cy;
    1.24 -            GetWindowRect(data->hwnd, &rect);
    1.25 +            if (GetWindowRect(data->hwnd, &rect)) {
    1.26 +                LONG cx, cy;
    1.27  
    1.28 -            cx = (rect.left + rect.right) / 2;
    1.29 -            cy = (rect.top + rect.bottom) / 2;
    1.30 +                cx = (rect.left + rect.right) / 2;
    1.31 +                cy = (rect.top + rect.bottom) / 2;
    1.32  
    1.33 -            /* Make an absurdly small clip rect */
    1.34 -            rect.left = cx - 1;
    1.35 -            rect.right = cx + 1;
    1.36 -            rect.top = cy - 1;
    1.37 -            rect.bottom = cy + 1;
    1.38 +                /* Make an absurdly small clip rect */
    1.39 +                rect.left = cx - 1;
    1.40 +                rect.right = cx + 1;
    1.41 +                rect.top = cy - 1;
    1.42 +                rect.bottom = cy + 1;
    1.43  
    1.44 -            if (ClipCursor(&rect)) {
    1.45 -                data->cursor_clipped_rect = rect;
    1.46 +                if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
    1.47 +                    if (ClipCursor(&rect)) {
    1.48 +                        data->cursor_clipped_rect = rect;
    1.49 +                    }
    1.50 +                }
    1.51              }
    1.52          } else {
    1.53 -            RECT clipped_rect;
    1.54              if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
    1.55                  ClientToScreen(data->hwnd, (LPPOINT) & rect);
    1.56                  ClientToScreen(data->hwnd, (LPPOINT) & rect + 1);
    1.57 -                if (!GetClipCursor(&clipped_rect) || SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
    1.58 +                if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
    1.59                      if (ClipCursor(&rect)) {
    1.60                          data->cursor_clipped_rect = rect;
    1.61                      }
    1.62                  }
    1.63              }
    1.64          }
    1.65 -    } else if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect)) == 0) {
    1.66 +    } else if (SDL_memcmp(&clipped_rect, &data->cursor_clipped_rect, sizeof(clipped_rect)) == 0) {
    1.67          ClipCursor(NULL);
    1.68          SDL_zero(data->cursor_clipped_rect);
    1.69      }