Skip to content

Commit

Permalink
Fixed Windows relative mouse coordinates when capturing the mouse ove…
Browse files Browse the repository at this point in the history
…r RDP
  • Loading branch information
slouken committed Aug 27, 2019
1 parent 0c26373 commit 13c4d5e
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/video/windows/SDL_windowsevents.c
Expand Up @@ -586,16 +586,22 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
SDL_SendMouseMotion(data->window, 0, 1, (int)rawmouse->lLastX, (int)rawmouse->lLastY);
} else {
/* synthesize relative moves from the abs position */
static SDL_Point initialMousePoint;
if (initialMousePoint.x == 0 && initialMousePoint.y == 0) {
initialMousePoint.x = rawmouse->lLastX;
initialMousePoint.y = rawmouse->lLastY;
static SDL_Point lastMousePoint;
SDL_bool virtual_desktop = (rawmouse->usFlags & MOUSE_VIRTUAL_DESKTOP) ? SDL_TRUE : SDL_FALSE;
int w = GetSystemMetrics(virtual_desktop ? SM_CXVIRTUALSCREEN : SM_CXSCREEN);
int h = GetSystemMetrics(virtual_desktop ? SM_CYVIRTUALSCREEN : SM_CYSCREEN);
int x = (int)(((float)rawmouse->lLastX / 65535.0f) * w);
int y = (int)(((float)rawmouse->lLastY / 65535.0f) * h);

if (lastMousePoint.x == 0 && lastMousePoint.y == 0) {
lastMousePoint.x = x;
lastMousePoint.y = y;
}

SDL_SendMouseMotion(data->window, 0, 1, (int)(rawmouse->lLastX-initialMousePoint.x), (int)(rawmouse->lLastY-initialMousePoint.y));
SDL_SendMouseMotion(data->window, 0, 1, (int)(x-lastMousePoint.x), (int)(y-lastMousePoint.y));

initialMousePoint.x = rawmouse->lLastX;
initialMousePoint.y = rawmouse->lLastY;
lastMousePoint.x = x;
lastMousePoint.y = y;
}
WIN_CheckRawMouseButtons(rawmouse->usButtonFlags, data);
} else if (isCapture) {
Expand Down

0 comments on commit 13c4d5e

Please sign in to comment.