Skip to content

Commit

Permalink
Improved fix for bug 4748 - Calling WIN_UpdateClipCursor() / WIN_Upda…
Browse files Browse the repository at this point in the history
…teClipCursorForWindows() on WIN_PumpEvents() causes beeping and choppy mouse cursor movement, right-click doesn't work
  • Loading branch information
slouken committed Feb 12, 2020
1 parent afb70f2 commit e261bd4
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions src/video/windows/SDL_windowswindow.c
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down

0 comments on commit e261bd4

Please sign in to comment.