From 4359a47b3e383de0fe20a98a3cc523ca0e0d8a76 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 2 Apr 2021 12:48:16 +0900 Subject: [PATCH] Simplify ClipCursor behaviour when RelativeMouseMode is enabled The implementation of clip logic for relative mode seemed to unnecessarily limit the usable area to the middle of the window, in a 2x2 pixel region. This has the adverse side effect of moving the operating system cursor to that location, even if it is in a valid location in the window. While in most scenarios this is handled correctly (by storing the original position of the cursor in the window and restoring when leaving relative mode), there are edge cases where this clip operation can cause WM_MOUSEMOVE to fire at a point in time where it counts as a relative delta from SDL's perspective. --- src/video/windows/SDL_windowswindow.c | 33 +++++---------------------- 1 file changed, 6 insertions(+), 27 deletions(-) diff --git a/src/video/windows/SDL_windowswindow.c b/src/video/windows/SDL_windowswindow.c index 4d6b685a8..65dc0fceb 100644 --- a/src/video/windows/SDL_windowswindow.c +++ b/src/video/windows/SDL_windowswindow.c @@ -992,33 +992,12 @@ WIN_UpdateClipCursor(SDL_Window *window) if ((mouse->relative_mode || (window->flags & SDL_WINDOW_MOUSE_GRABBED)) && (window->flags & SDL_WINDOW_INPUT_FOCUS)) { - if (mouse->relative_mode && !mouse->relative_mode_warp) { - if (GetWindowRect(data->hwnd, &rect)) { - LONG cx, cy; - - 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; - - if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) { - if (ClipCursor(&rect)) { - data->cursor_clipped_rect = rect; - } - } - } - } else { - if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) { - ClientToScreen(data->hwnd, (LPPOINT) & rect); - ClientToScreen(data->hwnd, (LPPOINT) & rect + 1); - if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) { - if (ClipCursor(&rect)) { - data->cursor_clipped_rect = rect; - } + if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) { + ClientToScreen(data->hwnd, (LPPOINT) & rect); + ClientToScreen(data->hwnd, (LPPOINT) & rect + 1); + if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) { + if (ClipCursor(&rect)) { + data->cursor_clipped_rect = rect; } } }