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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c
index c2fd85c..237d380 100644
--- a/src/video/windows/SDL_windowswindow.c
+++ b/src/video/windows/SDL_windowswindow.c
@@ -909,7 +909,7 @@ WIN_UpdateClipCursor(SDL_Window *window)
{
SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_Mouse *mouse = SDL_GetMouse();
- RECT rect;
+ RECT rect, clipped_rect;
if (data->in_title_click || data->focus_click_pending) {
return;
@@ -918,38 +918,43 @@ WIN_UpdateClipCursor(SDL_Window *window)
data->skip_update_clipcursor = SDL_FALSE;
return;
}
+ if (!GetClipCursor(&clipped_rect)) {
+ return;
+ }
if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
if (mouse->relative_mode && !mouse->relative_mode_warp) {
- LONG cx, cy;
- GetWindowRect(data->hwnd, &rect);
+ if (GetWindowRect(data->hwnd, &rect)) {
+ LONG cx, cy;
- cx = (rect.left + rect.right) / 2;
- cy = (rect.top + rect.bottom) / 2;
+ cx = (rect.left + rect.right) / 2;
+ cy = (rect.top + rect.bottom) / 2;
- /* Make an absurdly small clip rect */
- rect.left = cx - 1;
- rect.right = cx + 1;
- rect.top = cy - 1;
- rect.bottom = cy + 1;
+ /* Make an absurdly small clip rect */
+ rect.left = cx - 1;
+ rect.right = cx + 1;
+ rect.top = cy - 1;
+ rect.bottom = cy + 1;
- if (ClipCursor(&rect)) {
- data->cursor_clipped_rect = rect;
+ if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
+ if (ClipCursor(&rect)) {
+ 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 (!GetClipCursor(&clipped_rect) || SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
+ if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
if (ClipCursor(&rect)) {
data->cursor_clipped_rect = rect;
}
}
}
}
- } else if (GetClipCursor(&rect) && SDL_memcmp(&rect, &data->cursor_clipped_rect, sizeof(rect)) == 0) {
+ } else if (SDL_memcmp(&clipped_rect, &data->cursor_clipped_rect, sizeof(clipped_rect)) == 0) {
ClipCursor(NULL);
SDL_zero(data->cursor_clipped_rect);
}