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

This commit is contained in:
Sam Lantinga 2020-02-12 12:26:27 -08:00
parent afb70f2681
commit e261bd4205
1 changed files with 20 additions and 15 deletions

View File

@ -909,7 +909,7 @@ WIN_UpdateClipCursor(SDL_Window *window)
{ {
SDL_WindowData *data = (SDL_WindowData *) window->driverdata; SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
SDL_Mouse *mouse = SDL_GetMouse(); SDL_Mouse *mouse = SDL_GetMouse();
RECT rect; RECT rect, clipped_rect;
if (data->in_title_click || data->focus_click_pending) { if (data->in_title_click || data->focus_click_pending) {
return; return;
@ -918,12 +918,15 @@ WIN_UpdateClipCursor(SDL_Window *window)
data->skip_update_clipcursor = SDL_FALSE; data->skip_update_clipcursor = SDL_FALSE;
return; return;
} }
if (!GetClipCursor(&clipped_rect)) {
return;
}
if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) && if ((mouse->relative_mode || (window->flags & SDL_WINDOW_INPUT_GRABBED)) &&
(window->flags & SDL_WINDOW_INPUT_FOCUS)) { (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
if (mouse->relative_mode && !mouse->relative_mode_warp) { if (mouse->relative_mode && !mouse->relative_mode_warp) {
if (GetWindowRect(data->hwnd, &rect)) {
LONG cx, cy; LONG cx, cy;
GetWindowRect(data->hwnd, &rect);
cx = (rect.left + rect.right) / 2; cx = (rect.left + rect.right) / 2;
cy = (rect.top + rect.bottom) / 2; cy = (rect.top + rect.bottom) / 2;
@ -934,22 +937,24 @@ WIN_UpdateClipCursor(SDL_Window *window)
rect.top = cy - 1; rect.top = cy - 1;
rect.bottom = cy + 1; rect.bottom = cy + 1;
if (SDL_memcmp(&rect, &clipped_rect, sizeof(rect)) != 0) {
if (ClipCursor(&rect)) { if (ClipCursor(&rect)) {
data->cursor_clipped_rect = rect; data->cursor_clipped_rect = rect;
} }
}
}
} else { } else {
RECT clipped_rect;
if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) { if (GetClientRect(data->hwnd, &rect) && !IsRectEmpty(&rect)) {
ClientToScreen(data->hwnd, (LPPOINT) & rect); ClientToScreen(data->hwnd, (LPPOINT) & rect);
ClientToScreen(data->hwnd, (LPPOINT) & rect + 1); 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)) { if (ClipCursor(&rect)) {
data->cursor_clipped_rect = 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); ClipCursor(NULL);
SDL_zero(data->cursor_clipped_rect); SDL_zero(data->cursor_clipped_rect);
} }