Fixed leaving the cursor clip set when changing window focus

While the focus change happens, Windows appears to reset the cursor clip rectangle, and then restore it if the application that has focus has the clip rectangle set.

This fixes resetting the clip rectangle while changing focus between windows in the same application, e.g. the Source 2 editor.
main
Sam Lantinga 2024-03-11 10:58:40 -07:00
parent b322d27f62
commit ab5351f5d6
1 changed files with 19 additions and 10 deletions

View File

@ -1568,18 +1568,27 @@ void WIN_UpdateClipCursor(SDL_Window *window)
}
}
} else {
POINT first, second;
SDL_bool unclip_cursor = SDL_FALSE;
first.x = clipped_rect.left;
first.y = clipped_rect.top;
second.x = clipped_rect.right - 1;
second.y = clipped_rect.bottom - 1;
if (PtInRect(&data->cursor_clipped_rect, first) &&
PtInRect(&data->cursor_clipped_rect, second)) {
ClipCursor(NULL);
/* If the cursor is clipped to the screen, clear the clip state */
if (clipped_rect.left == 0 && clipped_rect.top == 0) {
unclip_cursor = SDL_TRUE;
} else {
POINT first, second;
first.x = clipped_rect.left;
first.y = clipped_rect.top;
second.x = clipped_rect.right - 1;
second.y = clipped_rect.bottom - 1;
if (PtInRect(&data->cursor_clipped_rect, first) &&
PtInRect(&data->cursor_clipped_rect, second)) {
unclip_cursor = SDL_TRUE;
}
}
if (unclip_cursor) {
ClipCursor(NULL);
SDL_zero(data->cursor_clipped_rect);
}
/* Note that we don't have the cursor clipped anymore, even if it's not us that reset it */
SDL_zero(data->cursor_clipped_rect);
}
data->last_updated_clipcursor = SDL_GetTicks();
}