Don't warp the mouse for relative mode when the window doesn't have focus

This commit is contained in:
Sam Lantinga 2021-08-13 11:39:41 -07:00
parent 629e9f820a
commit b28ed02803
2 changed files with 5 additions and 2 deletions

View File

@ -358,8 +358,10 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
mouse->last_y = center_y; mouse->last_y = center_y;
return 0; return 0;
} }
if (window && (window->flags & SDL_WINDOW_INPUT_FOCUS) != 0) {
SDL_WarpMouseInWindow(window, center_x, center_y); SDL_WarpMouseInWindow(window, center_x, center_y);
} }
}
if (relative) { if (relative) {
if (mouse->relative_mode) { if (mouse->relative_mode) {

View File

@ -663,7 +663,8 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
if (GetMouseMessageSource() != SDL_MOUSE_EVENT_SOURCE_TOUCH && if (GetMouseMessageSource() != SDL_MOUSE_EVENT_SOURCE_TOUCH &&
lParam != data->last_pointer_update) { lParam != data->last_pointer_update) {
SDL_SendMouseMotion(data->window, 0, 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)); SDL_SendMouseMotion(data->window, 0, 0, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
if (isWin10FCUorNewer && mouse->relative_mode_warp) { if (isWin10FCUorNewer && mouse->relative_mode_warp &&
(data->window->flags & SDL_WINDOW_INPUT_FOCUS)) {
/* To work around #3931, Win10 bug introduced in Fall Creators Update, where /* To work around #3931, Win10 bug introduced in Fall Creators Update, where
SetCursorPos() (SDL_WarpMouseInWindow()) doesn't reliably generate mouse events anymore, SetCursorPos() (SDL_WarpMouseInWindow()) doesn't reliably generate mouse events anymore,
after each windows mouse event generate a fake event for the middle of the window after each windows mouse event generate a fake event for the middle of the window